[kupfer] Propose .kfcom extension when saving commands to file



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

    Propose .kfcom extension when saving commands to file

 kupfer/plugin/core/commands.py |   29 +++++++++++++++++++++++++++++
 1 files changed, 29 insertions(+), 0 deletions(-)
---
diff --git a/kupfer/plugin/core/commands.py b/kupfer/plugin/core/commands.py
index 581507b..54990c5 100644
--- a/kupfer/plugin/core/commands.py
+++ b/kupfer/plugin/core/commands.py
@@ -25,3 +25,32 @@ class SaveToFile (Action):
 		return True
 	def object_types(self):
 		yield TextLeaf
+	def object_source(self, for_item=None):
+		return NameSource(_("Save As..."), ".kfcom")
+
+class NameSource (TextSource):
+	"""A source for new names for a file;
+	here we "autopropose" the source file's extension,
+	but allow overriding it as well as renaming to without
+	extension (selecting the normal TextSource-returned string).
+	"""
+	def __init__(self, name, extension, sourcefile=None):
+		TextSource.__init__(self, name)
+		self.sourcefile = sourcefile
+		self.extension = extension
+
+	def get_rank(self):
+		return 100
+
+	def get_items(self, text):
+		if not text:
+			return
+		t_root, t_ext = os.path.splitext(text)
+		yield TextLeaf(text) if t_ext else TextLeaf(t_root + self.extension)
+
+	def get_gicon(self):
+		return self.sourcefile and self.sourcefile.get_gicon()
+
+	def get_icon_name(self):
+		return "gtk-file"
+



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