[gnome-documents] categories: port to be a BaseManager subclass
- From: Cosimo Cecchi <cosimoc src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [gnome-documents] categories: port to be a BaseManager subclass
- Date: Wed, 19 Oct 2011 23:03:49 +0000 (UTC)
commit 6da7faf7d0930973c44d3c0aee7411a006e696b0
Author: Cosimo Cecchi <cosimoc gnome org>
Date: Fri Oct 14 13:28:06 2011 -0400
categories: port to be a BaseManager subclass
src/categories.js | 69 ++++++++++++++++++---------------------------
src/sidebar.js | 6 ++--
src/trackerController.js | 4 --
3 files changed, 31 insertions(+), 48 deletions(-)
---
diff --git a/src/categories.js b/src/categories.js
index b30296a..1193618 100644
--- a/src/categories.js
+++ b/src/categories.js
@@ -25,6 +25,7 @@ const Signals = imports.signals;
const _ = imports.gettext.gettext;
const Global = imports.global;
+const Manager = imports.manager;
const StockCategories = {
RECENT: 'recent',
@@ -33,15 +34,15 @@ const StockCategories = {
PRIVATE: 'private'
};
-function Category(id, name, icon) {
- this._init(id, name, icon);
+function Category(params) {
+ this._init(params);
};
Category.prototype = {
- _init: function(id, name, icon) {
- this.id = id;
- this.name = name;
- this.icon = icon;
+ _init: function(params) {
+ this.id = params.id;
+ this.name = params.name;
+ this.icon = params.icon;
},
getWhere: function() {
@@ -52,7 +53,7 @@ Category.prototype = {
if (this.id == StockCategories.SHARED)
return '{ ?urn nco:contributor ?contributor . ?urn nco:creator ?creator FILTER (?contributor != ?creator ) }';
- return '{ }';
+ return '';
},
getFilter: function() {
@@ -69,53 +70,39 @@ function CategoryManager() {
};
CategoryManager.prototype = {
+ __proto__: Manager.BaseManager.prototype,
+
_init: function() {
- this._categories = {};
+ Manager.BaseManager.prototype._init.call(this);
- let category;
+ let category, recent;
// Translators: this refers to new and recent documents
- category = new Category(StockCategories.RECENT, _("New and Recent"), '');
- this._categories[category.id] = category;
+ recent = new Category({ id: StockCategories.RECENT,
+ name: _("New and Recent"),
+ icon: '' });
+ this.addItem(recent);
+
// Translators: this refers to favorite documents
- category = new Category(StockCategories.FAVORITES, _("Favorites"), 'emblem-favorite-symbolic');
- this._categories[category.id] = category;
+ category = new Category({ id: StockCategories.FAVORITES,
+ name: _("Favorites"),
+ icon: 'emblem-favorite-symbolic' });
+ this.addItem(category);
// Translators: this refers to shared documents
- category = new Category(StockCategories.SHARED, _("Shared with you"), 'emblem-shared-symbolic');
- this._categories[category.id] = category;
+ category = new Category({ id: StockCategories.SHARED,
+ name: _("Shared with you"),
+ icon: 'emblem-shared-symbolic' });
+ this.addItem(category);
// Private category: currently unimplemented
// category = new Category(StockCategories.PRIVATE, _("Private"), 'channel-secure-symbolic');
// this._categories[category.id] = category;
- this.setActiveCategoryId(StockCategories.RECENT);
- },
-
- setActiveCategoryId: function(id) {
- let category = this._categories[id];
-
- if (!category)
- return;
-
- if (category != this.activeCategory) {
- this.activeCategory = category;
- this.emit('active-category-changed');
- }
- },
-
- getActiveCategoryId: function() {
- return this.activeCategory.id;
- },
-
- getActiveCategoryWhere: function() {
- return this.activeCategory.getWhere();
+ this.setActiveItem(recent);
},
getActiveCategoryFilter: function() {
- return this.activeCategory.getFilter();
- },
-
- getCategories: function() {
- return this._categories;
+ let active = this.getActiveItem();
+ return active.getFilter();
}
};
Signals.addSignalMethods(CategoryManager.prototype);
diff --git a/src/sidebar.js b/src/sidebar.js
index b2fff55..0cc32f2 100644
--- a/src/sidebar.js
+++ b/src/sidebar.js
@@ -66,9 +66,9 @@ SidebarModel.prototype = {
this._addCollection));
// insert categories
- let categories = Global.categoryManager.getCategories();
- for (idx in categories) {
- let category = categories[idx];
+ let items = Global.categoryManager.getItems();
+ for (idx in items) {
+ let category = items[idx];
iter = this.model.append();
Gd.sidebar_store_set(this.model, iter,
category.id, category.name, category.icon,
diff --git a/src/trackerController.js b/src/trackerController.js
index 94cf8b1..aa58b44 100644
--- a/src/trackerController.js
+++ b/src/trackerController.js
@@ -47,10 +47,6 @@ TrackerController.prototype = {
this._sourceManager.connect('active-source-changed',
Lang.bind(this, this._refresh));
- this._categoryManager = Global.categoryManager;
- this._categoryManager.connect('active-category-changed',
- Lang.bind(this, this._refresh));
-
this._offsetController = Global.offsetController;
this._offsetController.connect('offset-changed',
Lang.bind(this, this._performCurrentQuery));
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]