[gnome-documents/wip/split-view: 8/14] trackerController: Split it so that each view can have its own



commit e851ece42d3d5a82e92b84e08841ba6289a432de
Author: Debarshi Ray <debarshir gnome org>
Date:   Thu Oct 16 13:41:01 2014 +0200

    trackerController: Split it so that each view can have its own
    
    When we have multiple views, each of them would be showing different
    kinds of items, and they will be reacting differently to changes in
    search criteria. eg., the documents and collections views will always
    show only documents and collections, while the search view will show a
    mix of items depending on the current search criteria.
    
    Therefore, we need to allow each view to have its own implementation.
    
    Currently the only implementation is TrackerOverviewController, which
    is the same as the unified TrackerController that we had.
    
    https://bugzilla.gnome.org/show_bug.cgi?id=686461

 src/application.js       |    2 +-
 src/trackerController.js |   73 +++++++++++++++++++++++++++++++--------------
 2 files changed, 51 insertions(+), 24 deletions(-)
---
diff --git a/src/application.js b/src/application.js
index f147c2a..03cba8b 100644
--- a/src/application.js
+++ b/src/application.js
@@ -445,7 +445,7 @@ const Application = new Lang.Class({
         Search.initSearch(imports.shellSearchProvider);
 
         modeController = new WindowMode.ModeController();
-        trackerController = new TrackerController.TrackerController();
+        trackerController = new TrackerController.TrackerOverviewController();
         selectionController = new Selections.SelectionController();
 
         this._actionEntries = [
diff --git a/src/trackerController.js b/src/trackerController.js
index d21553e..1173b15 100644
--- a/src/trackerController.js
+++ b/src/trackerController.js
@@ -1,5 +1,5 @@
 /*
- * Copyright (c) 2011, 2013 Red Hat, Inc.
+ * Copyright (c) 2011, 2013, 2014 Red Hat, Inc.
  *
  * Gnome Documents is free software; you can redistribute it and/or modify
  * it under the terms of the GNU General Public License as published by the
@@ -111,9 +111,10 @@ const RefreshFlags = {
 const TrackerController = new Lang.Class({
     Name: 'TrackerController',
 
-    _init: function() {
+    _init: function(mode) {
         this._currentQuery = null;
         this._cancellable = new Gio.Cancellable();
+        this._mode = mode;
         this._queryQueued = false;
         this._queryQueuedFlags = RefreshFlags.NONE;
         this._querying = false;
@@ -125,22 +126,19 @@ const TrackerController = new Lang.Class({
 
         Application.sourceManager.connect('item-added', Lang.bind(this, this._onSourceAddedRemoved));
         Application.sourceManager.connect('item-removed', Lang.bind(this, this._onSourceAddedRemoved));
-        Application.sourceManager.connect('active-changed', Lang.bind(this, this._refreshForObject));
 
         Application.modeController.connect('window-mode-changed', Lang.bind(this,
             function(object, newMode) {
-                if (this._refreshPending && newMode == WindowMode.WindowMode.OVERVIEW)
+                if (this._refreshPending && newMode == this._mode)
                     this._refreshForSource();
             }));
 
-        Application.offsetController.connect('offset-changed', Lang.bind(this, this._performCurrentQuery));
-
-        Application.documentManager.connect('active-collection-changed', Lang.bind(this, 
this._refreshForObject));
-        Application.searchController.connect('search-string-changed', Lang.bind(this, 
this._refreshForObject));
-        Application.searchCategoryManager.connect('active-changed', Lang.bind(this, this._refreshForObject));
-        Application.searchTypeManager.connect('active-changed', Lang.bind(this, this._refreshForObject));
+        this._offsetController = this.getOffsetController();
+        this._offsetController.connect('offset-changed', Lang.bind(this, this._performCurrentQuery));
+    },
 
-        Application.searchMatchManager.connect('active-changed', Lang.bind(this, 
this._onSearchMatchChanged));
+    getOffsetController: function() {
+        log('Error: TrackerController implementations must override getOffsetController');
     },
 
     _setQueryStatus: function(status) {
@@ -159,6 +157,10 @@ const TrackerController = new Lang.Class({
         this.emit('query-status-changed', this._querying);
     },
 
+    getQuery: function() {
+        log('Error: TrackerController implementations must override getQuery');
+    },
+
     getQueryStatus: function() {
         return this._querying;
     },
@@ -177,7 +179,7 @@ const TrackerController = new Lang.Class({
         if (exception)
             this._onQueryError(exception);
         else
-            Application.offsetController.resetItemCount();
+            this._offsetController.resetItemCount();
 
         if (this._queryQueued) {
             this._queryQueued = false;
@@ -220,7 +222,7 @@ const TrackerController = new Lang.Class({
     },
 
     _performCurrentQuery: function() {
-        this._currentQuery = Application.queryBuilder.buildGlobalQuery();
+        this._currentQuery = this.getQuery();
         this._cancellable.reset();
 
         Application.connectionQueue.add(this._currentQuery.sparql,
@@ -231,7 +233,7 @@ const TrackerController = new Lang.Class({
         this._isStarted = true;
 
         if (flags & RefreshFlags.RESET_OFFSET)
-            Application.offsetController.resetOffset();
+            this._offsetController.resetOffset();
 
         if (this.getQueryStatus()) {
             this._cancellable.cancel();
@@ -245,7 +247,7 @@ const TrackerController = new Lang.Class({
         this._performCurrentQuery();
     },
 
-    _refreshForObject: function(_object, _item) {
+    refreshForObject: function(_object, _item) {
         this._refreshInternal(RefreshFlags.RESET_OFFSET);
     },
 
@@ -261,17 +263,10 @@ const TrackerController = new Lang.Class({
         this._refreshPending = false;
     },
 
-    _onSearchMatchChanged: function() {
-        // when the "match" search setting changes, refresh only if
-        // the search string is not empty
-        if (Application.searchController.getString() != '')
-            this._refreshInternal(RefreshFlags.RESET_OFFSET);
-    },
-
     _onSourceAddedRemoved: function(manager, item) {
         let mode = Application.modeController.getWindowMode();
 
-        if (mode == WindowMode.WindowMode.OVERVIEW)
+        if (mode == this._mode)
             this._refreshForSource();
         else
             this._refreshPending = true;
@@ -285,3 +280,35 @@ const TrackerController = new Lang.Class({
     }
 });
 Signals.addSignalMethods(TrackerController.prototype);
+
+const TrackerOverviewController = new Lang.Class({
+    Name: 'TrackerOverviewController',
+    Extends: TrackerController,
+
+    _init: function() {
+        this.parent(WindowMode.WindowMode.OVERVIEW);
+
+        Application.sourceManager.connect('active-changed', Lang.bind(this, this.refreshForObject));
+        Application.documentManager.connect('active-collection-changed', Lang.bind(this, 
this.refreshForObject));
+        Application.searchController.connect('search-string-changed', Lang.bind(this, 
this.refreshForObject));
+        Application.searchCategoryManager.connect('active-changed', Lang.bind(this, this.refreshForObject));
+        Application.searchTypeManager.connect('active-changed', Lang.bind(this, this.refreshForObject));
+
+        Application.searchMatchManager.connect('active-changed', Lang.bind(this, 
this._onSearchMatchChanged));
+    },
+
+    _onSearchMatchChanged: function() {
+        // when the "match" search setting changes, refresh only if
+        // the search string is not empty
+        if (Application.searchController.getString() != '')
+            this.refreshForObject();
+    },
+
+    getOffsetController: function() {
+        return Application.offsetController;
+    },
+
+    getQuery: function() {
+        return Application.queryBuilder.buildGlobalQuery();
+    },
+});


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