[nautilus/wip/alexpandelea/batchRename] Use GtkPopoverMenu instead of GtkMenuButton



commit 0578e664db4cb8ab3ea666316e9f462113e7a2cb
Author: Alexandru Pandelea <alexandru pandelea gmail com>
Date:   Wed Jun 29 23:36:53 2016 +0300

    Use GtkPopoverMenu instead of GtkMenuButton
    
    The GtkMenuButton is now a GtkToggleButton that shows a GtkPopoverMenu
    with the same actions that were before in the menu.

 src/nautilus-batch-rename.c                      |   31 +++++++---
 src/resources/ui/nautilus-batch-rename-dialog.ui |   74 ++++++++++++++--------
 2 files changed, 69 insertions(+), 36 deletions(-)
---
diff --git a/src/nautilus-batch-rename.c b/src/nautilus-batch-rename.c
index e5b2d99..50cd0db 100644
--- a/src/nautilus-batch-rename.c
+++ b/src/nautilus-batch-rename.c
@@ -52,6 +52,8 @@ struct _NautilusBatchRename
         GtkWidget               *add_button_label;
         GtkWidget               *numbering_order_label;
         GtkWidget               *scrolled_window;
+        GtkWidget               *numbering_order_popover;
+        GtkWidget               *numbering_order_button;
 
         GList                   *listbox_rows;
 
@@ -238,7 +240,7 @@ create_row_for_label (const gchar *new_text,
         g_object_set_data (G_OBJECT (row), "show-separator", GINT_TO_POINTER (show_separator));
 
         icon = gtk_image_new_from_icon_name ("media-playlist-consecutive-symbolic",
-                                            GTK_ICON_SIZE_SMALL_TOOLBAR);
+                                            GTK_ICON_SIZE_SMALL_TOOLBAR);
 
         box = g_object_new (GTK_TYPE_BOX,
                             "orientation",GTK_ORIENTATION_HORIZONTAL,
@@ -451,6 +453,21 @@ add_popover_closed (NautilusBatchRename *dialog)
 }
 
 static void
+numbering_order_button_clicked (NautilusBatchRename *dialog)
+{
+        if (gtk_widget_is_visible (dialog->numbering_order_popover))
+                gtk_widget_set_visible (dialog->numbering_order_popover, FALSE);
+        else
+                gtk_widget_set_visible (dialog->numbering_order_popover, TRUE);
+}
+
+static void
+numbering_order_popover_closed (NautilusBatchRename *dialog)
+{
+        gtk_toggle_button_set_active (GTK_TOGGLE_BUTTON (dialog->numbering_order_button), FALSE);
+}
+
+static void
 nautilus_batch_rename_initialize_actions (NautilusBatchRename *dialog)
 {
         GAction *action;
@@ -464,14 +481,6 @@ nautilus_batch_rename_initialize_actions (NautilusBatchRename *dialog)
         gtk_widget_insert_action_group (GTK_WIDGET (dialog),
                                         "dialog",
                                         G_ACTION_GROUP (dialog->action_group));
-
-        action = g_action_map_lookup_action (G_ACTION_MAP (dialog->action_group),
-                                             "numbering-order-changed-ascending");
-        g_simple_action_set_enabled (G_SIMPLE_ACTION (action),TRUE);
-
-        action = g_action_map_lookup_action (G_ACTION_MAP (dialog->action_group),
-                                             "numbering-order-changed-descending");
-        g_simple_action_set_enabled (G_SIMPLE_ACTION (action),TRUE);
 }
 
 static void
@@ -501,6 +510,8 @@ nautilus_batch_rename_class_init (NautilusBatchRenameClass *klass)
         gtk_widget_class_bind_template_child (widget_class, NautilusBatchRename, add_button_label);
         gtk_widget_class_bind_template_child (widget_class, NautilusBatchRename, numbering_order_label);
         gtk_widget_class_bind_template_child (widget_class, NautilusBatchRename, scrolled_window);
+        gtk_widget_class_bind_template_child (widget_class, NautilusBatchRename, numbering_order_popover);
+        gtk_widget_class_bind_template_child (widget_class, NautilusBatchRename, numbering_order_button);
 
         gtk_widget_class_bind_template_callback (widget_class, file_names_widget_entry_on_changed);
         gtk_widget_class_bind_template_callback (widget_class, batch_rename_dialog_on_closed);
@@ -508,6 +519,8 @@ nautilus_batch_rename_class_init (NautilusBatchRenameClass *klass)
         gtk_widget_class_bind_template_callback (widget_class, batch_rename_mode_changed);
         gtk_widget_class_bind_template_callback (widget_class, add_button_clicked);
         gtk_widget_class_bind_template_callback (widget_class, add_popover_closed);
+        gtk_widget_class_bind_template_callback (widget_class, numbering_order_button_clicked);
+        gtk_widget_class_bind_template_callback (widget_class, numbering_order_popover_closed);
 }
 
 GtkWidget*
diff --git a/src/resources/ui/nautilus-batch-rename-dialog.ui 
b/src/resources/ui/nautilus-batch-rename-dialog.ui
index 553dd64..6c1f529 100644
--- a/src/resources/ui/nautilus-batch-rename-dialog.ui
+++ b/src/resources/ui/nautilus-batch-rename-dialog.ui
@@ -148,11 +148,9 @@
                       </packing>
                     </child>
                     <child>
-                      <object class="GtkMenuButton" id="numbering_order_button">
+                      <object class="GtkToggleButton" id="numbering_order_button">
                         <property name="visible">True</property>
-                        <property name="sensitive">True</property>
-                        <property name="use-popover">True</property>
-                        <property name="menu_model">numbering_order_menu</property>
+                        <signal name="toggled" handler="numbering_order_button_clicked" swapped="yes" />
                         <child>
                           <object class="GtkBox">
                             <property name="visible">True</property>
@@ -306,8 +304,8 @@
   </template>
 
   <object class="GtkPopover" id="add_popover">
-    <property name="relative-to">add_button</property>
     <property name="position">bottom</property>
+    <property name="relative-to">add_button</property>
     <signal name="closed" handler="add_popover_closed" swapped="yes" />
     <child>
       <object class="GtkLabel">
@@ -323,26 +321,48 @@
     <property name="visible">True</property>
     <property name="icon_name">object-select-symbolic</property>
   </object>
-
-  <menu id="numbering_order_menu">
-    <section>
-      <item>
-        <attribute name="id">ascending</attribute>
-        <attribute name="label" translatable="yes">Original name (Ascending) </attribute>
-        <attribute name="action">dialog.numbering-order-changed-ascending</attribute>
-      </item>
-      <item>
-        <attribute name="label" translatable="yes">Original name (Descending)</attribute>
-        <attribute name="action">dialog.numbering-order-changed-descending</attribute>
-      </item>
-      <item>
-        <attribute name="label" translatable="yes">First Modified</attribute>
-        <attribute name="action">dialog.numbering-order-changed-first-modified</attribute>
-      </item>
-      <item>
-        <attribute name="label" translatable="yes">Last Modified</attribute>
-        <attribute name="action">dialog.numbering-order-changed-last-modified</attribute>
-      </item>
-    </section>
-  </menu>
+  <object class="GtkPopoverMenu" id="numbering_order_popover">
+    <property name="relative-to">numbering_order_button</property>
+    <property name="position">bottom</property>
+    <signal name="closed" handler="numbering_order_popover_closed" swapped="yes" />
+    <child>
+      <object class="GtkBox">
+        <property name="visible">True</property>
+        <property name="can_focus">True</property>
+        <property name="orientation">vertical</property>
+        <child>
+          <object class="GtkModelButton" id="original_ascending">
+            <property name="visible">True</property>
+            <property name="can_focus">True</property>
+            <property name="text" translatable="yes">Original name (Ascending) </property>
+            <property name="action-name">dialog.numbering-order-changed-ascending</property>
+          </object>
+        </child>
+        <child>
+          <object class="GtkModelButton" id="original_descending">
+            <property name="visible">True</property>
+            <property name="can_focus">True</property>
+            <property name="text" translatable="yes">Original name (Descending) </property>
+            <property name="action-name">dialog.numbering-order-changed-descending</property>
+          </object>
+        </child>
+        <child>
+          <object class="GtkModelButton" id="first_modified">
+            <property name="visible">True</property>
+            <property name="can_focus">True</property>
+            <property name="text" translatable="yes">First Modified</property>
+            <property name="action-name">dialog.numbering-order-changed-first-modified</property>
+          </object>
+        </child>
+        <child>
+          <object class="GtkModelButton" id="last_modified">
+            <property name="visible">True</property>
+            <property name="can_focus">True</property>
+            <property name="text" translatable="yes">Last Modified</property>
+            <property name="action-name">dialog.numbering-order-changed-last-modified</property>
+          </object>
+        </child>
+      </object>
+    </child>
+  </object>
 </interface>
\ No newline at end of file


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