[geary/wip/743960-split-header-2: 3/8] Set title of composer headerbar segment from subject



commit ccc7239576abd8cf6e46d150e90702097516b8a3
Author: Robert Schroll <rschroll gmail com>
Date:   Wed Feb 11 02:18:50 2015 -0500

    Set title of composer headerbar segment from subject

 src/client/composer/composer-box.vala    |    5 +++++
 src/client/composer/composer-widget.vala |   11 ++++++++++-
 src/client/composer/composer-window.vala |   15 ++++-----------
 3 files changed, 19 insertions(+), 12 deletions(-)
---
diff --git a/src/client/composer/composer-box.vala b/src/client/composer/composer-box.vala
index 3fc423c..e737a78 100644
--- a/src/client/composer/composer-box.vala
+++ b/src/client/composer/composer-box.vala
@@ -9,6 +9,7 @@ public class ComposerBox : Gtk.Frame, ComposerContainer {
     private ComposerWidget composer;
     private Gee.Set<Geary.App.Conversation>? prev_selection = null;
     private bool has_accel_group = false;
+    private Binding? title_binding = null;
     
     public Gtk.Window top_window {
         get { return (Gtk.Window) get_toplevel(); }
@@ -28,6 +29,8 @@ public class ComposerBox : Gtk.Frame, ComposerContainer {
             prev_selection = conversation_list_view.get_selected_conversations();
             conversation_list_view.get_selection().unselect_all();
             
+            title_binding = composer.bind_property("window-title", composer.header, "title",
+                BindingFlags.SYNC_CREATE);
             composer.header.parent.remove(composer.header);
             GearyApplication.instance.controller.main_window.main_toolbar.set_conversation_header(
                 composer.header);
@@ -74,6 +77,8 @@ public class ComposerBox : Gtk.Frame, ComposerContainer {
         if (get_style_context().has_class("full-pane"))
             GearyApplication.instance.controller.main_window.main_toolbar.remove_conversation_header(
                 composer.header);
+        if (title_binding != null)
+            title_binding.unbind();
         
         composer.state = ComposerWidget.ComposerState.DETACHED;
         composer.editor.focus_in_event.disconnect(on_focus_in);
diff --git a/src/client/composer/composer-widget.vala b/src/client/composer/composer-widget.vala
index 4c4bff3..8e5ea3a 100644
--- a/src/client/composer/composer-widget.vala
+++ b/src/client/composer/composer-widget.vala
@@ -60,6 +60,7 @@ public class ComposerWidget : Gtk.EventBox {
     private const string DRAFT_SAVING_TEXT = _("Saving");
     private const string DRAFT_ERROR_TEXT = _("Error saving");
     private const string BACKSPACE_TEXT = _("Press Backspace to delete quote");
+    private const string DEFAULT_TITLE = _("New Message");
     
     private const string URI_LIST_MIME_TYPE = "text/uri-list";
     private const string FILE_URI_PREFIX = "file://";
@@ -195,6 +196,8 @@ public class ComposerWidget : Gtk.EventBox {
     
     public string toolbar_text { get; set; }
     
+    public string window_title { get; set; }
+    
     private ContactListStore? contact_list_store = null;
     
     private string? body_html = null;
@@ -211,7 +214,7 @@ public class ComposerWidget : Gtk.EventBox {
     private EmailEntry bcc_entry;
     private Gtk.Label reply_to_label;
     private EmailEntry reply_to_entry;
-    public Gtk.Entry subject_entry;
+    private Gtk.Entry subject_entry;
     private Gtk.Label message_overlay_label;
     private Gtk.Box attachments_box;
     private Gtk.Alignment hidden_on_attachment_drag_over;
@@ -338,6 +341,12 @@ public class ComposerWidget : Gtk.EventBox {
         // testing, this can cause non-deterministic segfaults. Investigate why, and fix if possible.
         set_entry_completions();
         subject_entry = builder.get_object("subject") as Gtk.Entry;
+        subject_entry.bind_property("text", this, "window-title", BindingFlags.SYNC_CREATE,
+            (binding, source_value, ref target_value) => {
+                target_value = Geary.String.is_empty_or_whitespace(subject_entry.text)
+                    ? DEFAULT_TITLE : subject_entry.text.strip();
+                return true;
+            });
         Gtk.Alignment message_area = builder.get_object("message area") as Gtk.Alignment;
         actions = builder.get_object("compose actions") as Gtk.ActionGroup;
         // Can only happen after actions exits
diff --git a/src/client/composer/composer-window.vala b/src/client/composer/composer-window.vala
index 1f80853..ea5048b 100644
--- a/src/client/composer/composer-window.vala
+++ b/src/client/composer/composer-window.vala
@@ -7,29 +7,22 @@
 // Window for sending messages.
 public class ComposerWindow : Gtk.Window, ComposerContainer {
 
-    private const string DEFAULT_TITLE = _("New Message");
-    
     private bool closing = false;
     
     public ComposerWindow(ComposerWidget composer) {
         Object(type: Gtk.WindowType.TOPLEVEL);
         
         add(composer);
-        composer.subject_entry.changed.connect(() => {
-            string new_title = Geary.String.is_empty_or_whitespace(composer.subject_entry.text)
-                ? DEFAULT_TITLE : composer.subject_entry.text.strip();
-            if (GearyApplication.instance.is_running_unity)
-                title = new_title;
-            else
-                composer.header.title = new_title;
-        });
-        composer.subject_entry.changed();
         
         if (!GearyApplication.instance.is_running_unity) {
             composer.header.show_close_button = true;
             if (composer.header.parent != null)
                 composer.header.parent.remove(composer.header);
             set_titlebar(composer.header);
+            composer.bind_property("window-title", composer.header, "title",
+                BindingFlags.SYNC_CREATE);
+        } else {
+            composer.bind_property("window-title", this, "title", BindingFlags.SYNC_CREATE);
         }
         
         add_accel_group(composer.ui.get_accel_group());


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