[polari] app: Improve handling of stateful actions



commit 32f038df815d74f0fe3aae011552a305d60ec4fd
Author: Florian Müllner <fmuellner gnome org>
Date:   Fri Oct 4 22:23:45 2013 +0200

    app: Improve handling of stateful actions
    
    We adjust the state of the 'user-list' and 'selection-mode' actions
    when they are disabled. However as we do this directly after disabling
    the action, we behave inconsistently when the action is disabled
    elsewhere. Track the 'enabled' property separately instead to ensure
    consistency.

 src/application.js |   12 ++++++++----
 1 files changed, 8 insertions(+), 4 deletions(-)
---
diff --git a/src/application.js b/src/application.js
index 24a3a75..40195fe 100644
--- a/src/application.js
+++ b/src/application.js
@@ -188,8 +188,6 @@ const Application = new Lang.Class({
     _updateUserListAction: function(action) {
         let room = this._chatroomManager.getActiveRoom();
         action.enabled = room && room.channel.handle_type == Tp.HandleType.ROOM;
-        if (!action.enabled)
-            action.change_state(GLib.Variant.new('b', false));
     },
 
     _userListCreateHook: function(action) {
@@ -197,13 +195,15 @@ const Application = new Lang.Class({
             function() {
                 this._updateUserListAction(action);
             }));
+        action.connect('notify::enabled', function() {
+            if (!action.enabled)
+                action.change_state(GLib.Variant.new('b', false));
+        });
         this._updateUserListAction(action);
     },
 
     _updateSelectionModeAction: function(action) {
         action.enabled = this._chatroomManager.roomCount > 0;
-        if (!action.enabled)
-            action.change_state(GLib.Variant.new('b', false));
     },
 
     _selectionModeHook: function(action) {
@@ -211,6 +211,10 @@ const Application = new Lang.Class({
             function() {
                 this._updateSelectionModeAction(action);
             }));
+        action.connect('notify::enabled', function() {
+            if (!action.enabled)
+                action.change_state(GLib.Variant.new('b', false));
+        });
         this._updateSelectionModeAction(action);
     },
 


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