[kupfer] plugin.selection: Include part of selection in name



commit c891389f8394d26b511b8cc5cabdf36dd6b02361
Author: Ulrik Sverdrup <ulrik sverdrup gmail com>
Date:   Wed Aug 19 00:32:26 2009 +0200

    plugin.selection: Include part of selection in name
    
    since we show no description by default, it's nice to show just a
    small bit of the selection in the name itself.

 kupfer/plugin/selection.py |   11 ++++++++++-
 1 files changed, 10 insertions(+), 1 deletions(-)
---
diff --git a/kupfer/plugin/selection.py b/kupfer/plugin/selection.py
index de5d49a..95bd8a5 100644
--- a/kupfer/plugin/selection.py
+++ b/kupfer/plugin/selection.py
@@ -10,7 +10,16 @@ __author__ = "Ulrik Sverdrup <ulrik sverdrup gmail com>"
 
 class SelectedText (TextLeaf):
 	def __init__(self, text):
-		TextLeaf.__init__(self, text, _("Selected Text"))
+		lines = filter(None, text.splitlines())
+		summary = lines[0] if lines else text
+		maxlen = 10
+		if len(summary) > maxlen:
+			summary = summary[:maxlen] + u".."
+		TextLeaf.__init__(self, text, _('Selected Text "%s"') % summary)
+
+	def rank_key(self):
+		# return a constant rank key despite the changing name
+		return _("Selected Text")
 
 class InvisibleSourceLeaf (SourceLeaf):
 	"""Hack to hide this source"""



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