[gnome-documents] searchbar: simplify Searchbar/SearchController code
- From: Cosimo Cecchi <cosimoc src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [gnome-documents] searchbar: simplify Searchbar/SearchController code
- Date: Mon, 30 Apr 2012 22:26:57 +0000 (UTC)
commit 1fc629d6a2083626cf271eae5fa6954105a73023
Author: Cosimo Cecchi <cosimoc gnome org>
Date: Sat Mar 24 20:25:01 2012 -0400
searchbar: simplify Searchbar/SearchController code
Since the widget is owned by the window box, we can use methods on
it directly instead of going trough the controller.
src/embed.js | 2 -
src/mainWindow.js | 19 ++++++-----
src/searchbar.js | 91 ++++++++++++++++-------------------------------------
3 files changed, 37 insertions(+), 75 deletions(-)
---
diff --git a/src/embed.js b/src/embed.js
index 028610d..4578073 100644
--- a/src/embed.js
+++ b/src/embed.js
@@ -345,8 +345,6 @@ ViewEmbed.prototype = {
this._queryErrorId = 0;
}
- Global.searchController.setSearchVisible(false);
-
if (this._adjustmentValueId != 0) {
this._scrolledWinView.vadjustment.disconnect(this._adjustmentValueId);
this._adjustmentValueId = 0;
diff --git a/src/mainWindow.js b/src/mainWindow.js
index c85e956..3b9703b 100644
--- a/src/mainWindow.js
+++ b/src/mainWindow.js
@@ -91,6 +91,8 @@ MainWindow.prototype = {
Global.modeController.connect('fullscreen-changed',
Lang.bind(this, this._onFullscreenChanged));
+ Global.modeController.connect('window-mode-changed',
+ Lang.bind(this, this._onWindowModeChanged));
// the base layout is a vertical ClutterBox
this._clutterBoxLayout = new Clutter.BoxLayout({ vertical: true });
@@ -156,6 +158,11 @@ MainWindow.prototype = {
Global.settings.set_boolean('window-maximized', maximized);
},
+ _onWindowModeChanged: function() {
+ if (Global.modeController.getWindowMode() == WindowMode.WindowMode.PREVIEW)
+ this._searchbar.hide();
+ },
+
_onFullscreenChanged: function(controller, fullscreen) {
if (fullscreen)
this.window.fullscreen();
@@ -202,18 +209,12 @@ MainWindow.prototype = {
let keyval = event.get_keyval()[1];
if (Utils.isSearchEvent(event)) {
- let visible = Global.searchController.getSearchVisible();
- Global.searchController.setSearchVisible(!visible);
+ this._searchbar.toggle();
return true;
}
- if (!Global.searchController.getSearchIn()) {
- Global.searchController.deliverEvent(event);
- let handled = Global.searchController.getEventHandled();
-
- if (handled)
- return true;
- }
+ if (this._searchbar.deliverEvent(event))
+ return true;
if (Global.selectionController.getSelectionMode() &&
keyval == Gdk.KEY_Escape) {
diff --git a/src/searchbar.js b/src/searchbar.js
index 385a5d1..98c83ca 100644
--- a/src/searchbar.js
+++ b/src/searchbar.js
@@ -237,10 +237,7 @@ function SearchController() {
SearchController.prototype = {
_init: function() {
- this._searchVisible = false;
- this._searchIn = false;
this._dropdownState = false;
- this._eventHandled = false;
this._string = '';
},
@@ -271,45 +268,6 @@ SearchController.prototype = {
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);
- },
-
- setEventHandled: function(handled) {
- this._eventHandled = handled;
- },
-
- getEventHandled: function() {
- return this._eventHandled;
}
};
Signals.addSignalMethods(SearchController.prototype);
@@ -398,6 +356,9 @@ Searchbar.prototype = {
this._searchTypeId = 0;
this._searchMatchId = 0;
+ this._in = false;
+ this._visible = false;
+
this.widget = new Gtk.Toolbar();
this.widget.get_style_context().add_class(Gtk.STYLE_CLASS_PRIMARY_TOOLBAR);
@@ -455,7 +416,7 @@ Searchbar.prototype = {
let keyval = event.get_keyval()[1];
if (keyval == Gdk.KEY_Escape) {
- Global.searchController.setSearchVisible(false);
+ this.hide();
return true;
}
@@ -492,11 +453,6 @@ Searchbar.prototype = {
this._searchEntry.set_text('');
}));
- this._searchFocusId =
- Global.searchController.connect('search-visible-changed', Lang.bind(this, this._onSearchVisible));
- this._searchEventId =
- Global.searchController.connect('deliver-event', Lang.bind(this, this._onDeliverEvent));
-
this.widget.insert(item, 0);
this._searchEntry.set_text(Global.searchController.getString());
@@ -592,14 +548,10 @@ Searchbar.prototype = {
this._dropdownButton.set_active(state);
},
- _onSearchVisible: function() {
- if (Global.searchController.getSearchVisible())
- this._moveIn(Gtk.get_current_event_device());
- else
- this._moveOut();
- },
+ deliverEvent: function(event) {
+ if (this._in)
+ return false;
- _onDeliverEvent: function(controller, event) {
if (!this._searchEntry.get_realized())
this._searchEntry.realize();
@@ -621,35 +573,46 @@ Searchbar.prototype = {
if (((res && (newText != oldText)) || preeditChanged)) {
handled = true;
- if (!Global.searchController.getSearchIn())
- Global.searchController.setSearchVisible(true);
+ if (!this._in)
+ this.show();
}
- Global.searchController.setEventHandled(handled);
+ return handled;
+ },
+
+ toggle: function() {
+ if (this._visible)
+ this.hide();
+ else
+ this.show();
},
- _moveIn: function(eventDevice) {
+ show: function() {
+ let eventDevice = Gtk.get_current_event_device();
+
+ this._visible = true;
this._searchEntry.show();
Tweener.addTween(this.actor, { height: this.widget.get_preferred_height()[1],
time: 0.20,
transition: 'easeOutQuad',
onComplete: function() {
- Global.searchController.setSearchIn(true);
-
+ this._in = true;
Gd.entry_focus_hack(this._searchEntry, eventDevice);
},
onCompleteScope: this });
},
- _moveOut: function() {
+ hide: function() {
+ this._dropdownButton.set_active(false);
+ this._visible = false;
+
Tweener.addTween(this.actor, { height: 0,
time: 0.20,
transition: 'easeOutQuad',
onComplete: function() {
this._searchEntry.hide();
- this._dropdownButton.set_active(false);
- Global.searchController.setSearchIn(false);
+ this._in = false;
},
onCompleteScope: this });
}
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]