1
# Copyright (C) 2008 by Jelmer Vernooij <jelmer@samba.org>
3
# This program is free software; you can redistribute it and/or modify
4
# it under the terms of the GNU General Public License as published by
5
# the Free Software Foundation; either version 2 of the License, or
6
# (at your option) any later version.
8
# This program is distributed in the hope that it will be useful,
9
# but WITHOUT ANY WARRANTY; without even the implied warranty of
10
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
11
# GNU General Public License for more details.
13
# You should have received a copy of the GNU General Public License
14
# along with this program; if not, write to the Free Software
15
# Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
24
from bzrlib.plugins.search import index as _mod_index
27
class SearchCompletion(gtk.EntryCompletion):
28
def __init__(self, index):
29
super(SearchCompletion, self).__init__()
32
class SearchDialog(gtk.Dialog):
34
def __init__(self, branch, parent=None):
35
gtk.Dialog.__init__(self, title="Search Revisions",
37
flags=gtk.DIALOG_MODAL,
38
buttons=(gtk.STOCK_CANCEL, gtk.RESPONSE_CANCEL))
43
self.index = _mod_index.open_index_url(branch.base)
45
self.searchbar = gtk.HBox()
46
self.searchentry = gtk.Entry()
47
self.searchentry.connect('activate', self._searchentry_activate)
48
self.searchentry.set_completion(SearchCompletion(self.index))
49
self.searchbar.add(self.searchentry)
50
self.vbox.pack_start(self.searchbar, expand=False, fill=False)
52
self.results_model = gtk.ListStore(gobject.TYPE_STRING, gobject.TYPE_STRING)
53
self.results_treeview = gtk.TreeView(self.results_model)
55
documentname_column = gtk.TreeViewColumn("Document", gtk.CellRendererText(), text=0)
56
self.results_treeview.append_column(documentname_column)
58
summary_column = gtk.TreeViewColumn("Summary", gtk.CellRendererText(), text=1)
59
self.results_treeview.append_column(summary_column)
61
results_scrolledwindow = gtk.ScrolledWindow()
62
results_scrolledwindow.set_policy(gtk.POLICY_NEVER, gtk.POLICY_AUTOMATIC)
63
results_scrolledwindow.add(self.results_treeview)
65
self.vbox.pack_start(results_scrolledwindow, expand=True, fill=True)
67
self.set_default_size(600, 400)
71
def _searchentry_activate(self, entry):
72
self.results_model.clear()
73
self.index._branch.lock_read()
75
query = [(query_item,) for query_item in self.searchentry.get_text().split(" ")]
76
for result in self.index.search(query):
77
self.results_model.append([result.document_name(), result.summary()])
79
self.index._branch.unlock()