[nautilus/wip/neilh/toolbar-reorg: 1/16] toolbar: convert action menu from GMenu into GtkPopoverMenu



commit 6ab063d474c4535821bf7065e844d2a87a45ed4d
Author: Neil Herald <neil herald gmail com>
Date:   Sun Apr 24 10:20:04 2016 +0100

    toolbar: convert action menu from GMenu into GtkPopoverMenu
    
    This is in preparation for merging the view menu into the action menu.
    The action menu is currently a GMenu, which doesn't support the controls
    we have on the view menu, e.g. the zoom slider and the button rows.
    Converting to a GtkPopoverMenu will allow us to merge the menus.
    
    This is part of the toolbar menu redesign to improve the usability of
    the menus.
    
    https://bugzilla.gnome.org/show_bug.cgi?id=764632

 src/nautilus-toolbar.c                           |   32 +++++--
 src/nautilus-toolbar.h                           |    5 +-
 src/nautilus-ui-utilities.c                      |   23 ----
 src/nautilus-ui-utilities.h                      |    3 -
 src/nautilus-window.c                            |   11 +--
 src/resources/ui/nautilus-toolbar-action-menu.ui |  124 ++++++++++++++++------
 6 files changed, 124 insertions(+), 74 deletions(-)
---
diff --git a/src/nautilus-toolbar.c b/src/nautilus-toolbar.c
index b5ab60a..c4a9620 100644
--- a/src/nautilus-toolbar.c
+++ b/src/nautilus-toolbar.c
@@ -73,7 +73,8 @@ struct _NautilusToolbarPrivate {
         GtkWidget *operations_revealer;
         GtkWidget *operations_icon;
        GtkWidget *view_icon;
-       GMenu *action_menu;
+        GtkWidget *undo_button;
+        GtkWidget *redo_button;
 
        GtkWidget *forward_button;
        GtkWidget *back_button;
@@ -769,9 +770,11 @@ nautilus_toolbar_init (NautilusToolbar *self)
                                          self->priv->location_entry);
 
        builder = gtk_builder_new_from_resource ("/org/gnome/nautilus/ui/nautilus-toolbar-action-menu.ui");
-       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));
+        self->priv->undo_button = GTK_WIDGET (gtk_builder_get_object (builder, "undo"));
+        self->priv->redo_button = GTK_WIDGET (gtk_builder_get_object (builder, "redo"));
+        gtk_menu_button_set_popover (GTK_MENU_BUTTON (self->priv->action_button),
+                                     GTK_WIDGET (gtk_builder_get_object (builder, "action_menu_widget")));
+
        g_object_unref (builder);
 
         self->priv->progress_manager = nautilus_progress_info_manager_dup_singleton ();
@@ -919,10 +922,25 @@ nautilus_toolbar_new ()
                             NULL);
 }
 
-GMenu *
-nautilus_toolbar_get_action_menu (NautilusToolbar *self)
+static void
+set_string_property (GObject *object,
+                     char    *prop_name,
+                     char    *value)
+{
+        GValue val = G_VALUE_INIT;
+        g_value_init (&val, G_TYPE_STRING);
+        g_value_set_string (&val, value);
+        g_object_set_property (object, prop_name, &val);
+        g_value_unset (&val);
+}
+
+void
+nautilus_toolbar_update_undo_redo_labels (NautilusToolbar *self,
+                                          gchar           *undo_label,
+                                          gchar           *redo_label)
 {
-       return self->priv->action_menu;
+        set_string_property (G_OBJECT (self->priv->undo_button), "text", undo_label);
+        set_string_property (G_OBJECT (self->priv->redo_button), "text", redo_label);
 }
 
 GtkWidget *
diff --git a/src/nautilus-toolbar.h b/src/nautilus-toolbar.h
index 573c7c2..1b2a1eb 100644
--- a/src/nautilus-toolbar.h
+++ b/src/nautilus-toolbar.h
@@ -66,7 +66,10 @@ GtkWidget *nautilus_toolbar_new (void);
 
 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_update_undo_redo_labels (NautilusToolbar *self,
+                                               gchar           *undo_label,
+                                               gchar           *redo_label);
 
 void nautilus_toolbar_set_show_location_entry (NautilusToolbar *self,
                                               gboolean show_location_entry);
diff --git a/src/nautilus-ui-utilities.c b/src/nautilus-ui-utilities.c
index 67acdf5..837178b 100644
--- a/src/nautilus-ui-utilities.c
+++ b/src/nautilus-ui-utilities.c
@@ -145,29 +145,6 @@ 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/src/nautilus-ui-utilities.h b/src/nautilus-ui-utilities.h
index 46e8203..c214b80 100644
--- a/src/nautilus-ui-utilities.h
+++ b/src/nautilus-ui-utilities.h
@@ -34,9 +34,6 @@ 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-window.c b/src/nautilus-window.c
index 936db68..1d0b416 100644
--- a/src/nautilus-window.c
+++ b/src/nautilus-window.c
@@ -435,7 +435,6 @@ undo_manager_changed (NautilusWindow *window)
        gboolean undo_active, redo_active;
        gchar *undo_label, *undo_description, *redo_label, *redo_description;
        gboolean is_undo;
-       GMenu* undo_section;
        GAction *action;
 
        toolbar = NAUTILUS_TOOLBAR (window->priv->toolbar);
@@ -459,16 +458,12 @@ undo_manager_changed (NautilusWindow *window)
        action = g_action_map_lookup_action (G_ACTION_MAP (window), "redo");
        g_simple_action_set_enabled (G_SIMPLE_ACTION (action), redo_active);
 
-       undo_section = g_menu_new ();
        undo_label = undo_active ? undo_label : g_strdup (_("Undo"));
        redo_label = redo_active ? redo_label : g_strdup (_("Redo"));
-       g_menu_append (undo_section, undo_label, "win.undo");
-       g_menu_append (undo_section, redo_label, "win.redo");
-       nautilus_gmenu_replace_section (nautilus_toolbar_get_action_menu (toolbar),
-                                       "undo-redo-section",
-                                       G_MENU_MODEL (undo_section));
+        undo_label = undo_label == NULL ? g_strdup (_("Undo")) : undo_label;
+        redo_label = redo_label == NULL ? g_strdup (_("Redo")) : redo_label;
+        nautilus_toolbar_update_undo_redo_labels (toolbar, undo_label, redo_label);
 
-       g_object_unref (undo_section);
        g_free (undo_label);
        g_free (undo_description);
        g_free (redo_label);
diff --git a/src/resources/ui/nautilus-toolbar-action-menu.ui 
b/src/resources/ui/nautilus-toolbar-action-menu.ui
index a0eefd6..2ac1e24 100644
--- a/src/resources/ui/nautilus-toolbar-action-menu.ui
+++ b/src/resources/ui/nautilus-toolbar-action-menu.ui
@@ -1,35 +1,95 @@
 <?xml version="1.0"?>
 <interface>
   <!-- interface-requires gtk+ 3.0 -->
-  <menu id="action-menu">
-    <section>
-      <item>
-        <attribute name="label" translatable="yes">New _Folder</attribute>
-        <attribute name="action">view.new-folder</attribute>
-      </item>
-      <item>
-        <attribute name="label" translatable="yes">New _Tab</attribute>
-        <attribute name="action">win.new-tab</attribute>
-      </item>
-    </section>
-    <section>
-      <attribute name="id">undo-redo-section</attribute>
-    </section>
-    <section>
-      <item>
-        <attribute name="label" translatable="yes">Select _All</attribute>
-        <attribute name="action">view.select-all</attribute>
-      </item>
-      <item>
-        <attribute name="label" translatable="yes">Enter _Location</attribute>
-        <attribute name="action">win.enter-location</attribute>
-      </item>
-    </section>
-    <section>
-      <item>
-        <attribute name="label" translatable="yes">_Bookmark this Location</attribute>
-        <attribute name="action">win.bookmark-current-location</attribute>
-      </item>
-    </section>
-  </menu>
-</interface>
\ No newline at end of file
+  <object class="GtkPopoverMenu" id="action_menu_widget">
+    <child>
+      <object class="GtkBox">
+        <property name="visible">True</property>
+        <property name="can_focus">False</property>
+        <property name="border_width">9</property>
+        <property name="orientation">vertical</property>
+        <property name="width_request">160</property>
+        <child>
+          <object class="GtkModelButton" id="new-folder">
+            <property name="visible">True</property>
+            <property name="can_focus">True</property>
+            <property name="text" translatable="yes">New _Folder</property>
+            <property name="action-name">view.new-folder</property>
+          </object>
+        </child>
+        <child>
+          <object class="GtkModelButton" id="new-tab">
+            <property name="visible">True</property>
+            <property name="can_focus">True</property>
+            <property name="text" translatable="yes">New _Tab</property>
+            <property name="action-name">win.new-tab</property>
+          </object>
+        </child>
+        <child>
+          <object class="GtkSeparator">
+            <property name="visible">True</property>
+            <property name="orientation">horizontal</property>
+            <property name="margin-top">6</property>
+            <property name="margin-bottom">6</property>
+          </object>
+        </child>
+        <child>
+          <object class="GtkModelButton" id="undo">
+            <property name="visible">True</property>
+            <property name="can_focus">True</property>
+            <property name="text" translatable="yes">Undo</property>
+            <property name="action-name">win.undo</property>
+          </object>
+        </child>
+        <child>
+          <object class="GtkModelButton" id="redo">
+            <property name="visible">True</property>
+            <property name="can_focus">True</property>
+            <property name="text" translatable="yes">Redo</property>
+            <property name="action-name">win.redo</property>
+          </object>
+        </child>
+        <child>
+          <object class="GtkSeparator">
+            <property name="visible">True</property>
+            <property name="orientation">horizontal</property>
+            <property name="margin-top">6</property>
+            <property name="margin-bottom">6</property>
+          </object>
+        </child>
+        <child>
+          <object class="GtkModelButton" id="select-all">
+            <property name="visible">True</property>
+            <property name="can_focus">True</property>
+            <property name="text" translatable="yes">Select _All</property>
+            <property name="action-name">view.select-all</property>
+          </object>
+        </child>
+        <child>
+          <object class="GtkModelButton" id="enter-location">
+            <property name="visible">True</property>
+            <property name="can_focus">True</property>
+            <property name="text" translatable="yes">Enter _Location</property>
+            <property name="action-name">win.enter-location</property>
+          </object>
+        </child>
+        <child>
+          <object class="GtkSeparator">
+            <property name="visible">True</property>
+            <property name="orientation">horizontal</property>
+            <property name="margin-top">6</property>
+            <property name="margin-bottom">6</property>
+          </object>
+        </child>
+        <child>
+          <object class="GtkModelButton" id="bookmark-this-location">
+            <property name="visible">True</property>
+            <property name="can_focus">True</property>
+            <property name="text" translatable="yes">_Bookmark this Location</property>
+            <property name="action-name">win.bookmark-current-location</property>
+          </object>
+        </child>
+      </object>
+    </child>
+  </object>
+</interface>


[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]