[kupfer] Provide a multiple file selection as a MultipleLeaf object



commit 707e1d87c530be5883f75b9fd180fa40c049fa1e
Author: Ulrik Sverdrup <ulrik sverdrup gmail com>
Date:   Sun Jan 3 14:08:00 2010 +0100

    Provide a multiple file selection as a MultipleLeaf object
    
    We introduce an object to represent multiple objects at the same time,
    such as for a file selection of multiple files. It is not yet possible
    to perform file actions on a collection of FileLeaves, but it is
    planned.

 kupfer/objects.py                  |   27 +++++++++++++++++++++++++++
 kupfer/plugin/nautilusselection.py |   23 +++++++++++++++++------
 2 files changed, 44 insertions(+), 6 deletions(-)
---
diff --git a/kupfer/objects.py b/kupfer/objects.py
index 110e591..2b0e5cb 100644
--- a/kupfer/objects.py
+++ b/kupfer/objects.py
@@ -1196,3 +1196,30 @@ class ComposedLeaf (RunnableLeaf):
 		else:
 			return icons.ComposedIcon(obj.get_icon(), iobj.get_icon())
 
+class _MultipleLeafContentSource (Source):
+	def __init__(self, leaf):
+		Source.__init__(self, unicode(leaf))
+		self.leaf = leaf
+	def get_items(self):
+		return self.leaf.object
+
+class MultipleLeaf (Leaf):
+	"""
+	A Leaf representing a collection of leaves.
+
+	The represented object is a frozenset of the contained Leaves
+	"""
+	def __init__(self, obj, name):
+		Leaf.__init__(self, frozenset(obj), name)
+
+	def has_content(self):
+		return True
+
+	def content_source(self, alternate=False):
+		return _MultipleLeafContentSource(self)
+
+	def get_description(self):
+		n = len(self.object)
+		return ngettext("%s object", "%s objects", n) % (n, )
+	def get_gicon(self):
+		pass
diff --git a/kupfer/plugin/nautilusselection.py b/kupfer/plugin/nautilusselection.py
index 9131005..63a1905 100644
--- a/kupfer/plugin/nautilusselection.py
+++ b/kupfer/plugin/nautilusselection.py
@@ -3,9 +3,9 @@ import os
 import dbus
 import gobject
 
-from kupfer.objects import Source, Leaf, FileLeaf, SourceLeaf, PicklingHelperMixin
-from kupfer import objects
-from kupfer.helplib import DbusWeakCallback
+from kupfer.objects import Source, Leaf
+from kupfer.objects import FileLeaf, SourceLeaf, MultipleLeaf
+from kupfer.helplib import DbusWeakCallback, PicklingHelperMixin
 from kupfer import plugin_support
 
 __kupfer_name__ = _("Selected File")
@@ -23,9 +23,17 @@ class SelectedFile (FileLeaf):
 		basename = gobject.filename_display_basename(filepath)
 		FileLeaf.__init__(self, filepath, _('Selected File "%s"') % basename)
 
-	def repr_key(self):
-		# return a constant rank key despite the changing name
-		return "Selected File"
+	def __repr__(self):
+		return "<%s %s>" % (__name__, self.qf_id)
+
+class SelectedFiles (MultipleLeaf):
+	qf_id = "selectedfile"
+	def __init__(self, paths):
+		files = [FileLeaf(path) for path in paths]
+		MultipleLeaf.__init__(self, files, "Selected Files")
+
+	def __repr__(self):
+		return "<%s %s>" % (__name__, self.qf_id)
 
 class InvisibleSourceLeaf (SourceLeaf):
 	"""Hack to hide this source"""
@@ -56,10 +64,13 @@ class SelectionSource (Source, PicklingHelperMixin):
 	def get_items(self):
 		if len(self._selection) == 1:
 			yield SelectedFile(self._selection[0])
+		elif len(self._selection) > 1:
+			yield SelectedFiles(self._selection)
 
 	def get_description(self):
 		return None
 	def provides(self):
 		yield FileLeaf
+		yield MultipleLeaf
 	def get_leaf_repr(self):
 		return InvisibleSourceLeaf(self)



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