[gnome-documents] searchbar: move the search entry to a separate file
- From: Cosimo Cecchi <cosimoc src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [gnome-documents] searchbar: move the search entry to a separate file
- Date: Fri, 28 Oct 2011 19:20:14 +0000 (UTC)
commit b0c89e35058b6ee979b485275cb8b6be95fcbd3c
Author: Cosimo Cecchi <cosimoc gnome org>
Date: Wed Oct 26 10:57:00 2011 -0400
searchbar: move the search entry to a separate file
src/Makefile-js.am | 1 +
src/mainToolbar.js | 60 -------------------------------
src/mainWindow.js | 10 ++++--
src/searchbar.js | 99 ++++++++++++++++++++++++++++++++++++++++++++++++++++
4 files changed, 107 insertions(+), 63 deletions(-)
---
diff --git a/src/Makefile-js.am b/src/Makefile-js.am
index 6371328..25fce67 100644
--- a/src/Makefile-js.am
+++ b/src/Makefile-js.am
@@ -21,6 +21,7 @@ dist_js_DATA = \
offsetController.js \
preview.js \
query.js \
+ searchbar.js \
selectionController.js \
sidebar.js \
sources.js \
diff --git a/src/mainToolbar.js b/src/mainToolbar.js
index fdee33e..637985b 100644
--- a/src/mainToolbar.js
+++ b/src/mainToolbar.js
@@ -33,8 +33,6 @@ const Global = imports.global;
const Tweener = imports.util.tweener;
const WindowMode = imports.windowMode;
-const _SEARCH_ENTRY_TIMEOUT = 200;
-
function MainToolbar() {
this._init();
}
@@ -42,8 +40,6 @@ function MainToolbar() {
MainToolbar.prototype = {
_init: function() {
this._model = null;
- this._searchFocusId = 0;
- this._searchEntryTimeout = 0;
this.widget = new Gtk.Toolbar({ icon_size: Gtk.IconSize.MENU });
this.widget.get_style_context().add_class(Gtk.STYLE_CLASS_MENUBAR);
@@ -55,11 +51,6 @@ MainToolbar.prototype = {
},
_clearToolbar: function() {
- if (this._searchFocusId != 0) {
- Global.focusController.disconnect(this._searchFocusId);
- this._searchFocusId = 0;
- }
-
this.widget.foreach(Lang.bind(this, function(widget) {
widget.destroy();
}));
@@ -95,55 +86,8 @@ MainToolbar.prototype = {
item.set_expand(true);
item.add(box);
- this._searchEntry = new Gtk.Entry({ width_request: 260,
- secondary_icon_name: 'edit-find-symbolic',
- secondary_icon_sensitive: false,
- secondary_icon_activatable: false });
- let item2 = new Gtk.ToolItem();
- item2.add(this._searchEntry);
-
- this._searchEntry.connect('changed', Lang.bind(this, function() {
- let text = this._searchEntry.get_text();
- if (text && text != '') {
- this._searchEntry.secondary_icon_name = 'edit-clear-symbolic';
- this._searchEntry.secondary_icon_sensitive = true;
- this._searchEntry.secondary_icon_activatable = true;
- } else {
- this._searchEntry.secondary_icon_name = 'edit-find-symbolic';
- this._searchEntry.secondary_icon_sensitive = false;
- this._searchEntry.secondary_icon_activatable = false;
- }
-
- if (this._searchEntryTimeout != 0) {
- Mainloop.source_remove(this._searchEntryTimeout);
- this._searchEntryTimeout = 0;
- }
-
- this._searchEntryTimeout = Mainloop.timeout_add(_SEARCH_ENTRY_TIMEOUT, Lang.bind(this,
- function() {
- this._searchEntryTimeout = 0;
-
- let currentText = this._searchEntry.get_text();
- Global.searchFilterController.setFilter(currentText);
- }));
- }));
-
- this._searchEntry.connect('icon-release', Lang.bind(this, function() {
- this._searchEntry.set_text('');
- }));
-
- this._searchFocusId =
- Global.focusController.connect('focus-search', Lang.bind(this,
- function() {
- this._searchEntry.grab_focus();
- }));
-
this.widget.insert(item, 0);
- this.widget.insert(item2, 1);
-
this.widget.show_all();
-
- this._searchEntry.set_text(Global.searchFilterController.getFilter());
},
_populateForPreview: function(model) {
@@ -231,10 +175,6 @@ MainToolbar.prototype = {
this._updateModelLabels();
},
- getSearchEntry: function() {
- return this._searchEntry;
- },
-
destroy: function() {
Global.modeController.disconnect(this._windowModeId);
this.widget.destroy();
diff --git a/src/mainWindow.js b/src/mainWindow.js
index b7e7166..c629d2f 100644
--- a/src/mainWindow.js
+++ b/src/mainWindow.js
@@ -28,6 +28,7 @@ const Mainloop = imports.mainloop;
const Embed = imports.embed;
const Global = imports.global;
+const Searchbar = imports.searchbar;
const Sidebar = imports.sidebar;
const WindowMode = imports.windowMode;
@@ -83,14 +84,17 @@ MainWindow.prototype = {
Global.modeController.connect('fullscreen-changed',
Lang.bind(this, this._onFullscreenChanged));
- this._grid = new Gtk.Grid({ orientation: Gtk.Orientation.HORIZONTAL });
+ this._grid = new Gtk.Grid({ orientation: Gtk.Orientation.VERTICAL });
this.window.add(this._grid);
+ this._searchbar = new Searchbar.Searchbar();
+ this._grid.attach(this._searchbar.widget, 0, 0, 2, 1);
+
this._sidebar = new Sidebar.Sidebar();
- this._grid.add(this._sidebar.widget);
+ this._grid.attach(this._sidebar.widget, 0, 1, 1, 1);
this._embed = new Embed.ViewEmbed();
- this._grid.add(this._embed.widget);
+ this._grid.attach(this._embed.widget, 1, 1, 1, 1);
this._grid.show_all();
},
diff --git a/src/searchbar.js b/src/searchbar.js
new file mode 100644
index 0000000..9752716
--- /dev/null
+++ b/src/searchbar.js
@@ -0,0 +1,99 @@
+/*
+ * Copyright (c) 2011 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
+ * Free Software Foundation; either version 2 of the License, or (at your
+ * option) any later version.
+ *
+ * Gnome Documents is distributed in the hope that it will be useful, but
+ * WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY
+ * or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
+ * for more details.
+ *
+ * You should have received a copy of the GNU General Public License along
+ * with Gnome Documents; if not, write to the Free Software Foundation,
+ * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
+ *
+ * Author: Cosimo Cecchi <cosimoc redhat com>
+ *
+ */
+
+const Gtk = imports.gi.Gtk;
+
+const Lang = imports.lang;
+const Mainloop = imports.mainloop;
+
+const Global = imports.global;
+
+const _SEARCH_ENTRY_TIMEOUT = 200;
+
+function Searchbar() {
+ this._init();
+}
+
+Searchbar.prototype = {
+ _init: function() {
+ this._searchFocusId = 0;
+ this._searchEntryTimeout = 0;
+
+ this.widget = new Gtk.Toolbar();
+ this.widget.get_style_context().add_class(Gtk.STYLE_CLASS_PRIMARY_TOOLBAR);
+
+ this._searchEntry = new Gtk.Entry({ width_request: 260,
+ margin_left: 64,
+ margin_right: 64,
+ secondary_icon_name: 'edit-find-symbolic',
+ secondary_icon_sensitive: false,
+ secondary_icon_activatable: false });
+ let item = new Gtk.ToolItem();
+ item.set_expand(true);
+ item.add(this._searchEntry);
+
+ this._searchEntry.connect('changed', Lang.bind(this, function() {
+ let text = this._searchEntry.get_text();
+ if (text && text != '') {
+ this._searchEntry.secondary_icon_name = 'edit-clear-symbolic';
+ this._searchEntry.secondary_icon_sensitive = true;
+ this._searchEntry.secondary_icon_activatable = true;
+ } else {
+ this._searchEntry.secondary_icon_name = 'edit-find-symbolic';
+ this._searchEntry.secondary_icon_sensitive = false;
+ this._searchEntry.secondary_icon_activatable = false;
+ }
+
+ if (this._searchEntryTimeout != 0) {
+ Mainloop.source_remove(this._searchEntryTimeout);
+ this._searchEntryTimeout = 0;
+ }
+
+ this._searchEntryTimeout = Mainloop.timeout_add(_SEARCH_ENTRY_TIMEOUT, Lang.bind(this,
+ function() {
+ this._searchEntryTimeout = 0;
+
+ let currentText = this._searchEntry.get_text();
+ Global.searchFilterController.setFilter(currentText);
+ }));
+ }));
+
+ this._searchEntry.connect('icon-release', Lang.bind(this, function() {
+ this._searchEntry.set_text('');
+ }));
+
+ this._searchFocusId =
+ Global.focusController.connect('focus-search', Lang.bind(this,
+ function() {
+ this._searchEntry.grab_focus();
+ }));
+
+ this.widget.insert(item, 0);
+ this._searchEntry.set_text(Global.searchFilterController.getFilter());
+ },
+
+ destroy: function() {
+ if (this._searchFocusId != 0) {
+ Global.focusController.disconnect(this._searchFocusId);
+ this._searchFocusId = 0;
+ }
+ }
+};
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]