/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 annotate/gannotate.py

  • Committer: Jelmer Vernooij
  • Date: 2011-04-06 14:53:44 UTC
  • Revision ID: jelmer@samba.org-20110406145344-m6s0i7q7ssjwhmwq
Support use without gtk.Spinner, which is only available in pygtk >= 2.22.

Show diffs side-by-side

added added

removed removed

Lines of Context:
23
23
import pango
24
24
import re
25
25
 
26
 
from bzrlib import patiencediff, tsort
 
26
from bzrlib import patiencediff
27
27
from bzrlib.errors import NoSuchRevision
28
28
from bzrlib.revision import NULL_REVISION, CURRENT_REVISION
29
29
 
30
 
from colormap import AnnotateColorMap, AnnotateColorSaturation
 
30
from bzrlib.plugins.gtk.annotate.colormap import AnnotateColorSaturation
31
31
from bzrlib.plugins.gtk.revisionview import RevisionView
32
32
from bzrlib.plugins.gtk.window import Window
33
33
 
49
49
        self.all = all
50
50
        self.plain = plain
51
51
        self._branch = branch
52
 
        
 
52
 
53
53
        Window.__init__(self, parent)
54
 
        
 
54
 
55
55
        self.set_icon(self.render_icon(gtk.STOCK_FIND, gtk.ICON_SIZE_BUTTON))
56
56
        self.annotate_colormap = AnnotateColorSaturation()
57
57
 
68
68
        self.revisionview.set_file_id(file_id)
69
69
        self.revision_id = getattr(tree, 'get_revision_id', 
70
70
                                   lambda: CURRENT_REVISION)()
71
 
        
 
71
 
72
72
        # [revision id, line number, author, revno, highlight color, line]
73
73
        self.annomodel = gtk.ListStore(gobject.TYPE_STRING,
74
 
                                       gobject.TYPE_STRING,
 
74
                                       gobject.TYPE_INT,
75
75
                                       gobject.TYPE_STRING,
76
76
                                       gobject.TYPE_STRING,
77
77
                                       gobject.TYPE_STRING,
78
78
                                       gobject.TYPE_STRING)
79
 
        
 
79
 
80
80
        last_seen = None
81
81
        try:
82
82
            branch.lock_read()
86
86
            for revision_id, revno in revno_map.iteritems():
87
87
                self.dotted[revision_id] = '.'.join(str(num) for num in revno)
88
88
            for line_no, (revision, revno, line)\
89
 
                    in enumerate(self._annotate(tree, file_id)):
 
89
                in enumerate(self._annotate(tree, file_id)):
90
90
                if revision.revision_id == last_seen and not self.all:
91
91
                    revno = author = ""
92
92
                else:
102
102
                                       revno,
103
103
                                       None,
104
104
                                       line.rstrip("\r\n")
105
 
                                      ])
 
105
                                       ])
106
106
                self.annotations.append(revision)
107
107
 
108
108
            if not self.plain:
125
125
            # bar?
126
126
            print("gannotate: Line number %d does't exist. Defaulting to "
127
127
                  "line 1." % lineno)
128
 
            return
 
128
            return
129
129
        else:
130
130
            row = lineno - 1
131
131
 
218
218
        hbox.pack_start(self.goto_button, expand=False, fill=True)
219
219
        hbox.show()
220
220
        vbox.pack_start(hbox, expand=False, fill=True)
221
 
        
 
221
 
222
222
        self.pane = pane = gtk.VPaned()
223
223
        pane.add1(swbox)
224
224
        pane.add2(self.revisionview)
260
260
            else:
261
261
                tree2 = repository.revision_tree(NULL_REVISION)
262
262
        from bzrlib.plugins.gtk.diff import DiffWindow
263
 
        window = DiffWindow()
 
263
        window = DiffWindow(self)
264
264
        window.set_diff("Diff for line %d" % (row+1), tree1, tree2)
265
265
        window.set_file(tree1.id2path(self.file_id))
266
266
        window.show()
318
318
        col.add_attribute(cell, "text", TEXT_LINE_COL)
319
319
        tv.append_column(col)
320
320
 
321
 
        # FIXME: Now that C-f is now used for search by text we
322
 
        # may as well disable the auto search.
323
 
        tv.set_search_column(LINE_NUM_COL)
 
321
        # interactive substring search
 
322
        def search_equal_func(model, column, key, iter):
 
323
            return model.get_value(iter, TEXT_LINE_COL).lower().find(key.lower()) == -1
 
324
 
 
325
        tv.set_enable_search(True)
 
326
        tv.set_search_equal_func(search_equal_func)
324
327
 
325
328
        return tv
326
329
 
532
535
 
533
536
    def _match(self, model, iterator, column):
534
537
        matching_case = self._match_case.get_active()
535
 
        string, = model.get(iterator, column)
 
538
        cell_value, = model.get(iterator, column)
536
539
        key = self._entry.get_text()
537
 
        if self._regexp.get_active():
 
540
        if column == LINE_NUM_COL:
 
541
            # FIXME: For goto-line there are faster algorithms than searching 
 
542
            # every line til we find the right one! -- mbp 2011-01-27
 
543
            return key.strip() == str(cell_value)
 
544
        elif self._regexp.get_active():
538
545
            if matching_case:
539
 
                match = re.compile(key).search(string, 1)
 
546
                match = re.compile(key).search(cell_value, 1)
540
547
            else:
541
 
                match = re.compile(key, re.I).search(string, 1)
 
548
                match = re.compile(key, re.I).search(cell_value, 1)
542
549
        else:
543
550
            if not matching_case:
544
 
                string = string.lower()
 
551
                cell_value = cell_value.lower()
545
552
                key = key.lower()
546
 
            match = string.find(key) != -1
 
553
            match = cell_value.find(key) != -1
547
554
 
548
555
        return match
549
556