[geary/wip/765516-gtk-widget-conversation-viewer: 179/187] Don't show draft messages when editing them.



commit ca0bc12f1f4395a97e3414e4b7d4aa98884bcde0
Author: Michael James Gratton <mike vee net>
Date:   Mon Sep 19 12:27:37 2016 +1000

    Don't show draft messages when editing them.
    
    * src/client/conversation-viewer/conversation-listbox.vala (EmailRow):
      Add a grid to the row, then add the email view to that. Allow embedded
      composers to also be added to the grid, hide the email view when the
      composer is for a draft. Fix code making asumptions about EmailRow's
      child.
      (ConversationListBox::add_embedded_composer): Add draft param, pass it
      through to the email row. Update call sites.
    
    * src/client/conversation-viewer/conversation-email.vala
      (ConversationEmail): Remove composer related prop and methods, since
      its handled by EmailRow now.
    
    * ui/geary.css: Update widget hierarchy.

 src/client/application/geary-controller.vala       |    2 +-
 .../conversation-viewer/conversation-email.vala    |   19 -------
 .../conversation-viewer/conversation-listbox.vala  |   58 +++++++++++++++-----
 ui/geary.css                                       |    4 +-
 4 files changed, 47 insertions(+), 36 deletions(-)
---
diff --git a/src/client/application/geary-controller.vala b/src/client/application/geary-controller.vala
index 16c5f4c..1cf6b11 100644
--- a/src/client/application/geary-controller.vala
+++ b/src/client/application/geary-controller.vala
@@ -2272,7 +2272,7 @@ public class GearyController : Geary.BaseObject {
                     main_window.conversation_viewer.conversation_scroller
                 );
                 if (conversation_view != null) {
-                    conversation_view.add_embedded_composer(embed);
+                    conversation_view.add_embedded_composer(embed, is_draft);
                 }
             }
         } else {
diff --git a/src/client/conversation-viewer/conversation-email.vala 
b/src/client/conversation-viewer/conversation-email.vala
index c77e911..6b8b0d6 100644
--- a/src/client/conversation-viewer/conversation-email.vala
+++ b/src/client/conversation-viewer/conversation-email.vala
@@ -260,9 +260,6 @@ public class ConversationEmail : Gtk.Box {
     /** Determines if all message's web views have finished loading. */
     public bool message_bodies_loaded { get; private set; default = false; }
 
-    /** The embedded composer for this email, if any. */
-    public ComposerEmbed composer { get; private set; default = null; }
-
     // Backing for attached_messages
     private Gee.List<ConversationMessage> _attached_messages =
         new Gee.LinkedList<ConversationMessage>();
@@ -562,22 +559,6 @@ public class ConversationEmail : Gtk.Box {
     }
 
     /**
-     * Attach an embedded composer to this email view.
-     */
-    public void attach_composer(ComposerEmbed embed) {
-        this.composer = embed;
-        add(embed);
-    }
-
-    /**
-     * Detaches an embedded composer to this email view.
-     */
-    public void remove_composer(ComposerEmbed embed) {
-        remove(embed);
-        this.composer = null;
-    }
-
-    /**
      * Returns a new Iterable over all message views in this email view
      */
     internal Gee.Iterator<ConversationMessage> message_view_iterator() {
diff --git a/src/client/conversation-viewer/conversation-listbox.vala 
b/src/client/conversation-viewer/conversation-listbox.vala
index b342f61..b2cc158 100644
--- a/src/client/conversation-viewer/conversation-listbox.vala
+++ b/src/client/conversation-viewer/conversation-listbox.vala
@@ -52,6 +52,11 @@ public class ConversationListBox : Gtk.ListBox {
         private const string LAST_CLASS = "geary-last";
         private const string MATCH_CLASS = "geary-match";
 
+        // The email view for this row
+        public ConversationEmail view { get; private set; }
+
+        // The embedded composer for this row, if any
+        public ComposerEmbed composer { get; private set; default = null; }
 
         // Is the row showing the email's message body or just headers?
         public bool is_expanded { get; private set; default = false; }
@@ -76,6 +81,8 @@ public class ConversationListBox : Gtk.ListBox {
             set { set_style_context_class(LAST_CLASS, value); }
         }
 
+        private Gtk.Grid container = new Gtk.Grid();
+
 
         // We can only scroll to a specific row once it has been
         // allocated space. This signal allows the viewer to hook up
@@ -83,12 +90,14 @@ public class ConversationListBox : Gtk.ListBox {
         public signal void should_scroll();
 
 
-        public ConversationEmail view {
-            get { return (ConversationEmail) get_child(); }
-        }
-
         public EmailRow(ConversationEmail view) {
-            add(view);
+            this.view = view;
+
+            this.container.set_orientation(Gtk.Orientation.VERTICAL);
+            this.container.show();
+            this.container.add(view);
+
+            add(this.container);
         }
 
         public new void expand() {
@@ -102,6 +111,26 @@ public class ConversationListBox : Gtk.ListBox {
             update_row_expansion();
         }
 
+        /**
+         * Attach an embedded composer to this email view.
+         */
+        public void attach_composer(ComposerEmbed embed, bool is_draft) {
+            this.composer = embed;
+            this.container.add(embed);
+            if (is_draft) {
+                this.view.hide();
+            }
+        }
+
+        /**
+         * Detaches an embedded composer to this email view.
+         */
+        public void remove_composer(ComposerEmbed embed) {
+            this.view.show();
+            this.container.remove(embed);
+            this.composer = null;
+        }
+
         public void enable_should_scroll() {
             this.size_allocate.connect(on_size_allocate);
         }
@@ -143,9 +172,10 @@ public class ConversationListBox : Gtk.ListBox {
 
 
     private static int on_sort(Gtk.ListBoxRow row1, Gtk.ListBoxRow row2) {
-        ConversationEmail? msg1 = row1.get_child() as ConversationEmail;
-        ConversationEmail? msg2 = row2.get_child() as ConversationEmail;
-        return Geary.Email.compare_sent_date_ascending(msg1.email, msg2.email);
+        return Geary.Email.compare_sent_date_ascending(
+            ((EmailRow) row1).view.email,
+            ((EmailRow) row2).view.email
+        );
     }
 
 
@@ -356,15 +386,15 @@ public class ConversationListBox : Gtk.ListBox {
     /**
      * Adds an an embedded composer to the view.
      */
-    public void add_embedded_composer(ComposerEmbed embed) {
+    public void add_embedded_composer(ComposerEmbed embed, bool is_draft) {
         EmailRow? row = this.id_to_row.get(embed.referred.id);
         if (row != null) {
-            row.view.attach_composer(embed);
+            row.attach_composer(embed, is_draft);
             embed.loaded.connect((box) => {
-                    embed.grab_focus();
+                    row.grab_focus();
                 });
             embed.vanished.connect((box) => {
-                    row.view.remove_composer(embed);
+                    row.remove_composer(embed);
                 });
         } else {
             error("Could not find referred email for embedded composer: %s",
@@ -734,7 +764,7 @@ public class ConversationListBox : Gtk.ListBox {
      */
     private Gee.Iterator<ConversationEmail> email_view_iterator() {
         return this.id_to_row.values.map<ConversationEmail>((row) => {
-                return (ConversationEmail) row.get_child();
+                return ((EmailRow) row).view;
             });
     }
 
@@ -846,7 +876,7 @@ public class ConversationListBox : Gtk.ListBox {
         // be appended last. Finally, don't let rows with active
         // composers be collapsed.
         if (row.is_expanded) {
-            if (this.last_email_row != row && row.view.composer == null) {
+            if (this.last_email_row != row && row.composer == null) {
                 row.collapse();
             }
         } else {
diff --git a/ui/geary.css b/ui/geary.css
index ff7899b..790055b 100644
--- a/ui/geary.css
+++ b/ui/geary.css
@@ -67,11 +67,11 @@ row.geary-folder-popover-list-row > label {
   box-shadow: 0 4px 8px 1px rgba(0,0,0,0.4);
   transition: margin 0.1s;
 }
-.conversation-listbox > row > box {
+.conversation-listbox > row > grid {
   background: @theme_base_color;
   transition: background 0.25s;
 }
-.conversation-listbox > row:hover > box {
+.conversation-listbox > row:hover > grid {
   background: shade(@theme_base_color, 0.96);
 }
 .conversation-listbox > row.geary-expanded {


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