/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: 2010-02-28 15:19:15 UTC
  • mfrom: (674.1.1 bzr-gtk)
  • Revision ID: jelmer@samba.org-20100228151915-bvwflj8ongj2fwqd
Merge qense's indicator application work, but don't require appindicator to be installed.

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
 
26
from bzrlib import patiencediff, tsort
27
27
from bzrlib.errors import NoSuchRevision
28
28
from bzrlib.revision import NULL_REVISION, CURRENT_REVISION
29
29
 
30
 
from colormap import AnnotateColorSaturation
 
30
from colormap import AnnotateColorMap, 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_INT,
 
74
                                       gobject.TYPE_STRING,
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
 
212
212
        hbox.pack_start(self.back_button, expand=False, fill=True)
213
213
        self.forward_button = self._create_forward_button()
214
214
        hbox.pack_start(self.forward_button, expand=False, fill=True)
215
 
        self.find_button = self._create_find_button()
216
 
        hbox.pack_start(self.find_button, expand=False, fill=True)
217
 
        self.goto_button = self._create_goto_button()
218
 
        hbox.pack_start(self.goto_button, expand=False, fill=True)
219
215
        hbox.show()
220
216
        vbox.pack_start(hbox, expand=False, fill=True)
221
 
 
 
217
        
222
218
        self.pane = pane = gtk.VPaned()
223
219
        pane.add1(swbox)
224
220
        pane.add2(self.revisionview)
238
234
 
239
235
        self.add(vbox)
240
236
 
241
 
    def _search_by_text(self, *ignored): # (accel_group, window, key, modifiers):
 
237
    def _search_by_text(self, accel_group, window, key, modifiers):
242
238
        self._search.show_for('text')
243
239
        self._search.set_target(self.annoview, TEXT_LINE_COL)
244
240
 
245
 
    def _search_by_line(self, *ignored): # accel_group, window, key, modifiers):
 
241
    def _search_by_line(self, accel_group, window, key, modifiers):
246
242
        self._search.show_for('line')
247
243
        self._search.set_target(self.annoview, LINE_NUM_COL)
248
244
 
260
256
            else:
261
257
                tree2 = repository.revision_tree(NULL_REVISION)
262
258
        from bzrlib.plugins.gtk.diff import DiffWindow
263
 
        window = DiffWindow(self)
 
259
        window = DiffWindow()
264
260
        window.set_diff("Diff for line %d" % (row+1), tree1, tree2)
265
261
        window.set_file(tree1.id2path(self.file_id))
266
262
        window.show()
348
344
        button.set_sensitive(False)
349
345
        return button
350
346
 
351
 
    def _create_find_button(self):
352
 
        button = gtk.Button()
353
 
        button.set_use_stock(True)
354
 
        button.set_label("gtk-find")
355
 
        button.set_tooltip_text("Search for text (Ctrl+F)")
356
 
        button.connect("clicked", self._search_by_text)
357
 
        button.set_relief(gtk.RELIEF_NONE)
358
 
        button.show()
359
 
        button.set_sensitive(True)
360
 
        return button
361
 
 
362
 
    def _create_goto_button(self):
363
 
        button = gtk.Button()
364
 
        button.set_label("Goto Line")
365
 
        button.set_tooltip_text("Scroll to a line by entering its number (Ctrl+G)")
366
 
        button.connect("clicked", self._search_by_line)
367
 
        button.set_relief(gtk.RELIEF_NONE)
368
 
        button.show()
369
 
        button.set_sensitive(True)
370
 
        return button
371
 
 
372
347
    def go_back(self):
373
348
        last_tree = self.tree
374
349
        rev_id = self._selected_revision()
532
507
 
533
508
    def _match(self, model, iterator, column):
534
509
        matching_case = self._match_case.get_active()
535
 
        cell_value, = model.get(iterator, column)
 
510
        string, = model.get(iterator, column)
536
511
        key = self._entry.get_text()
537
 
        if column == LINE_NUM_COL:
538
 
            # FIXME: For goto-line there are faster algorithms than searching 
539
 
            # every line til we find the right one! -- mbp 2011-01-27
540
 
            return key.strip() == str(cell_value)
541
 
        elif self._regexp.get_active():
 
512
        if self._regexp.get_active():
542
513
            if matching_case:
543
 
                match = re.compile(key).search(cell_value, 1)
 
514
                match = re.compile(key).search(string, 1)
544
515
            else:
545
 
                match = re.compile(key, re.I).search(cell_value, 1)
 
516
                match = re.compile(key, re.I).search(string, 1)
546
517
        else:
547
518
            if not matching_case:
548
 
                cell_value = cell_value.lower()
 
519
                string = string.lower()
549
520
                key = key.lower()
550
 
            match = cell_value.find(key) != -1
 
521
            match = string.find(key) != -1
551
522
 
552
523
        return match
553
524