[geary/wip/778728-split-composer: 16/19] Simply and update ComposerContainer interface and implementations.



commit 3fc6d9b16e50fa3f6a633cc83b388cceee5a73b6
Author: Michael James Gratton <mike vee net>
Date:   Wed Oct 4 16:19:57 2017 -0700

    Simply and update ComposerContainer interface and implementations.
    
    * src/client/composer/composer-container.vala (ComposerContainer): Remove
      ::present and ::get_focus, update call sites to just get these diretly
      from their top levels. Make :top_window protected, we only need this
      since the interface itself doesn't extend GtkWidget and it's an
      implementation detail. Update implementations.
    
    * src/client/composer/composer-window.vala (ComposerContainer): Pass a
      config object to the ctor so we don't need to use the depreciated
      global application instance to get to it.
    
    * src/client/composer/composer-widget.vala (ComposerWidget): Don't
      attempt to implement copy/paste for Gtk.Entry instances, we'll do that
      elsewhere.

 src/client/application/geary-controller.vala |    2 +-
 src/client/composer/composer-box.vala        |    6 +-
 src/client/composer/composer-container.vala  |   14 +---
 src/client/composer/composer-embed.vala      |   10 +--
 src/client/composer/composer-widget.vala     |   95 +++++++++++++++-----------
 src/client/composer/composer-window.vala     |    9 +--
 6 files changed, 70 insertions(+), 66 deletions(-)
---
diff --git a/src/client/application/geary-controller.vala b/src/client/application/geary-controller.vala
index b263530..767abfb 100644
--- a/src/client/application/geary-controller.vala
+++ b/src/client/application/geary-controller.vala
@@ -2295,7 +2295,7 @@ public class GearyController : Geary.BaseObject {
                 );
             }
         } else {
-            new ComposerWindow(widget);
+            new ComposerWindow(widget, this.application.config);
             widget.state = ComposerWidget.ComposerState.DETACHED;
         }
 
diff --git a/src/client/composer/composer-box.vala b/src/client/composer/composer-box.vala
index e3116d8..c4ae911 100644
--- a/src/client/composer/composer-box.vala
+++ b/src/client/composer/composer-box.vala
@@ -10,12 +10,12 @@
  */
 public class ComposerBox : Gtk.Frame, ComposerContainer {
 
-    public Gtk.ApplicationWindow top_window {
+    internal ComposerWidget composer { get; set; }
+
+    protected Gtk.ApplicationWindow top_window {
         get { return (Gtk.ApplicationWindow) get_toplevel(); }
     }
 
-    internal ComposerWidget composer { get; set; }
-
     protected Gee.MultiMap<string, string>? old_accelerators { get; set; }
 
     private MainToolbar main_toolbar { get; private set; }
diff --git a/src/client/composer/composer-container.vala b/src/client/composer/composer-container.vala
index da82724..387581a 100644
--- a/src/client/composer/composer-container.vala
+++ b/src/client/composer/composer-container.vala
@@ -21,17 +21,6 @@ public interface ComposerContainer {
     // We use old_accelerators to keep track of the accelerators we temporarily disabled.
     protected abstract Gee.MultiMap<string, string>? old_accelerators { get; set; }
 
-    // The toplevel window for the container. Note that it needs to be a GtkApplicationWindow.
-    public abstract Gtk.ApplicationWindow top_window { get; }
-
-    public virtual void present() {
-        this.top_window.present();
-    }
-
-    public virtual unowned Gtk.Widget get_focus() {
-        return this.top_window.get_focus();
-    }
-
     public abstract void close_container();
 
     /**
@@ -45,6 +34,9 @@ public interface ComposerContainer {
      */
     public abstract void remove_composer();
 
+    // The toplevel window for the container. Note that it needs to be a GtkApplicationWindow.
+    protected abstract Gtk.ApplicationWindow top_window { get; }
+
     protected virtual bool on_focus_in() {
         if (this.old_accelerators == null) {
             this.old_accelerators = new Gee.HashMultiMap<string, string>();
diff --git a/src/client/composer/composer-embed.vala b/src/client/composer/composer-embed.vala
index 37d67bc..9b4bcc8 100644
--- a/src/client/composer/composer-embed.vala
+++ b/src/client/composer/composer-embed.vala
@@ -14,12 +14,12 @@ public class ComposerEmbed : Gtk.EventBox, ComposerContainer {
 
     public Geary.Email referred { get; private set; }
 
-    public Gtk.ApplicationWindow top_window {
+    internal ComposerWidget composer { get; set; }
+
+    protected Gtk.ApplicationWindow top_window {
         get { return (Gtk.ApplicationWindow) get_toplevel(); }
     }
 
-    internal ComposerWidget composer { get; set; }
-
     protected Gee.MultiMap<string, string>? old_accelerators { get; set; }
 
     private Gtk.ScrolledWindow outer_scroller;
@@ -186,10 +186,6 @@ public class ComposerEmbed : Gtk.EventBox, ComposerContainer {
         return ret;
     }
 
-    public void present() {
-        top_window.present();
-    }
-
     public void vanish() {
         hide();
         this.composer.state = ComposerWidget.ComposerState.DETACHED;
diff --git a/src/client/composer/composer-widget.vala b/src/client/composer/composer-widget.vala
index ad2489d..9183268 100644
--- a/src/client/composer/composer-widget.vala
+++ b/src/client/composer/composer-widget.vala
@@ -1056,7 +1056,11 @@ public class ComposerWidget : Gtk.EventBox {
         }
 
         update_composer_view();
-        this.container.present();
+
+        Gtk.Window? window = get_toplevel() as Gtk.Window;
+        if (window != null) {
+            window.present();
+        }
         set_focus();
     }
 
@@ -1114,12 +1118,17 @@ public class ComposerWidget : Gtk.EventBox {
         if (this.is_blank)
             return CloseStatus.DO_CLOSE;
 
-        this.container.present();
+        Gtk.Window? window = get_toplevel() as Gtk.Window;
+        if (window != null) {
+            window.present();
+        }
 
         CloseStatus status = CloseStatus.PENDING_CLOSE;
         if (this.can_save) {
-            AlertDialog dialog = new TernaryConfirmationDialog(container.top_window,
-                _("Do you want to discard this message?"), null, Stock._KEEP, Stock._DISCARD, 
+            AlertDialog dialog = new TernaryConfirmationDialog(
+                get_toplevel() as Gtk.Window,
+                _("Do you want to discard this message?"),
+                null, Stock._KEEP, Stock._DISCARD,
                 Gtk.ResponseType.CLOSE, "suggested-action");
             Gtk.ResponseType response = dialog.run();
             if (response == Gtk.ResponseType.CANCEL ||
@@ -1137,8 +1146,10 @@ public class ComposerWidget : Gtk.EventBox {
                 discard_and_exit_async.begin();
             }
         } else {
-            AlertDialog dialog = new ConfirmationDialog(container.top_window,
-                _("Do you want to discard this message?"), null, Stock._DISCARD, "destructive-action");
+            AlertDialog dialog = new ConfirmationDialog(
+                get_toplevel() as Gtk.Window,
+                _("Do you want to discard this message?"),
+                null, Stock._DISCARD, "destructive-action");
             Gtk.ResponseType response = dialog.run();
             if (response == Gtk.ResponseType.OK) {
                 discard_and_exit_async.begin();
@@ -1169,9 +1180,17 @@ public class ComposerWidget : Gtk.EventBox {
     private void on_detach() {
         if (this.state == ComposerState.DETACHED)
             return;
-        Gtk.Widget? focus = this.container.top_window.get_focus();
+
+        // Get the currently focused widget before we remove ourselves
+        // from the window
+        Gtk.Widget? focus = null;
+        Gtk.Window? toplevel = get_toplevel() as Gtk.Window;
+        if (toplevel != null) {
+            focus = toplevel.get_focus();
+        }
+
         this.container.remove_composer();
-        ComposerWindow window = new ComposerWindow(this);
+        ComposerWindow window = new ComposerWindow(this, this.config);
 
         // Workaround a GTK+ crasher, Bug 771812. When the composer is
         // re-parented, its menu_button's popover keeps a reference to
@@ -1253,7 +1272,8 @@ public class ComposerWidget : Gtk.EventBox {
             confirmation = _("Send message without an attachment?");
         }
         if (confirmation != null) {
-            ConfirmationDialog dialog = new ConfirmationDialog(container.top_window,
+            ConfirmationDialog dialog = new ConfirmationDialog(
+                get_toplevel() as Gtk.Window,
                 confirmation, null, Stock._OK, "suggested-action");
             return (dialog.run() == Gtk.ResponseType.OK);
         }
@@ -1590,7 +1610,9 @@ public class ComposerWidget : Gtk.EventBox {
     }
 
     private void attachment_failed(string msg) {
-        ErrorDialog dialog = new ErrorDialog(this.container.top_window, _("Cannot add attachment"), msg);
+        ErrorDialog dialog = new ErrorDialog(
+            get_toplevel() as Gtk.Window, _("Cannot add attachment"), msg
+        );
         dialog.run();
     }
 
@@ -1678,17 +1700,11 @@ public class ComposerWidget : Gtk.EventBox {
     }
 
     private void on_cut(SimpleAction action, Variant? param) {
-        if (this.container.get_focus() == this.editor)
-            this.editor.cut_clipboard();
-        else if (this.container.get_focus() is Gtk.Editable)
-            ((Gtk.Editable) this.container.get_focus()).cut_clipboard();
+        this.editor.cut_clipboard();
     }
 
     private void on_copy(SimpleAction action, Variant? param) {
-        if (this.container.get_focus() == this.editor)
-            this.editor.copy_clipboard();
-        else if (this.container.get_focus() is Gtk.Editable)
-            ((Gtk.Editable) this.container.get_focus()).copy_clipboard();
+        this.editor.copy_clipboard();
     }
 
     private void on_copy_link(SimpleAction action, Variant? param) {
@@ -1700,15 +1716,11 @@ public class ComposerWidget : Gtk.EventBox {
     }
 
     private void on_paste(SimpleAction action, Variant? param) {
-        if (this.container.get_focus() == this.editor)
-            this.editor.paste_plain_text();
-        else if (this.container.get_focus() is Gtk.Editable)
-            ((Gtk.Editable) this.container.get_focus()).paste_clipboard();
+        this.editor.paste_plain_text();
     }
 
     private void on_paste_with_formatting(SimpleAction action, Variant? param) {
-        if (this.container.get_focus() == this.editor)
-            this.editor.paste_rich_text();
+        this.editor.paste_rich_text();
     }
 
     private void on_select_all(SimpleAction action, Variant? param) {
@@ -1783,8 +1795,10 @@ public class ComposerWidget : Gtk.EventBox {
     }
 
     private void on_select_color() {
-        Gtk.ColorChooserDialog dialog = new Gtk.ColorChooserDialog(_("Select Color"),
-            this.container.top_window);
+        Gtk.ColorChooserDialog dialog = new Gtk.ColorChooserDialog(
+            _("Select Color"),
+            get_toplevel() as Gtk.Window
+        );
         if (dialog.run() == Gtk.ResponseType.OK) {
             this.editor.execute_editing_command_with_argument(
                 "forecolor", dialog.get_rgba().to_string()
@@ -1807,19 +1821,22 @@ public class ComposerWidget : Gtk.EventBox {
     }
 
     private void update_message_overlay_label_style() {
-        Gdk.RGBA window_background = container.top_window.get_style_context()
-            .get_background_color(Gtk.StateFlags.NORMAL);
-        Gdk.RGBA label_background = message_overlay_label.get_style_context()
-            .get_background_color(Gtk.StateFlags.NORMAL);
-        
-        if (label_background == window_background)
-            return;
-        
-        message_overlay_label.get_style_context().changed.disconnect(
-            on_message_overlay_label_style_changed);
-        message_overlay_label.override_background_color(Gtk.StateFlags.NORMAL, window_background);
-        message_overlay_label.get_style_context().changed.connect(
-            on_message_overlay_label_style_changed);
+        Gtk.Window? window = get_toplevel() as Gtk.Window;
+        if (window != null) {
+            Gdk.RGBA window_background = window.get_style_context()
+                .get_background_color(Gtk.StateFlags.NORMAL);
+            Gdk.RGBA label_background = message_overlay_label.get_style_context()
+                .get_background_color(Gtk.StateFlags.NORMAL);
+
+            if (label_background == window_background)
+                return;
+
+            message_overlay_label.get_style_context().changed.disconnect(
+                on_message_overlay_label_style_changed);
+            message_overlay_label.override_background_color(Gtk.StateFlags.NORMAL, window_background);
+            message_overlay_label.get_style_context().changed.connect(
+                on_message_overlay_label_style_changed);
+        }
     }
 
     [GtkCallback]
diff --git a/src/client/composer/composer-window.vala b/src/client/composer/composer-window.vala
index 7c1e3b8..b4ffd19 100644
--- a/src/client/composer/composer-window.vala
+++ b/src/client/composer/composer-window.vala
@@ -10,18 +10,17 @@
  */
 public class ComposerWindow : Gtk.ApplicationWindow, ComposerContainer {
 
-    public Gtk.ApplicationWindow top_window {
-        get { return this; }
-    }
 
     internal ComposerWidget composer { get; set; }
 
+    protected Gtk.ApplicationWindow top_window { get { return this; } }
+
     protected Gee.MultiMap<string, string>? old_accelerators { get; set; }
 
     private bool closing = false;
 
 
-    public ComposerWindow(ComposerWidget composer) {
+    public ComposerWindow(ComposerWidget composer, Configuration config) {
         Object(type: Gtk.WindowType.TOPLEVEL);
         this.composer = composer;
 
@@ -36,7 +35,7 @@ public class ComposerWindow : Gtk.ApplicationWindow, ComposerContainer {
         focus_in_event.connect(on_focus_in);
         focus_out_event.connect(on_focus_out);
 
-        if (composer.config.desktop_environment == Configuration.DesktopEnvironment.UNITY) {
+        if (config.desktop_environment == Configuration.DesktopEnvironment.UNITY) {
             composer.embed_header();
             composer.bind_property("window-title", this, "title", BindingFlags.SYNC_CREATE);
         } else {


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