[kupfer] plugins.clipboard: new action for source Clipboards: Clear



commit fdd4d940029b54be9b3554808a8ffca57c617c5e
Author: Karol BÄ?dkowski <karol bedkowski gmail com>
Date:   Tue Mar 9 21:44:10 2010 +0100

    plugins.clipboard: new action for source Clipboards: Clear
    
    As long plugin can collect a huge amount of various data, we should provide
    user-frendly method to clear content and free some memory.

 kupfer/plugin/clipboard.py |   29 +++++++++++++++++++++++++++--
 1 files changed, 27 insertions(+), 2 deletions(-)
---
diff --git a/kupfer/plugin/clipboard.py b/kupfer/plugin/clipboard.py
index 7a21c0f..b10360e 100644
--- a/kupfer/plugin/clipboard.py
+++ b/kupfer/plugin/clipboard.py
@@ -1,5 +1,6 @@
 __kupfer_name__ = _("Clipboards")
 __kupfer_sources__ = ("ClipboardSource", )
+__kupfer_actions__ = ("ClearClipboards", )
 __description__ = _("Recent clipboards")
 __version__ = ""
 __author__ = "Ulrik Sverdrup <ulrik sverdrup gmail com>"
@@ -8,7 +9,7 @@ from collections import deque
 
 import gtk
 
-from kupfer.objects import Source, TextLeaf
+from kupfer.objects import Source, TextLeaf, Action, SourceLeaf
 from kupfer import plugin_support
 from kupfer.weaklib import gobject_connect_weakly
 
@@ -38,6 +39,27 @@ class ClipboardText (TextLeaf):
 			'Clipboard with %(num)d lines "%(desc)s"',
 			numlines) % {"num": numlines, "desc": desc }
 
+
+class ClearClipboards(Action):
+	def __init__(self):
+		Action.__init__(self, _("Clear"))
+
+	def activate(self, leaf):
+		leaf.object.clear()
+
+	def item_types(self):
+		yield SourceLeaf
+
+	def valid_for_item(self, leaf):
+		return isinstance(leaf.object, ClipboardSource)
+
+	def get_description(self):
+		return _("Remove all recent clipboards")
+
+	def get_icon_name(self):
+		return "edit-clear"
+
+
 class ClipboardSource (Source):
 	def __init__(self):
 		Source.__init__(self, _("Clipboards"))
@@ -71,7 +93,7 @@ class ClipboardSource (Source):
 		while len(self.clipboards) > max_len:
 			self.clipboards.popleft()
 		self.mark_for_update()
-	
+
 	def get_items(self):
 		for t in reversed(self.clipboards):
 			yield ClipboardText(t)
@@ -85,3 +107,6 @@ class ClipboardSource (Source):
 	def provides(self):
 		yield TextLeaf
 
+	def clear(self):
+		self.clipboards.clear()
+		self.mark_for_update()



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