[geary: 1/3] main-toolbar: Use a header group



commit 7d207dbb7756b7ec20bdd75d30b4ac915b174f16
Author: Adrien Plazas <kekun plazas laposte net>
Date:   Sat Jan 18 13:27:29 2020 +0100

    main-toolbar: Use a header group
    
    This simplifies the code handling the location of the window decorations
    by using HdyHeaderGroup, whis is designed specifically for that.

 src/client/components/main-toolbar.vala     | 32 +++++------------------------
 src/client/composer/composer-headerbar.vala |  1 +
 src/client/composer/composer-window.vala    |  1 -
 ui/main-toolbar.ui                          |  9 +++++++-
 4 files changed, 14 insertions(+), 29 deletions(-)
---
diff --git a/src/client/components/main-toolbar.vala b/src/client/components/main-toolbar.vala
index 5afaea6c..57a87b00 100644
--- a/src/client/components/main-toolbar.vala
+++ b/src/client/components/main-toolbar.vala
@@ -14,8 +14,6 @@ public class MainToolbar : Gtk.Box {
     public string folder { get; set; }
     // Close button settings
     public bool show_close_button { get; set; default = true; }
-    public bool show_close_button_left { get; private set; default = true; }
-    public bool show_close_button_right { get; private set; default = true; }
     // Search and find bar
     public bool search_open { get; set; default = false; }
     public bool find_open { get; set; default = false; }
@@ -33,7 +31,6 @@ public class MainToolbar : Gtk.Box {
     private Gtk.ToggleButton search_conversations_button;
     [GtkChild]
     private Gtk.MenuButton main_menu_button;
-    private Binding guest_header_binding;
 
     // Conversation header elements
     [GtkChild]
@@ -51,6 +48,9 @@ public class MainToolbar : Gtk.Box {
     [GtkChild]
     private Gtk.ToggleButton find_button;
 
+    [GtkChild]
+    private Hdy.HeaderGroup header_group;
+
     private bool show_trash_button = true;
 
     // Load these at construction time
@@ -72,10 +72,6 @@ public class MainToolbar : Gtk.Box {
             this.bind_property("account", this.folder_header, "title", BindingFlags.SYNC_CREATE);
             this.bind_property("folder", this.folder_header, "subtitle", BindingFlags.SYNC_CREATE);
         }
-        this.bind_property("show-close-button-left", this.folder_header, "show-close-button",
-            BindingFlags.SYNC_CREATE);
-        this.bind_property("show-close-button-right", this.conversation_header, "show-close-button",
-            BindingFlags.SYNC_CREATE);
 
         // Assemble the main/mark menus
         Gtk.Builder builder = new Gtk.Builder.from_resource("/org/gnome/Geary/main-toolbar-menus.ui");
@@ -95,27 +91,21 @@ public class MainToolbar : Gtk.Box {
 
         this.bind_property("find-open", this.find_button, "active",
             BindingFlags.SYNC_CREATE | BindingFlags.BIDIRECTIONAL);
-
-        Gtk.Settings.get_default().notify["gtk-decoration-layout"].connect(set_window_buttons);
-        this.realize.connect(set_window_buttons);
     }
 
     public void set_conversation_header(Gtk.HeaderBar header) {
         conversation_header.hide();
         header.get_style_context().add_class("geary-titlebar");
         header.get_style_context().add_class("geary-titlebar-right");
-        guest_header_binding = bind_property("show-close-button-right", header,
-            "show-close-button", BindingFlags.SYNC_CREATE);
+        this.header_group.add_header_bar(header);
         pack_start(header, true, true);
-        header.decoration_layout = conversation_header.decoration_layout;
     }
 
     public void remove_conversation_header(Gtk.HeaderBar header) {
         remove(header);
         header.get_style_context().remove_class("geary-titlebar");
         header.get_style_context().remove_class("geary-titlebar-right");
-        guest_header_binding.unbind();
-        header.decoration_layout = Gtk.Settings.get_default().gtk_decoration_layout;
+        this.header_group.remove_header_bar(header);
         conversation_header.show();
     }
 
@@ -124,18 +114,6 @@ public class MainToolbar : Gtk.Box {
         update_conversation_buttons();
     }
 
-    private void set_window_buttons() {
-        string[] buttons = Gtk.Settings.get_default().gtk_decoration_layout.split(":");
-        this.show_close_button_left = this.show_close_button;
-        this.show_close_button_right = this.show_close_button;
-        this.folder_header.decoration_layout = buttons[0] + ":";
-        this.conversation_header.decoration_layout = (
-            (buttons.length == 2)
-            ? ":" + buttons[1]
-            : ""
-        );
-    }
-
     // Updates tooltip text depending on number of conversations selected.
     private void update_conversation_buttons() {
         this.mark_message_button.tooltip_text = ngettext(
diff --git a/src/client/composer/composer-headerbar.vala b/src/client/composer/composer-headerbar.vala
index 4fde97cd..9b08c22f 100644
--- a/src/client/composer/composer-headerbar.vala
+++ b/src/client/composer/composer-headerbar.vala
@@ -42,6 +42,7 @@ public class Composer.Headerbar : Gtk.HeaderBar {
         Gtk.Settings.get_default().notify["gtk-decoration-layout"].connect(
             on_gtk_decoration_layout_changed
         );
+        this.show_close_button = this.config.desktop_environment != UNITY;
     }
 
     public override void destroy() {
diff --git a/src/client/composer/composer-window.vala b/src/client/composer/composer-window.vala
index 4e77d8c4..a1488b44 100644
--- a/src/client/composer/composer-window.vala
+++ b/src/client/composer/composer-window.vala
@@ -44,7 +44,6 @@ public class Composer.Window : Gtk.ApplicationWindow, Container {
         if (application.config.desktop_environment == UNITY) {
             composer.embed_header();
         } else {
-            composer.header.show_close_button = true;
             set_titlebar(this.composer.header);
         }
 
diff --git a/ui/main-toolbar.ui b/ui/main-toolbar.ui
index 5cf9e4d8..e9991fff 100644
--- a/ui/main-toolbar.ui
+++ b/ui/main-toolbar.ui
@@ -14,6 +14,7 @@
       <object class="GtkHeaderBar" id="folder_header">
         <property name="visible">True</property>
         <property name="can_focus">False</property>
+        <property name="show_close_button" bind-source="MainToolbar" bind-property="show_close_button" 
bind-flags="sync-create"/>
         <child>
           <object class="GtkButton" id="compose_new_message_button">
             <property name="visible">True</property>
@@ -100,7 +101,7 @@
       <object class="GtkHeaderBar" id="conversation_header">
         <property name="visible">True</property>
         <property name="can_focus">False</property>
-        <property name="show_close_button">True</property>
+        <property name="show_close_button" bind-source="MainToolbar" bind-property="show_close_button" 
bind-flags="sync-create"/>
         <child>
           <object class="GtkBox" id="reply_forward_buttons">
             <property name="visible">True</property>
@@ -344,4 +345,10 @@
       </packing>
     </child>
   </template>
+  <object class="HdyHeaderGroup" id="header_group">
+    <headerbars>
+      <headerbar name="folder_header"/>
+      <headerbar name="conversation_header"/>
+    </headerbars>
+  </object>
 </interface>


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