gui/collection: Convert checkbox into a right click menu

This feature isn't used very often, and keeping the checkbox in the
sidebar looks pretty ugly.

Fixes #50: Remove Collection checkbox
Signed-off-by: Anna Schumaker <Anna@OcarinaProject.net>
This commit is contained in:
Anna Schumaker 2016-05-05 08:25:09 -04:00
parent d2c4a36945
commit 25211e93ac
4 changed files with 58 additions and 30 deletions

View File

@ -1,4 +1,5 @@
6.4.11: 6.4.11:
- Move collection enabled checkboxes into a right click menu
- Various UI tweaks - Various UI tweaks
6.4.11-rc: 6.4.11-rc:

View File

@ -10,8 +10,6 @@
enum collection_sidebar_columns { enum collection_sidebar_columns {
C_SB_IMAGE, C_SB_IMAGE,
C_SB_ENABLED,
C_SB_SHOW_ENABLED,
C_SB_PATH, C_SB_PATH,
C_SB_LIBRARY, C_SB_LIBRARY,
}; };
@ -28,8 +26,6 @@ static void __collection_set_header(GtkTreeIter *iter, const gchar *image,
static void __collection_set_library(GtkTreeIter *iter, struct library *library) static void __collection_set_library(GtkTreeIter *iter, struct library *library)
{ {
gtk_tree_store_set(GTK_TREE_STORE(c_model), iter, gtk_tree_store_set(GTK_TREE_STORE(c_model), iter,
C_SB_ENABLED, library->li_enabled,
C_SB_SHOW_ENABLED, true,
C_SB_IMAGE, "folder", C_SB_IMAGE, "folder",
C_SB_PATH, library->li_path, C_SB_PATH, library->li_path,
C_SB_LIBRARY, library, -1); C_SB_LIBRARY, library, -1);
@ -58,18 +54,25 @@ void __collection_activated(GtkTreeView *treeview, GtkTreePath *path,
gui_collection_idle_enable(); gui_collection_idle_enable();
} }
void __collection_toggled(GtkCellRendererToggle *toggle, gchar *path, void __collection_toggled(GtkCheckMenuItem *check, gpointer data)
gpointer data)
{ {
GtkTreeView *treeview = GTK_TREE_VIEW(gui_builder_widget("o_collection_view"));
GtkTreeSelection *selection = gtk_tree_view_get_selection(treeview);
struct library *library = NULL; struct library *library = NULL;
GtkTreePath *path;
GtkTreeIter iter; GtkTreeIter iter;
GList *rows;
if (gtk_tree_model_get_iter_from_string(c_model, &iter, path)) rows = gtk_tree_selection_get_selected_rows(selection, &c_model);
if (!rows)
return;
path = rows->data;
if (gtk_tree_model_get_iter(c_model, &iter, path))
library = __collection_get_library(&iter); library = __collection_get_library(&iter);
if (!library) if (!library)
return; return;
collection_set_enabled(library, !library->li_enabled); collection_set_enabled(library, gtk_check_menu_item_get_active(check));
__collection_set_library(&iter, library); __collection_set_library(&iter, library);
} }
@ -100,6 +103,35 @@ out:
return true; return true;
} }
bool __collection_buttonpress(GtkWidget *widget, GdkEventButton *event, gpointer data)
{
GtkCheckMenuItem *check = GTK_CHECK_MENU_ITEM(gui_builder_widget("o_collection_enabled"));
GtkTreeView *treeview = GTK_TREE_VIEW(gui_builder_widget("o_collection_view"));
GtkTreeSelection *selection = gtk_tree_view_get_selection(treeview);
GtkMenu *menu = GTK_MENU(gui_builder_widget("o_collection_rc"));
struct library *library = NULL;
GtkTreePath *path;
GtkTreeIter iter;
if (event->button != 3)
return false;
if (gtk_tree_view_get_path_at_pos(treeview, event->x, event->y,
&path, NULL, NULL, NULL))
gtk_tree_selection_select_path(selection, path);
if (gtk_tree_model_get_iter(c_model, &iter, path))
library = __collection_get_library(&iter);
if (library) {
gtk_check_menu_item_set_active(check, library->li_enabled);
gtk_menu_popup(menu, NULL, NULL, NULL, NULL,
event->button, event->time);
}
gtk_tree_path_free(path);
return true;
}
void __collection_add(GtkButton *button, GtkFileChooser *chooser) void __collection_add(GtkButton *button, GtkFileChooser *chooser)
{ {
gchar *filename = gtk_file_chooser_get_filename(chooser); gchar *filename = gtk_file_chooser_get_filename(chooser);

View File

@ -210,14 +210,23 @@
<property name="can_focus">False</property> <property name="can_focus">False</property>
<property name="icon_name">window-close</property> <property name="icon_name">window-close</property>
</object> </object>
<object class="GtkMenu" id="o_collection_rc">
<property name="visible">True</property>
<property name="can_focus">False</property>
<child>
<object class="GtkCheckMenuItem" id="o_collection_enabled">
<property name="visible">True</property>
<property name="can_focus">False</property>
<property name="label" translatable="yes">Library Path Enabled</property>
<property name="use_underline">True</property>
<signal name="toggled" handler="__collection_toggled" swapped="no"/>
</object>
</child>
</object>
<object class="GtkTreeStore" id="o_collection_store"> <object class="GtkTreeStore" id="o_collection_store">
<columns> <columns>
<!-- column-name Image --> <!-- column-name Image -->
<column type="gchararray"/> <column type="gchararray"/>
<!-- column-name Enabled -->
<column type="gboolean"/>
<!-- column-name ShowEnabled -->
<column type="gboolean"/>
<!-- column-name Path --> <!-- column-name Path -->
<column type="gchararray"/> <column type="gchararray"/>
<!-- column-name Library --> <!-- column-name Library -->
@ -747,6 +756,7 @@
<property name="model">o_collection_store</property> <property name="model">o_collection_store</property>
<property name="headers_visible">False</property> <property name="headers_visible">False</property>
<property name="enable_tree_lines">True</property> <property name="enable_tree_lines">True</property>
<signal name="button-press-event" handler="__collection_buttonpress" swapped="no"/>
<signal name="key-press-event" handler="__collection_keypress" swapped="no"/> <signal name="key-press-event" handler="__collection_keypress" swapped="no"/>
<signal name="row-activated" handler="__collection_activated" swapped="no"/> <signal name="row-activated" handler="__collection_activated" swapped="no"/>
<child internal-child="selection"> <child internal-child="selection">
@ -767,28 +777,13 @@
</child> </child>
</object> </object>
</child> </child>
<child>
<object class="GtkTreeViewColumn" id="treeviewcolumn4">
<property name="title" translatable="yes">Enabled</property>
<child>
<object class="GtkCellRendererToggle" id="cellrenderertoggle1">
<signal name="toggled" handler="__collection_toggled" swapped="no"/>
</object>
<attributes>
<attribute name="visible">2</attribute>
<attribute name="active">1</attribute>
</attributes>
</child>
</object>
</child>
<child> <child>
<object class="GtkTreeViewColumn" id="treeviewcolumn5"> <object class="GtkTreeViewColumn" id="treeviewcolumn5">
<property name="title" translatable="yes">Path</property> <property name="title" translatable="yes">Path</property>
<child> <child>
<object class="GtkCellRendererText" id="cellrenderertext3"/> <object class="GtkCellRendererText" id="cellrenderertext3"/>
<attributes> <attributes>
<attribute name="markup">3</attribute> <attribute name="markup">1</attribute>
<attribute name="text">3</attribute>
</attributes> </attributes>
</child> </child>
</object> </object>

View File

@ -70,7 +70,7 @@ static void test_collection_sidebar()
gtk_tree_model_get_iter_first(model, &iter); gtk_tree_model_get_iter_first(model, &iter);
test_equal(gtk_tree_model_iter_n_children(model, &iter), 2); test_equal(gtk_tree_model_iter_n_children(model, &iter), 2);
gtk_tree_model_iter_nth_child(model, &child, &iter, 0); gtk_tree_model_iter_nth_child(model, &child, &iter, 0);
gtk_tree_model_get(model, &child, 4, &library, -1); gtk_tree_model_get(model, &child, 2, &library, -1);
test_equal((void *)library, (void *)library_get(0)); test_equal((void *)library, (void *)library_get(0));
/* Run two idle events to scan the added path. */ /* Run two idle events to scan the added path. */
@ -85,7 +85,7 @@ static void test_collection_sidebar()
gtk_tree_model_get_iter_first(model, &iter); gtk_tree_model_get_iter_first(model, &iter);
test_equal(gtk_tree_model_iter_n_children(model, &iter), 2); test_equal(gtk_tree_model_iter_n_children(model, &iter), 2);
gtk_tree_model_iter_nth_child(model, &child, &iter, 0); gtk_tree_model_iter_nth_child(model, &child, &iter, 0);
gtk_tree_model_get(model, &child, 4, &library, -1); gtk_tree_model_get(model, &child, 2, &library, -1);
test_equal((void *)library, (void *)library_get(0)); test_equal((void *)library, (void *)library_get(0));
path = gtk_tree_model_get_path(model, &child); path = gtk_tree_model_get_path(model, &child);