bzr branch
http://gegoxaren.bato24.eu/bzr/b-gtk/fix-viz
524
by Jelmer Vernooij
Add search dialog. |
1 |
# Copyright (C) 2008 by Jelmer Vernooij <jelmer@samba.org>
|
2 |
#
|
|
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.
|
|
7 |
#
|
|
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.
|
|
12 |
#
|
|
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
|
|
16 |
||
734.1.1
by Curtis Hovey
Mechanical changes made by pygi.convert.sh. |
17 |
from gi.repository import GObject |
18 |
from gi.repository import Gtk |
|
555.1.1
by Jasper Groenewegen
Add i18n support |
19 |
|
524
by Jelmer Vernooij
Add search dialog. |
20 |
from bzrlib.plugins.search import index as _mod_index |
729.1.1
by Jelmer Vernooij
Move i18n support to a separate file, so gettext files aren't loaded unless bzr-gtk is used. |
21 |
|
22 |
from bzrlib.plugins.gtk.i18n import _i18n |
|
525
by Jelmer Vernooij
Show results in search window. |
23 |
|
734.1.51
by Curtis Hovey
Fix the initializer for many classes. |
24 |
|
734.1.1
by Curtis Hovey
Mechanical changes made by pygi.convert.sh. |
25 |
class SearchDialog(Gtk.Dialog): |
524
by Jelmer Vernooij
Add search dialog. |
26 |
"""Search dialog.""" |
734.1.51
by Curtis Hovey
Fix the initializer for many classes. |
27 |
|
533.11.1
by Jelmer Vernooij
Ask user whether to index if there is no index present yet. |
28 |
def __init__(self, index, parent=None): |
734.1.51
by Curtis Hovey
Fix the initializer for many classes. |
29 |
super(SearchDialog, self).__init__( |
30 |
title="Search Revisions", parent=parent, |
|
31 |
flags=Gtk.DialogFlags.MODAL, |
|
32 |
buttons=(Gtk.STOCK_OK, Gtk.ResponseType.OK, |
|
33 |
Gtk.STOCK_CANCEL, Gtk.ResponseType.CANCEL)) |
|
734.1.24
by Curtis Hovey
Updated most of BranchView to gtk3. |
34 |
pixbuf = self.render_icon_pixbuf(Gtk.STOCK_FIND, Gtk.IconSize.MENU) |
555.1.1
by Jasper Groenewegen
Add i18n support |
35 |
self.set_icon(pixbuf) |
36 |
||
524
by Jelmer Vernooij
Add search dialog. |
37 |
# Get arguments
|
533.11.1
by Jelmer Vernooij
Ask user whether to index if there is no index present yet. |
38 |
self.index = index |
525
by Jelmer Vernooij
Show results in search window. |
39 |
|
734.1.1
by Curtis Hovey
Mechanical changes made by pygi.convert.sh. |
40 |
self.searchbar = Gtk.HBox() |
41 |
searchbar_label = Gtk.Label(label=_i18n("Search for:")) |
|
555.1.1
by Jasper Groenewegen
Add i18n support |
42 |
self.searchbar.pack_start(searchbar_label, False, False, 0) |
734.1.1
by Curtis Hovey
Mechanical changes made by pygi.convert.sh. |
43 |
self.searchentry = Gtk.Entry() |
525
by Jelmer Vernooij
Show results in search window. |
44 |
self.searchentry.connect('activate', self._searchentry_activate) |
527
by Jelmer Vernooij
Remove partial completion support, since I can't find the required functionality in pygtk. |
45 |
# TODO: Completion using the bzr-search suggests functionality
|
525
by Jelmer Vernooij
Show results in search window. |
46 |
self.searchbar.add(self.searchentry) |
734.1.51
by Curtis Hovey
Fix the initializer for many classes. |
47 |
self.get_content_area().pack_start(self.searchbar, False, False, 0) |
525
by Jelmer Vernooij
Show results in search window. |
48 |
|
734.1.51
by Curtis Hovey
Fix the initializer for many classes. |
49 |
self.results_model = Gtk.ListStore( |
50 |
GObject.TYPE_STRING, GObject.TYPE_STRING, GObject.TYPE_PYOBJECT) |
|
734.1.1
by Curtis Hovey
Mechanical changes made by pygi.convert.sh. |
51 |
self.results_treeview = Gtk.TreeView(self.results_model) |
734.1.51
by Curtis Hovey
Fix the initializer for many classes. |
52 |
self.results_treeview.connect( |
53 |
"row-activated", self._searchresult_row_activated) |
|
525
by Jelmer Vernooij
Show results in search window. |
54 |
|
734.1.51
by Curtis Hovey
Fix the initializer for many classes. |
55 |
documentname_column = Gtk.TreeViewColumn( |
56 |
_i18n("Document"), Gtk.CellRendererText(), text=0) |
|
525
by Jelmer Vernooij
Show results in search window. |
57 |
self.results_treeview.append_column(documentname_column) |
58 |
||
734.1.51
by Curtis Hovey
Fix the initializer for many classes. |
59 |
summary_column = Gtk.TreeViewColumn( |
60 |
_i18n("Summary"), Gtk.CellRendererText(), text=1) |
|
525
by Jelmer Vernooij
Show results in search window. |
61 |
self.results_treeview.append_column(summary_column) |
62 |
||
734.1.1
by Curtis Hovey
Mechanical changes made by pygi.convert.sh. |
63 |
results_scrolledwindow = Gtk.ScrolledWindow() |
734.1.51
by Curtis Hovey
Fix the initializer for many classes. |
64 |
results_scrolledwindow.set_policy( |
65 |
Gtk.PolicyType.NEVER, Gtk.PolicyType.AUTOMATIC) |
|
525
by Jelmer Vernooij
Show results in search window. |
66 |
results_scrolledwindow.add(self.results_treeview) |
67 |
||
734.1.51
by Curtis Hovey
Fix the initializer for many classes. |
68 |
self.get_content_area().pack_start( |
69 |
results_scrolledwindow, True, True, 0) |
|
525
by Jelmer Vernooij
Show results in search window. |
70 |
|
71 |
self.set_default_size(600, 400) |
|
524
by Jelmer Vernooij
Add search dialog. |
72 |
# Show the dialog
|
73 |
self.show_all() |
|
525
by Jelmer Vernooij
Show results in search window. |
74 |
|
526
by Jelmer Vernooij
Switch to found revision when clicking ok in search window. |
75 |
def get_revision(self): |
76 |
(path, focus) = self.results_treeview.get_cursor() |
|
77 |
if path is None: |
|
78 |
return None |
|
79 |
iter = self.results_model.get_iter(path) |
|
80 |
return self.results_model.get_value(iter, 2) |
|
81 |
||
525
by Jelmer Vernooij
Show results in search window. |
82 |
def _searchentry_activate(self, entry): |
83 |
self.results_model.clear() |
|
84 |
self.index._branch.lock_read() |
|
85 |
try: |
|
734.1.51
by Curtis Hovey
Fix the initializer for many classes. |
86 |
query = [ |
87 |
(query_item,) |
|
88 |
for query_item in self.searchentry.get_text().split(" ")] |
|
525
by Jelmer Vernooij
Show results in search window. |
89 |
for result in self.index.search(query): |
526
by Jelmer Vernooij
Switch to found revision when clicking ok in search window. |
90 |
if isinstance(result, _mod_index.FileTextHit): |
91 |
revid = result.text_key[-1] |
|
92 |
elif isinstance(result, _mod_index.RevisionHit): |
|
93 |
revid = result.revision_key[0] |
|
94 |
else: |
|
95 |
raise AssertionError() |
|
734.1.51
by Curtis Hovey
Fix the initializer for many classes. |
96 |
self.results_model.append( |
97 |
[result.document_name(), result.summary(), revid]) |
|
525
by Jelmer Vernooij
Show results in search window. |
98 |
finally: |
99 |
self.index._branch.unlock() |
|
555.1.1
by Jasper Groenewegen
Add i18n support |
100 |
|
101 |
def _searchresult_row_activated(self, treeview, path, view_column): |
|
734.1.1
by Curtis Hovey
Mechanical changes made by pygi.convert.sh. |
102 |
self.response(Gtk.ResponseType.OK) |