/b-gtk/fix-viz

To get this branch, use:
bzr branch http://gegoxaren.bato24.eu/bzr/b-gtk/fix-viz

« back to all changes in this revision

Viewing changes to search.py

  • Committer: Curtis Hovey
  • Date: 2011-08-12 20:25:28 UTC
  • mto: This revision was merged to the branch mainline in revision 741.
  • Revision ID: sinzui.is@verizon.net-20110812202528-4xf4a2t23urx50d2
Updated gst to gtk3.

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
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
 
 
17
from gi.repository import GObject
 
18
from gi.repository import Gtk
 
19
 
 
20
from bzrlib.plugins.search import index as _mod_index
 
21
 
 
22
from bzrlib.plugins.gtk.i18n import _i18n
 
23
 
 
24
class SearchDialog(Gtk.Dialog):
 
25
    """Search dialog."""
 
26
    def __init__(self, index, parent=None):
 
27
        GObject.GObject.__init__(self, title="Search Revisions",
 
28
                                  parent=parent,
 
29
                                  flags=Gtk.DialogFlags.MODAL,
 
30
                                  buttons=(Gtk.STOCK_OK, Gtk.ResponseType.OK,
 
31
                                           Gtk.STOCK_CANCEL, Gtk.ResponseType.CANCEL))
 
32
        pixbuf = self.render_icon(Gtk.STOCK_FIND, Gtk.IconSize.MENU)
 
33
        self.set_icon(pixbuf)
 
34
        
 
35
        # Get arguments
 
36
        self.index = index
 
37
 
 
38
        self.searchbar = Gtk.HBox()
 
39
        searchbar_label = Gtk.Label(label=_i18n("Search for:"))
 
40
        self.searchbar.pack_start(searchbar_label, False, False, 0)
 
41
        self.searchentry = Gtk.Entry()
 
42
        self.searchentry.connect('activate', self._searchentry_activate)
 
43
        # TODO: Completion using the bzr-search suggests functionality
 
44
        self.searchbar.add(self.searchentry)
 
45
        self.vbox.pack_start(self.searchbar, expand=False, fill=False)
 
46
 
 
47
        self.results_model = Gtk.ListStore(GObject.TYPE_STRING, GObject.TYPE_STRING, GObject.TYPE_PYOBJECT)
 
48
        self.results_treeview = Gtk.TreeView(self.results_model)
 
49
        self.results_treeview.connect("row-activated", self._searchresult_row_activated)
 
50
 
 
51
        documentname_column = Gtk.TreeViewColumn(_i18n("Document"), Gtk.CellRendererText(), text=0)
 
52
        self.results_treeview.append_column(documentname_column)
 
53
 
 
54
        summary_column = Gtk.TreeViewColumn(_i18n("Summary"), Gtk.CellRendererText(), text=1)
 
55
        self.results_treeview.append_column(summary_column)
 
56
 
 
57
        results_scrolledwindow = Gtk.ScrolledWindow()
 
58
        results_scrolledwindow.set_policy(Gtk.PolicyType.NEVER, Gtk.PolicyType.AUTOMATIC)
 
59
        results_scrolledwindow.add(self.results_treeview)
 
60
 
 
61
        self.vbox.pack_start(results_scrolledwindow, expand=True, fill=True)
 
62
 
 
63
        self.set_default_size(600, 400)
 
64
        # Show the dialog
 
65
        self.show_all()
 
66
 
 
67
    def get_revision(self):
 
68
        (path, focus) = self.results_treeview.get_cursor()
 
69
        if path is None:
 
70
            return None
 
71
        iter = self.results_model.get_iter(path)
 
72
        return self.results_model.get_value(iter, 2)
 
73
 
 
74
    def _searchentry_activate(self, entry):
 
75
        self.results_model.clear()
 
76
        self.index._branch.lock_read()
 
77
        try:
 
78
            query = [(query_item,) for query_item in self.searchentry.get_text().split(" ")]
 
79
            for result in self.index.search(query):
 
80
                if isinstance(result, _mod_index.FileTextHit):
 
81
                    revid = result.text_key[-1]
 
82
                elif isinstance(result, _mod_index.RevisionHit):
 
83
                    revid = result.revision_key[0]
 
84
                else:
 
85
                    raise AssertionError()
 
86
                self.results_model.append([result.document_name(), result.summary(), revid])
 
87
        finally:
 
88
            self.index._branch.unlock()
 
89
    
 
90
    def _searchresult_row_activated(self, treeview, path, view_column):
 
91
        self.response(Gtk.ResponseType.OK)