[kupfer] Add SaveToFile action for ComposedLeaves to save commands to file



commit 5e60835f430b0947689d0974c1f8a3bd73dd6dd1
Author: Ulrik Sverdrup <ulrik sverdrup gmail com>
Date:   Wed Feb 10 04:02:04 2010 +0100

    Add SaveToFile action for ComposedLeaves to save commands to file

 kupfer/plugin/core/__init__.py |    3 ++-
 kupfer/plugin/core/commands.py |   27 +++++++++++++++++++++++++++
 2 files changed, 29 insertions(+), 1 deletions(-)
---
diff --git a/kupfer/plugin/core/__init__.py b/kupfer/plugin/core/__init__.py
index bfeb542..32111d0 100644
--- a/kupfer/plugin/core/__init__.py
+++ b/kupfer/plugin/core/__init__.py
@@ -37,12 +37,13 @@ def register_subplugin(module):
 		globals()[attr] += object_names
 		globals().update((sym, getattr(module, sym)) for sym in object_names)
 
-from kupfer.plugin.core import contents, selection, text, internal
+from kupfer.plugin.core import contents, selection, text, internal, commands
 
 register_subplugin(contents)
 register_subplugin(selection)
 register_subplugin(text)
 register_subplugin(internal)
+register_subplugin(commands)
 
 if _is_debug():
 	from kupfer.plugin.core import debug
diff --git a/kupfer/plugin/core/commands.py b/kupfer/plugin/core/commands.py
new file mode 100644
index 0000000..581507b
--- /dev/null
+++ b/kupfer/plugin/core/commands.py
@@ -0,0 +1,27 @@
+__kupfer_actions__ = ("SaveToFile", )
+
+import os
+
+from kupfer.objects import Action, FileLeaf, TextLeaf, TextSource
+from kupfer.obj.compose import ComposedLeaf
+from kupfer import execfile
+
+
+class SaveToFile (Action):
+	def __init__(self):
+		Action.__init__(self, _("Save As..."))
+
+	def has_result(self):
+		return True
+
+	def activate(self, obj, iobj):
+		execfile.save_to_file(obj, iobj.object)
+		return FileLeaf(os.path.abspath(iobj.object))
+
+	def item_types(self):
+		yield ComposedLeaf
+
+	def requires_object(self):
+		return True
+	def object_types(self):
+		yield TextLeaf



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