[gedit] Move the creation of the menu out of the status combo
- From: Paolo Borelli <pborelli src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [gedit] Move the creation of the menu out of the status combo
- Date: Sun, 28 Apr 2013 14:15:52 +0000 (UTC)
commit a66279f5bd9017c94f31ffb4589ebf9cf3fc4fb0
Author: Paolo Borelli <pborelli gnome org>
Date: Sun Apr 28 16:13:44 2013 +0200
Move the creation of the menu out of the status combo
Now that it extends GtkMenuButton it is cleaner to just move the
creation of the menu in the caller side and simply use set_popup.
This also opens the possibility of using GMenu or to use radio items.
gedit/gedit-status-combo-box.c | 113 +-------------
gedit/gedit-status-combo-box.h | 19 +--
gedit/gedit-window-private.h | 17 +-
gedit/gedit-window.c | 347 ++++++++++++++++------------------------
4 files changed, 151 insertions(+), 345 deletions(-)
---
diff --git a/gedit/gedit-status-combo-box.c b/gedit/gedit-status-combo-box.c
index 0ea5f2b..090a5b6 100644
--- a/gedit/gedit-status-combo-box.c
+++ b/gedit/gedit-status-combo-box.c
@@ -199,9 +199,6 @@ gedit_status_combo_box_init (GeditStatusComboBox *self)
gtk_box_pack_start (GTK_BOX (self->priv->hbox), self->priv->arrow, FALSE, TRUE, 0);
- self->priv->menu = gtk_menu_new ();
- gtk_menu_button_set_popup (GTK_MENU_BUTTON (self), self->priv->menu);
-
/* make it as small as possible */
context = gtk_widget_get_style_context (GTK_WIDGET (self));
gtk_style_context_add_provider (context,
@@ -230,13 +227,9 @@ void
gedit_status_combo_box_set_label (GeditStatusComboBox *combo,
const gchar *label)
{
- gchar *text;
-
g_return_if_fail (GEDIT_IS_STATUS_COMBO_BOX (combo));
- text = g_strconcat (" ", label, ": ", NULL);
- gtk_label_set_markup (GTK_LABEL (combo->priv->label), text);
- g_free (text);
+ gtk_label_set_markup (GTK_LABEL (combo->priv->label), label);
}
const gchar *
@@ -247,108 +240,4 @@ gedit_status_combo_box_get_label (GeditStatusComboBox *combo)
return gtk_label_get_label (GTK_LABEL (combo->priv->label));
}
-static void
-item_activated (GtkMenuItem *item,
- GeditStatusComboBox *combo)
-{
- gedit_status_combo_box_set_item (combo, item);
-}
-
-/**
- * gedit_status_combo_box_add_item:
- * @combo:
- * @item:
- * @text: (allow-none):
- */
-void
-gedit_status_combo_box_add_item (GeditStatusComboBox *combo,
- GtkMenuItem *item,
- const gchar *text)
-{
- g_return_if_fail (GEDIT_IS_STATUS_COMBO_BOX (combo));
- g_return_if_fail (GTK_IS_MENU_ITEM (item));
-
- gtk_menu_shell_append (GTK_MENU_SHELL (combo->priv->menu), GTK_WIDGET (item));
-
- gedit_status_combo_box_set_item_text (combo, item, text);
- g_signal_connect (item, "activate", G_CALLBACK (item_activated), combo);
-}
-
-void
-gedit_status_combo_box_remove_item (GeditStatusComboBox *combo,
- GtkMenuItem *item)
-{
- g_return_if_fail (GEDIT_IS_STATUS_COMBO_BOX (combo));
- g_return_if_fail (GTK_IS_MENU_ITEM (item));
-
- gtk_container_remove (GTK_CONTAINER (combo->priv->menu),
- GTK_WIDGET (item));
-}
-
-/**
- * gedit_status_combo_box_get_items:
- * @combo:
- *
- * Returns: (element-type Gtk.Widget) (transfer container):
- */
-GList *
-gedit_status_combo_box_get_items (GeditStatusComboBox *combo)
-{
- g_return_val_if_fail (GEDIT_IS_STATUS_COMBO_BOX (combo), NULL);
-
- return gtk_container_get_children (GTK_CONTAINER (combo->priv->menu));
-}
-
-const gchar *
-gedit_status_combo_box_get_item_text (GeditStatusComboBox *combo,
- GtkMenuItem *item)
-{
- const gchar *ret = NULL;
-
- g_return_val_if_fail (GEDIT_IS_STATUS_COMBO_BOX (combo), NULL);
- g_return_val_if_fail (GTK_IS_MENU_ITEM (item), NULL);
-
- ret = g_object_get_data (G_OBJECT (item), COMBO_BOX_TEXT_DATA);
-
- return ret;
-}
-
-/**
- * gedit_status_combo_box_set_item_text:
- * @combo:
- * @item:
- * @text: (allow-none):
- */
-void
-gedit_status_combo_box_set_item_text (GeditStatusComboBox *combo,
- GtkMenuItem *item,
- const gchar *text)
-{
- g_return_if_fail (GEDIT_IS_STATUS_COMBO_BOX (combo));
- g_return_if_fail (GTK_IS_MENU_ITEM (item));
-
- g_object_set_data_full (G_OBJECT (item),
- COMBO_BOX_TEXT_DATA,
- g_strdup (text),
- (GDestroyNotify)g_free);
-}
-
-void
-gedit_status_combo_box_set_item (GeditStatusComboBox *combo,
- GtkMenuItem *item)
-{
- g_return_if_fail (GEDIT_IS_STATUS_COMBO_BOX (combo));
- g_return_if_fail (GTK_IS_MENU_ITEM (item));
-
- g_signal_emit (combo, signals[CHANGED], 0, item, NULL);
-}
-
-GtkLabel *
-gedit_status_combo_box_get_item_label (GeditStatusComboBox *combo)
-{
- g_return_val_if_fail (GEDIT_IS_STATUS_COMBO_BOX (combo), NULL);
-
- return GTK_LABEL (combo->priv->item);
-}
-
/* ex:set ts=8 noet: */
diff --git a/gedit/gedit-status-combo-box.h b/gedit/gedit-status-combo-box.h
index acefbbf..24cc06e 100644
--- a/gedit/gedit-status-combo-box.h
+++ b/gedit/gedit-status-combo-box.h
@@ -58,30 +58,13 @@ struct _GeditStatusComboBoxClass
};
GType gedit_status_combo_box_get_type (void) G_GNUC_CONST;
+
GtkWidget *gedit_status_combo_box_new (const gchar *label);
const gchar *gedit_status_combo_box_get_label (GeditStatusComboBox *combo);
void gedit_status_combo_box_set_label (GeditStatusComboBox *combo,
const gchar *label);
-void gedit_status_combo_box_add_item (GeditStatusComboBox *combo,
- GtkMenuItem *item,
- const gchar *text);
-void gedit_status_combo_box_remove_item (GeditStatusComboBox *combo,
- GtkMenuItem *item);
-
-GList *gedit_status_combo_box_get_items (GeditStatusComboBox *combo);
-const gchar *gedit_status_combo_box_get_item_text (GeditStatusComboBox *combo,
- GtkMenuItem *item);
-void gedit_status_combo_box_set_item_text (GeditStatusComboBox *combo,
- GtkMenuItem *item,
- const gchar *text);
-
-void gedit_status_combo_box_set_item (GeditStatusComboBox *combo,
- GtkMenuItem *item);
-
-GtkLabel *gedit_status_combo_box_get_item_label (GeditStatusComboBox *combo);
-
G_END_DECLS
#endif /* __GEDIT_STATUS_COMBO_BOX_H__ */
diff --git a/gedit/gedit-window-private.h b/gedit/gedit-window-private.h
index 0599ba2..87c6b3b 100644
--- a/gedit/gedit-window-private.h
+++ b/gedit/gedit-window-private.h
@@ -60,9 +60,6 @@ struct _GeditWindowPrivate
GtkWidget *hpaned;
GtkWidget *vpaned;
- GtkWidget *tab_width_combo;
- GtkWidget *language_combo;
-
GeditMessageBus *message_bus;
PeasExtensionSet *extensions;
@@ -73,14 +70,16 @@ struct _GeditWindowPrivate
/* statusbar and context ids for statusbar messages */
GtkWidget *statusbar;
+ GtkWidget *tab_width_combo;
+ GtkWidget *tab_width_combo_menu;
+ GtkWidget *language_combo;
+ GtkWidget *language_combo_menu;
guint generic_message_cid;
guint tip_message_cid;
- guint bracket_match_message_cid;
-
- /* signal handler ids */
- guint tab_width_id;
- guint spaces_instead_of_tabs_id;
- guint language_changed_id;
+ guint bracket_match_message_cid;
+ GBinding *spaces_instead_of_tabs_binding;
+ guint tab_width_id;
+ guint language_changed_id;
/* Menus & Toolbars */
GtkUIManager *manager;
diff --git a/gedit/gedit-window.c b/gedit/gedit-window.c
index ed0191c..d63308f 100644
--- a/gedit/gedit-window.c
+++ b/gedit/gedit-window.c
@@ -1959,26 +1959,21 @@ statusbar_visibility_changed (GtkWidget *statusbar,
}
static void
-tab_width_combo_changed (GeditStatusComboBox *combo,
- GtkMenuItem *item,
- GeditWindow *window)
+tab_width_combo_item_activated (GtkMenuItem *item,
+ GeditWindow *window)
{
GeditView *view;
guint width_data = 0;
view = gedit_window_get_active_view (window);
-
if (!view)
return;
width_data = GPOINTER_TO_INT (g_object_get_data (G_OBJECT (item), TAB_WIDTH_DATA));
-
if (width_data == 0)
return;
- g_signal_handler_block (view, window->priv->tab_width_id);
gtk_source_view_set_tab_width (GTK_SOURCE_VIEW (view), width_data);
- g_signal_handler_unblock (view, window->priv->tab_width_id);
}
static void
@@ -1986,78 +1981,73 @@ use_spaces_toggled (GtkCheckMenuItem *item,
GeditWindow *window)
{
GeditView *view;
+ gboolean active;
view = gedit_window_get_active_view (window);
-
- g_signal_handler_block (view, window->priv->spaces_instead_of_tabs_id);
- gtk_source_view_set_insert_spaces_instead_of_tabs (
- GTK_SOURCE_VIEW (view),
- gtk_check_menu_item_get_active (item));
- g_signal_handler_unblock (view, window->priv->spaces_instead_of_tabs_id);
-}
-
-static void
-language_combo_changed (GeditStatusComboBox *combo,
- GtkMenuItem *item,
- GeditWindow *window)
-{
- GeditDocument *doc;
- GtkSourceLanguage *language;
-
- doc = gedit_window_get_active_document (window);
-
- if (!doc)
+ if (!view)
return;
- language = GTK_SOURCE_LANGUAGE (g_object_get_data (G_OBJECT (item), LANGUAGE_DATA));
+ active = gtk_check_menu_item_get_active (item);
- g_signal_handler_block (doc, window->priv->language_changed_id);
- gedit_document_set_language (doc, language);
- g_signal_handler_unblock (doc, window->priv->language_changed_id);
+ gtk_source_view_set_insert_spaces_instead_of_tabs (GTK_SOURCE_VIEW (view),
+ active);
}
-typedef struct
-{
- const gchar *label;
- guint width;
-} TabWidthDefinition;
-
static void
-fill_tab_width_combo (GeditWindow *window)
-{
- static TabWidthDefinition defs[] = {
- {"2", 2},
- {"4", 4},
- {"8", 8},
- {"", 0}, /* custom size */
- {NULL, 0}
- };
+create_tab_width_combo (GeditWindow *window)
+{
+ static guint tab_widths[] = { 2, 4, 8 };
- GeditStatusComboBox *combo = GEDIT_STATUS_COMBO_BOX (window->priv->tab_width_combo);
guint i = 0;
GtkWidget *item;
- while (defs[i].label != NULL)
+ window->priv->tab_width_combo = gedit_status_combo_box_new (_("Tab Width:"));
+ window->priv->tab_width_combo_menu = gtk_menu_new ();
+ gtk_menu_button_set_popup (GTK_MENU_BUTTON (window->priv->tab_width_combo),
+ window->priv->tab_width_combo_menu);
+ gtk_widget_show (window->priv->tab_width_combo);
+ gtk_box_pack_end (GTK_BOX (window->priv->statusbar),
+ window->priv->tab_width_combo,
+ FALSE,
+ TRUE,
+ 0);
+
+ for (i = 0; i < G_N_ELEMENTS (tab_widths); i++)
{
- 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));
+ gchar *label = g_strdup_printf ("%u", tab_widths[i]);
+ item = gtk_menu_item_new_with_label (label);
+ g_free (label);
- gedit_status_combo_box_add_item (combo,
- GTK_MENU_ITEM (item),
- defs[i].label);
+ g_object_set_data (G_OBJECT (item), TAB_WIDTH_DATA, GINT_TO_POINTER (tab_widths[i]));
- if (defs[i].width != 0)
- gtk_widget_show (item);
+ g_signal_connect (item,
+ "activate",
+ G_CALLBACK (tab_width_combo_item_activated),
+ window);
- ++i;
+ gtk_menu_shell_append (GTK_MENU_SHELL (window->priv->tab_width_combo_menu),
+ GTK_WIDGET (item));
+ gtk_widget_show (item);
}
+ /* Add a hidden item for custom values */
+ item = gtk_menu_item_new ();
+ gtk_menu_shell_append (GTK_MENU_SHELL (window->priv->tab_width_combo_menu),
+ GTK_WIDGET (item));
+
+ g_signal_connect (item,
+ "activate",
+ G_CALLBACK (tab_width_combo_item_activated),
+ window);
+
item = gtk_separator_menu_item_new ();
- gedit_status_combo_box_add_item (combo, GTK_MENU_ITEM (item), NULL);
+ gtk_menu_shell_append (GTK_MENU_SHELL (window->priv->tab_width_combo_menu),
+ GTK_WIDGET (item));
gtk_widget_show (item);
item = gtk_check_menu_item_new_with_label (_("Use Spaces"));
- gedit_status_combo_box_add_item (combo, GTK_MENU_ITEM (item), NULL);
+ gtk_menu_shell_append (GTK_MENU_SHELL (window->priv->tab_width_combo_menu),
+ GTK_WIDGET (item));
gtk_widget_show (item);
g_signal_connect (item,
@@ -2067,22 +2057,52 @@ fill_tab_width_combo (GeditWindow *window)
}
static void
-fill_language_combo (GeditWindow *window)
+language_combo_item_activated (GtkMenuItem *item,
+ GeditWindow *window)
+{
+ GeditDocument *doc;
+ GtkSourceLanguage *language;
+
+ doc = gedit_window_get_active_document (window);
+
+ if (!doc)
+ return;
+
+ language = GTK_SOURCE_LANGUAGE (g_object_get_data (G_OBJECT (item), LANGUAGE_DATA));
+ gedit_document_set_language (doc, language);
+}
+
+static void
+create_language_combo (GeditWindow *window)
{
GtkSourceLanguageManager *lm;
const gchar * const *ids;
const gchar *name;
- GtkWidget *menu_item;
+ GtkWidget *item;
gint i;
+ window->priv->language_combo = gedit_status_combo_box_new (NULL);
+ window->priv->language_combo_menu = gtk_menu_new ();
+ gtk_menu_button_set_popup (GTK_MENU_BUTTON (window->priv->language_combo),
+ window->priv->language_combo_menu);
+ gtk_widget_show (window->priv->language_combo);
+ gtk_box_pack_end (GTK_BOX (window->priv->statusbar),
+ window->priv->language_combo,
+ FALSE,
+ TRUE,
+ 0);
+
name = _("Plain Text");
- menu_item = gtk_menu_item_new_with_label (name);
- gtk_widget_show (menu_item);
+ item = gtk_menu_item_new_with_label (name);
+ gtk_widget_show (item);
- g_object_set_data (G_OBJECT (menu_item), LANGUAGE_DATA, NULL);
- gedit_status_combo_box_add_item (GEDIT_STATUS_COMBO_BOX (window->priv->language_combo),
- GTK_MENU_ITEM (menu_item),
- name);
+ g_object_set_data (G_OBJECT (item), LANGUAGE_DATA, NULL);
+ gtk_menu_shell_append (GTK_MENU_SHELL (window->priv->language_combo_menu),
+ GTK_WIDGET (item));
+ g_signal_connect (item,
+ "activate",
+ G_CALLBACK (language_combo_item_activated),
+ window);
lm = gtk_source_language_manager_get_default ();
ids = gtk_source_language_manager_get_language_ids (lm);
@@ -2092,21 +2112,25 @@ fill_language_combo (GeditWindow *window)
GtkSourceLanguage *lang;
lang = gtk_source_language_manager_get_language (lm, ids[i]);
-
+
if (!gtk_source_language_get_hidden (lang))
{
name = gtk_source_language_get_name (lang);
- menu_item = gtk_menu_item_new_with_label (name);
- gtk_widget_show (menu_item);
+ item = gtk_menu_item_new_with_label (name);
+ gtk_widget_show (item);
- g_object_set_data_full (G_OBJECT (menu_item),
+ g_object_set_data_full (G_OBJECT (item),
LANGUAGE_DATA,
g_object_ref (lang),
(GDestroyNotify)g_object_unref);
- gedit_status_combo_box_add_item (GEDIT_STATUS_COMBO_BOX
(window->priv->language_combo),
- GTK_MENU_ITEM (menu_item),
- name);
+ gtk_menu_shell_append (GTK_MENU_SHELL (window->priv->language_combo_menu),
+ GTK_WIDGET (item));
+
+ g_signal_connect (item,
+ "activate",
+ G_CALLBACK (language_combo_item_activated),
+ window);
}
}
}
@@ -2132,35 +2156,8 @@ create_statusbar (GeditWindow *window,
TRUE,
0);
- window->priv->tab_width_combo = gedit_status_combo_box_new (_("Tab Width"));
- gtk_widget_show (window->priv->tab_width_combo);
- gtk_box_pack_end (GTK_BOX (window->priv->statusbar),
- window->priv->tab_width_combo,
- FALSE,
- TRUE,
- 0);
-
- fill_tab_width_combo (window);
-
- g_signal_connect (G_OBJECT (window->priv->tab_width_combo),
- "changed",
- G_CALLBACK (tab_width_combo_changed),
- window);
-
- window->priv->language_combo = gedit_status_combo_box_new (NULL);
- gtk_widget_show (window->priv->language_combo);
- gtk_box_pack_end (GTK_BOX (window->priv->statusbar),
- window->priv->language_combo,
- FALSE,
- TRUE,
- 0);
-
- fill_language_combo (window);
-
- g_signal_connect (G_OBJECT (window->priv->language_combo),
- "changed",
- G_CALLBACK (language_combo_changed),
- window);
+ create_tab_width_combo (window);
+ create_language_combo (window);
g_signal_connect_after (G_OBJECT (window->priv->statusbar),
"notify::visible",
@@ -2421,62 +2418,31 @@ set_title (GeditWindow *window)
#undef MAX_TITLE_LENGTH
static void
-set_tab_width_item_blocked (GeditWindow *window,
- GtkMenuItem *item)
-{
- g_signal_handlers_block_by_func (window->priv->tab_width_combo,
- tab_width_combo_changed,
- window);
-
- gedit_status_combo_box_set_item (GEDIT_STATUS_COMBO_BOX (window->priv->tab_width_combo),
- item);
-
- g_signal_handlers_unblock_by_func (window->priv->tab_width_combo,
- tab_width_combo_changed,
- window);
-}
-
-static void
-spaces_instead_of_tabs_changed (GObject *object,
- GParamSpec *pspec,
- GeditWindow *window)
-{
- GeditView *view = GEDIT_VIEW (object);
- gboolean active = gtk_source_view_get_insert_spaces_instead_of_tabs (
- GTK_SOURCE_VIEW (view));
- GList *children = gedit_status_combo_box_get_items (
- GEDIT_STATUS_COMBO_BOX (window->priv->tab_width_combo));
- GtkCheckMenuItem *item;
-
- item = GTK_CHECK_MENU_ITEM (g_list_last (children)->data);
-
- gtk_check_menu_item_set_active (item, active);
-
- g_list_free (children);
-}
-
-static void
tab_width_changed (GObject *object,
GParamSpec *pspec,
GeditWindow *window)
{
GList *items;
GList *item;
- GeditStatusComboBox *combo = GEDIT_STATUS_COMBO_BOX (window->priv->tab_width_combo);
guint new_tab_width;
+ gchar *label;
gboolean found = FALSE;
- items = gedit_status_combo_box_get_items (combo);
+ items = gtk_container_get_children (GTK_CONTAINER (window->priv->tab_width_combo_menu));
new_tab_width = gtk_source_view_get_tab_width (GTK_SOURCE_VIEW (object));
+ label = g_strdup_printf (_("Tab Width: %u"), new_tab_width);
+ gedit_status_combo_box_set_label (GEDIT_STATUS_COMBO_BOX (window->priv->tab_width_combo),
+ label);
+ g_free (label);
+
for (item = items; item; item = item->next)
{
guint tab_width = GPOINTER_TO_INT (g_object_get_data (G_OBJECT (item->data), TAB_WIDTH_DATA));
if (tab_width == new_tab_width)
{
- set_tab_width_item_blocked (window, GTK_MENU_ITEM (item->data));
found = TRUE;
}
@@ -2484,18 +2450,10 @@ tab_width_changed (GObject *object,
{
if (!found)
{
- /* Set for the last item the custom thing */
- gchar *text;
-
- text = g_strdup_printf ("%u", new_tab_width);
- gedit_status_combo_box_set_item_text (combo,
- 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));
+ /* Show the last menu item with a custom value */
+ label = g_strdup_printf ("%u", new_tab_width);
+ gtk_menu_item_set_label (GTK_MENU_ITEM (item->data), label);
+ g_free (label);
gtk_widget_show (GTK_WIDGET (item->data));
}
else
@@ -2515,43 +2473,18 @@ language_changed (GObject *object,
GParamSpec *pspec,
GeditWindow *window)
{
- GList *items;
- GList *item;
- GeditStatusComboBox *combo = GEDIT_STATUS_COMBO_BOX (window->priv->language_combo);
GtkSourceLanguage *new_language;
- const gchar *new_id;
-
- items = gedit_status_combo_box_get_items (combo);
+ const gchar *label;
new_language = gtk_source_buffer_get_language (GTK_SOURCE_BUFFER (object));
if (new_language)
- new_id = gtk_source_language_get_id (new_language);
+ label = gtk_source_language_get_name (new_language);
else
- new_id = NULL;
-
- for (item = items; item; item = item->next)
- {
- GtkSourceLanguage *lang = g_object_get_data (G_OBJECT (item->data), LANGUAGE_DATA);
-
- if ((new_id == NULL && lang == NULL) ||
- (new_id != NULL && lang != NULL && strcmp (gtk_source_language_get_id (lang),
- new_id) == 0))
- {
- g_signal_handlers_block_by_func (window->priv->language_combo,
- language_combo_changed,
- window);
-
- gedit_status_combo_box_set_item (GEDIT_STATUS_COMBO_BOX
(window->priv->language_combo),
- GTK_MENU_ITEM (item->data));
+ label = _("Plain Text");
- g_signal_handlers_unblock_by_func (window->priv->language_combo,
- language_combo_changed,
- window);
- }
- }
-
- g_list_free (items);
+ gedit_status_combo_box_set_label (GEDIT_STATUS_COMBO_BOX (window->priv->language_combo),
+ label);
}
static void
@@ -2560,9 +2493,13 @@ update_statusbar (GeditWindow *window,
GeditView *new_view)
{
GeditDocument *doc;
+ GList *items;
+ GtkCheckMenuItem *item;
if (old_view)
{
+ g_clear_object (&window->priv->spaces_instead_of_tabs_binding);
+
if (window->priv->tab_width_id)
{
g_signal_handler_disconnect (old_view,
@@ -2571,14 +2508,6 @@ update_statusbar (GeditWindow *window,
window->priv->tab_width_id = 0;
}
- if (window->priv->spaces_instead_of_tabs_id)
- {
- g_signal_handler_disconnect (old_view,
- window->priv->spaces_instead_of_tabs_id);
-
- window->priv->spaces_instead_of_tabs_id = 0;
- }
-
if (window->priv->language_changed_id)
{
g_signal_handler_disconnect (gtk_text_view_get_buffer (GTK_TEXT_VIEW (old_view)),
@@ -2603,14 +2532,22 @@ update_statusbar (GeditWindow *window,
gtk_widget_show (window->priv->tab_width_combo);
gtk_widget_show (window->priv->language_combo);
+ /* find the use spaces item */
+ items = gtk_container_get_children (GTK_CONTAINER (window->priv->tab_width_combo_menu));
+ item = GTK_CHECK_MENU_ITEM (g_list_last (items)->data);
+ g_list_free (items);
+
+ window->priv->spaces_instead_of_tabs_binding =
+ g_object_bind_property (new_view,
+ "insert-spaces-instead-of-tabs",
+ item,
+ "active",
+ G_BINDING_BIDIRECTIONAL | G_BINDING_SYNC_CREATE);
+
window->priv->tab_width_id = g_signal_connect (new_view,
"notify::tab-width",
G_CALLBACK (tab_width_changed),
window);
- window->priv->spaces_instead_of_tabs_id = g_signal_connect (new_view,
- "notify::insert-spaces-instead-of-tabs",
- G_CALLBACK
(spaces_instead_of_tabs_changed),
- window);
window->priv->language_changed_id = g_signal_connect (doc,
"notify::language",
@@ -2619,7 +2556,6 @@ update_statusbar (GeditWindow *window,
/* call it for the first time */
tab_width_changed (G_OBJECT (new_view), NULL, window);
- spaces_instead_of_tabs_changed (G_OBJECT (new_view), NULL, window);
language_changed (G_OBJECT (doc), NULL, window);
}
@@ -3566,22 +3502,21 @@ on_tab_removed (GeditMultiNotebook *multi,
G_CALLBACK (editable_changed),
window);
- if (window->priv->tab_width_id && tab == gedit_multi_notebook_get_active_tab (multi))
+ if (tab == gedit_multi_notebook_get_active_tab (multi))
{
- g_signal_handler_disconnect (view, window->priv->tab_width_id);
- window->priv->tab_width_id = 0;
- }
+ g_clear_object (&window->priv->spaces_instead_of_tabs_binding);
- if (window->priv->spaces_instead_of_tabs_id && tab == gedit_multi_notebook_get_active_tab (multi))
- {
- g_signal_handler_disconnect (view, window->priv->spaces_instead_of_tabs_id);
- window->priv->spaces_instead_of_tabs_id = 0;
- }
+ if (window->priv->tab_width_id)
+ {
+ g_signal_handler_disconnect (view, window->priv->tab_width_id);
+ window->priv->tab_width_id = 0;
+ }
- if (window->priv->language_changed_id && tab == gedit_multi_notebook_get_active_tab (multi))
- {
- g_signal_handler_disconnect (doc, window->priv->language_changed_id);
- window->priv->language_changed_id = 0;
+ if (window->priv->language_changed_id)
+ {
+ g_signal_handler_disconnect (doc, window->priv->language_changed_id);
+ window->priv->language_changed_id = 0;
+ }
}
g_return_if_fail (num_tabs >= 0);
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]