[kupfer] thunar: implement "Send To" action



commit 48afcca689ec52e6bc5b6ee7130d9b8437cb4c5c
Author: Karol BÄ?dkowski <karol bedkowski gmail com>
Date:   Fri May 28 23:16:49 2010 +0200

    thunar: implement "Send To" action
    
    New action allow to launch select files by application from "Sent To"
    group.  Targets are plain  .desktop files in $XDG_DATA_DIRS/Thunar/sendto/.
    
    Co-authored-by: Ulrik

 kupfer/plugin/thunar.py |   58 ++++++++++++++++++++++++++++++++++++++++++++--
 1 files changed, 55 insertions(+), 3 deletions(-)
---
diff --git a/kupfer/plugin/thunar.py b/kupfer/plugin/thunar.py
index 4bea653..894e06d 100644
--- a/kupfer/plugin/thunar.py
+++ b/kupfer/plugin/thunar.py
@@ -3,6 +3,7 @@ __kupfer_sources__ = ("ThunarObjects", )
 __kupfer_actions__ = (
 	"Reveal",
 	"GetInfo",
+	"SendTo",
 )
 __description__ = _("File manager Thunar actions")
 __version__ = ""
@@ -14,11 +15,12 @@ import dbus
 import gio
 
 from kupfer.objects import Leaf, Action, Source
-from kupfer.objects import FileLeaf, RunnableLeaf, SourceLeaf
+from kupfer.objects import FileLeaf, RunnableLeaf, SourceLeaf, AppLeaf
 from kupfer.obj.apps import AppLeafContentMixin
-from kupfer import pretty
+from kupfer import config
 from kupfer import plugin_support
-
+from kupfer import pretty
+from kupfer import utils
 
 plugin_support.check_dbus_connection()
 
@@ -94,6 +96,32 @@ class GetInfo (Action):
 	def get_description(self):
 		return _("Show information about file in file manager")
 
+
+class SendTo (Action):
+	""" Send files to  selected app from "send to" list """
+	def __init__(self):
+		Action.__init__(self, _("Send To..."))
+
+	def activate_multiple(self, leaves, iobjs):
+		for app in iobjs:
+			utils.launch_app(app.object, paths=[leaf.object for leaf in leaves])
+
+	def activate(self, leaf, iobj):
+		self.activate_multiple((leaf, ), (iobj, ))
+
+	def item_types(self):
+		yield FileLeaf
+
+	def requires_object(self):
+		return True
+
+	def object_types(self):
+		yield AppLeaf
+
+	def object_source(self, for_item=None):
+		return _SendToAppsSource()
+
+
 class EmptyTrash (RunnableLeaf):
 	def __init__(self):
 		RunnableLeaf.__init__(self, None, _("Empty Trash"))
@@ -117,3 +145,27 @@ class ThunarObjects (AppLeafContentMixin, Source):
 
 	def provides(self):
 		yield RunnableLeaf
+
+
+class _SendToAppsSource (Source):
+	""" Send To items source """
+	def __init__(self):
+		Source.__init__(self, _("Thunar Send To Objects"))
+
+	def get_items(self):
+		for data_dir in config.get_data_dirs("sendto", package="Thunar"):
+			for filename in os.listdir(data_dir):
+				if not filename.endswith('.desktop'):
+					continue
+				file_path = os.path.join(data_dir, filename)
+				if not os.path.isfile(file_path):
+					continue
+				item = gio.unix.desktop_app_info_new_from_filename(file_path)
+				if item:
+					yield AppLeaf(item)
+
+	def get_icon_name(self):
+		return "Thunar"
+
+	def provides(self):
+		yield AppLeaf



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