[gnome-documents/wip/cosimoc/view-rework: 42/42] view: move search actions here too



commit ccfdf4c54d2dc1533726b2326c0b3a1b93822bab
Author: Cosimo Cecchi <cosimoc gnome org>
Date:   Mon Aug 8 21:27:44 2016 -0700

    view: move search actions here too
    
    These are really view actions. Move them over.

 src/application.js |   20 +-------------------
 src/manager.js     |   10 ----------
 src/searchbar.js   |    2 +-
 src/view.js        |   51 ++++++++++++++++++++++++++++++++++++++++++++++++++-
 4 files changed, 52 insertions(+), 31 deletions(-)
---
diff --git a/src/application.js b/src/application.js
index a758299..a82395d 100644
--- a/src/application.js
+++ b/src/application.js
@@ -484,25 +484,7 @@ const Application = new Lang.Class({
             { name: 'search',
               callback: Utils.actionToggleCallback,
               state: GLib.Variant.new('b', false),
-              accels: ['<Primary>f'] },
-            { name: 'search-source',
-              parameter_type: 's',
-              state: GLib.Variant.new('s', Search.SearchSourceStock.ALL),
-              window_modes: [WindowMode.WindowMode.COLLECTIONS,
-                             WindowMode.WindowMode.DOCUMENTS,
-                             WindowMode.WindowMode.SEARCH] },
-            { name: 'search-type',
-              parameter_type: 's',
-              state: GLib.Variant.new('s', Search.SearchTypeStock.ALL),
-              window_modes: [WindowMode.WindowMode.COLLECTIONS,
-                             WindowMode.WindowMode.DOCUMENTS,
-                             WindowMode.WindowMode.SEARCH] },
-            { name: 'search-match',
-              parameter_type: 's',
-              state: GLib.Variant.new('s', Search.SearchMatchStock.ALL),
-              window_modes: [WindowMode.WindowMode.COLLECTIONS,
-                             WindowMode.WindowMode.DOCUMENTS,
-                             WindowMode.WindowMode.SEARCH] }
+              accels: ['<Primary>f'] }
         ];
 
         if (!this.isBooks)
diff --git a/src/manager.js b/src/manager.js
index 256b023..7252b31 100644
--- a/src/manager.js
+++ b/src/manager.js
@@ -184,16 +184,6 @@ const BaseModel = new Lang.Class({
         this._manager.connect('item-added', Lang.bind(this, this._refreshModel));
         this._manager.connect('item-removed', Lang.bind(this, this._refreshModel));
 
-        let application = Gio.Application.get_default();
-        let actionId = this._manager.getActionId();
-        application.connect('action-state-changed::' + actionId, Lang.bind(this, function(actionGroup, 
actionName, value) {
-            let itemId = value.get_string()[0];
-            this._manager.setActiveItemById(itemId);
-        }));
-        this._manager.connect('active-changed', Lang.bind(this, function(manager, activeItem) {
-            application.change_action_state(actionId, GLib.Variant.new('s', activeItem.id));
-        }));
-
         this._refreshModel();
     },
 
diff --git a/src/searchbar.js b/src/searchbar.js
index d1fe31a..c560063 100644
--- a/src/searchbar.js
+++ b/src/searchbar.js
@@ -136,7 +136,7 @@ const Dropdown = new Lang.Class({
 
              // HACK: see https://bugzilla.gnome.org/show_bug.cgi?id=733977
              let popover = new Gtk.Popover();
-             popover.bind_model(model, 'app');
+             popover.bind_model(model, 'view');
              let w = popover.get_child();
              w.reparent(grid);
              w.valign = Gtk.Align.START;
diff --git a/src/view.js b/src/view.js
index fb4fbcf..99a2fa5 100644
--- a/src/view.js
+++ b/src/view.js
@@ -39,6 +39,7 @@ const Mainloop = imports.mainloop;
 const Application = imports.application;
 const ErrorBox = imports.errorBox;
 const MainToolbar = imports.mainToolbar;
+const Search = imports.search;
 const WindowMode = imports.windowMode;
 const Utils = imports.utils;
 
@@ -420,7 +421,22 @@ const ViewContainer = new Lang.Class({
             { settingsKey: 'view-as',
               stateChanged: Lang.bind(this, this._updateTypeForSettings) },
             { settingsKey: 'sort-by',
-              stateChanged: Lang.bind(this, this._updateSortForSettings) }
+              stateChanged: Lang.bind(this, this._updateSortForSettings) },
+            { name: 'search-source',
+              parameter_type: 's',
+              state: GLib.Variant.new('s', Search.SearchSourceStock.ALL),
+              stateChanged: Lang.bind(this, this._updateSearchSource),
+              create_hook: Lang.bind(this, this._initSearchSource) },
+            { name: 'search-type',
+              parameter_type: 's',
+              state: GLib.Variant.new('s', Search.SearchTypeStock.ALL),
+              stateChanged: Lang.bind(this, this._updateSearchType),
+              create_hook: Lang.bind(this, this._initSearchType) },
+            { name: 'search-match',
+              parameter_type: 's',
+              state: GLib.Variant.new('s', Search.SearchMatchStock.ALL),
+              stateChanged: Lang.bind(this, this._updateSearchMatch),
+              create_hook: Lang.bind(this, this._initSearchMatch) }
         ];
     },
 
@@ -464,6 +480,39 @@ const ViewContainer = new Lang.Class({
         this._model.set_sort_column_id(sortBy, sortType);
     },
 
+    _initSearchSource: function(action) {
+        Application.sourceManager.connect('active-changed', Lang.bind(this, function(manager, activeItem) {
+            action.state = GLib.Variant.new('s', activeItem.id);
+        }));
+    },
+
+    _initSearchType: function(action) {
+        Application.searchTypeManager.connect('active-changed', Lang.bind(this, function(manager, 
activeItem) {
+            action.state = GLib.Variant.new('s', activeItem.id);
+        }));
+    },
+
+    _initSearchMatch: function(action) {
+        Application.searchMatchManager.connect('active-changed', Lang.bind(this, function(manager, 
activeItem) {
+            action.state = GLib.Variant.new('s', activeItem.id);
+        }));
+    },
+
+    _updateSearchSource: function(action) {
+        let itemId = action.state.get_string()[0];
+        Application.sourceManager.setActiveItemById(itemId);
+    },
+
+    _updateSearchType: function(action) {
+        let itemId = action.state.get_string()[0];
+        Application.searchTypeManager.setActiveItemById(itemId);
+    },
+
+    _updateSearchMatch: function(action) {
+        let itemId = action.state.get_string()[0];
+        Application.searchMatchManager.setActiveItemById(itemId);
+    },
+
     _activateResult: function() {
         let doc = this._getFirstDocument();
         if (doc)


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