[gnome-documents] all: unify FocusController and SearchFilterController
- From: Cosimo Cecchi <cosimoc src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [gnome-documents] all: unify FocusController and SearchFilterController
- Date: Wed, 2 Nov 2011 20:49:07 +0000 (UTC)
commit d08d2e3aaae057794a11c1ea5eb2c3086c878182
Author: Cosimo Cecchi <cosimoc gnome org>
Date: Sun Oct 30 01:05:57 2011 -0400
all: unify FocusController and SearchFilterController
Simplifies code mostly.
src/application.js | 1 -
src/embed.js | 2 ++
src/filters.js | 36 ++++++++++++++++++++++++++++++++++--
src/global.js | 1 -
src/mainWindow.js | 7 ++++---
src/searchbar.js | 31 ++++++++++++++-----------------
src/trackerController.js | 2 +-
src/windowMode.js | 26 --------------------------
8 files changed, 55 insertions(+), 51 deletions(-)
---
diff --git a/src/application.js b/src/application.js
index 5c4ebaf..8278007 100644
--- a/src/application.js
+++ b/src/application.js
@@ -155,7 +155,6 @@ Application.prototype = {
Global.trackerController = new TrackerController.TrackerController();
Global.selectionController = new Selections.SelectionController();
Global.modeController = new WindowMode.ModeController();
- Global.focusController = new WindowMode.FocusController();
this._mainWindow = new MainWindow.MainWindow();
this.activate();
diff --git a/src/embed.js b/src/embed.js
index df8f1a4..8ecaebf 100644
--- a/src/embed.js
+++ b/src/embed.js
@@ -329,6 +329,8 @@ ViewEmbed.prototype = {
this._queryErrorId = 0;
}
+ Global.searchFilterController.setSearchVisible(false);
+
if (!this._scrolledWinPreview) {
this._scrolledWinPreview = new Gtk.ScrolledWindow({ hexpand: true,
vexpand: true,
diff --git a/src/filters.js b/src/filters.js
index b440881..72dcdfe 100644
--- a/src/filters.js
+++ b/src/filters.js
@@ -29,6 +29,8 @@ function SearchFilterController() {
SearchFilterController.prototype = {
_init: function() {
+ this._searchVisible = false;
+ this._searchIn = false;
this._dropdownState = false;
this._filter = '';
},
@@ -38,7 +40,7 @@ SearchFilterController.prototype = {
return;
this._filter = filter;
- this.emit('changed', this._filter);
+ this.emit('search-filter-changed', this._filter);
},
getFilter: function() {
@@ -48,12 +50,42 @@ SearchFilterController.prototype = {
setDropownState: function(state) {
if (state != this._dropdownState) {
this._dropdownState = state;
- this.emit('search-dropdown', this._dropdownState);
+ this.emit('search-dropdown-changed', this._dropdownState);
}
},
getDropdownState: function() {
return this._dropdownState;
+ },
+
+ setSearchVisible: function(visible) {
+ if (visible != this._searchVisible) {
+ 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(SearchFilterController.prototype);
diff --git a/src/global.js b/src/global.js
index c6083e7..bc72928 100644
--- a/src/global.js
+++ b/src/global.js
@@ -24,7 +24,6 @@ let categoryManager = null;
let connection = null;
let documentManager = null;
let errorHandler = null;
-let focusController = null;
let goaClient = null;
let matchManager = null;
let modeController = null;
diff --git a/src/mainWindow.js b/src/mainWindow.js
index aff38e8..8249a1f 100644
--- a/src/mainWindow.js
+++ b/src/mainWindow.js
@@ -261,12 +261,13 @@ MainWindow.prototype = {
}
if (Utils.isSearchEvent(event)) {
- Global.focusController.toggleSearch();
+ let visible = Global.searchFilterController.getSearchVisible();
+ Global.searchFilterController.setSearchVisible(!visible);
return true;
}
- if (!Global.focusController.getSearchVisible()) {
- Global.focusController.deliverEvent(event);
+ if (!Global.searchFilterController.getSearchIn()) {
+ Global.searchFilterController.deliverEvent(event);
return true;
}
diff --git a/src/searchbar.js b/src/searchbar.js
index c601904..de70924 100644
--- a/src/searchbar.js
+++ b/src/searchbar.js
@@ -131,7 +131,7 @@ Dropdown.prototype = {
this.widget.show_all();
- Global.searchFilterController.connect('search-dropdown',
+ Global.searchFilterController.connect('search-dropdown-changed',
Lang.bind(this, this._onSearchDropdown));
this._onSearchDropdown();
},
@@ -171,7 +171,6 @@ Searchbar.prototype = {
this._searchEventId = 0;
this._searchFocusId = 0;
this._searchEntryTimeout = 0;
- this._searchFadingIn = false;
this.widget = new Gtk.Toolbar();
this.widget.get_style_context().add_class(Gtk.STYLE_CLASS_PRIMARY_TOOLBAR);
@@ -212,7 +211,7 @@ Searchbar.prototype = {
let keyval = event.get_keyval()[1];
if (keyval == Gdk.KEY_Escape) {
- this._moveOut();
+ Global.searchFilterController.setSearchVisible(false);
return true;
}
@@ -250,9 +249,9 @@ Searchbar.prototype = {
}));
this._searchFocusId =
- Global.focusController.connect('toggle-search', Lang.bind(this, this._onToggleSearch));
+ Global.searchFilterController.connect('search-visible-changed', Lang.bind(this, this._onSearchVisible));
this._searchEventId =
- Global.focusController.connect('deliver-event', Lang.bind(this, this._onDeliverEvent));
+ Global.searchFilterController.connect('deliver-event', Lang.bind(this, this._onDeliverEvent));
this.widget.insert(item, 0);
this._searchEntry.set_text(Global.searchFilterController.getFilter());
@@ -262,23 +261,23 @@ Searchbar.prototype = {
destroy: function() {
if (this._searchFocusId != 0) {
- Global.focusController.disconnect(this._searchFocusId);
+ Global.searchFilterController.disconnect(this._searchFocusId);
this._searchFocusId = 0;
}
if (this._searchEventId != 0) {
- Global.focusController.disconnect(this._searchEventId);
+ Global.searchFilterController.disconnect(this._searchEventId);
this._searchEventId = 0;
}
this.widget.destroy();
},
- _onToggleSearch: function() {
- if (Global.focusController.getSearchVisible())
- this._moveOut();
- else
+ _onSearchVisible: function() {
+ if (Global.searchFilterController.getSearchVisible())
this._moveIn(Gtk.get_current_event_device());
+ else
+ this._moveOut();
},
_onDeliverEvent: function(controller, event) {
@@ -299,21 +298,19 @@ Searchbar.prototype = {
this._searchEntry.disconnect(preeditChangedId);
if (((res && (newText != oldText)) || preeditChanged) &&
- !this._searchFadingIn) {
- this._moveIn(event.get_device());
+ !Global.searchFilterController.getSearchIn()) {
+ Global.searchFilterController.setSearchVisible(true);
}
},
_moveIn: function(eventDevice) {
this._searchEntry.show();
- this._searchFadingIn = true;
Tweener.addTween(this.actor, { height: this.widget.get_preferred_height()[1],
time: 0.20,
transition: 'easeOutQuad',
onComplete: function() {
- this._searchFadingIn = false;
- Global.focusController.setSearchVisible(true);
+ Global.searchFilterController.setSearchIn(true);
Gd.entry_focus_hack(this._searchEntry, eventDevice);
},
@@ -321,13 +318,13 @@ Searchbar.prototype = {
},
_moveOut: function() {
- Global.focusController.setSearchVisible(false);
Tweener.addTween(this.actor, { height: 0,
time: 0.20,
transition: 'easeOutQuad',
onComplete: function() {
this._searchEntry.hide();
this._dropdownButton.set_active(false);
+ Global.searchFilterController.setSearchIn(false);
},
onCompleteScope: this });
}
diff --git a/src/trackerController.js b/src/trackerController.js
index 50ce50a..95d09c0 100644
--- a/src/trackerController.js
+++ b/src/trackerController.js
@@ -59,7 +59,7 @@ TrackerController.prototype = {
Global.sideFilterController.connect('changed',
Lang.bind(this, this._refresh));
- Global.searchFilterController.connect('changed',
+ Global.searchFilterController.connect('search-filter-changed',
Lang.bind(this, this._onSearchFilterChanged));
// perform initial query
diff --git a/src/windowMode.js b/src/windowMode.js
index ac53659..7ba2d29 100644
--- a/src/windowMode.js
+++ b/src/windowMode.js
@@ -82,29 +82,3 @@ ModeController.prototype = {
}
};
Signals.addSignalMethods(ModeController.prototype);
-
-function FocusController() {
- this._init();
-};
-
-FocusController.prototype = {
- _init: function() {
- },
-
- toggleSearch: function() {
- this.emit('toggle-search');
- },
-
- getSearchVisible: function() {
- return this._searchVisible;
- },
-
- setSearchVisible: function(visible) {
- this._searchVisible = visible;
- },
-
- deliverEvent: function(event) {
- this.emit('deliver-event', event);
- }
-};
-Signals.addSignalMethods(FocusController.prototype);
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]