[geary/mjog/mutiple-main-windows: 13/14] Always update Application.MainWindow title



commit 446e9b869922312e1ae9f5d4d88f36e413b2f6e8
Author: Michael Gratton <mike vee net>
Date:   Mon Nov 18 15:27:46 2019 +1100

    Always update Application.MainWindow title
    
    Update the main window title with the folder/account name or in-window
    composer subject even when using CSD since this helps differenciate
    between multiple windows when open.

 .../application/application-main-window.vala       | 41 +++++++++++++++-------
 src/client/composer/composer-widget.vala           | 25 +++++++++++--
 src/client/composer/composer-window.vala           | 24 +------------
 .../conversation-viewer/conversation-viewer.vala   | 32 +++++++++--------
 4 files changed, 71 insertions(+), 51 deletions(-)
---
diff --git a/src/client/application/application-main-window.vala 
b/src/client/application/application-main-window.vala
index b8b2c39a..fee96fa2 100644
--- a/src/client/application/application-main-window.vala
+++ b/src/client/application/application-main-window.vala
@@ -341,6 +341,32 @@ public class Application.MainWindow :
         base.destroy();
     }
 
+    /** Updates the window's title and headerbar titles. */
+    public void update_title() {
+        string title = _("Geary");
+        if (this.selected_folder != null) {
+            /// Translators: Main window title, first string
+            /// substitution being the currently selected folder name,
+            /// the second being the selected account name.
+            title = _("%s — %s").printf(
+                this.selected_folder.get_display_name(),
+                this.selected_folder.account.information.display_name
+            );
+        }
+        this.title = title;
+
+        this.main_toolbar.account = (
+            this.selected_folder != null
+            ? this.selected_folder.account.information.display_name
+            : ""
+        );
+        this.main_toolbar.folder = (
+            this.selected_folder != null
+            ? this.selected_folder.get_display_name()
+            : ""
+        );
+    }
+
     /** Updates the window's account status info bars. */
     public void update_account_status(Geary.Account.Status status,
                                       bool has_auth_error,
@@ -448,6 +474,7 @@ public class Application.MainWindow :
                 this.previous_non_search_folder = to_select;
             }
             update_conversation_actions(NONE);
+            update_title();
             this.main_toolbar.update_trash_button(
                 !this.is_shift_down && this.selected_folder_supports_trash
             );
@@ -935,20 +962,10 @@ public class Application.MainWindow :
         this.main_toolbar.bind_property("find-open", this.conversation_viewer.conversation_find_bar,
                 "search-mode-enabled", BindingFlags.SYNC_CREATE | BindingFlags.BIDIRECTIONAL);
         if (config.desktop_environment == UNITY) {
-            BindingTransformFunc title_func = (binding, source, ref target) => {
-                string folder = selected_folder != null ? selected_folder.get_display_name() + " " : "";
-                string account = main_toolbar.account != null ? "(%s)".printf(main_toolbar.account) : "";
-
-                target = "%s%s - %s".printf(folder, account, Client.NAME);
-
-                return true;
-            };
-            bind_property("current-folder", this, "title", BindingFlags.SYNC_CREATE, (owned) title_func);
-            main_toolbar.bind_property("account", this, "title", BindingFlags.SYNC_CREATE, (owned) 
title_func);
-            main_layout.pack_start(main_toolbar, false, true, 0);
+            this.main_layout.pack_start(main_toolbar, false, true, 0);
         } else {
             main_toolbar.show_close_button = true;
-            set_titlebar(main_toolbar);
+            set_titlebar(this.main_toolbar);
         }
 
         // Status bar
diff --git a/src/client/composer/composer-widget.vala b/src/client/composer/composer-widget.vala
index d1103b35..7274abae 100644
--- a/src/client/composer/composer-widget.vala
+++ b/src/client/composer/composer-widget.vala
@@ -24,6 +24,10 @@ public class Composer.Widget : Gtk.EventBox, Geary.BaseInterface {
     /** The email fields the composer requires for referred email. */
     public const Geary.Email.Field REQUIRED_FIELDS = ENVELOPE | BODY;
 
+    /// Translators: Title for an empty composer window
+    private const string DEFAULT_TITLE = _("New Message");
+
+
     public enum ComposeType {
         NEW_MESSAGE,
         REPLY,
@@ -714,8 +718,9 @@ public class Composer.Widget : Gtk.EventBox, Geary.BaseInterface {
 
     /** Detaches the composer and opens it in a new window. */
     public void detach() {
-        Gtk.Widget? focused_widget = this.container.top_window.get_focus();
+        Gtk.Widget? focused_widget = null;
         if (this.container != null) {
+            focused_widget = this.container.top_window.get_focus();
             this.container.close();
         }
         Window new_window = new Window(this, this.application);
@@ -1384,6 +1389,22 @@ public class Composer.Widget : Gtk.EventBox, Geary.BaseInterface {
         return check_send_on_return(event) && base.key_press_event(event);
     }
 
+    /** Updates the composer's top level window and headerbar title. */
+    public void update_window_title() {
+        string subject = this.subject.strip();
+        if (Geary.String.is_empty(subject)) {
+            subject = DEFAULT_TITLE;
+        }
+
+        if (this.container != null) {
+            this.container.top_window.title = subject;
+        }
+
+        if (this.application.config.desktop_environment != UNITY) {
+            this.header.title = subject;
+        }
+    }
+
     internal void set_mode(PresentationMode new_mode) {
         this.current_mode = new_mode;
         this.header.set_mode(new_mode);
@@ -2554,7 +2575,7 @@ public class Composer.Widget : Gtk.EventBox, Geary.BaseInterface {
     [GtkCallback]
     private void on_subject_changed() {
         draft_changed();
-        notify_property("subject");
+        update_window_title();
     }
 
     [GtkCallback]
diff --git a/src/client/composer/composer-window.vala b/src/client/composer/composer-window.vala
index 91bfc08b..7e6f4056 100644
--- a/src/client/composer/composer-window.vala
+++ b/src/client/composer/composer-window.vala
@@ -15,9 +15,6 @@
 public class Composer.Window : Gtk.ApplicationWindow, Container {
 
 
-    private const string DEFAULT_TITLE = _("New Message");
-
-
     /** {@inheritDoc} */
     public Gtk.ApplicationWindow? top_window {
         get { return this; }
@@ -43,6 +40,7 @@ public class Composer.Window : Gtk.ApplicationWindow, Container {
 
         add(this.composer);
 
+        this.composer.update_window_title();
         if (application.config.desktop_environment == UNITY) {
             composer.embed_header();
         } else {
@@ -50,9 +48,6 @@ public class Composer.Window : Gtk.ApplicationWindow, Container {
             set_titlebar(this.composer.header);
         }
 
-        composer.notify["subject"].connect(() => { update_title(); } );
-        update_title();
-
         show();
         set_position(Gtk.WindowPosition.CENTER);
     }
@@ -127,21 +122,4 @@ public class Composer.Window : Gtk.ApplicationWindow, Container {
         return ret;
     }
 
-    private void update_title() {
-        string subject = this.composer.subject.strip();
-        if (Geary.String.is_empty_or_whitespace(subject)) {
-            subject = DEFAULT_TITLE;
-        }
-
-        switch (this.application.config.desktop_environment) {
-        case UNITY:
-            this.title = subject;
-            break;
-
-        default:
-            this.composer.header.title = subject;
-            break;
-        }
-    }
-
 }
diff --git a/src/client/conversation-viewer/conversation-viewer.vala 
b/src/client/conversation-viewer/conversation-viewer.vala
index 126a30e2..2c3ec220 100644
--- a/src/client/conversation-viewer/conversation-viewer.vala
+++ b/src/client/conversation-viewer/conversation-viewer.vala
@@ -162,6 +162,7 @@ public class ConversationViewer : Gtk.Stack, Geary.BaseInterface {
             box.vanished.connect(on_composer_closed);
             this.composer_page.add(box);
             set_visible_child(this.composer_page);
+            composer.update_window_title();
         }
     }
 
@@ -188,6 +189,7 @@ public class ConversationViewer : Gtk.Stack, Geary.BaseInterface {
                 embed,
                 composer.current_draft_id != null
             );
+            composer.update_window_title();
         }
 
         conversation_scroller.kinetic_scrolling = true;
@@ -487,21 +489,23 @@ public class ConversationViewer : Gtk.Stack, Geary.BaseInterface {
 
             // Restore the old selection
             var main_window = get_toplevel() as Application.MainWindow;
-            if (main_window != null &&
-                this.selection_while_composing != null) {
-                ConversationListView conversation_list =
-                    main_window.conversation_list_view;
-                if (this.selection_while_composing.is_empty) {
-                    conversation_list.conversations_selected(
-                        this.selection_while_composing
-                    );
-                } else {
-                    conversation_list.select_conversations(
-                        this.selection_while_composing
-                    );
-                }
+            if (main_window != null) {
+                main_window.update_title();
+
+                if (this.selection_while_composing != null) {
+                    var conversation_list = main_window.conversation_list_view;
+                    if (this.selection_while_composing.is_empty) {
+                        conversation_list.conversations_selected(
+                            this.selection_while_composing
+                        );
+                    } else {
+                        conversation_list.select_conversations(
+                            this.selection_while_composing
+                        );
+                    }
 
-                this.selection_while_composing = null;
+                    this.selection_while_composing = null;
+                }
             }
         }
     }


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