[geary: 2/6] conversation-viewer: move actions to the bottom when they don't fit




commit 9c6ca541cc0d35e0629ecd8ba88be63abfa5317d
Author: Julian Sparber <julian sparber net>
Date:   Fri Oct 9 17:20:31 2020 +0200

    conversation-viewer: move actions to the bottom when they don't fit

 .../application/application-main-window.vala       |  8 ++-
 .../components-conversation-action-bar.vala        | 12 ++--
 .../components-conversation-header-bar.vala        | 70 ++++++++++++++++++++++
 src/client/components/main-toolbar.vala            | 24 ++++----
 .../conversation-viewer/conversation-viewer.vala   |  1 -
 src/client/meson.build                             |  1 +
 ui/application-main-window.ui                      | 18 ++++++
 ui/components-conversation-action-bar.ui           | 21 ++++++-
 ui/components-conversation-header-bar.ui           | 36 +++++++++++
 ui/main-toolbar.ui                                 | 32 +---------
 ui/org.gnome.Geary.gresource.xml                   |  1 +
 11 files changed, 170 insertions(+), 54 deletions(-)
---
diff --git a/src/client/application/application-main-window.vala 
b/src/client/application/application-main-window.vala
index 90d5b249e..19f044925 100644
--- a/src/client/application/application-main-window.vala
+++ b/src/client/application/application-main-window.vala
@@ -334,6 +334,10 @@ public class Application.MainWindow :
     [GtkChild]
     private Gtk.ScrolledWindow conversation_list_scrolled;
     [GtkChild]
+    private Gtk.Box conversation_viewer_box;
+    [GtkChild]
+    private Components.ConversationActionBar conversation_viewer_action_bar;
+    [GtkChild]
     private Gtk.SizeGroup folder_size_group;
     [GtkChild]
     private Gtk.SizeGroup folder_separator_size_group;
@@ -1266,7 +1270,7 @@ public class Application.MainWindow :
 
         this.conversation_viewer.hexpand = true;
         this.conversation_size_group.add_widget(this.conversation_viewer);
-        this.main_leaflet.add_with_properties(this.conversation_viewer, "name", "conversation", null);
+        this.conversation_viewer_box.add(this.conversation_viewer);
 
 
         // Setup conversation actions
@@ -1279,7 +1283,7 @@ public class Application.MainWindow :
                                                 BindingFlags.SYNC_CREATE | BindingFlags.BIDIRECTIONAL);
 
         // Main toolbar
-        this.main_toolbar = new MainToolbar(config);
+        this.main_toolbar = new MainToolbar(config, conversation_viewer_action_bar);
         this.main_toolbar.add_to_size_groups(this.folder_size_group,
                                              this.folder_separator_size_group,
                                              this.conversations_size_group,
diff --git a/src/client/components/components-conversation-action-bar.vala 
b/src/client/components/components-conversation-action-bar.vala
index cb5745219..cd868b212 100644
--- a/src/client/components/components-conversation-action-bar.vala
+++ b/src/client/components/components-conversation-action-bar.vala
@@ -12,7 +12,7 @@ public class Components.ConversationActionBar : Gtk.Revealer {
     private ulong owner_notify;
 
     [GtkChild]
-    private Gtk.Box action_box;
+    public Gtk.Box action_box;
 
     public ConversationActionBar() {
     }
@@ -23,17 +23,17 @@ public class Components.ConversationActionBar : Gtk.Revealer {
      */
     public void add_conversation_actions(Components.ConversationActions actions) {
         if (actions.owner == this)
-          return;
+            return;
 
         actions.take_ownership(this);
         action_box.pack_start(actions.mark_copy_move_buttons, false, false);
         action_box.pack_end(actions.archive_trash_delete_buttons, false, false);
         reveal_child = true;
         this.owner_notify = actions.notify["owner"].connect(() => {
-           if (actions.owner != this) {
-             reveal_child = false;
-             actions.disconnect (this.owner_notify);
-           }
+            if (actions.owner != this) {
+                reveal_child = false;
+                actions.disconnect (this.owner_notify);
+            }
         });
     }
 }
diff --git a/src/client/components/components-conversation-header-bar.vala 
b/src/client/components/components-conversation-header-bar.vala
new file mode 100644
index 000000000..ce28c2365
--- /dev/null
+++ b/src/client/components/components-conversation-header-bar.vala
@@ -0,0 +1,70 @@
+/*
+ * Copyright © 2020 Purism SPC
+ *
+ * This software is licensed under the GNU Lesser General Public License
+ * (version 2.1 or later).  See the COPYING file in this distribution.
+ */
+
+[GtkTemplate (ui = "/org/gnome/Geary/components-conversation-header-bar.ui")]
+public class Components.ConversationHeaderBar : Gtk.HeaderBar {
+    public Components.ConversationActionBar action_bar { get; set; }
+    public bool folded { get; set; }
+
+    private ulong owner_notify;
+    private Gtk.Widget? reply_forward_buttons;
+    private Gtk.Widget? archive_trash_delete_buttons;
+
+    public ConversationHeaderBar() {
+    }
+
+    public override void size_allocate(Gtk.Allocation allocation) {
+        update_action_bar();
+        base.size_allocate(allocation);
+    }
+
+    [GtkCallback]
+    private void update_action_bar () {
+        /* Only show the action_bar when the conversation_header is shown */
+        if (parent == null)
+            action_bar.reveal_child = false;
+        else if (reply_forward_buttons != null && archive_trash_delete_buttons != null)
+            if (action_bar.reveal_child && get_allocated_width() > 600) {
+                action_bar.reveal_child = false;
+                remove_action_parent();
+                pack_start(reply_forward_buttons);
+                pack_end(archive_trash_delete_buttons);
+            } else if (!action_bar.reveal_child && get_allocated_width() < 600) {
+                remove_action_parent();
+                action_bar.action_box.pack_start(reply_forward_buttons, false, false);
+                action_bar.action_box.pack_end(archive_trash_delete_buttons, false, false);
+                action_bar.reveal_child = true;
+            }
+    }
+
+    private void remove_action_parent() {
+        if (reply_forward_buttons != null && reply_forward_buttons.parent != null)
+            reply_forward_buttons.parent.remove(reply_forward_buttons);
+        if (archive_trash_delete_buttons != null && archive_trash_delete_buttons.parent != null)
+            archive_trash_delete_buttons.parent.remove(archive_trash_delete_buttons);
+    }
+
+    public void add_conversation_actions(Components.ConversationActions actions) {
+        if (actions.owner != this) {
+            actions.take_ownership(this);
+            pack_start(actions.mark_copy_move_buttons);
+            pack_end(actions.find_button);   
+
+            reply_forward_buttons = actions.reply_forward_buttons;
+            archive_trash_delete_buttons = actions.archive_trash_delete_buttons;
+            update_action_bar();
+            this.owner_notify = actions.notify["owner"].connect(() => {
+                if (actions.owner != this) {
+                    action_bar.reveal_child = false;
+                    reply_forward_buttons = null;
+                    archive_trash_delete_buttons = null;
+                    actions.disconnect (this.owner_notify);
+                }
+            });
+        }
+    }
+}
diff --git a/src/client/components/main-toolbar.vala b/src/client/components/main-toolbar.vala
index 6458b7fbc..ab0e3ba1d 100644
--- a/src/client/components/main-toolbar.vala
+++ b/src/client/components/main-toolbar.vala
@@ -17,6 +17,8 @@ public class MainToolbar : Hdy.Leaflet {
     // Search bar
     public bool search_open { get; set; default = false; }
 
+    private Components.ConversationActionBar conversation_viewer_action_bar;
+
     [GtkChild]
     private Hdy.Leaflet conversations_leaflet;
 
@@ -40,18 +42,21 @@ public class MainToolbar : Hdy.Leaflet {
 
     // Conversation header elements
     [GtkChild]
-    private Gtk.HeaderBar conversation_header;
+    private Components.ConversationHeaderBar conversation_header;
 
     [GtkChild]
     private Hdy.HeaderGroup header_group;
 
     Gtk.SizeGroup conversation_group;
 
-    public MainToolbar(Application.Configuration config) {
+    public MainToolbar(Application.Configuration config,
+                       Components.ConversationActionBar action_bar) {
         if (config.desktop_environment != UNITY) {
             this.bind_property("account", this.conversations_header, "title", BindingFlags.SYNC_CREATE);
             this.bind_property("folder", this.conversations_header, "subtitle", BindingFlags.SYNC_CREATE);
         }
+        this.conversation_viewer_action_bar = action_bar;
+        this.conversation_header.action_bar = action_bar;
 
         // Assemble the main/mark menus
         Gtk.Builder builder = new Gtk.Builder.from_resource("/org/gnome/Geary/main-toolbar-menus.ui");
@@ -63,17 +68,6 @@ public class MainToolbar : Hdy.Leaflet {
             BindingFlags.SYNC_CREATE | BindingFlags.BIDIRECTIONAL);
     }
 
-    public void add_conversation_actions(Components.ConversationActions actions) {
-        if (actions.owner == this)
-          return;
-
-        actions.take_ownership(this);
-        conversation_header.pack_start(actions.mark_copy_move_buttons);
-        conversation_header.pack_start(actions.reply_forward_buttons);
-        conversation_header.pack_end(actions.find_button);
-        conversation_header.pack_end(actions.archive_trash_delete_buttons);
-    }
-
     public void set_conversation_header(Gtk.HeaderBar header) {
         remove(conversation_header);
         this.header_group.add_gtk_header_bar(header);
@@ -111,4 +105,8 @@ public class MainToolbar : Hdy.Leaflet {
         conversations_group.add_swipeable(this.conversations_leaflet);
         conversation_group.add_swipeable(this);
     }
+
+    public void add_conversation_actions(Components.ConversationActions actions) {
+        conversation_header.add_conversation_actions(actions);
+    }
 }
diff --git a/src/client/conversation-viewer/conversation-viewer.vala 
b/src/client/conversation-viewer/conversation-viewer.vala
index a5098764f..74706f8ca 100644
--- a/src/client/conversation-viewer/conversation-viewer.vala
+++ b/src/client/conversation-viewer/conversation-viewer.vala
@@ -532,5 +532,4 @@ public class ConversationViewer : Gtk.Stack, Geary.BaseInterface {
             }
         }
     }
-
 }
diff --git a/src/client/meson.build b/src/client/meson.build
index 4efadc6de..56a07fa42 100644
--- a/src/client/meson.build
+++ b/src/client/meson.build
@@ -49,6 +49,7 @@ client_vala_sources = files(
   'components/components-attachment-pane.vala',
   'components/components-conversation-actions.vala',
   'components/components-conversation-action-bar.vala',
+  'components/components-conversation-header-bar.vala',
   'components/components-entry-undo.vala',
   'components/components-info-bar-stack.vala',
   'components/components-info-bar.vala',
diff --git a/ui/application-main-window.ui b/ui/application-main-window.ui
index c55e42abd..1b41310d6 100644
--- a/ui/application-main-window.ui
+++ b/ui/application-main-window.ui
@@ -137,6 +137,24 @@
                     <property name="navigatable">False</property>
                   </packing>
                 </child>
+                <child>
+                  <object class="GtkBox" id="conversation_viewer_box">
+                    <property name="visible">True</property>
+                    <property name="can_focus">False</property>
+                    <property name="orientation">vertical</property>
+                    <child>
+                      <object class="ComponentsConversationActionBar" id="conversation_viewer_action_bar">
+                        <property name="visible">True</property>
+                      </object>
+                      <packing>
+                        <property name="pack_type">end</property>
+                      </packing>
+                    </child>
+                  </object>
+                  <packing>
+                    <property name="name">conversation</property>
+                  </packing>
+                </child>
               </object>
               <packing>
                 <property name="expand">True</property>
diff --git a/ui/components-conversation-action-bar.ui b/ui/components-conversation-action-bar.ui
index ae49683fd..6fc03f440 100644
--- a/ui/components-conversation-action-bar.ui
+++ b/ui/components-conversation-action-bar.ui
@@ -11,11 +11,28 @@
     <property name="can_focus">False</property>
     <property name="transition_type">slide-up</property>
     <child>
-      <object class="GtkBox" id="action_box">
+      <object class="GtkBox">
         <property name="visible">True</property>
         <property name="can_focus">False</property>
         <property name="hexpand">True</property>
-        <property name="margin">6</property>
+        <property name="orientation">vertical</property>
+        <child>
+          <object class="GtkSeparator">
+            <property name="visible">True</property>
+            <property name="can_focus">False</property>
+          </object>
+        </child>
+        <child>
+          <object class="GtkBox" id="action_box">
+            <property name="visible">True</property>
+            <property name="can_focus">False</property>
+            <property name="hexpand">True</property>
+            <property name="margin_top">6</property>
+            <property name="margin_bottom">6</property>
+            <property name="margin_start">6</property>
+            <property name="margin_end">6</property>
+          </object>
+        </child>
       </object>
     </child>
   </template>
diff --git a/ui/components-conversation-header-bar.ui b/ui/components-conversation-header-bar.ui
new file mode 100644
index 000000000..1677c72a8
--- /dev/null
+++ b/ui/components-conversation-header-bar.ui
@@ -0,0 +1,36 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<interface>
+  <requires lib="gtk+" version="3.20"/>
+  <template class="ComponentsConversationHeaderBar" parent="GtkHeaderBar">
+    <property name="visible">True</property>
+    <property name="can_focus">False</property>
+    <property name="hexpand">True</property>
+    <signal name="notify::parent" handler="update_action_bar" swapped="no"/>
+    <child>
+      <object class="GtkButton" id="conversation_back">
+        <property name="can_focus">False</property>
+        <property name="receives_default">False</property>
+        <property name="valign">center</property>
+        <property name="use-underline">True</property>
+        <property name="visible" bind-property="folded" bind-source="ComponentsConversationHeaderBar" 
bind-flags="sync-create"/>
+        <property name="action_name">win.navigation-back</property>
+        <style>
+          <class name="image-button"/>
+        </style>
+        <child internal-child="accessible">
+          <object class="AtkObject" id="a11y-conversation-back">
+            <property name="accessible-name" translatable="yes">Back</property>
+          </object>
+        </child>
+        <child>
+          <object class="GtkImage" id="conversation_back_image">
+            <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>
+      </object>
+    </child>
+  </template>
+</interface>
diff --git a/ui/main-toolbar.ui b/ui/main-toolbar.ui
index 64f888ee7..ed9948b15 100644
--- a/ui/main-toolbar.ui
+++ b/ui/main-toolbar.ui
@@ -158,37 +158,9 @@
       </packing>
     </child>
     <child>
-      <object class="GtkHeaderBar" id="conversation_header">
-        <property name="visible">True</property>
-        <property name="can_focus">False</property>
-        <property name="hexpand">True</property>
+      <object class="ComponentsConversationHeaderBar" id="conversation_header">
         <property name="show_close_button" bind-source="MainToolbar" bind-property="show_close_button" 
bind-flags="sync-create"/>
-        <child>
-          <object class="GtkButton" id="conversation_back">
-            <property name="can_focus">False</property>
-            <property name="receives_default">False</property>
-            <property name="valign">center</property>
-            <property name="use-underline">True</property>
-            <property name="visible" bind-source="MainToolbar" bind-property="folded" 
bind-flags="sync-create"/>
-            <property name="action_name">win.navigation-back</property>
-            <style>
-              <class name="image-button"/>
-            </style>
-            <child internal-child="accessible">
-              <object class="AtkObject" id="a11y-conversation-back">
-                <property name="accessible-name" translatable="yes">Back</property>
-              </object>
-            </child>
-            <child>
-              <object class="GtkImage" id="conversation_back_image">
-                <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>
-          </object>
-        </child>
+        <property name="folded" bind-source="MainToolbar" bind-property="folded" bind-flags="sync-create"/>
       </object>
       <packing>
         <property name="name">conversation</property>
diff --git a/ui/org.gnome.Geary.gresource.xml b/ui/org.gnome.Geary.gresource.xml
index 0b9e900fd..e22a8f927 100644
--- a/ui/org.gnome.Geary.gresource.xml
+++ b/ui/org.gnome.Geary.gresource.xml
@@ -13,6 +13,7 @@
     <file compressed="true" preprocess="xml-stripblanks">components-attachment-pane.ui</file>
     <file compressed="true" preprocess="xml-stripblanks">components-attachment-pane-menus.ui</file>
     <file compressed="true" preprocess="xml-stripblanks">components-attachment-view.ui</file>
+    <file compressed="true" preprocess="xml-stripblanks">components-conversation-header-bar.ui</file>
     <file compressed="true" preprocess="xml-stripblanks">components-conversation-action-bar.ui</file>
     <file compressed="true" preprocess="xml-stripblanks">components-conversation-actions.ui</file>
     <file compressed="true" preprocess="xml-stripblanks">components-in-app-notification.ui</file>


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