summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorCosimo Cecchi <cosimoc@gnome.org>2015-01-25 17:12:09 +0000
committerCosimo Cecchi <cosimoc@gnome.org>2015-01-26 11:19:22 +0000
commitbe0f488a2d2525deab363ebf98ce548395e60d90 (patch)
treea17b1c6baa1037ec431a89ae494e1d014f6796c3
parentb20990b1eb4d1d4636d409f3235133358994059a (diff)
downloadnautilus-be0f488a2d2525deab363ebf98ce548395e60d90.tar.gz
toolbar: rework how Undo/Redo actions are added to the menu
Currently we always reload the menu from scratch and reset the menu button; the intent of the code here is to modify the menu in-place.
-rw-r--r--libnautilus-private/nautilus-ui-utilities.c23
-rw-r--r--libnautilus-private/nautilus-ui-utilities.h3
-rw-r--r--src/nautilus-toolbar.c24
-rw-r--r--src/nautilus-toolbar.h4
-rw-r--r--src/nautilus-view.c15
5 files changed, 41 insertions, 28 deletions
diff --git a/libnautilus-private/nautilus-ui-utilities.c b/libnautilus-private/nautilus-ui-utilities.c
index 388b9b74e..71619b325 100644
--- a/libnautilus-private/nautilus-ui-utilities.c
+++ b/libnautilus-private/nautilus-ui-utilities.c
@@ -144,6 +144,29 @@ nautilus_gmenu_add_item_in_submodel (GMenu *menu,
}
void
+nautilus_gmenu_replace_section (GMenu *menu,
+ const gchar *section_id,
+ GMenuModel *section)
+{
+ GMenuModel *orig_section;
+ GMenuItem *item;
+ gint idx;
+
+ orig_section = find_gmenu_model (G_MENU_MODEL (menu), section_id);
+ g_return_if_fail (orig_section != NULL);
+
+ g_menu_remove_all (G_MENU (orig_section));
+
+ for (idx = 0; idx < g_menu_model_get_n_items (section); idx++) {
+ item = g_menu_item_new_from_model (section, idx);
+ g_menu_append_item (G_MENU (orig_section), item);
+ g_object_unref (item);
+ }
+
+ g_object_unref (orig_section);
+}
+
+void
nautilus_pop_up_context_menu (GtkWidget *parent,
GMenu *menu,
GdkEventButton *event)
diff --git a/libnautilus-private/nautilus-ui-utilities.h b/libnautilus-private/nautilus-ui-utilities.h
index 18b3d78a4..f85dacd26 100644
--- a/libnautilus-private/nautilus-ui-utilities.h
+++ b/libnautilus-private/nautilus-ui-utilities.h
@@ -35,6 +35,9 @@ void nautilus_gmenu_merge (GMenu *original,
GMenu *gmenu_to_merge,
const gchar *submodel_name,
gboolean prepend);
+void nautilus_gmenu_replace_section (GMenu *menu,
+ const gchar *section_id,
+ GMenuModel *section);
void nautilus_pop_up_context_menu (GtkWidget *parent,
GMenu *menu,
GdkEventButton *event);
diff --git a/src/nautilus-toolbar.c b/src/nautilus-toolbar.c
index 461a6a58f..4a2052a01 100644
--- a/src/nautilus-toolbar.c
+++ b/src/nautilus-toolbar.c
@@ -565,29 +565,11 @@ nautilus_toolbar_class_init (NautilusToolbarClass *klass)
}
void
-nautilus_toolbar_action_menu_add_item (NautilusToolbar *self,
- GMenuItem *item,
- const gchar *section_name)
-{
- nautilus_gmenu_add_item_in_submodel (self->priv->action_menu,
- item,
- section_name,
- FALSE);
-}
-
-void
nautilus_toolbar_reset_menus (NautilusToolbar *self)
{
NautilusWindowSlot *slot;
NautilusView *view;
GActionGroup *view_action_group;
- GtkBuilder *builder;
-
- builder = gtk_builder_new_from_resource ("/org/gnome/nautilus/nautilus-toolbar-action-menu.xml");
- self->priv->action_menu = G_MENU (gtk_builder_get_object (builder, "action-menu"));
- gtk_menu_button_set_menu_model (GTK_MENU_BUTTON (self->priv->action_button),
- G_MENU_MODEL (self->priv->action_menu));
- g_object_unref (builder);
/* Allow actions from the current view to be activated through
* the view menu and action menu of the toolbar */
@@ -648,6 +630,12 @@ nautilus_toolbar_new (NautilusWindow *window)
NULL);
}
+GMenu *
+nautilus_toolbar_get_action_menu (NautilusToolbar *self)
+{
+ return self->priv->action_menu;
+}
+
GtkWidget *
nautilus_toolbar_get_path_bar (NautilusToolbar *self)
{
diff --git a/src/nautilus-toolbar.h b/src/nautilus-toolbar.h
index bfec6233e..a2caf496e 100644
--- a/src/nautilus-toolbar.h
+++ b/src/nautilus-toolbar.h
@@ -67,12 +67,10 @@ GtkWidget *nautilus_toolbar_new (NautilusWindow *window);
GtkWidget *nautilus_toolbar_get_path_bar (NautilusToolbar *self);
GtkWidget *nautilus_toolbar_get_location_entry (NautilusToolbar *self);
+GMenu *nautilus_toolbar_get_action_menu (NautilusToolbar *self);
void nautilus_toolbar_set_show_location_entry (NautilusToolbar *self,
gboolean show_location_entry);
-void nautilus_toolbar_action_menu_add_item (NautilusToolbar *self,
- GMenuItem *item,
- const gchar *section_name);
void nautilus_toolbar_reset_menus (NautilusToolbar *self);
void nautilus_toolbar_view_menu_widget_set_zoom_level (NautilusToolbar *self,
diff --git a/src/nautilus-view.c b/src/nautilus-view.c
index 7443f4ad6..d689b5249 100644
--- a/src/nautilus-view.c
+++ b/src/nautilus-view.c
@@ -6417,8 +6417,8 @@ real_update_toolbar_menus (NautilusView *view)
NautilusFileUndoManagerState undo_state;
gboolean undo_active, redo_active;
gchar *undo_label, *undo_description, *redo_label, *redo_description;
- GMenuItem *undo_menu_item, *redo_menu_item;
gboolean is_undo;
+ GMenu* undo_section;
undo_label = undo_description = redo_label = redo_description = NULL;
@@ -6441,17 +6441,18 @@ real_update_toolbar_menus (NautilusView *view)
&redo_label, &redo_description);
}
+ undo_section = g_menu_new ();
undo_label = undo_active ? undo_label : g_strdup (_("Undo"));
redo_label = redo_active ? redo_label : g_strdup (_("Redo"));
- undo_menu_item = g_menu_item_new (undo_label, "view.undo");
- redo_menu_item = g_menu_item_new (redo_label, "view.redo");
- nautilus_toolbar_action_menu_add_item (toolbar, undo_menu_item, "undo-redo-section");
- nautilus_toolbar_action_menu_add_item (toolbar, redo_menu_item, "undo-redo-section");
+ g_menu_append (undo_section, undo_label, "view.undo");
+ g_menu_append (undo_section, redo_label, "view.redo");
+ nautilus_gmenu_replace_section (nautilus_toolbar_get_action_menu (toolbar),
+ "undo-redo-section",
+ G_MENU_MODEL (undo_section));
nautilus_view_update_actions_state (view);
- g_object_unref (undo_menu_item);
- g_object_unref (redo_menu_item);
+ g_object_unref (undo_section);
g_free (undo_label);
g_free (undo_description);
g_free (redo_label);