/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: rodney.dawes at canonical
  • Date: 2008-10-25 06:02:09 UTC
  • Revision ID: rodney.dawes@canonical.com-20081025060209-irlizouino63cs1m
        * preferences/__init__.py:
        Remove the dialog separator
        Remove useless extra call to self._create_pages()
        Make the default window size smaller
        Set the default border width on various widgets
        Set the current notebook page to the first one

        * preferences/identity.py:
        Set various border widths appropriately
        Align the labels to the left
        Remove the unneeded bold markup from the labels
        Change the "User Id" label to "E-Mail"
        Align the radio group labels to the top of the groups

        * preferences/plugins.py:
        Set various border widths appropriately
        Set the default paned position to something more sensible
        Set the shadow type on the treeview's scrolled window to in
        Align the Author and Version labels to the left

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