[kupfer] notes: Add factory search action Get Note Search Results...



commit e096afd556531a847eee325f200e200ff2c5db56
Author: William Friesen <wfriesen gmail com>
Date:   Mon Feb 1 22:31:52 2010 +1100

    notes: Add factory search action Get Note Search Results...

 kupfer/plugin/notes.py |   43 +++++++++++++++++++++++++++++++++++++++++++
 1 files changed, 43 insertions(+), 0 deletions(-)
---
diff --git a/kupfer/plugin/notes.py b/kupfer/plugin/notes.py
index af9c164..06b8a2a 100644
--- a/kupfer/plugin/notes.py
+++ b/kupfer/plugin/notes.py
@@ -8,6 +8,7 @@ __kupfer_sources__ = ("NotesSource", )
 __kupfer_actions__ = (
 		"AppendToNote",
 		"CreateNote",
+		"GetNoteSearchResults",
 	)
 __description__ = _("Gnote or Tomboy notes")
 __version__ = ""
@@ -135,6 +136,48 @@ class CreateNote (Action):
 	def get_icon_name(self):
 		return "gtk-new"
 
+class GetNoteSearchResults (Action):
+	def __init__(self):
+		Action.__init__(self, ("Get Note Search Results..."))
+
+	def is_factory(self):
+		return True
+
+	def activate(self, leaf):
+		query = leaf.object
+		return NoteSearchSource(query)
+
+	def item_types(self):
+		yield TextLeaf
+
+	def get_description(self):
+		return _("Show search results for this query")
+
+	def get_icon_name(self):
+		return "gtk-search"
+
+class NoteSearchSource (Source):
+	def __init__(self, query):
+		self.query = query.lower()
+		Source.__init__(self, _("Notes"))
+
+	def get_items(self):
+		notes = _get_notes_interface(activate=True)
+		noteuris = notes.SearchNotes(self.query, False)
+		for noteuri in noteuris:
+			title = notes.GetNoteTitle(noteuri)
+			date = notes.GetNoteChangeDate(noteuri)
+			yield Note(noteuri, title, date)
+
+	def repr_key(self):
+		return self.query
+
+	def get_gicon(self):
+		return icons.get_gicon_with_fallbacks(None, PROGRAM_IDS)
+
+	def provides(self):
+		yield Note
+
 class Note (Leaf):
 	"""The Note Leaf's represented object is the Note URI"""
 	def __init__(self, obj, name, date):



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