[gnome-documents] selections: add a Delete option for collections we create
- From: Cosimo Cecchi <cosimoc src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [gnome-documents] selections: add a Delete option for collections we create
- Date: Wed, 16 Nov 2011 02:47:32 +0000 (UTC)
commit 1a3d2495f009797d1cb279e34cc2046c0a74e754
Author: Cosimo Cecchi <cosimoc gnome org>
Date: Tue Nov 15 00:47:43 2011 -0500
selections: add a Delete option for collections we create
src/documents.js | 49 +++++++++++++++++++++++++++++++++++++++++++++++++
src/query.js | 6 ++++++
src/selections.js | 21 +++++++++++++++++++++
3 files changed, 76 insertions(+), 0 deletions(-)
---
diff --git a/src/documents.js b/src/documents.js
index 7a435e1..89f885b 100644
--- a/src/documents.js
+++ b/src/documents.js
@@ -95,6 +95,33 @@ SingleItemJob.prototype = {
}
};
+function DeleteItemJob(urn) {
+ this._init(urn);
+}
+
+// deletes the given resource
+DeleteItemJob.prototype = {
+ _init: function(urn) {
+ this._urn = urn;
+ },
+
+ run: function(callback) {
+ this._callback = callback;
+
+ let query = Global.queryBuilder.buildDeleteResourceQuery(this._urn);
+ Global.connectionQueue.update(query.sparql, null, Lang.bind(this,
+ function(object, res) {
+ try {
+ object.update_finish(res);
+ } catch (e) {
+ log(e);
+ }
+
+ this._callback();
+ }));
+ }
+};
+
function CollectionIconWatcher(collection) {
this._init(collection);
}
@@ -610,6 +637,24 @@ LocalDocument.prototype = {
Global.errorHandler.addLoadError(this, e);
}
}));
+ },
+
+ canTrash: function() {
+ return this.collection;
+ },
+
+ trash: function() {
+ if (this.collection) {
+ let job = new DeleteItemJob(this.id);
+ job.run(Lang.bind(this,
+ function() {
+ // FIXME: this should be done automatically when tracker
+ // will support change notifications for collections
+ Global.documentManager.getModel().documentRemoved(this);
+ Global.documentManager.removeItemById(this.id);
+ Global.collectionManager.removeItemById(this.id);
+ }));
+ }
}
};
@@ -755,6 +800,10 @@ GoogleDocument.prototype = {
}
}));
}));
+ },
+
+ canTrash: function() {
+ return false;
}
};
diff --git a/src/query.js b/src/query.js
index 2847392..7596512 100644
--- a/src/query.js
+++ b/src/query.js
@@ -255,5 +255,11 @@ QueryBuilder.prototype = {
'nao:identifier \"' + LOCAL_COLLECTIONS_IDENTIFIER + name + '\" }');
return new Query(sparql);
+ },
+
+ buildDeleteResourceQuery: function(resource) {
+ let sparql = ('DELETE { <%s> a rdfs:Resource }').format(resource);
+
+ return new Query(sparql);
}
};
diff --git a/src/selections.js b/src/selections.js
index c43bc8e..6cae128 100644
--- a/src/selections.js
+++ b/src/selections.js
@@ -646,6 +646,11 @@ SelectionToolbar.prototype = {
this._toolbarCollection.connect('clicked', Lang.bind(this, this._onToolbarCollection));
this._toolbarCollection.show();
+ this._toolbarTrash = new Gtk.ToolButton({ icon_name: 'user-trash-symbolic' });
+ this._toolbarTrash.set_tooltip_text(_("Delete"));
+ this.widget.insert(this._toolbarTrash, -1);
+ this._toolbarTrash.connect('clicked', Lang.bind(this, this._onToolbarTrash));
+
this._toolbarOpen = new Gtk.ToolButton({ icon_name: 'document-open-symbolic' });
this.widget.insert(this._toolbarOpen, -1);
this._toolbarOpen.connect('clicked', Lang.bind(this, this._onToolbarOpen));
@@ -699,6 +704,7 @@ SelectionToolbar.prototype = {
let apps = [];
let favCount = 0;
let showFavorite = true;
+ let canTrash = true;
this._insideRefresh = true;
@@ -713,6 +719,9 @@ SelectionToolbar.prototype = {
if ((doc.defaultAppName) &&
(apps.indexOf(doc.defaultAppName) == -1))
apps.push(doc.defaultAppName);
+
+ if (!doc.canTrash())
+ canTrash = false;
}));
showFavorite &= ((favCount == 0) || (favCount == selection.length));
@@ -720,6 +729,8 @@ SelectionToolbar.prototype = {
// if we're showing the favorite icon, also show the separator
this._separator.set_visible(showFavorite);
+ this._toolbarTrash.set_visible(canTrash);
+
let openLabel = null;
if (apps.length == 1) {
// Translators: this is the Open action in a context menu
@@ -798,6 +809,16 @@ SelectionToolbar.prototype = {
}));
},
+ _onToolbarTrash: function(widget) {
+ let selection = Global.selectionController.getSelection();
+
+ selection.forEach(Lang.bind(this,
+ function(urn) {
+ let doc = Global.documentManager.getItemById(urn);
+ doc.trash();
+ }));
+ },
+
_fadeIn: function() {
if (this.actor.opacity != 0)
return;
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]