[nautilus/wip/antoniof/gtk4-preparation-discontinued-api: 9/19] toolbar: Don't subclass HdyHeaderBar




commit ca40468646ec80ad9da782eab303846352c54e5f
Author: António Fernandes <antoniof gnome org>
Date:   Sun Dec 19 12:40:34 2021 +0000

    toolbar: Don't subclass HdyHeaderBar
    
    In GTK4 we are not going to be able to subclass headerbars.
    
    But subclassing GtkWidget directly implies adding a lot of
    boilerplate to behave as a container.
    
    The easy way around that is going to be AdwBin. Use GtkBin for the
    time being, but introduce a wraper for a missing method.

 src/nautilus-gtk4-helpers.c          |   9 +
 src/nautilus-gtk4-helpers.h          |   5 +
 src/nautilus-toolbar.c               |   4 +-
 src/nautilus-toolbar.h               |   2 +-
 src/resources/ui/nautilus-toolbar.ui | 391 ++++++++++++++++++-----------------
 5 files changed, 215 insertions(+), 196 deletions(-)
---
diff --git a/src/nautilus-gtk4-helpers.c b/src/nautilus-gtk4-helpers.c
index 8a20c2dac..3080d76b2 100644
--- a/src/nautilus-gtk4-helpers.c
+++ b/src/nautilus-gtk4-helpers.c
@@ -1,5 +1,14 @@
 #include "nautilus-gtk4-helpers.h"
 
+void
+adw_bin_set_child (AdwBin    *bin,
+                   GtkWidget *child)
+{
+    g_assert (GTK_IS_BIN (bin));
+
+    gtk_container_add (GTK_CONTAINER (bin), child);
+}
+
 void
 gtk_button_set_child (GtkButton *button,
                       GtkWidget *child)
diff --git a/src/nautilus-gtk4-helpers.h b/src/nautilus-gtk4-helpers.h
index 65fa55f31..d966c48cc 100644
--- a/src/nautilus-gtk4-helpers.h
+++ b/src/nautilus-gtk4-helpers.h
@@ -7,6 +7,11 @@
 G_BEGIN_DECLS
 #if GTK_MAJOR_VERSION < 4
 
+#define AdwBin GtkBin
+#define ADW_BIN GTK_BIN
+
+void adw_bin_set_child             (AdwBin            *bin,
+                                    GtkWidget         *child);
 void gtk_button_set_child          (GtkButton         *button,
                                     GtkWidget         *child);
 void gtk_box_append                (GtkBox            *box,
diff --git a/src/nautilus-toolbar.c b/src/nautilus-toolbar.c
index 5fe4e63a4..aedaf68bb 100644
--- a/src/nautilus-toolbar.c
+++ b/src/nautilus-toolbar.c
@@ -60,7 +60,7 @@ typedef enum
 
 struct _NautilusToolbar
 {
-    GtkHeaderBar parent_instance;
+    GtkBin parent_instance;
 
     NautilusWindow *window;
 
@@ -127,7 +127,7 @@ enum
 
 static GParamSpec *properties[NUM_PROPERTIES] = { NULL, };
 
-G_DEFINE_TYPE (NautilusToolbar, nautilus_toolbar, HDY_TYPE_HEADER_BAR);
+G_DEFINE_TYPE (NautilusToolbar, nautilus_toolbar, GTK_TYPE_BIN);
 
 static void nautilus_toolbar_set_window_slot_real (NautilusToolbar    *self,
                                                    NautilusWindowSlot *slot);
diff --git a/src/nautilus-toolbar.h b/src/nautilus-toolbar.h
index 364bc76d8..6f49acee1 100644
--- a/src/nautilus-toolbar.h
+++ b/src/nautilus-toolbar.h
@@ -32,7 +32,7 @@ G_BEGIN_DECLS
 
 #define NAUTILUS_TYPE_TOOLBAR nautilus_toolbar_get_type()
 
-G_DECLARE_FINAL_TYPE (NautilusToolbar, nautilus_toolbar, NAUTILUS, TOOLBAR, HdyHeaderBar)
+G_DECLARE_FINAL_TYPE (NautilusToolbar, nautilus_toolbar, NAUTILUS, TOOLBAR, GtkBin)
 
 GtkWidget *nautilus_toolbar_new (void);
 
diff --git a/src/resources/ui/nautilus-toolbar.ui b/src/resources/ui/nautilus-toolbar.ui
index 8c7fafa0c..d7089d36a 100644
--- a/src/resources/ui/nautilus-toolbar.ui
+++ b/src/resources/ui/nautilus-toolbar.ui
@@ -135,206 +135,108 @@
       </object>
     </child>
   </object>
-  <template class="NautilusToolbar" parent="HdyHeaderBar">
+  <template class="NautilusToolbar" parent="GtkBin">
     <property name="visible">True</property>
-    <property name="can_focus">False</property>
-    <property name="show_close_button">True</property>
-    <child type="title">
-      <object class="GtkBox" id="header_toolbar">
-        <property name="width_request">270</property>
-        <property name="visible">True</property>
-        <property name="can_focus">False</property>
-        <property name="spacing">6</property>
-        <child>
-          <object class="GtkStack" id="toolbar_switcher">
-            <property name="visible">True</property>
-            <property name="can_focus">False</property>
-            <property name="valign">center</property>
-            <property name="hexpand">False</property>
-            <property name="transition_type">crossfade</property>
-            <child>
-              <object class="GtkBox" id="path_bar_container">
-                <property name="can_focus">False</property>
-                <property name="valign">center</property>
-                <style>
-                  <class name="path-bar-box"/>
-                </style>
-              </object>
-              <packing>
-                <property name="name">pathbar</property>
-              </packing>
-            </child>
-            <child>
-              <object class="GtkBox" id="location_entry_container">
-                <property name="can_focus">False</property>
-                <style>
-                  <class name="linked"/>
-                </style>
-              </object>
-              <packing>
-                <property name="name">location</property>
-                <property name="position">1</property>
-              </packing>
-            </child>
-            <child>
-              <object class="GtkBox" id="search_container">
-                <property name="visible">True</property>
-                <property name="can_focus">False</property>
-                <property name="orientation">vertical</property>
-              </object>
-              <packing>
-                <property name="name">search</property>
-                <property name="position">2</property>
-              </packing>
-            </child>
-          </object>
-        </child>
-        <child>
-          <object class="GtkToggleButton" id="search_button">
-            <property name="visible">True</property>
-            <property name="can_focus">True</property>
-            <property name="receives_default">False</property>
-            <property name="tooltip_text" translatable="yes">Search</property>
-            <property name="halign">center</property>
-            <property name="valign">center</property>
-            <property name="action_name">slot.search-visible</property>
-            <child>
-              <object class="GtkImage" id="search_icon">
-                <property name="visible">True</property>
-                <property name="can_focus">False</property>
-                <property name="icon_name">edit-find-symbolic</property>
-                <property name="icon_size">1</property>
-              </object>
-            </child>
-            <style>
-              <class name="image-button"/>
-            </style>
-          </object>
-          <packing>
-            <property name="position">2</property>
-          </packing>
-        </child>
-      </object>
-    </child>
     <child>
-      <object class="GtkBox" id="navigation_box">
+      <object class="HdyHeaderBar">
         <property name="visible">True</property>
         <property name="can_focus">False</property>
-        <child>
-          <object class="GtkButton" id="back_button">
+        <property name="show_close_button">True</property>
+        <child type="title">
+          <object class="GtkBox" id="header_toolbar">
+            <property name="width_request">270</property>
             <property name="visible">True</property>
-            <property name="can_focus">True</property>
-            <property name="receives_default">False</property>
-            <property name="tooltip_text" translatable="yes">Go back</property>
-            <property name="halign">center</property>
-            <property name="valign">center</property>
-            <property name="action_name">win.back</property>
+            <property name="can_focus">False</property>
+            <property name="spacing">6</property>
             <child>
-              <object class="GtkImage" id="back_icon">
+              <object class="GtkStack" id="toolbar_switcher">
                 <property name="visible">True</property>
                 <property name="can_focus">False</property>
-                <property name="icon_name">go-previous-symbolic</property>
-                <property name="icon_size">1</property>
+                <property name="valign">center</property>
+                <property name="hexpand">False</property>
+                <property name="transition_type">crossfade</property>
+                <child>
+                  <object class="GtkBox" id="path_bar_container">
+                    <property name="can_focus">False</property>
+                    <property name="valign">center</property>
+                    <style>
+                      <class name="path-bar-box"/>
+                    </style>
+                  </object>
+                  <packing>
+                    <property name="name">pathbar</property>
+                  </packing>
+                </child>
+                <child>
+                  <object class="GtkBox" id="location_entry_container">
+                    <property name="can_focus">False</property>
+                    <style>
+                      <class name="linked"/>
+                    </style>
+                  </object>
+                  <packing>
+                    <property name="name">location</property>
+                    <property name="position">1</property>
+                  </packing>
+                </child>
+                <child>
+                  <object class="GtkBox" id="search_container">
+                    <property name="visible">True</property>
+                    <property name="can_focus">False</property>
+                    <property name="orientation">vertical</property>
+                  </object>
+                  <packing>
+                    <property name="name">search</property>
+                    <property name="position">2</property>
+                  </packing>
+                </child>
               </object>
             </child>
-            <style>
-              <class name="image-button"/>
-            </style>
-          </object>
-          <packing>
-            <property name="position">0</property>
-          </packing>
-        </child>
-        <child>
-          <object class="GtkButton" id="forward_button">
-            <property name="visible">True</property>
-            <property name="can_focus">True</property>
-            <property name="receives_default">False</property>
-            <property name="tooltip_text" translatable="yes">Go forward</property>
-            <property name="halign">center</property>
-            <property name="valign">center</property>
-            <property name="action_name">win.forward</property>
             <child>
-              <object class="GtkImage" id="forward_icon">
+              <object class="GtkToggleButton" id="search_button">
                 <property name="visible">True</property>
-                <property name="can_focus">False</property>
-                <property name="icon_name">go-next-symbolic</property>
-                <property name="icon_size">1</property>
-              </object>
-            </child>
-            <style>
-              <class name="image-button"/>
-            </style>
-          </object>
-          <packing>
-            <property name="position">1</property>
-          </packing>
-        </child>
-        <style>
-          <class name="linked"/>
-          <class name="raised"/>
-        </style>
-      </object>
-    </child>
-    <child>
-      <object class="GtkBox">
-        <property name="visible">True</property>
-        <property name="can_focus">False</property>
-        <property name="margin_start">72</property>
-        <child>
-          <object class="GtkRevealer" id="operations_revealer">
-            <property name="visible">True</property>
-            <property name="can_focus">False</property>
-            <property name="halign">center</property>
-            <property name="valign">center</property>
-            <property name="transition_type">slide-right</property>
-            <child>
-              <object class="GtkMenuButton" id="operations_button">
                 <property name="can_focus">True</property>
                 <property name="receives_default">False</property>
-                <property name="tooltip_text" translatable="yes">Show operations</property>
-                <property name="margin_end">6</property>
-                <property name="popover">operations_popover</property>
-                <signal name="toggled" handler="on_operations_button_toggled" object="NautilusToolbar" 
swapped="yes"/>
+                <property name="tooltip_text" translatable="yes">Search</property>
+                <property name="halign">center</property>
+                <property name="valign">center</property>
+                <property name="action_name">slot.search-visible</property>
                 <child>
-                  <object class="GtkDrawingArea" id="operations_icon">
-                    <property name="width_request">16</property>
-                    <property name="height_request">16</property>
+                  <object class="GtkImage" id="search_icon">
                     <property name="visible">True</property>
                     <property name="can_focus">False</property>
-                    <property name="halign">center</property>
-                    <property name="valign">center</property>
-                    <signal name="draw" handler="on_operations_icon_draw" object="NautilusToolbar" 
swapped="no"/>
+                    <property name="icon_name">edit-find-symbolic</property>
+                    <property name="icon_size">1</property>
                   </object>
                 </child>
                 <style>
-                  <class name="button"/>
+                  <class name="image-button"/>
                 </style>
               </object>
+              <packing>
+                <property name="position">2</property>
+              </packing>
             </child>
           </object>
-          <packing>
-            <property name="position">0</property>
-          </packing>
         </child>
         <child>
-          <object class="GtkBox">
+          <object class="GtkBox" id="navigation_box">
             <property name="visible">True</property>
             <property name="can_focus">False</property>
-            <property name="halign">center</property>
-            <property name="valign">center</property>
-            <property name="margin_end">6</property>
             <child>
-              <object class="GtkButton" id="view_toggle_button">
+              <object class="GtkButton" id="back_button">
                 <property name="visible">True</property>
                 <property name="can_focus">True</property>
                 <property name="receives_default">False</property>
-                <property name="tooltip_text" translatable="yes">Toggle view</property>
-                <property name="action_name">slot.files-view-mode-toggle</property>
+                <property name="tooltip_text" translatable="yes">Go back</property>
+                <property name="halign">center</property>
+                <property name="valign">center</property>
+                <property name="action_name">win.back</property>
                 <child>
-                  <object class="GtkImage" id="view_toggle_icon">
+                  <object class="GtkImage" id="back_icon">
                     <property name="visible">True</property>
                     <property name="can_focus">False</property>
+                    <property name="icon_name">go-previous-symbolic</property>
                     <property name="icon_size">1</property>
                   </object>
                 </child>
@@ -347,23 +249,24 @@
               </packing>
             </child>
             <child>
-              <object class="GtkMenuButton" id="view_button">
+              <object class="GtkButton" id="forward_button">
                 <property name="visible">True</property>
                 <property name="can_focus">True</property>
-                <property name="receives_default">True</property>
-                <property name="tooltip_text" translatable="yes" comments="“View” is a noun">View 
options</property>
-                <property name="halign">start</property>
-                <property name="action_name">win.view-menu</property>
-                <property name="menu-model">view_menu</property>
+                <property name="receives_default">False</property>
+                <property name="tooltip_text" translatable="yes">Go forward</property>
+                <property name="halign">center</property>
+                <property name="valign">center</property>
+                <property name="action_name">win.forward</property>
                 <child>
-                  <object class="GtkImage">
+                  <object class="GtkImage" id="forward_icon">
                     <property name="visible">True</property>
                     <property name="can_focus">False</property>
-                    <property name="icon_name">pan-down-symbolic</property>
+                    <property name="icon_name">go-next-symbolic</property>
+                    <property name="icon_size">1</property>
                   </object>
                 </child>
                 <style>
-                  <class name="disclosure-button"/>
+                  <class name="image-button"/>
                 </style>
               </object>
               <packing>
@@ -372,41 +275,143 @@
             </child>
             <style>
               <class name="linked"/>
+              <class name="raised"/>
             </style>
           </object>
-          <packing>
-            <property name="position">2</property>
-          </packing>
         </child>
         <child>
-          <object class="GtkMenuButton" id="app_button">
+          <object class="GtkBox">
             <property name="visible">True</property>
-            <property name="can_focus">True</property>
-            <property name="receives_default">False</property>
-            <property name="halign">center</property>
-            <property name="valign">center</property>
-            <property name="menu-model">app_menu</property>
+            <property name="can_focus">False</property>
+            <property name="margin_start">72</property>
             <child>
-              <object class="GtkImage">
+              <object class="GtkRevealer" id="operations_revealer">
                 <property name="visible">True</property>
                 <property name="can_focus">False</property>
-                <property name="icon_name">open-menu-symbolic</property>
-                <property name="icon_size">1</property>
+                <property name="halign">center</property>
+                <property name="valign">center</property>
+                <property name="transition_type">slide-right</property>
+                <child>
+                  <object class="GtkMenuButton" id="operations_button">
+                    <property name="can_focus">True</property>
+                    <property name="receives_default">False</property>
+                    <property name="tooltip_text" translatable="yes">Show operations</property>
+                    <property name="margin_end">6</property>
+                    <property name="popover">operations_popover</property>
+                    <signal name="toggled" handler="on_operations_button_toggled" object="NautilusToolbar" 
swapped="yes"/>
+                    <child>
+                      <object class="GtkDrawingArea" id="operations_icon">
+                        <property name="width_request">16</property>
+                        <property name="height_request">16</property>
+                        <property name="visible">True</property>
+                        <property name="can_focus">False</property>
+                        <property name="halign">center</property>
+                        <property name="valign">center</property>
+                        <signal name="draw" handler="on_operations_icon_draw" object="NautilusToolbar" 
swapped="no"/>
+                      </object>
+                    </child>
+                    <style>
+                      <class name="button"/>
+                    </style>
+                  </object>
+                </child>
               </object>
+              <packing>
+                <property name="position">0</property>
+              </packing>
+            </child>
+            <child>
+              <object class="GtkBox">
+                <property name="visible">True</property>
+                <property name="can_focus">False</property>
+                <property name="halign">center</property>
+                <property name="valign">center</property>
+                <property name="margin_end">6</property>
+                <child>
+                  <object class="GtkButton" id="view_toggle_button">
+                    <property name="visible">True</property>
+                    <property name="can_focus">True</property>
+                    <property name="receives_default">False</property>
+                    <property name="tooltip_text" translatable="yes">Toggle view</property>
+                    <property name="action_name">slot.files-view-mode-toggle</property>
+                    <child>
+                      <object class="GtkImage" id="view_toggle_icon">
+                        <property name="visible">True</property>
+                        <property name="can_focus">False</property>
+                        <property name="icon_size">1</property>
+                      </object>
+                    </child>
+                    <style>
+                      <class name="image-button"/>
+                    </style>
+                  </object>
+                  <packing>
+                    <property name="position">0</property>
+                  </packing>
+                </child>
+                <child>
+                  <object class="GtkMenuButton" id="view_button">
+                    <property name="visible">True</property>
+                    <property name="can_focus">True</property>
+                    <property name="receives_default">True</property>
+                    <property name="tooltip_text" translatable="yes" comments="“View” is a noun">View 
options</property>
+                    <property name="halign">start</property>
+                    <property name="action_name">win.view-menu</property>
+                    <property name="menu-model">view_menu</property>
+                    <child>
+                      <object class="GtkImage">
+                        <property name="visible">True</property>
+                        <property name="can_focus">False</property>
+                        <property name="icon_name">pan-down-symbolic</property>
+                      </object>
+                    </child>
+                    <style>
+                      <class name="disclosure-button"/>
+                    </style>
+                  </object>
+                  <packing>
+                    <property name="position">1</property>
+                  </packing>
+                </child>
+                <style>
+                  <class name="linked"/>
+                </style>
+              </object>
+              <packing>
+                <property name="position">2</property>
+              </packing>
+            </child>
+            <child>
+              <object class="GtkMenuButton" id="app_button">
+                <property name="visible">True</property>
+                <property name="can_focus">True</property>
+                <property name="receives_default">False</property>
+                <property name="halign">center</property>
+                <property name="valign">center</property>
+                <property name="menu-model">app_menu</property>
+                <child>
+                  <object class="GtkImage">
+                    <property name="visible">True</property>
+                    <property name="can_focus">False</property>
+                    <property name="icon_name">open-menu-symbolic</property>
+                    <property name="icon_size">1</property>
+                  </object>
+                </child>
+                <style>
+                  <class name="image-button"/>
+                </style>
+              </object>
+              <packing>
+                <property name="position">3</property>
+              </packing>
             </child>
-            <style>
-              <class name="image-button"/>
-            </style>
           </object>
           <packing>
+            <property name="pack_type">end</property>
             <property name="position">3</property>
           </packing>
         </child>
       </object>
-      <packing>
-        <property name="pack_type">end</property>
-        <property name="position">3</property>
-      </packing>
     </child>
   </template>
 </interface>


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