diff options
author | Alan F <ajf@eth0.org.uk> | 2014-02-03 15:32:34 +0000 |
---|---|---|
committer | Alan F <ajf@eth0.org.uk> | 2014-02-03 15:32:34 +0000 |
commit | 044bfd7d985c152a4d2350f3d7d51f8302ec49c9 (patch) | |
tree | e9a9cdcf4b405c332169c639feafd5ff90aaa676 /src | |
parent | b06b8290bef019462a45f36de6f10abfe8b13c6d (diff) |
GTK seems to be destroyingt and recreating columns in some circumstances (I don't think it used to do this), which means binding it as an argument on a button signal causes a crash. Workaround by searching for the column by title.
Diffstat (limited to 'src')
-rw-r--r-- | src/trg-tree-view.c | 43 |
1 files changed, 32 insertions, 11 deletions
diff --git a/src/trg-tree-view.c b/src/trg-tree-view.c index 1be9dad..7585180 100644 --- a/src/trg-tree-view.c +++ b/src/trg-tree-view.c @@ -332,18 +332,12 @@ view_popup_menu(GtkButton * button, GdkEventButton * event, TrgTreeViewPrivate *priv = TRG_TREE_VIEW_GET_PRIVATE(tv); GtkWidget *menu, *menuitem; trg_column_description *desc; + guint n_showing = 0; GList *li; menu = gtk_menu_new(); desc = g_object_get_data(G_OBJECT(column), GDATA_KEY_COLUMN_DESC); - menuitem = gtk_check_menu_item_new_with_label(desc->header); - gtk_check_menu_item_set_active(GTK_CHECK_MENU_ITEM(menuitem), TRUE); - g_signal_connect(menuitem, "activate", - G_CALLBACK(trg_tree_view_hide_column), column); - gtk_widget_set_sensitive(menuitem, - !(desc->flags & TRG_COLUMN_UNREMOVABLE)); - gtk_menu_shell_append(GTK_MENU_SHELL(menu), menuitem); for (li = priv->columns; li; li = g_list_next(li)) { trg_column_description *desc = (trg_column_description *) li->data; @@ -354,8 +348,19 @@ view_popup_menu(GtkButton * button, GdkEventButton * event, G_CALLBACK(trg_tree_view_user_add_column_cb), desc); gtk_menu_shell_append(GTK_MENU_SHELL(menu), menuitem); + } else { + n_showing++; } } + + menuitem = gtk_check_menu_item_new_with_label(desc->header); + gtk_check_menu_item_set_active(GTK_CHECK_MENU_ITEM(menuitem), TRUE); + g_signal_connect(menuitem, "activate", + G_CALLBACK(trg_tree_view_hide_column), column); + gtk_widget_set_sensitive(menuitem, + !(desc->flags & TRG_COLUMN_UNREMOVABLE) && n_showing > 1); + gtk_menu_shell_prepend(GTK_MENU_SHELL(menu), menuitem); + gtk_widget_show_all(menu); gtk_menu_popup(GTK_MENU(menu), NULL, NULL, NULL, NULL, @@ -363,12 +368,28 @@ view_popup_menu(GtkButton * button, GdkEventButton * event, gdk_event_get_time((GdkEvent *) event)); } +/* This used to get the column as an argument binded when the signal was + * created, but it seems GTK now destroys and recreates them in some + * circumstances. So bind the column description instead and search for the + * column by its title. + */ static gboolean col_onButtonPressed(GtkButton * button, - GdkEventButton * event, GtkTreeViewColumn * col) + GdkEventButton * event, trg_column_description *desc) { if (event->type == GDK_BUTTON_PRESS && event->button == 3) { - view_popup_menu(button, event, col); + GtkTreeView *gtv = GTK_TREE_VIEW(gtk_widget_get_parent(GTK_WIDGET(button))); + GList *cols = gtk_tree_view_get_columns(gtv); + GList *li; + for (li = cols; li; li = g_list_next(li)) { + GtkTreeViewColumn *col = GTK_TREE_VIEW_COLUMN(li->data); + if (!g_strcmp0(desc->header, gtk_tree_view_column_get_title(col))) { + view_popup_menu(button, event, col); + break; + } + } + g_list_free(cols); + return TRUE; } @@ -564,11 +585,11 @@ trg_tree_view_add_column_after(TrgTreeView * tv, gtk_tree_view_move_column_after(GTK_TREE_VIEW(tv), column, after_col); - column_button = gtk_tree_view_column_get_button(column); + column_button = GTK_BUTTON(gtk_tree_view_column_get_button(column)); g_signal_connect(column_button, "button-press-event", G_CALLBACK(col_onButtonPressed), - column); + desc); if (desc->out) *(desc->out) = column; |