[gnome-documents] manager: add a BaseManager class implementation
- From: Cosimo Cecchi <cosimoc src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [gnome-documents] manager: add a BaseManager class implementation
- Date: Wed, 19 Oct 2011 23:03:43 +0000 (UTC)
commit 786d55ae0ddfd8be9dedd480439fe27b100bf409
Author: Cosimo Cecchi <cosimoc gnome org>
Date: Fri Oct 14 13:26:15 2011 -0400
manager: add a BaseManager class implementation
This will be useful to share code between the various manager in
gnome-documents.
src/Makefile-js.am | 1 +
src/manager.js | 113 ++++++++++++++++++++++++++++++++++++++++++++++++++++
2 files changed, 114 insertions(+), 0 deletions(-)
---
diff --git a/src/Makefile-js.am b/src/Makefile-js.am
index dff929c..6371328 100644
--- a/src/Makefile-js.am
+++ b/src/Makefile-js.am
@@ -17,6 +17,7 @@ dist_js_DATA = \
main.js \
mainToolbar.js \
mainWindow.js \
+ manager.js \
offsetController.js \
preview.js \
query.js \
diff --git a/src/manager.js b/src/manager.js
new file mode 100644
index 0000000..39ba11a
--- /dev/null
+++ b/src/manager.js
@@ -0,0 +1,113 @@
+/*
+ * 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 Signals = imports.signals;
+
+function BaseManager() {
+ this._init();
+};
+
+BaseManager.prototype = {
+ _init: function() {
+ this._items = {};
+ this._activeItem = null;
+ },
+
+ getItemById: function(id) {
+ let retval = this._items[id];
+
+ if (!retval)
+ retval = null;
+
+ return retval;
+ },
+
+ addItem: function(item) {
+ this._items[item.id] = item;
+ this.emit('item-added', item);
+ },
+
+ setActiveItem: function(item) {
+ if (!item)
+ return false;
+
+ if (item != this._activeItem) {
+ this._activeItem = item;
+ this.emit('active-changed', this._activeItem);
+
+ return true;
+ }
+
+ return false;
+ },
+
+ setActiveItemById: function(id) {
+ let item = this.getItemById(id);
+ return this.setActiveItem(item);
+ },
+
+ getItems: function() {
+ return this._items;
+ },
+
+ getItemsCount: function() {
+ return Object.keys(this._items).length;
+ },
+
+ getActiveItem: function() {
+ return this._activeItem;
+ },
+
+ removeItem: function(item) {
+ this.removeItemById(item.id);
+ },
+
+ removeMatchingItems: function(filterFunc) {
+ for (idx in this._items) {
+ let item = this._items[idx];
+ if (!filterFunc(item))
+ this.removeItemById(idx);
+ }
+ },
+
+ removeItemById: function(id) {
+ let item = this._items[id];
+
+ if (item) {
+ delete this._items[id];
+ this.emit('item-removed', item);
+ }
+ },
+
+ clear: function() {
+ this._items = {};
+ this._activeItem = null;
+ },
+
+ getFilter: function() {
+ let item = this.getActiveItem();
+ if (item && item.getFilter())
+ return item.getFilter();
+
+ return '';
+ }
+};
+Signals.addSignalMethods(BaseManager.prototype);
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]