[gnome-documents] all: move Search/SideFilterControllers to Sidebar and Searchbar modules



commit fb9efa6accaf0d64e47f5b6713d8dc22ae84a9b2
Author: Cosimo Cecchi <cosimoc gnome org>
Date:   Tue Nov 1 11:37:59 2011 -0400

    all: move Search/SideFilterControllers to Sidebar and Searchbar modules
    
    No code changes, just shuffling pieces around to improve readability.

 src/Makefile-js.am       |    1 -
 src/application.js       |    6 +-
 src/documents.js         |    8 +-
 src/embed.js             |   10 ++--
 src/filters.js           |  153 ----------------------------------------------
 src/global.js            |    4 +-
 src/mainToolbar.js       |    8 +-
 src/mainWindow.js        |   12 ++--
 src/query.js             |    2 +-
 src/searchbar.js         |  106 ++++++++++++++++++++++++++------
 src/sidebar.js           |   74 ++++++++++++++++++++--
 src/trackerController.js |   10 ++--
 12 files changed, 185 insertions(+), 209 deletions(-)
---
diff --git a/src/Makefile-js.am b/src/Makefile-js.am
index a0828e6..382511a 100644
--- a/src/Makefile-js.am
+++ b/src/Makefile-js.am
@@ -8,7 +8,6 @@ dist_js_DATA = \
     embed.js \
     error.js \
     errorBox.js \
-    filters.js \
     gDataMiner.js \
     global.js \
     iconView.js \
diff --git a/src/application.js b/src/application.js
index e03db60..b4a617f 100644
--- a/src/application.js
+++ b/src/application.js
@@ -38,7 +38,6 @@ const ChangeMonitor = imports.changeMonitor;
 const Collections = imports.collections;
 const Documents = imports.documents;
 const Error = imports.error;
-const Filters = imports.filters;
 const Format = imports.format;
 const Global = imports.global;
 const Main = imports.main;
@@ -48,6 +47,7 @@ const Path = imports.path;
 const Query = imports.query;
 const Searchbar = imports.searchbar;
 const Selections = imports.selections;
+const Sidebar = imports.sidebar;
 const Sources = imports.sources;
 const TrackerController = imports.trackerController;
 const Tweener = imports.util.tweener;
@@ -121,7 +121,7 @@ Application.prototype = {
         Global.application = this;
         Global.settings = new Gio.Settings({ schema: 'org.gnome.documents' });
         Global.offsetController = new OffsetController.OffsetController();
-        Global.searchFilterController = new Filters.SearchFilterController();
+        Global.searchController = new Searchbar.SearchController();
         Global.categoryManager = new Categories.CategoryManager();
         Global.errorHandler = new Error.ErrorHandler();
 
@@ -150,7 +150,7 @@ Application.prototype = {
                         Global.queryBuilder = new Query.QueryBuilder();
                         Global.changeMonitor = new ChangeMonitor.TrackerChangeMonitor();
                         Global.collectionManager = new Collections.CollectionManager();
-                        Global.sideFilterController = new Filters.SideFilterController();
+                        Global.sidebarController = new Sidebar.SidebarController();
                         Global.documentManager = new Documents.DocumentManager();
                         Global.trackerController = new TrackerController.TrackerController();
                         Global.selectionController = new Selections.SelectionController();
diff --git a/src/documents.js b/src/documents.js
index a73c3c8..424697e 100644
--- a/src/documents.js
+++ b/src/documents.js
@@ -75,8 +75,8 @@ DocCommon.prototype = {
             Global.settings.connect('changed::list-view',
                                     Lang.bind(this, this.refreshIcon));
         this._filterId =
-            Global.sideFilterController.connect('changed',
-                                                Lang.bind(this, this.refreshIcon));
+            Global.sidebarController.connect('changed',
+                                             Lang.bind(this, this.refreshIcon));
     },
 
     refresh: function() {
@@ -182,7 +182,7 @@ DocCommon.prototype = {
         let pixbuf = this.pixbuf;
         let activeItem;
 
-        activeItem = Global.sideFilterController.getWhereItem();
+        activeItem = Global.sidebarController.getWhereItem();
 
         if (this.favorite &&
             (!activeItem ||
@@ -229,7 +229,7 @@ DocCommon.prototype = {
 
     destroy: function() {
         Global.settings.disconnect(this._refreshIconId);
-        Global.sideFilterController.disconnect(this._filterId);
+        Global.sidebarController.disconnect(this._filterId);
     },
 
     open: function(screen, timestamp) {
diff --git a/src/embed.js b/src/embed.js
index 44a1dbc..bc90430 100644
--- a/src/embed.js
+++ b/src/embed.js
@@ -170,7 +170,7 @@ ViewEmbed.prototype  = {
     },
 
     _windowModeChangeFlash: function() {
-        let visible = Global.sideFilterController.getSidebarVisible();
+        let visible = Global.sidebarController.getSidebarVisible();
 
         // if the sidebar is visible, wait until it completed fading in before
         // putting back the view
@@ -197,15 +197,15 @@ ViewEmbed.prototype  = {
         let mode = Global.modeController.getWindowMode();
 
         if (mode == WindowMode.WindowMode.OVERVIEW) {
-            let visible = Global.sideFilterController.getSidebarVisible();
+            let visible = Global.sidebarController.getSidebarVisible();
 
             // if the sidebar is visible, wait until it completed fading in before
             // putting back the view
             if (visible) {
                 let sidebarInId =
-                    Global.sideFilterController.connect('sidebar-in-changed', Lang.bind(this,
+                    Global.sidebarController.connect('sidebar-in-changed', Lang.bind(this,
                         function() {
-                            Global.sideFilterController.disconnect(sidebarInId);
+                            Global.sidebarController.disconnect(sidebarInId);
                             this._prepareForOverview();
                         }));
             } else {
@@ -401,7 +401,7 @@ ViewEmbed.prototype  = {
             this._queryErrorId = 0;
         }
 
-        Global.searchFilterController.setSearchVisible(false);
+        Global.searchController.setSearchVisible(false);
 
         if (this._adjustmentValueId != 0) {
             this._scrolledWinView.vadjustment.disconnect(this._adjustmentValueId);
diff --git a/src/global.js b/src/global.js
index 9adb9a8..029121e 100644
--- a/src/global.js
+++ b/src/global.js
@@ -28,10 +28,10 @@ let goaClient = null;
 let modeController = null;
 let offsetController = null;
 let queryBuilder = null;
-let searchFilterController = null;
+let searchController = null;
 let searchMatchManager = null;
 let searchTypeManager = null;
-let sideFilterController = null;
+let sidebarController = null;
 let selectionController = null;
 let settings = null;
 let stage = null;
diff --git a/src/mainToolbar.js b/src/mainToolbar.js
index bc3bf95..5684a94 100644
--- a/src/mainToolbar.js
+++ b/src/mainToolbar.js
@@ -63,7 +63,7 @@ MainToolbar.prototype = {
         this._model = null;
 
         if (this._whereId != 0) {
-            Global.sideFilterController.disconnect(this._whereId);
+            Global.sidebarController.disconnect(this._whereId);
             this._whereId = 0;
         }
 
@@ -184,8 +184,8 @@ MainToolbar.prototype = {
 
         // connect to sidebar filter changes while in this mode
         this._whereId =
-            Global.sideFilterController.connect('changed',
-                                                Lang.bind(this, this._onSideFilterChanged));
+            Global.sidebarController.connect('changed',
+                                             Lang.bind(this, this._onSideFilterChanged));
         this._onSideFilterChanged();
 
         this.widget.show_all();
@@ -255,7 +255,7 @@ MainToolbar.prototype = {
     },
 
     _onSideFilterChanged: function() {
-        let item = Global.sideFilterController.getWhereItem();
+        let item = Global.sidebarController.getWhereItem();
 
         if (!item)
             return;
diff --git a/src/mainWindow.js b/src/mainWindow.js
index 23e8ab2..68373f1 100644
--- a/src/mainWindow.js
+++ b/src/mainWindow.js
@@ -256,19 +256,19 @@ MainWindow.prototype = {
         let keyval = event.get_keyval()[1];
 
         if (keyval == Gdk.KEY_F9) {
-            let visible = Global.sideFilterController.getSidebarVisible();
-            Global.sideFilterController.setSidebarVisible(!visible);
+            let visible = Global.sidebarController.getSidebarVisible();
+            Global.sidebarController.setSidebarVisible(!visible);
             return true;
         }
 
         if (Utils.isSearchEvent(event)) {
-            let visible = Global.searchFilterController.getSearchVisible();
-            Global.searchFilterController.setSearchVisible(!visible);
+            let visible = Global.searchController.getSearchVisible();
+            Global.searchController.setSearchVisible(!visible);
             return true;
         }
 
-        if (!Global.searchFilterController.getSearchIn()) {
-            Global.searchFilterController.deliverEvent(event);
+        if (!Global.searchController.getSearchIn()) {
+            Global.searchController.deliverEvent(event);
             return true;
         }
 
diff --git a/src/query.js b/src/query.js
index 82a1b7b..0cabe0f 100644
--- a/src/query.js
+++ b/src/query.js
@@ -136,7 +136,7 @@ QueryBuilder.prototype = {
 
         if (global) {
             globalSparql +=
-                Global.sideFilterController.getWhere() +
+                Global.sidebarController.getWhere() +
                 this._buildFilterString() +
                 ' } ' +
                 'ORDER BY DESC (?mtime)' +
diff --git a/src/searchbar.js b/src/searchbar.js
index d224a0b..9a76e6c 100644
--- a/src/searchbar.js
+++ b/src/searchbar.js
@@ -27,6 +27,7 @@ const _ = imports.gettext.gettext;
 
 const Lang = imports.lang;
 const Mainloop = imports.mainloop;
+const Signals = imports.signals;
 
 const Global = imports.global;
 const Manager = imports.manager;
@@ -99,11 +100,11 @@ SearchMatch.prototype = {
         if (this.id == SEARCH_MATCH_TITLE)
             return ('fn:contains ' +
                     '(fn:lower-case (tracker:coalesce(nie:title(?urn), nfo:fileName(?urn))), ' +
-                    '"%s")').format(Global.searchFilterController.getString());
+                    '"%s")').format(Global.searchController.getString());
         if (this.id == SEARCH_MATCH_AUTHOR)
             return ('fn:contains ' +
                     '(fn:lower-case (tracker:coalesce(nco:fullname(?creator), nco:fullname(?publisher))), ' +
-                    '"%s")').format(Global.searchFilterController.getString());
+                    '"%s")').format(Global.searchController.getString());
 
         return '';
     }
@@ -130,6 +131,75 @@ SearchMatchManager.prototype = {
     }
 };
 
+function SearchController() {
+    this._init();
+};
+
+SearchController.prototype = {
+    _init: function() {
+        this._searchVisible = false;
+        this._searchIn = false;
+        this._dropdownState = false;
+        this._string = '';
+    },
+
+    setString: function(string) {
+        if (this._string == string)
+            return;
+
+        this._string = string;
+        this.emit('search-string-changed', this._string);
+    },
+
+    getString: function() {
+        return this._string;
+    },
+
+    setDropownState: function(state) {
+        if (this._dropdownState == state)
+            return;
+
+        this._dropdownState = state;
+        this.emit('search-dropdown-changed', this._dropdownState);
+    },
+
+    getDropdownState: function() {
+        return this._dropdownState;
+    },
+
+    setSearchVisible: function(visible) {
+        if (this._searchVisible == visible)
+            return;
+
+        this._searchVisible = visible;
+        this.emit('search-visible-changed', this._searchVisible);
+
+        if (!this._searchVisible)
+            this.setDropownState(false);
+    },
+
+    getSearchVisible: function() {
+        return this._searchVisible;
+    },
+
+    setSearchIn: function(setting) {
+        if (this._searchIn == setting)
+            return;
+
+        this._searchIn = setting;
+        this.emit('search-in-changed', this._searchIn);
+    },
+
+    getSearchIn: function() {
+        return this._searchIn;
+    },
+
+    deliverEvent: function(event) {
+        this.emit('deliver-event', event);
+    }
+};
+Signals.addSignalMethods(SearchController.prototype);
+
 function Dropdown() {
     this._init();
 }
@@ -155,13 +225,13 @@ Dropdown.prototype = {
 
         this.widget.show_all();
 
-        Global.searchFilterController.connect('search-dropdown-changed',
-                                              Lang.bind(this, this._onSearchDropdown));
+        Global.searchController.connect('search-dropdown-changed',
+                                        Lang.bind(this, this._onSearchDropdown));
         this._onSearchDropdown();
     },
 
     _onSearchDropdown: function() {
-        let state = Global.searchFilterController.getDropdownState();
+        let state = Global.searchController.getDropdownState();
         if (state)
             this._fadeIn();
         else
@@ -217,7 +287,7 @@ Searchbar.prototype = {
         this._dropdownButton.connect('toggled', Lang.bind(this,
             function() {
                 let active = this._dropdownButton.get_active();
-                Global.searchFilterController.setDropownState(active);
+                Global.searchController.setDropownState(active);
             }));
 
         box.add(this._dropdownButton);
@@ -235,7 +305,7 @@ Searchbar.prototype = {
                 let keyval = event.get_keyval()[1];
 
                 if (keyval == Gdk.KEY_Escape) {
-                    Global.searchFilterController.setSearchVisible(false);
+                    Global.searchController.setSearchVisible(false);
                     return true;
                 }
 
@@ -264,7 +334,7 @@ Searchbar.prototype = {
                     this._searchEntryTimeout = 0;
 
                     let currentText = this._searchEntry.get_text();
-                    Global.searchFilterController.setString(currentText);
+                    Global.searchController.setString(currentText);
             }));
         }));
 
@@ -273,24 +343,24 @@ Searchbar.prototype = {
         }));
 
         this._searchFocusId =
-            Global.searchFilterController.connect('search-visible-changed', Lang.bind(this, this._onSearchVisible));
+            Global.searchController.connect('search-visible-changed', Lang.bind(this, this._onSearchVisible));
         this._searchEventId =
-            Global.searchFilterController.connect('deliver-event', Lang.bind(this, this._onDeliverEvent));
+            Global.searchController.connect('deliver-event', Lang.bind(this, this._onDeliverEvent));
 
         this.widget.insert(item, 0);
-        this._searchEntry.set_text(Global.searchFilterController.getString());
+        this._searchEntry.set_text(Global.searchController.getString());
 
         this.widget.show_all();
     },
 
     destroy: function() {
         if (this._searchFocusId != 0) {
-            Global.searchFilterController.disconnect(this._searchFocusId);
+            Global.searchController.disconnect(this._searchFocusId);
             this._searchFocusId = 0;
         }
 
         if (this._searchEventId != 0) {
-            Global.searchFilterController.disconnect(this._searchEventId);
+            Global.searchController.disconnect(this._searchEventId);
             this._searchEventId = 0;
         }
 
@@ -298,7 +368,7 @@ Searchbar.prototype = {
     },
 
     _onSearchVisible: function() {
-        if (Global.searchFilterController.getSearchVisible())
+        if (Global.searchController.getSearchVisible())
             this._moveIn(Gtk.get_current_event_device());
         else
             this._moveOut();
@@ -322,8 +392,8 @@ Searchbar.prototype = {
         this._searchEntry.disconnect(preeditChangedId);
 
         if (((res && (newText != oldText)) || preeditChanged) &&
-            !Global.searchFilterController.getSearchIn()) {
-            Global.searchFilterController.setSearchVisible(true);
+            !Global.searchController.getSearchIn()) {
+            Global.searchController.setSearchVisible(true);
         }
     },
 
@@ -334,7 +404,7 @@ Searchbar.prototype = {
                                        time: 0.20,
                                        transition: 'easeOutQuad',
                                        onComplete: function() {
-                                           Global.searchFilterController.setSearchIn(true);
+                                           Global.searchController.setSearchIn(true);
 
                                            Gd.entry_focus_hack(this._searchEntry, eventDevice);
                                        },
@@ -348,7 +418,7 @@ Searchbar.prototype = {
                                        onComplete: function() {
                                            this._searchEntry.hide();
                                            this._dropdownButton.set_active(false);
-                                           Global.searchFilterController.setSearchIn(false);
+                                           Global.searchController.setSearchIn(false);
                                        },
                                        onCompleteScope: this });
     }
diff --git a/src/sidebar.js b/src/sidebar.js
index 9cad582..ac3dabc 100644
--- a/src/sidebar.js
+++ b/src/sidebar.js
@@ -36,6 +36,66 @@ const WindowMode = imports.windowMode;
 
 const _SIDEBAR_WIDTH_REQUEST = 240;
 
+function SidebarController() {
+    this._init();
+}
+
+SidebarController.prototype = {
+    _init: function() {
+        // intialize to last category
+        this._whereItem = Global.categoryManager.getActiveItem();
+
+        this._sidebarVisible = true;
+        this._sidebarIn = false;
+    },
+
+    setActiveItem: function(controller, item) {
+        if (this._whereItem == item)
+            return;
+
+        this._whereItem = item;
+        controller.setActiveItem(this._whereItem);
+
+        this.emit('changed', this._whereItem);
+    },
+
+    setSidebarVisible: function(visible) {
+        if (this._sidebarVisible == visible)
+            return;
+
+        this._sidebarVisible = visible;
+        this.emit('sidebar-visible-changed', this._sidebarVisible);
+    },
+
+    getSidebarVisible: function() {
+        return this._sidebarVisible;
+    },
+
+    setSidebarIn: function(setting) {
+        if (this._sidebarIn == setting)
+            return;
+
+        this._sidebarIn = setting;
+        this.emit('sidebar-in-changed', this._sidebarIn);
+    },
+
+    getSidebarIn: function() {
+        return this._sidebarIn;
+    },
+
+    getWhere: function() {
+        if (!this._whereItem)
+            return '';
+
+        return this._whereItem.getWhere();
+    },
+
+    getWhereItem: function() {
+        return this._whereItem;
+    }
+};
+Signals.addSignalMethods(SidebarController.prototype);
+
 const SidebarModelColumns = {
     ID: 0,
     NAME: 1,
@@ -208,7 +268,7 @@ SidebarView.prototype = {
                     controller = Global.collectionManager;
 
                 let item = controller.getItemById(id);
-                Global.sideFilterController.setActiveItem(controller, item);
+                Global.sidebarController.setActiveItem(controller, item);
             }));
 
         let col = new Gtk.TreeViewColumn();
@@ -374,8 +434,8 @@ Sidebar.prototype = {
 
         Global.modeController.connect('window-mode-changed',
                                       Lang.bind(this, this._onWindowModeChanged));
-        Global.sideFilterController.connect('sidebar-visible-changed',
-                                            Lang.bind(this, this._onSidebarVisible));
+        Global.sidebarController.connect('sidebar-visible-changed',
+                                         Lang.bind(this, this._onSidebarVisible));
 
         this._onSidebarVisible();
     },
@@ -385,7 +445,7 @@ Sidebar.prototype = {
                                        time: 0.15,
                                        transition: 'easeInQuad',
                                        onComplete: function() {
-                                           Global.sideFilterController.setSidebarIn(false);
+                                           Global.sidebarController.setSidebarIn(false);
                                        },
                                        onCompleteScope: this });
     },
@@ -395,7 +455,7 @@ Sidebar.prototype = {
                                        time: 0.15,
                                        transition: 'easeOutQuad',
                                        onComplete: function() {
-                                           Global.sideFilterController.setSidebarIn(true);
+                                           Global.sidebarController.setSidebarIn(true);
                                        },
                                        onCompleteScope: this });
     },
@@ -404,13 +464,13 @@ Sidebar.prototype = {
         if (mode == WindowMode.WindowMode.PREVIEW) {
             this._moveOut();
         } else if (mode == WindowMode.WindowMode.OVERVIEW) {
-            if (Global.sideFilterController.getSidebarVisible())
+            if (Global.sidebarController.getSidebarVisible())
                 this._moveIn();
         }
     },
 
     _onSidebarVisible: function() {
-        let visible = Global.sideFilterController.getSidebarVisible();
+        let visible = Global.sidebarController.getSidebarVisible();
         if (visible)
             this._moveIn();
         else
diff --git a/src/trackerController.js b/src/trackerController.js
index 12ad9c6..67697a5 100644
--- a/src/trackerController.js
+++ b/src/trackerController.js
@@ -57,10 +57,10 @@ TrackerController.prototype = {
         this._offsetController.connect('offset-changed',
                                        Lang.bind(this, this._performCurrentQuery));
 
-        Global.sideFilterController.connect('changed',
-                                            Lang.bind(this, this._refresh));
-        Global.searchFilterController.connect('search-string-changed',
-                                              Lang.bind(this, this._onSearchRefresh));
+        Global.sidebarController.connect('changed',
+                                         Lang.bind(this, this._refresh));
+        Global.searchController.connect('search-string-changed',
+                                        Lang.bind(this, this._onSearchRefresh));
         Global.searchMatchManager.connect('active-changed',
                                           Lang.bind(this, this._onSearchMatchChanged));
         Global.searchTypeManager.connect('active-changed',
@@ -170,7 +170,7 @@ TrackerController.prototype = {
     _onSearchMatchChanged: function() {
         // when the "match" search setting changes, refresh only if
         // the search string is not empty
-        if (Global.searchFilterController.getString() != '')
+        if (Global.searchController.getString() != '')
             this._onSearchRefresh();
     },
 



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