[geary/mjog/mail-merge-plugin: 38/72] Composer.Widget: Add focused_input_widget property




commit 2c7fe7dbc9f3c4c782b8ad1399e1f4323edffd8a
Author: Michael Gratton <mike vee net>
Date:   Wed Jul 8 16:07:38 2020 +1000

    Composer.Widget: Add focused_input_widget property
    
    Support tracking the last focused input widget so that text can be
    inserted into it as needed.

 src/client/composer/composer-widget.vala | 21 +++++++++++++++++++++
 ui/composer-widget.ui                    |  1 +
 2 files changed, 22 insertions(+)
---
diff --git a/src/client/composer/composer-widget.vala b/src/client/composer/composer-widget.vala
index 8e4600a2d..c62fb8040 100644
--- a/src/client/composer/composer-widget.vala
+++ b/src/client/composer/composer-widget.vala
@@ -290,6 +290,15 @@ public class Composer.Widget : Gtk.EventBox, Geary.BaseInterface {
     /** The email body editor widget. */
     public WebView editor { get; private set; }
 
+    /**
+     * The last focused text input widget.
+     *
+     * This may be a Gtk.Entry if an address field or the subject was
+     * most recently focused, or the {@link editor} if the body was
+     * most recently focused.
+     */
+    public Gtk.Widget? focused_input_widget { get; private set; default = null; }
+
     /** Determines if the composer can send the message. */
     public bool can_send {
         get {
@@ -1352,6 +1361,18 @@ public class Composer.Widget : Gtk.EventBox, Geary.BaseInterface {
         }
    }
 
+    [GtkCallback]
+    private void on_set_focus_child() {
+        var window = get_toplevel() as Gtk.Window;
+        if (window != null) {
+            Gtk.Widget? last_focused = window.get_focus();
+            if (last_focused == this.editor ||
+                (last_focused is Gtk.Entry && last_focused.is_ancestor(this))) {
+                this.focused_input_widget = last_focused;
+            }
+        }
+    }
+
     [GtkCallback]
     private bool on_drag_motion() {
         show_attachment_overlay(true);
diff --git a/ui/composer-widget.ui b/ui/composer-widget.ui
index cf57b42c5..2f86903da 100644
--- a/ui/composer-widget.ui
+++ b/ui/composer-widget.ui
@@ -9,6 +9,7 @@
     <signal name="drag-drop" handler="on_drag_drop" swapped="no"/>
     <signal name="drag-leave" handler="on_drag_leave" swapped="no"/>
     <signal name="drag-motion" handler="on_drag_motion" swapped="no"/>
+    <signal name="set-focus-child" handler="on_set_focus_child" after="yes" swapped="no"/>
     <child>
       <object class="GtkBox" id="composer_container">
         <property name="visible">True</property>


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