[kupfer] trash: Move the MoveToTrash action from fileactions to trash plugin



commit f5d5047b1fd6cfe85ca3f9eaf81189e8788dda74
Author: Ulrik Sverdrup <ulrik sverdrup gmail com>
Date:   Tue Mar 22 01:45:24 2011 +0100

    trash: Move the MoveToTrash action from fileactions to trash plugin
    
    Also ask GIO if each file actually can be trashed.

 kupfer/plugin/fileactions.py |   20 --------------------
 kupfer/plugin/trash.py       |   29 +++++++++++++++++++++++++++++
 2 files changed, 29 insertions(+), 20 deletions(-)
---
diff --git a/kupfer/plugin/fileactions.py b/kupfer/plugin/fileactions.py
index 17fd9e3..abf2982 100644
--- a/kupfer/plugin/fileactions.py
+++ b/kupfer/plugin/fileactions.py
@@ -2,7 +2,6 @@ __kupfer_name__ = _("File Actions")
 __kupfer_sources__ = ()
 __kupfer_text_sources__ = ()
 __kupfer_actions__ = (
-		"Trash",
 		"MoveTo",
 		"Rename",
 		"CopyTo",
@@ -20,7 +19,6 @@ import re
 # since "path" is a very generic name, you often forget..
 from os import path as os_path
 
-from kupfer.objects import OperationError
 from kupfer.objects import Action, FileLeaf, TextLeaf, TextSource
 from kupfer import utils, pretty
 from kupfer import plugin_support
@@ -44,24 +42,6 @@ __kupfer_settings__ = plugin_support.PluginSettings(
 	},
 )
 
-class Trash (Action):
-	# this should never be default
-	rank_adjust = -10
-	def __init__(self):
-		Action.__init__(self, _("Move to Trash"))
-
-	def activate(self, leaf):
-		gfile = gio.File(leaf.object)
-		gfile.trash()
-	def valid_for_item(self, item):
-		return os.access(item.object, os.R_OK | os.W_OK)
-	def get_description(self):
-		return _("Move this file to trash")
-	def get_icon_name(self):
-		return "user-trash-full"
-	def item_types(self):
-		yield FileLeaf
-
 def _good_destination(dpath, spath):
 	"""If directory path @dpath is a valid destination for file @spath
 	to be copied or moved to. Additional checking is done in
diff --git a/kupfer/plugin/trash.py b/kupfer/plugin/trash.py
index 9830891..02b9d83 100644
--- a/kupfer/plugin/trash.py
+++ b/kupfer/plugin/trash.py
@@ -1,4 +1,5 @@
 __kupfer_name__ = _("Trash")
+__kupfer_actions__ = ("MoveToTrash", )
 __kupfer_sources__ = ("TrashSource", )
 __description__ = _("Access trash contents")
 __version__ = "2009-12-06"
@@ -7,6 +8,7 @@ __author__ = "Ulrik Sverdrup <ulrik sverdrup gmail com>"
 import gio
 
 from kupfer.objects import Leaf, Action, Source, SourceLeaf, FileLeaf
+from kupfer.objects import OperationError
 from kupfer.obj.fileactions import Open
 from kupfer import utils, icons, pretty
 
@@ -14,6 +16,33 @@ from kupfer import utils, icons, pretty
 
 TRASH_URI = 'trash://'
 
+class MoveToTrash (Action):
+	# this should never be default
+	rank_adjust = -10
+	def __init__(self):
+		Action.__init__(self, _("Move to Trash"))
+
+	def activate(self, leaf):
+		gfile = gio.File(leaf.object)
+		try:
+			gfile.trash()
+		except gio.Error as exc:
+			raise OperationError(exc)
+
+	def valid_for_item(self, item):
+		gfile = gio.File(item.object)
+		if not gfile.query_exists(None):
+			return False
+		info = gfile.query_info(gio.FILE_ATTRIBUTE_ACCESS_CAN_TRASH)
+		return info.get_attribute_boolean(gio.FILE_ATTRIBUTE_ACCESS_CAN_TRASH)
+	def get_description(self):
+		return _("Move this file to trash")
+	def get_icon_name(self):
+		return "user-trash-full"
+	def item_types(self):
+		yield FileLeaf
+
+
 class RestoreTrashedFile (Action):
 	def __init__(self):
 		Action.__init__(self, _("Restore"))



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