[gnome-documents] Protect against spurious view-as signals



commit 78a41e8e9b8fc39aef7cc2d314f7cb9a625f492c
Author: Debarshi Ray <debarshir gnome org>
Date:   Wed Feb 5 17:13:02 2014 +0100

    Protect against spurious view-as signals
    
    Do not let the GAction and GSettings unnecessarily change each others
    state and value when there has been no change.
    
    Listen to the GAction's state for actually changing the UI, because
    someone using dconf-editor will still be able to emit spurious
    changed::view-as signals from GSettings.
    
    https://bugzilla.gnome.org/show_bug.cgi?id=723690

 src/application.js |    7 +++++--
 src/documents.js   |    4 ++--
 src/view.js        |    2 +-
 3 files changed, 8 insertions(+), 5 deletions(-)
---
diff --git a/src/application.js b/src/application.js
index db64dbf..9766c1f 100644
--- a/src/application.js
+++ b/src/application.js
@@ -160,7 +160,9 @@ const Application = new Lang.Class({
     _viewAsCreateHook: function(action) {
         settings.connect('changed::view-as', Lang.bind(this,
             function() {
-                action.state = settings.get_value('view-as');
+                let state = settings.get_value('view-as');
+                if (state.get_string()[0] != action.state.get_string()[0])
+                    action.state = state;
             }));
     },
 
@@ -187,7 +189,8 @@ const Application = new Lang.Class({
     },
 
     _onActionViewAs: function(action, parameter) {
-        settings.set_value('view-as', parameter);
+        if (parameter.get_string()[0] != action.state.get_string()[0])
+            settings.set_value('view-as', parameter);
     },
 
     _onActionOpenCurrent: function() {
diff --git a/src/documents.js b/src/documents.js
index 5e4d934..212e90e 100644
--- a/src/documents.js
+++ b/src/documents.js
@@ -248,8 +248,8 @@ const DocCommon = new Lang.Class({
         this.populateFromCursor(cursor);
 
         this._refreshIconId =
-            Application.settings.connect('changed::view-as',
-                                         Lang.bind(this, this.refreshIcon));
+            Application.application.connect('action-state-changed::view-as',
+                                            Lang.bind(this, this.refreshIcon));
         this._filterId =
             Application.searchCategoryManager.connect('active-changed',
                                                       Lang.bind(this, this.refreshIcon));
diff --git a/src/view.js b/src/view.js
index 8eaa6de..a52194a 100644
--- a/src/view.js
+++ b/src/view.js
@@ -206,7 +206,7 @@ const ViewContainer = new Lang.Class({
                             Lang.bind(this, this._onViewSelectionChanged));
 
         // connect to settings change for list/grid view
-        this._viewSettingsId = Application.settings.connect('changed::view-as',
+        this._viewSettingsId = Application.application.connect('action-state-changed::view-as',
             Lang.bind(this, this._updateTypeForSettings));
         this._updateTypeForSettings();
 


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