gui/treeview: Add a function for accessing the treeview

And rename the widget from "o_treeview" to just "treeview".

I wanted to rename gui/view.c to gui/treeview.c at some point.  I
decided to gradually rework things into a new file to make it easier to
track progress.

Signed-off-by: Anna Schumaker <Anna@NoWheyCreamery.com>
This commit is contained in:
Anna Schumaker 2016-08-23 07:41:27 -04:00
parent 3fc19275f3
commit c49b77a24a
7 changed files with 59 additions and 4 deletions

View File

@ -7,6 +7,7 @@
#include <gui/builder.h>
#include <gui/filter.h>
#include <gui/queue.h>
#include <gui/treeview.h>
#include <gui/view.h>
#include <gui/window.h>
#include <glib/gi18n.h>
@ -293,7 +294,7 @@ void __view_rc_add_new(GtkMenuItem *item, gpointer data)
static void __view_rc_add_other(GtkWidget *item, gpointer data)
{
GtkTreeView *treeview = GTK_TREE_VIEW(gui_builder_widget("o_treeview"));
GtkTreeView *treeview = gui_treeview();
GtkTreeSelection *selection = gtk_tree_view_get_selection(treeview);
struct playlist *playlist = (struct playlist *)data;
struct view_add_data vad_data = {
@ -381,7 +382,7 @@ void gui_view_init()
GtkTreeViewColumn *col;
int i, pos;
view_treeview = GTK_TREE_VIEW(gui_builder_widget("o_treeview"));
view_treeview = gui_treeview();
for (i = 0; i < GUI_MODEL_N_COLUMNS; i++) {
col = gtk_tree_view_get_column(view_treeview, i);

13
include/gui/treeview.h Normal file
View File

@ -0,0 +1,13 @@
/*
* Copyright 2016 (c) Anna Schumaker.
*/
#ifndef OCARINA_GUI_TREEVIEW_H
#define OCARINA_GUI_TREEVIEW_H
/* Called to access the treeview widget. */
static inline GtkTreeView *gui_treeview()
{
return GTK_TREE_VIEW(gui_builder_widget("treeview"));
}
#endif /* OCARINA_GUI_TREEVIEW_H */

View File

@ -876,7 +876,7 @@ audio-volume-medium</property>
<property name="vexpand">True</property>
<property name="shadow_type">in</property>
<child>
<object class="GtkTreeView" id="o_treeview">
<object class="GtkTreeView" id="treeview">
<property name="visible">True</property>
<property name="can_focus">True</property>
<property name="enable_search">False</property>

View File

@ -3,6 +3,7 @@ window
idle
model
filter
treeview
view
queue
sidebar

View File

@ -9,6 +9,7 @@ gui_unit_test(Window)
gui_unit_test(Idle)
gui_unit_test(Model)
gui_unit_test(Filter)
gui_unit_test(Treeview)
gui_unit_test(View)
gui_unit_test(Queue)
gui_unit_test(Sidebar)

38
tests/gui/treeview.c Normal file
View File

@ -0,0 +1,38 @@
/*
* Copyright 2016 (c) Anna Schumaker.
*/
#include <core/core.h>
#include <core/idle.h>
#include <gui/filter.h>
#include <gui/model.h>
#include <gui/treeview.h>
#include <tests/test.h>
struct core_init_data init_data = {};
void test_treeview()
{
g_assert_nonnull(gui_treeview());
g_assert_true(GTK_IS_TREE_VIEW(gui_treeview()));
}
int main(int argc, char **argv)
{
int ret;
gtk_init(&argc, NULL);
core_init(&argc, NULL, &init_data);
gui_builder_init("share/ocarina/ocarina.ui");
gui_model_init();
gui_filter_init();
while (idle_run_task()) {}
g_test_init(&argc, &argv, NULL);
g_test_add_func("/Gui/Treeview", test_treeview);
ret = g_test_run();
core_deinit();
gui_filter_deinit();
gui_model_deinit();
return ret;
}

View File

@ -9,6 +9,7 @@
#include <gui/builder.h>
#include <gui/filter.h>
#include <gui/model.h>
#include <gui/treeview.h>
#include <gui/view.h>
#include <tests/test.h>
#include <tests/gui.h>
@ -57,7 +58,7 @@ static void test_treeview()
gui_filter_set_playlist(playlist_get(PL_SYSTEM, "Collection"));
filter = GTK_TREE_MODEL(gui_filter_get());
treeview = GTK_TREE_VIEW(gui_builder_widget("o_treeview"));
treeview = gui_treeview();
for (i = 0; i < GUI_MODEL_N_COLUMNS; i++)
g_assert_false(settings_has(QUEUE_SETTINGS[i]));