Tab width popup: only select a menu item when the menu is open (#311)

This fixes a gdk window assertion error that occurs every time xed
is opened, as well as causes the correct menu item to actually be
selected as expected (it currently isn't).
This commit is contained in:
Stephen Collins 2019-06-15 02:21:57 -06:00 committed by JosephMcc
parent 2520d1c087
commit 7bdc217e8c
2 changed files with 27 additions and 12 deletions

View File

@ -57,6 +57,7 @@ struct _XedWindowPrivate
GtkWidget *tab_width_button; GtkWidget *tab_width_button;
GtkWidget *tab_width_menu; GtkWidget *tab_width_menu;
GtkWidget *tab_width_item;
GtkWidget *language_button; GtkWidget *language_button;
GtkWidget *language_popover; GtkWidget *language_popover;
GtkWidget *show_side_pane_button; GtkWidget *show_side_pane_button;

View File

@ -1362,6 +1362,19 @@ typedef struct
guint width; guint width;
} TabWidthDefinition; } TabWidthDefinition;
static void
tab_width_menu_popped_up (GtkMenu *menu,
gpointer flipped_rect,
gpointer final_rect,
gboolean flipped_x,
gboolean flipped_y,
gpointer user_data)
{
XedWindow *window = XED_WINDOW (user_data);
gtk_menu_shell_select_item (GTK_MENU_SHELL (window->priv->tab_width_menu), GTK_WIDGET (window->priv->tab_width_item));
}
static void static void
setup_tab_width_menu (XedWindow *window) setup_tab_width_menu (XedWindow *window)
{ {
@ -1400,6 +1413,8 @@ setup_tab_width_menu (XedWindow *window)
gtk_widget_show (item); gtk_widget_show (item);
g_signal_connect (item, "toggled", G_CALLBACK (use_spaces_toggled), window); g_signal_connect (item, "toggled", G_CALLBACK (use_spaces_toggled), window);
g_signal_connect (window->priv->tab_width_menu, "popped-up", G_CALLBACK (tab_width_menu_popped_up), window);
} }
static void static void
@ -1762,15 +1777,6 @@ set_title (XedWindow *window)
#undef MAX_TITLE_LENGTH #undef MAX_TITLE_LENGTH
static void
set_tab_width_item_blocked (XedWindow *window,
GtkMenuItem *item)
{
g_signal_handlers_block_by_func(item, tab_width_button_clicked, window);
gtk_menu_shell_select_item (GTK_MENU_SHELL (window->priv->tab_width_menu), GTK_WIDGET (item));
g_signal_handlers_unblock_by_func(item, tab_width_button_clicked, window);
}
static void static void
spaces_instead_of_tabs_changed (GObject *object, spaces_instead_of_tabs_changed (GObject *object,
GParamSpec *pspec, GParamSpec *pspec,
@ -1807,7 +1813,11 @@ tab_width_changed (GObject *object,
if (tab_width == new_tab_width) if (tab_width == new_tab_width)
{ {
set_tab_width_item_blocked (window, GTK_MENU_ITEM(item->data)); window->priv->tab_width_item = item->data;
if (gtk_widget_get_realized (window->priv->tab_width_menu))
{
gtk_menu_shell_select_item (GTK_MENU_SHELL (window->priv->tab_width_menu), GTK_WIDGET (item->data));
}
found = TRUE; found = TRUE;
} }
@ -1821,7 +1831,11 @@ tab_width_changed (GObject *object,
text = g_strdup_printf ("%u", new_tab_width); text = g_strdup_printf ("%u", new_tab_width);
gtk_menu_item_set_label (GTK_MENU_ITEM(item->data), text); gtk_menu_item_set_label (GTK_MENU_ITEM(item->data), text);
set_tab_width_item_blocked (window, GTK_MENU_ITEM(item->data)); window->priv->tab_width_item = item->data;
if (gtk_widget_get_realized (window->priv->tab_width_menu))
{
gtk_menu_shell_select_item (GTK_MENU_SHELL (window->priv->tab_width_menu), GTK_WIDGET (item->data));
}
gtk_widget_show (GTK_WIDGET(item->data)); gtk_widget_show (GTK_WIDGET(item->data));
} }
else else