[gnome-documents] searchbar: implement selection of filter match
- From: Cosimo Cecchi <cosimoc src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [gnome-documents] searchbar: implement selection of filter match
- Date: Wed, 2 Nov 2011 20:49:12 +0000 (UTC)
commit 98000d51ac7aa549535ac07a622614de04bb30aa
Author: Cosimo Cecchi <cosimoc gnome org>
Date: Sun Oct 30 01:43:39 2011 -0400
searchbar: implement selection of filter match
src/application.js | 4 +-
src/filters.js | 14 +++++-----
src/global.js | 4 +-
src/query.js | 15 +----------
src/searchbar.js | 60 ++++++++++++++++++++++++++++++++++-----------
src/trackerController.js | 15 +++++++++--
6 files changed, 69 insertions(+), 43 deletions(-)
---
diff --git a/src/application.js b/src/application.js
index 8278007..e03db60 100644
--- a/src/application.js
+++ b/src/application.js
@@ -145,8 +145,8 @@ Application.prototype = {
}
Global.sourceManager = new Sources.SourceManager();
- Global.matchManager = new Searchbar.MatchManager();
- Global.typeManager = new Searchbar.SearchTypeManager();
+ Global.searchMatchManager = new Searchbar.SearchMatchManager();
+ Global.searchTypeManager = new Searchbar.SearchTypeManager();
Global.queryBuilder = new Query.QueryBuilder();
Global.changeMonitor = new ChangeMonitor.TrackerChangeMonitor();
Global.collectionManager = new Collections.CollectionManager();
diff --git a/src/filters.js b/src/filters.js
index 72dcdfe..9dd1621 100644
--- a/src/filters.js
+++ b/src/filters.js
@@ -32,19 +32,19 @@ SearchFilterController.prototype = {
this._searchVisible = false;
this._searchIn = false;
this._dropdownState = false;
- this._filter = '';
+ this._string = '';
},
- setFilter: function(filter) {
- if (this._filter == filter)
+ setString: function(string) {
+ if (this._string == string)
return;
- this._filter = filter;
- this.emit('search-filter-changed', this._filter);
+ this._string = string;
+ this.emit('search-string-changed', this._string);
},
- getFilter: function() {
- return this._filter;
+ getString: function() {
+ return this._string;
},
setDropownState: function(state) {
diff --git a/src/global.js b/src/global.js
index bc72928..9adb9a8 100644
--- a/src/global.js
+++ b/src/global.js
@@ -25,15 +25,15 @@ let connection = null;
let documentManager = null;
let errorHandler = null;
let goaClient = null;
-let matchManager = null;
let modeController = null;
let offsetController = null;
let queryBuilder = null;
let searchFilterController = null;
+let searchMatchManager = null;
+let searchTypeManager = null;
let sideFilterController = null;
let selectionController = null;
let settings = null;
let stage = null;
let sourceManager = null;
let trackerController = null;
-let typeManager = null;
diff --git a/src/query.js b/src/query.js
index d6b1e49..cf5778f 100644
--- a/src/query.js
+++ b/src/query.js
@@ -105,19 +105,6 @@ QueryBuilder.prototype = {
return sparql;
},
- _buildFilterSearch: function() {
- let filter =
- ('(fn:contains ' +
- '(fn:lower-case (tracker:coalesce(nie:title(?urn), nfo:fileName(?urn))), ' +
- '"%s") ||' +
- 'fn:contains ' +
- '(fn:lower-case (tracker:coalesce(nco:fullname(?creator), nco:fullname(?publisher))), ' +
- '"%s"))').format(Global.searchFilterController.getFilter(),
- Global.searchFilterController.getFilter());
-
- return filter;
- },
-
_buildFilterType: function() {
let filter =
'(fn:contains(rdf:type(?urn), \"nfo#PaginatedTextDocument\") ||'
@@ -130,7 +117,7 @@ QueryBuilder.prototype = {
_buildFilterString: function() {
let sparql = 'FILTER (';
- sparql += '(' + this._buildFilterSearch() + ')';
+ sparql += Global.searchMatchManager.getFilter();
sparql += ' && ';
sparql += Global.sourceManager.getFilter();
sparql += ' && ';
diff --git a/src/searchbar.js b/src/searchbar.js
index de70924..dc6fb69 100644
--- a/src/searchbar.js
+++ b/src/searchbar.js
@@ -74,35 +74,65 @@ SearchTypeManager.prototype = {
}
};
-function Match(params) {
+const SEARCH_MATCH_AUTHOR = 'author';
+const SEARCH_MATCH_TITLE = 'title';
+const SEARCH_MATCH_ALL = 'all';
+
+function SearchMatch(params) {
this._init(params);
}
-Match.prototype = {
+SearchMatch.prototype = {
_init: function(params) {
this.id = params.id;
this.name = params.name;
+ },
+
+ getFilter: function() {
+ let res = null;
+
+ if (this.id == SEARCH_MATCH_ALL)
+ res = (this._getFilterById(SEARCH_MATCH_TITLE) +
+ ' || ' +
+ this._getFilterById(SEARCH_MATCH_AUTHOR));
+ if (!res)
+ res = this._getFilterById(this.id);
+
+ return '(' + res + ')';
+ },
+
+ _getFilterById: function(id) {
+ if (id == SEARCH_MATCH_TITLE)
+ return ('fn:contains ' +
+ '(fn:lower-case (tracker:coalesce(nie:title(?urn), nfo:fileName(?urn))), ' +
+ '"%s")').format(Global.searchFilterController.getString());
+ if (id == SEARCH_MATCH_AUTHOR)
+ return ('fn:contains ' +
+ '(fn:lower-case (tracker:coalesce(nco:fullname(?creator), nco:fullname(?publisher))), ' +
+ '"%s")').format(Global.searchFilterController.getString());
+
+ return '';
}
};
-function MatchManager() {
+function SearchMatchManager() {
this._init();
}
-MatchManager.prototype = {
+SearchMatchManager.prototype = {
__proto__: Manager.BaseManager.prototype,
_init: function() {
Manager.BaseManager.prototype._init.call(this, _("Match"));
- this.addItem(new Match({ id: 'all',
- name: _("All") }));
- this.addItem(new Match({ id: 'title',
- name: _("Title") }));
- this.addItem(new Match({ id: 'author',
- name: _("Author") }));
+ this.addItem(new SearchMatch({ id: SEARCH_MATCH_ALL,
+ name: _("All") }));
+ this.addItem(new SearchMatch({ id: SEARCH_MATCH_TITLE,
+ name: _("Title") }));
+ this.addItem(new SearchMatch({ id: SEARCH_MATCH_AUTHOR,
+ name: _("Author") }));
- this.setActiveItemById('all');
+ this.setActiveItemById(SEARCH_MATCH_ALL);
}
};
@@ -113,8 +143,8 @@ function Dropdown() {
Dropdown.prototype = {
_init: function() {
this._sourceView = new Manager.BaseView(Global.sourceManager);
- this._typeView = new Manager.BaseView(Global.typeManager);
- this._matchView = new Manager.BaseView(Global.matchManager);
+ this._typeView = new Manager.BaseView(Global.searchTypeManager);
+ this._matchView = new Manager.BaseView(Global.searchMatchManager);
this.widget = new Gtk.Frame({ shadow_type: Gtk.ShadowType.IN });
this.actor = new GtkClutter.Actor({ contents: this.widget,
@@ -240,7 +270,7 @@ Searchbar.prototype = {
this._searchEntryTimeout = 0;
let currentText = this._searchEntry.get_text();
- Global.searchFilterController.setFilter(currentText);
+ Global.searchFilterController.setString(currentText);
}));
}));
@@ -254,7 +284,7 @@ Searchbar.prototype = {
Global.searchFilterController.connect('deliver-event', Lang.bind(this, this._onDeliverEvent));
this.widget.insert(item, 0);
- this._searchEntry.set_text(Global.searchFilterController.getFilter());
+ this._searchEntry.set_text(Global.searchFilterController.getString());
this.widget.show_all();
},
diff --git a/src/trackerController.js b/src/trackerController.js
index 95d09c0..f030b6c 100644
--- a/src/trackerController.js
+++ b/src/trackerController.js
@@ -59,8 +59,10 @@ TrackerController.prototype = {
Global.sideFilterController.connect('changed',
Lang.bind(this, this._refresh));
- Global.searchFilterController.connect('search-filter-changed',
- Lang.bind(this, this._onSearchFilterChanged));
+ Global.searchFilterController.connect('search-string-changed',
+ Lang.bind(this, this._onSearchRefresh));
+ Global.searchMatchManager.connect('active-changed',
+ Lang.bind(this, this._onSearchMatchChanged));
// perform initial query
this._refresh();
@@ -158,11 +160,18 @@ TrackerController.prototype = {
this._performCurrentQuery();
},
- _onSearchFilterChanged: function() {
+ _onSearchRefresh: function() {
this._offsetController.resetOffset();
this._refresh();
},
+ _onSearchMatchChanged: function() {
+ // when the "match" search setting changes, refresh only if
+ // the search string is not empty
+ if (Global.searchFilterController.getString() != '')
+ this._onSearchRefresh();
+ },
+
_onSourceAddedRemoved: function(manager, item) {
// When a source is added or removed, refresh the model only if
// the current source is All.
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]