[geary/mjog/1118-composer-insert-link] Components.WebView: Remove selection_changed signal




commit 506a5b5fc6c9835ade4c7369d1c172921069d1b6
Author: Michael Gratton <mike vee net>
Date:   Sat Jan 16 00:24:53 2021 +1100

    Components.WebView: Remove selection_changed signal
    
    Now that vala only notifies on property changes when the value actually
    changes, and GLib emits a warning when connecting to notify signals for
    properties that don't exist, it's safer to use notify signals for
    property changes, and hence this isn't needed any more.
    
    This patch removes the signal, ensures the `has_selection` gets set
    correctly, and updates signal listeners to use notify instead.
    
    Fixes #1058, #1118 and possibly others.

 src/client/components/components-web-view.vala           |  5 +----
 src/client/composer/composer-editor.vala                 |  8 ++++----
 src/client/composer/composer-widget.vala                 |  6 ++----
 src/client/conversation-viewer/conversation-message.vala | 12 ++++--------
 4 files changed, 11 insertions(+), 20 deletions(-)
---
diff --git a/src/client/components/components-web-view.vala b/src/client/components/components-web-view.vala
index 361b08dc3..f49ebb0a0 100644
--- a/src/client/components/components-web-view.vala
+++ b/src/client/components/components-web-view.vala
@@ -296,9 +296,6 @@ public abstract class Components.WebView : WebKit.WebView, Geary.BaseInterface {
     /** Emitted when the web view's content has changed. */
     public signal void document_modified();
 
-    /** Emitted when the view's selection has changed. */
-    public signal void selection_changed(bool has_selection);
-
     /** Emitted when a user clicks a link in the view. */
     public signal void link_activated(string uri);
 
@@ -801,7 +798,7 @@ public abstract class Components.WebView : WebKit.WebView, Geary.BaseInterface {
 
     private void on_selection_changed(GLib.Variant? parameters) {
         if (parameters != null && parameters.classify() == BOOLEAN) {
-            selection_changed(parameters.get_boolean());
+            this.has_selection = parameters.get_boolean();
         } else {
             warning("Could not get JS selection value");
         }
diff --git a/src/client/composer/composer-editor.vala b/src/client/composer/composer-editor.vala
index e47ba9405..8ee1b98ba 100644
--- a/src/client/composer/composer-editor.vala
+++ b/src/client/composer/composer-editor.vala
@@ -168,7 +168,7 @@ public class Composer.Editor : Gtk.Grid, Geary.BaseInterface {
         this.body.cursor_context_changed.connect(on_cursor_context_changed);
         this.body.get_editor_state().notify["typing-attributes"].connect(on_typing_attributes_changed);
         this.body.mouse_target_changed.connect(on_mouse_target_changed);
-        this.body.selection_changed.connect(on_selection_changed);
+        this.body.notify["has-selection"].connect(on_selection_changed);
         this.body.set_hexpand(true);
         this.body.set_vexpand(true);
         this.body.show();
@@ -534,7 +534,7 @@ public class Composer.Editor : Gtk.Grid, Geary.BaseInterface {
         get_action(Action.Edit.REDO).set_enabled(can_redo);
     }
 
-    private void on_selection_changed(bool has_selection) {
+    private void on_selection_changed() {
         update_cursor_actions();
     }
 
@@ -624,9 +624,9 @@ public class Composer.Editor : Gtk.Grid, Geary.BaseInterface {
                 // the URL entry, then the editor will lose its
                 // selection, the inset link action will become
                 // disabled, and the popover will disappear
-                this.body.selection_changed.disconnect(on_selection_changed);
+                this.body.notify["has-selection"].disconnect(on_selection_changed);
                 popover.closed.connect(() => {
-                        this.body.selection_changed.connect(on_selection_changed);
+                        this.body.notify["has-selection"].connect(on_selection_changed);
                         style.set_state(NORMAL);
                     });
 
diff --git a/src/client/composer/composer-widget.vala b/src/client/composer/composer-widget.vala
index 37172593d..5ff1922e1 100644
--- a/src/client/composer/composer-widget.vala
+++ b/src/client/composer/composer-widget.vala
@@ -1145,10 +1145,8 @@ public class Composer.Widget : Gtk.EventBox, Geary.BaseInterface {
     private void on_content_loaded() {
         this.update_signature.begin(null);
         if (this.can_delete_quote) {
-            this.editor.body.selection_changed.connect(
-                () => {
-                    this.can_delete_quote = false;
-                }
+            this.editor.body.notify["has-selection"].connect(
+                () => { this.can_delete_quote = false; }
             );
         }
     }
diff --git a/src/client/conversation-viewer/conversation-message.vala 
b/src/client/conversation-viewer/conversation-message.vala
index ed94bcfca..72d8a575f 100644
--- a/src/client/conversation-viewer/conversation-message.vala
+++ b/src/client/conversation-viewer/conversation-message.vala
@@ -499,10 +499,6 @@ public class ConversationMessage : Gtk.Grid, Geary.BaseInterface {
         content_loaded();
     }
 
-    private void trigger_selection_changed(bool has_selection) {
-        selection_changed(has_selection);
-    }
-
     private ConversationMessage(Geary.EmailHeaderSet headers,
                                 string? preview,
                                 bool load_remote_resources,
@@ -616,13 +612,12 @@ public class ConversationMessage : Gtk.Grid, Geary.BaseInterface {
                 on_link_activated(new GLib.Variant("s", link));
             });
         this.web_view.mouse_target_changed.connect(on_mouse_target_changed);
+        this.web_view.notify["has-selection"].connect(on_selection_changed);
         this.web_view.notify["is-loading"].connect(on_is_loading_notify);
         this.web_view.resource_load_started.connect(on_resource_load_started);
         this.web_view.remote_image_load_blocked.connect(on_remote_images_blocked);
-        this.web_view.selection_changed.connect(on_selection_changed);
         this.web_view.internal_resource_loaded.connect(trigger_internal_resource_loaded);
         this.web_view.content_loaded.connect(trigger_content_loaded);
-        this.web_view.selection_changed.connect(trigger_selection_changed);
         this.web_view.set_hexpand(true);
         this.web_view.set_vexpand(true);
         this.web_view.show();
@@ -1431,8 +1426,9 @@ public class ConversationMessage : Gtk.Grid, Geary.BaseInterface {
         link_popover.popup();
     }
 
-    private void on_selection_changed(bool has_selection) {
-        set_action_enabled(ACTION_COPY_SELECTION, has_selection);
+    private void on_selection_changed() {
+        set_action_enabled(ACTION_COPY_SELECTION, this.web_view.has_selection);
+        selection_changed(this.web_view.has_selection);
     }
 
     private void on_remote_images_blocked() {


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