Use XedStatusMenuButton instead -ComboBox in statusbar, for consistency.

This commit is contained in:
Tomasz Gąsior 2018-07-22 20:13:26 +02:00
parent 06a20265ea
commit 986655d6aa
2 changed files with 33 additions and 28 deletions

View File

@ -55,7 +55,8 @@ struct _XedWindowPrivate
GtkWidget *hpaned; GtkWidget *hpaned;
GtkWidget *vpaned; GtkWidget *vpaned;
GtkWidget *tab_width_combo; GtkWidget *tab_width_button;
GtkWidget *tab_width_menu;
GtkWidget *language_button; GtkWidget *language_button;
GtkWidget *language_popover; GtkWidget *language_popover;
GtkWidget *show_side_pane_button; GtkWidget *show_side_pane_button;

View File

@ -1296,8 +1296,7 @@ statusbar_visibility_changed (GtkWidget *statusbar,
} }
static void static void
tab_width_combo_changed (XedStatusComboBox *combo, tab_width_button_clicked (GtkMenuItem *item,
GtkMenuItem *item,
XedWindow *window) XedWindow *window)
{ {
XedView *view; XedView *view;
@ -1317,9 +1316,7 @@ tab_width_combo_changed (XedStatusComboBox *combo,
return; return;
} }
g_signal_handler_block (view, window->priv->tab_width_id);
gtk_source_view_set_tab_width (GTK_SOURCE_VIEW(view), width_data); gtk_source_view_set_tab_width (GTK_SOURCE_VIEW(view), width_data);
g_signal_handler_unblock (view, window->priv->tab_width_id);
} }
static void static void
@ -1342,21 +1339,25 @@ typedef struct
} TabWidthDefinition; } TabWidthDefinition;
static void static void
fill_tab_width_combo (XedWindow *window) setup_tab_width_menu (XedWindow *window)
{ {
static TabWidthDefinition defs[] = { { "2", 2 }, { "4", 4 }, { "8", 8 }, { "", 0 }, /* custom size */ static TabWidthDefinition defs[] = { { "2", 2 }, { "4", 4 }, { "8", 8 }, { "", 0 }, /* custom size */
{ NULL, 0 } }; { NULL, 0 } };
XedStatusComboBox *combo = XED_STATUS_COMBO_BOX(window->priv->tab_width_combo);
guint i = 0; guint i = 0;
GtkWidget *item; GtkWidget *item;
window->priv->tab_width_menu = gtk_menu_new ();
while (defs[i].label != NULL) while (defs[i].label != NULL)
{ {
item = gtk_menu_item_new_with_label (defs[i].label); item = gtk_menu_item_new_with_label (defs[i].label);
g_object_set_data (G_OBJECT(item), TAB_WIDTH_DATA, GINT_TO_POINTER(defs[i].width)); g_object_set_data (G_OBJECT(item), TAB_WIDTH_DATA, GINT_TO_POINTER(defs[i].width));
xed_status_combo_box_add_item (combo, GTK_MENU_ITEM(item), defs[i].label); gtk_menu_shell_append (GTK_MENU_SHELL (window->priv->tab_width_menu), item);
g_signal_connect(G_OBJECT (item), "activate",
G_CALLBACK (tab_width_button_clicked), window);
if (defs[i].width != 0) if (defs[i].width != 0)
{ {
@ -1367,11 +1368,11 @@ fill_tab_width_combo (XedWindow *window)
} }
item = gtk_separator_menu_item_new (); item = gtk_separator_menu_item_new ();
xed_status_combo_box_add_item (combo, GTK_MENU_ITEM(item), NULL); gtk_menu_shell_append (GTK_MENU_SHELL (window->priv->tab_width_menu), item);
gtk_widget_show (item); gtk_widget_show (item);
item = gtk_check_menu_item_new_with_label (_("Use Spaces")); item = gtk_check_menu_item_new_with_label (_("Use Spaces"));
xed_status_combo_box_add_item (combo, GTK_MENU_ITEM(item), NULL); gtk_menu_shell_append (GTK_MENU_SHELL (window->priv->tab_width_menu), item);
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);
@ -1431,16 +1432,16 @@ create_statusbar (XedWindow *window,
gtk_widget_set_margin_start (GTK_WIDGET (window->priv->statusbar), 0); gtk_widget_set_margin_start (GTK_WIDGET (window->priv->statusbar), 0);
gtk_widget_set_margin_end (GTK_WIDGET (window->priv->statusbar), 0); gtk_widget_set_margin_end (GTK_WIDGET (window->priv->statusbar), 0);
window->priv->tab_width_combo = xed_status_combo_box_new (_("Tab Width")); window->priv->tab_width_button = xed_status_menu_button_new ();
gtk_widget_show (window->priv->tab_width_combo); gtk_widget_show (window->priv->tab_width_button);
gtk_box_pack_end (GTK_BOX (window->priv->statusbar), window->priv->tab_width_combo, FALSE, FALSE, 0); gtk_box_pack_end (GTK_BOX (window->priv->statusbar), window->priv->tab_width_button, FALSE, FALSE, 0);
gtk_widget_set_margin_bottom (GTK_WIDGET (window->priv->tab_width_combo), 2); gtk_widget_set_margin_bottom (GTK_WIDGET (window->priv->tab_width_button), 2);
gtk_widget_set_margin_top (GTK_WIDGET (window->priv->tab_width_combo), 2); gtk_widget_set_margin_top (GTK_WIDGET (window->priv->tab_width_button), 2);
fill_tab_width_combo (window); setup_tab_width_menu (window);
g_signal_connect(G_OBJECT (window->priv->tab_width_combo), "changed", gtk_menu_button_set_popup (GTK_MENU_BUTTON (window->priv->tab_width_button),
G_CALLBACK (tab_width_combo_changed), window); window->priv->tab_width_menu);
window->priv->language_button = xed_status_menu_button_new (); window->priv->language_button = xed_status_menu_button_new ();
gtk_widget_show (window->priv->language_button); gtk_widget_show (window->priv->language_button);
@ -1741,9 +1742,9 @@ static void
set_tab_width_item_blocked (XedWindow *window, set_tab_width_item_blocked (XedWindow *window,
GtkMenuItem *item) GtkMenuItem *item)
{ {
g_signal_handlers_block_by_func(window->priv->tab_width_combo, tab_width_combo_changed, window); g_signal_handlers_block_by_func(item, tab_width_button_clicked, window);
xed_status_combo_box_set_item (XED_STATUS_COMBO_BOX(window->priv->tab_width_combo), item); gtk_menu_shell_select_item (GTK_MENU_SHELL (window->priv->tab_width_menu), GTK_WIDGET (item));
g_signal_handlers_unblock_by_func(window->priv->tab_width_combo, tab_width_combo_changed, window); g_signal_handlers_unblock_by_func(item, tab_width_button_clicked, window);
} }
static void static void
@ -1753,7 +1754,7 @@ spaces_instead_of_tabs_changed (GObject *object,
{ {
XedView *view = XED_VIEW(object); XedView *view = XED_VIEW(object);
gboolean active = gtk_source_view_get_insert_spaces_instead_of_tabs (GTK_SOURCE_VIEW(view)); gboolean active = gtk_source_view_get_insert_spaces_instead_of_tabs (GTK_SOURCE_VIEW(view));
GList *children = xed_status_combo_box_get_items (XED_STATUS_COMBO_BOX(window->priv->tab_width_combo)); GList *children = gtk_container_get_children (GTK_CONTAINER (window->priv->tab_width_menu));
GtkCheckMenuItem *item; GtkCheckMenuItem *item;
item = GTK_CHECK_MENU_ITEM(g_list_last (children)->data); item = GTK_CHECK_MENU_ITEM(g_list_last (children)->data);
gtk_check_menu_item_set_active (item, active); gtk_check_menu_item_set_active (item, active);
@ -1767,11 +1768,11 @@ tab_width_changed (GObject *object,
{ {
GList *items; GList *items;
GList *item; GList *item;
XedStatusComboBox *combo = XED_STATUS_COMBO_BOX(window->priv->tab_width_combo);
guint new_tab_width; guint new_tab_width;
gchar *label;
gboolean found = FALSE; gboolean found = FALSE;
items = xed_status_combo_box_get_items (combo); items = gtk_container_get_children (GTK_CONTAINER (window->priv->tab_width_menu));
new_tab_width = gtk_source_view_get_tab_width (GTK_SOURCE_VIEW(object)); new_tab_width = gtk_source_view_get_tab_width (GTK_SOURCE_VIEW(object));
@ -1793,8 +1794,7 @@ tab_width_changed (GObject *object,
gchar *text; gchar *text;
text = g_strdup_printf ("%u", new_tab_width); text = g_strdup_printf ("%u", new_tab_width);
xed_status_combo_box_set_item_text (combo, GTK_MENU_ITEM(item->data), text); gtk_menu_item_set_label (GTK_MENU_ITEM(item->data), text);
gtk_label_set_text (GTK_LABEL(gtk_bin_get_child (GTK_BIN (item->data))), text);
set_tab_width_item_blocked (window, GTK_MENU_ITEM(item->data)); set_tab_width_item_blocked (window, GTK_MENU_ITEM(item->data));
gtk_widget_show (GTK_WIDGET(item->data)); gtk_widget_show (GTK_WIDGET(item->data));
@ -1808,6 +1808,10 @@ tab_width_changed (GObject *object,
} }
} }
label = g_strdup_printf (_("Tab Width: %u"), new_tab_width);
xed_status_menu_button_set_label (XED_STATUS_MENU_BUTTON (window->priv->tab_width_button), label);
g_free (label);
g_list_free (items); g_list_free (items);
} }
@ -1956,7 +1960,7 @@ notebook_switch_page (GtkNotebook *book,
xed_statusbar_set_overwrite (XED_STATUSBAR (window->priv->statusbar), xed_statusbar_set_overwrite (XED_STATUSBAR (window->priv->statusbar),
gtk_text_view_get_overwrite (GTK_TEXT_VIEW(view))); gtk_text_view_get_overwrite (GTK_TEXT_VIEW(view)));
gtk_widget_show (window->priv->tab_width_combo); gtk_widget_show (window->priv->tab_width_button);
gtk_widget_show (window->priv->language_button); gtk_widget_show (window->priv->language_button);
window->priv->tab_width_id = g_signal_connect(view, "notify::tab-width", G_CALLBACK (tab_width_changed), window); window->priv->tab_width_id = g_signal_connect(view, "notify::tab-width", G_CALLBACK (tab_width_changed), window);
@ -2692,7 +2696,7 @@ notebook_tab_removed (XedNotebook *notebook,
xed_statusbar_clear_overwrite (XED_STATUSBAR(window->priv->statusbar)); xed_statusbar_clear_overwrite (XED_STATUSBAR(window->priv->statusbar));
/* hide the combos */ /* hide the combos */
gtk_widget_hide (window->priv->tab_width_combo); gtk_widget_hide (window->priv->tab_width_button);
gtk_widget_hide (window->priv->language_button); gtk_widget_hide (window->priv->language_button);
} }