[geary] Set the side of the window buttons in the HeaderBar from the GTK theme



commit 02eca78f64626b1ae2bfdf7591379c9a7e83905c
Author: Robert Schroll <rschroll gmail com>
Date:   Sat Jul 19 22:51:51 2014 -0400

    Set the side of the window buttons in the HeaderBar from the GTK theme
    
    Make two sets of the buttons, one for the start and one for the end of
    the HeaderBar, and show one or the other based on the the theme.  Watch
    the style context for changes in the theme and update accordingly.  Once
    the composer is detached, the default close button is used, so hide both
    and stop watching for style updates.  This assumes we never re-attach a
    composer.
    
    We also add a bit of space between the separator and the detach button.
    
    https://bugzilla.gnome.org/show_bug.cgi?id=733372

 src/client/composer/composer-headerbar.vala |   58 ++++++++++++++++++++++-----
 1 files changed, 48 insertions(+), 10 deletions(-)
---
diff --git a/src/client/composer/composer-headerbar.vala b/src/client/composer/composer-headerbar.vala
index 3d1f40f..948b425 100644
--- a/src/client/composer/composer-headerbar.vala
+++ b/src/client/composer/composer-headerbar.vala
@@ -12,6 +12,8 @@ public class ComposerHeaderbar : PillHeaderbar {
     
     private Gtk.Button recipients;
     private Gtk.Label recipients_label;
+    private Gtk.Box win_buttons_start;
+    private Gtk.Box win_buttons_end;
     
     public ComposerHeaderbar(Gtk.ActionGroup action_group) {
         base(action_group);
@@ -21,14 +23,33 @@ public class ComposerHeaderbar : PillHeaderbar {
         Gtk.Button send_button = create_toolbar_button(null, ComposerWidget.ACTION_SEND, true);
         send_button.get_style_context().add_class("suggested-action");
         
-        Gtk.Box win_buttons = new Gtk.Box(Gtk.Orientation.HORIZONTAL, 0);
+        bool rtl = (get_direction() == Gtk.TextDirection.RTL);
+        
+        win_buttons_start = new Gtk.Box(Gtk.Orientation.HORIZONTAL, 0);
         Gtk.Button detach_button = create_toolbar_button(null, ComposerWidget.ACTION_DETACH);
         Gtk.Button close_button = create_toolbar_button(null, ComposerWidget.ACTION_CLOSE);
         detach_button.set_relief(Gtk.ReliefStyle.NONE);
         close_button.set_relief(Gtk.ReliefStyle.NONE);
-        win_buttons.pack_end(close_button);
-        win_buttons.pack_end(detach_button);
-        win_buttons.pack_end(new Gtk.Separator(Gtk.Orientation.VERTICAL));
+        if (rtl)
+            detach_button.set_margin_left(6);
+        else
+            detach_button.set_margin_right(6);
+        win_buttons_start.pack_start(close_button);
+        win_buttons_start.pack_start(detach_button);
+        win_buttons_start.pack_start(new Gtk.Separator(Gtk.Orientation.VERTICAL));
+        
+        win_buttons_end = new Gtk.Box(Gtk.Orientation.HORIZONTAL, 0);
+        detach_button = create_toolbar_button(null, ComposerWidget.ACTION_DETACH);
+        close_button = create_toolbar_button(null, ComposerWidget.ACTION_CLOSE);
+        detach_button.set_relief(Gtk.ReliefStyle.NONE);
+        close_button.set_relief(Gtk.ReliefStyle.NONE);
+        if (rtl)
+            detach_button.set_margin_right(6);
+        else
+            detach_button.set_margin_left(6);
+        win_buttons_end.pack_end(close_button);
+        win_buttons_end.pack_end(detach_button);
+        win_buttons_end.pack_end(new Gtk.Separator(Gtk.Orientation.VERTICAL));
         
         Gtk.Box attach_buttons = new Gtk.Box(Gtk.Orientation.HORIZONTAL, 0);
         Gtk.Button attach_only = create_toolbar_button(null, ComposerWidget.ACTION_ADD_ATTACHMENT);
@@ -46,11 +67,12 @@ public class ComposerHeaderbar : PillHeaderbar {
         recipients.add(recipients_label);
         recipients.clicked.connect(() => { state = ComposerWidget.ComposerState.INLINE; });
         
-        bind_property("state", win_buttons, "visible", BindingFlags.SYNC_CREATE,
-            (binding, source_value, ref target_value) => {
-                target_value = (state != ComposerWidget.ComposerState.DETACHED);
-                return true;
-            });
+        notify["state"].connect((s, p) => {
+            if (state == ComposerWidget.ComposerState.DETACHED) {
+                get_style_context().changed.disconnect(set_win_buttons_side);
+                win_buttons_start.visible = win_buttons_end.visible = false;
+            }
+        });
         bind_property("state", recipients, "visible", BindingFlags.SYNC_CREATE,
             (binding, source_value, ref target_value) => {
                 target_value = (state == ComposerWidget.ComposerState.INLINE_COMPACT);
@@ -62,20 +84,36 @@ public class ComposerHeaderbar : PillHeaderbar {
             BindingFlags.SYNC_CREATE);
         bind_property("send-enabled", send_button, "sensitive", BindingFlags.SYNC_CREATE);
         
+        add_start(win_buttons_start);
         add_start(attach_buttons);
         add_start(recipients);
 #if !GTK_3_12
         add_end(send_button);
 #endif
-        add_end(win_buttons);
+        add_end(win_buttons_end);
 #if GTK_3_12
         add_end(send_button);
 #endif
+        get_style_context().changed.connect(set_win_buttons_side);
     }
     
     public void set_recipients(string label, string tooltip) {
         recipients_label.label = label;
         recipients.tooltip_text = tooltip;
     }
+    
+    private void set_win_buttons_side() {
+        string layout;
+        bool at_end = false;
+        get_toplevel().style_get("decoration-button-layout", out layout);
+        // Based on logic of close_button_at_end in gtkheaderbar.c: Close button appears
+        // at end iff "close" follows a colon in the layout string.
+        if (layout != null) {
+            int colon_ind = layout.index_of(":");
+            at_end = (colon_ind >= 0 && layout.index_of("close", colon_ind) >= 0);
+        }
+        win_buttons_start.visible = !at_end;
+        win_buttons_end.visible = at_end;
+    }
 }
 


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