[kupfer: 12/38] fileactions: Allow creating archives from a collection of files
- From: Ulrik Sverdrup <usverdrup src gnome org>
- To: svn-commits-list gnome org
- Cc:
- Subject: [kupfer: 12/38] fileactions: Allow creating archives from a collection of files
- Date: Sat, 16 Jan 2010 17:12:48 +0000 (UTC)
commit 2e6a114884ff8d67d2c7aeb178be8f543b06acb3
Author: Ulrik Sverdrup <ulrik sverdrup gmail com>
Date: Fri Jan 15 00:20:41 2010 +0100
fileactions: Allow creating archives from a collection of files
We port the archive actions in the File Actions plugin to the multiple
dispatch protocol. This means that with multiple selected files, the
actions now allow to create one archive with all the files.
This is what the comma trick + multiple dispatch is made for, now it's
possible to select some files in nautilus, invoke kupfer's magic
keybinding (or open kupfer, type Ctrl+G) and go
Selected Files -> Create Archive.
kupfer/plugin/fileactions.py | 43 +++++++++++++++++++++++++++++++----------
1 files changed, 32 insertions(+), 11 deletions(-)
---
diff --git a/kupfer/plugin/fileactions.py b/kupfer/plugin/fileactions.py
index 1457794..26be955 100644
--- a/kupfer/plugin/fileactions.py
+++ b/kupfer/plugin/fileactions.py
@@ -157,6 +157,9 @@ class Rename (Action, pretty.OutputMixin):
else:
return FileLeaf(dest)
+ def activate_multiple(self, objs, iobjs):
+ raise NotImplementedError
+
def item_types(self):
yield FileLeaf
def valid_for_item(self, item):
@@ -237,12 +240,18 @@ class UnpackHere (Action):
class CreateArchive (Action):
def __init__(self):
Action.__init__(self, _("Create Archive"))
+
+ @classmethod
+ def _make_archive(cls, filepaths):
+ cmd = ["file-roller", "--add"]
+ cmd.extend(filepaths)
+ utils.spawn_async(cmd)
+
def activate(self, leaf):
- utils.launch_commandline("file-roller --add %s" % leaf.object)
+ self._make_archive((leaf.object, ))
+ def activate_multiple(self, objs):
+ self._make_archive([L.object for L in objs])
- def valid_for_item(self, item):
- # FIXME: Only for directories right now
- return item.is_dir()
def item_types(self):
yield FileLeaf
def get_description(self):
@@ -251,18 +260,30 @@ class CreateArchive (Action):
class CreateArchiveIn (Action):
def __init__(self):
Action.__init__(self, _("Create Archive In..."))
+
+ @classmethod
+ def _make_archive(cls, basename, dirpath, filepaths):
+ archive_type = __kupfer_settings__["archive_type"]
+ archive_path = \
+ utils.get_destpath_in_directory(dirpath, basename, archive_type)
+ cmd = ["file-roller", "--add-to=%s" % (archive_path, )]
+ cmd.extend(filepaths)
+ utils.spawn_async(cmd)
+ return archive_path
+
def activate(self, leaf, iobj):
archive_type = __kupfer_settings__["archive_type"]
dirpath = iobj.object
basename = os_path.basename(leaf.object)
- archive_path = \
- utils.get_destpath_in_directory(dirpath, basename, archive_type)
- utils.launch_commandline("file-roller --add-to='%s' '%s'" %
- (archive_path, leaf.object))
+ self._make_archive(basename, dirpath, (leaf.object, ))
+
+ def activate_multiple(self, objs, iobjs):
+ archive_type = __kupfer_settings__["archive_type"]
+ for iobj in iobjs:
+ dirpath = iobj.object
+ basename = "archive"
+ self._make_archive("archive", dirpath, [L.object for L in objs])
- def valid_for_item(self, item):
- # FIXME: Only for directories right now
- return item.is_dir()
def item_types(self):
yield FileLeaf
def requires_object(self):
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]