[gnome-documents] documents: Let everybody provide their own trash implementation



commit 918ff4ca79eeb1fd530f59915eab1f769fc9c085
Author: Debarshi Ray <debarshir gnome org>
Date:   Wed Jul 30 18:22:44 2014 +0200

    documents: Let everybody provide their own trash implementation
    
    ... and implement it for local documents.
    
    https://bugzilla.gnome.org/show_bug.cgi?id=661599

 src/documents.js |   34 ++++++++++++++++++++++++++++------
 1 files changed, 28 insertions(+), 6 deletions(-)
---
diff --git a/src/documents.js b/src/documents.js
index f9d7c27..dc20ca2 100644
--- a/src/documents.js
+++ b/src/documents.js
@@ -369,6 +369,20 @@ const DocCommon = new Lang.Class({
         log('Error: DocCommon implementations must override canTrash');
     },
 
+    trash: function() {
+        if (!this.canTrash())
+            return;
+
+        this.trashImpl();
+
+        let job = new DeleteItemJob(this.id);
+        job.run(null);
+    },
+
+    trashImpl: function() {
+        log('Error: DocCommon implementations must override trashImpl');
+    },
+
     createThumbnail: function(callback) {
         log('Error: DocCommon implementations must override createThumbnail');
     },
@@ -707,14 +721,22 @@ const LocalDocument = new Lang.Class({
     },
 
     canTrash: function() {
-        return this.collection;
+        return true;
     },
 
-    trash: function() {
-        if (this.collection) {
-            let job = new DeleteItemJob(this.id);
-            job.run(null);
-        }
+    trashImpl: function() {
+        if (this.collection)
+            return;
+
+        let file = Gio.file_new_for_uri(this.uri);
+        file.delete_async(GLib.PRIORITY_DEFAULT, null, Lang.bind(this,
+            function(source, res) {
+                try {
+                    file.delete_finish(res);
+                } catch(e) {
+                    log('Unable to delete ' + this.uri + ': ' + e.message);
+                }
+            }));
     }
 });
 


[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]