[glade] GladeWindow: move actions to top



commit 33fa9a707a2c33fdd65c96817755842d1547d378
Author: Juan Pablo Ugarte <juanpablougarte gmail com>
Date:   Wed Jul 29 19:48:44 2020 -0300

    GladeWindow: move actions to top
    
    Give catalog actions a more prominent place than the bottom toolbar
    
    Fix issue #452 "GtkComboBox cell renderers editor is too hard to discover"

 src/glade-window.c | 57 +++++++++++----------------------
 src/glade.glade    | 92 +++++++++++++++++++++++++++++++++---------------------
 2 files changed, 75 insertions(+), 74 deletions(-)
---
diff --git a/src/glade-window.c b/src/glade-window.c
index b12ad4941..c4b8145f1 100644
--- a/src/glade-window.c
+++ b/src/glade-window.c
@@ -101,8 +101,7 @@ struct _GladeWindowPrivate
   GtkWidget *undo_button;       /* undo/redo button, right click for history */
   GtkWidget *redo_button;
 
-  GtkWidget *toolbar;           /* Actions are added to the toolbar */
-  gint actions_start;           /* start of action items */
+  GtkButtonBox *actions;        /* Actions are added to the headerbar */
 
   GtkWidget *center_paned;
   GtkWidget *left_paned;
@@ -235,36 +234,24 @@ action_disconnect (gpointer data, GClosure *closure)
 static void
 clean_actions (GladeWindow *window)
 {
-  GtkContainer *container = GTK_CONTAINER (window->priv->toolbar);
-  GtkToolbar *bar = GTK_TOOLBAR (window->priv->toolbar);
-  GtkToolItem *item;
+  GtkContainer *container = GTK_CONTAINER (window->priv->actions);
+  g_autoptr (GList) children = gtk_container_get_children (container);
+  GList *l;
 
-  if (window->priv->actions_start)
-    {
-      while ((item =
-              gtk_toolbar_get_nth_item (bar, window->priv->actions_start)))
-        gtk_container_remove (container, GTK_WIDGET (item));
-    }
+  for (l = children; l; l = g_list_next(l))
+    gtk_container_remove (container, l->data);
 }
 
 static void
 add_actions (GladeWindow *window, GladeWidget *widget, GList *actions)
 {
-  GtkToolbar *bar = GTK_TOOLBAR (window->priv->toolbar);
-  GtkToolItem *item = gtk_separator_tool_item_new ();
-  gint n = 0;
   GList *l;
 
-  gtk_toolbar_insert (bar, item, -1);
-  gtk_widget_show (GTK_WIDGET (item));
-
-  if (window->priv->actions_start == 0)
-    window->priv->actions_start = gtk_toolbar_get_item_index (bar, item);
-
   for (l = actions; l; l = g_list_next (l))
     {
       GladeWidgetAction    *action = l->data;
       GladeWidgetActionDef *adef   = glade_widget_action_get_def (action);
+      GtkWidget *button;
 
       if (!adef->important || !glade_widget_action_get_visible (action))
         continue;
@@ -275,37 +262,30 @@ add_actions (GladeWindow *window, GladeWidget *widget, GList *actions)
           continue;
         }
 
-      item = gtk_tool_button_new (NULL, adef->label);
-      gtk_tool_button_set_icon_name (GTK_TOOL_BUTTON (item),
-                                     (adef->stock) ? adef->stock : "system-run");
+      button = gtk_button_new_from_icon_name ((adef->stock) ? adef->stock : "system-run-symbolic",
+                                              GTK_ICON_SIZE_MENU);
 
       if (adef->label)
-        gtk_widget_set_tooltip_text (GTK_WIDGET (item), adef->label);
+        gtk_widget_set_tooltip_text (button, adef->label);
 
-      g_object_set_data (G_OBJECT (item), "glade-widget", widget);
+      g_object_set_data (G_OBJECT (button), "glade-widget", widget);
 
       /* We use destroy_data to keep track of notify::sensitive callbacks
        * on the action object and disconnect them when the toolbar item
        * gets destroyed.
        */
-      g_signal_connect_data (item, "clicked",
+      g_signal_connect_data (button, "clicked",
                              G_CALLBACK (activate_action),
                              action, action_disconnect, 0);
 
-      gtk_widget_set_sensitive (GTK_WIDGET (item), 
-                                glade_widget_action_get_sensitive (action));
+      gtk_widget_set_sensitive (button, glade_widget_action_get_sensitive (action));
 
       g_signal_connect (action, "notify::sensitive",
-                        G_CALLBACK (activate_action), GTK_WIDGET (item));
+                        G_CALLBACK (activate_action), button);
 
-      gtk_toolbar_insert (bar, item, -1);
-      gtk_tool_item_set_homogeneous (item, FALSE);
-      gtk_widget_show_all (GTK_WIDGET (item));
-      n++;
+      gtk_widget_show (button);
+      gtk_box_pack_start (GTK_BOX (window->priv->actions), button, FALSE, FALSE, 0);
     }
-
-  if (n == 0)
-    clean_actions (window);
 }
 
 static GladeProject *
@@ -325,6 +305,8 @@ project_selection_changed_cb (GladeProject *project, GladeWindow *window)
   GList        *list;
   gint          num;
 
+  clean_actions (window);
+
   active_project = get_active_project (window);
 
   /* This is sometimes called with a NULL project (to make the label
@@ -344,7 +326,6 @@ project_selection_changed_cb (GladeProject *project, GladeWindow *window)
         {
           glade_widget = glade_widget_get_from_gobject (G_OBJECT (list->data));
 
-          clean_actions (window);
           if (glade_widget_get_actions (glade_widget))
             add_actions (window, glade_widget, glade_widget_get_actions (glade_widget));
         }
@@ -2480,7 +2461,7 @@ glade_window_class_init (GladeWindowClass *klass)
   gtk_widget_class_bind_template_child_private (widget_class, GladeWindow, inspectors_stack);
   gtk_widget_class_bind_template_child_private (widget_class, GladeWindow, editor);
   gtk_widget_class_bind_template_child_private (widget_class, GladeWindow, statusbar);
-  gtk_widget_class_bind_template_child_private (widget_class, GladeWindow, toolbar);
+  gtk_widget_class_bind_template_child_private (widget_class, GladeWindow, actions);
   gtk_widget_class_bind_template_child_private (widget_class, GladeWindow, undo_button);
   gtk_widget_class_bind_template_child_private (widget_class, GladeWindow, redo_button);
 
diff --git a/src/glade.glade b/src/glade.glade
index 2f7e62c3f..75a30a339 100644
--- a/src/glade.glade
+++ b/src/glade.glade
@@ -267,6 +267,7 @@ Author: Juan Pablo Ugarte
                       <object class="GtkToolbar" id="toolbar">
                         <property name="visible">True</property>
                         <property name="can-focus">False</property>
+                        <property name="show-arrow">False</property>
                         <child>
                           <object class="GtkToolButton" id="selector_button">
                             <property name="visible">True</property>
@@ -352,6 +353,22 @@ Author: Juan Pablo Ugarte
                             <property name="can-focus">False</property>
                             <property name="border-width">2</property>
                             <property name="spacing">4</property>
+                            <child>
+                              <object class="GtkButtonBox" id="actions">
+                                <property name="visible">True</property>
+                                <property name="can-focus">False</property>
+                                <property name="homogeneous">True</property>
+                                <property name="layout-style">expand</property>
+                                <child>
+                                  <placeholder/>
+                                </child>
+                              </object>
+                              <packing>
+                                <property name="expand">False</property>
+                                <property name="fill">True</property>
+                                <property name="position">1</property>
+                              </packing>
+                            </child>
                           </object>
                           <packing>
                             <property name="expand">False</property>
@@ -621,6 +638,43 @@ Author: Juan Pablo Ugarte
             <property name="position">3</property>
           </packing>
         </child>
+        <child>
+          <object class="GtkButton" id="intro_button">
+            <property name="name">intro-button</property>
+            <property name="visible">True</property>
+            <property name="can-focus">True</property>
+            <property name="receives-default">True</property>
+            <property name="tooltip-text" translatable="yes">Start/resume interactive UI 
introduction</property>
+            <property name="action-name">app.intro</property>
+            <property name="relief">none</property>
+            <property name="use-underline">True</property>
+            <child>
+              <object class="GtkImage">
+                <property name="name">glade-brand-image</property>
+                <property name="visible">True</property>
+                <property name="can-focus">False</property>
+                <property name="icon-name">glade-brand-symbolic</property>
+                <property name="icon_size">3</property>
+                <style>
+                  <class name="glade-tight-fit"/>
+                </style>
+              </object>
+            </child>
+          </object>
+          <packing>
+            <property name="pack-type">end</property>
+            <property name="position">4</property>
+          </packing>
+        </child>
+        <child>
+          <object class="GtkSeparator">
+            <property name="visible">True</property>
+            <property name="can-focus">False</property>
+          </object>
+          <packing>
+            <property name="position">6</property>
+          </packing>
+        </child>
         <child>
           <object class="GtkButtonBox">
             <property name="visible">True</property>
@@ -673,45 +727,11 @@ Author: Juan Pablo Ugarte
             </child>
           </object>
           <packing>
-            <property name="position">5</property>
-          </packing>
-        </child>
-        <child>
-          <object class="GtkSeparator">
-            <property name="visible">True</property>
-            <property name="can-focus">False</property>
-          </object>
-          <packing>
-            <property name="position">6</property>
+            <property name="position">7</property>
           </packing>
         </child>
         <child>
-          <object class="GtkButton" id="intro_button">
-            <property name="name">intro-button</property>
-            <property name="visible">True</property>
-            <property name="can-focus">True</property>
-            <property name="receives-default">True</property>
-            <property name="tooltip-text" translatable="yes">Start/resume interactive UI 
introduction</property>
-            <property name="action-name">app.intro</property>
-            <property name="relief">none</property>
-            <property name="use-underline">True</property>
-            <child>
-              <object class="GtkImage">
-                <property name="name">glade-brand-image</property>
-                <property name="visible">True</property>
-                <property name="can-focus">False</property>
-                <property name="icon-name">glade-brand-symbolic</property>
-                <property name="icon_size">3</property>
-                <style>
-                  <class name="glade-tight-fit"/>
-                </style>
-              </object>
-            </child>
-          </object>
-          <packing>
-            <property name="pack-type">end</property>
-            <property name="position">7</property>
-          </packing>
+          <placeholder/>
         </child>
       </object>
     </child>


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