/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: Curtis Hovey
  • Date: 2011-09-03 22:00:09 UTC
  • mto: This revision was merged to the branch mainline in revision 738.
  • Revision ID: sinzui.is@verizon.net-20110903220009-rvrgi2q1npy27jsw
Added basic tests to verify __eq__ is fixed.

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:
93
93
                    last_seen = revision.revision_id
94
 
                    author = revision.get_apparent_author()
 
94
                    author = ", ".join(revision.get_apparent_authors())
95
95
 
96
96
                if revision.revision_id not in self.revisions:
97
97
                    self.revisions[revision.revision_id] = revision
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
 
139
139
        current_revision.timestamp = time.time()
140
140
        current_revision.message = '[Not yet committed]'
141
141
        current_revision.parent_ids = tree.get_parent_ids()
142
 
        current_revision.properties['branch-nick'] = self.branch.nick
 
142
        current_revision.properties['branch-nick'] = self.branch._get_nick(local=True)
143
143
        current_revno = '%d?' % (self.branch.revno() + 1)
144
144
        repository = self.branch.repository
145
145
        if self.revision_id == CURRENT_REVISION:
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)
215
219
        hbox.show()
216
220
        vbox.pack_start(hbox, expand=False, fill=True)
217
 
        
 
221
 
218
222
        self.pane = pane = gtk.VPaned()
219
223
        pane.add1(swbox)
220
224
        pane.add2(self.revisionview)
234
238
 
235
239
        self.add(vbox)
236
240
 
237
 
    def _search_by_text(self, accel_group, window, key, modifiers):
 
241
    def _search_by_text(self, *ignored): # (accel_group, window, key, modifiers):
238
242
        self._search.show_for('text')
239
243
        self._search.set_target(self.annoview, TEXT_LINE_COL)
240
244
 
241
 
    def _search_by_line(self, accel_group, window, key, modifiers):
 
245
    def _search_by_line(self, *ignored): # accel_group, window, key, modifiers):
242
246
        self._search.show_for('line')
243
247
        self._search.set_target(self.annoview, LINE_NUM_COL)
244
248
 
256
260
            else:
257
261
                tree2 = repository.revision_tree(NULL_REVISION)
258
262
        from bzrlib.plugins.gtk.diff import DiffWindow
259
 
        window = DiffWindow()
 
263
        window = DiffWindow(self)
260
264
        window.set_diff("Diff for line %d" % (row+1), tree1, tree2)
261
265
        window.set_file(tree1.id2path(self.file_id))
262
266
        window.show()
314
318
        col.add_attribute(cell, "text", TEXT_LINE_COL)
315
319
        tv.append_column(col)
316
320
 
317
 
        # FIXME: Now that C-f is now used for search by text we
318
 
        # may as well disable the auto search.
319
 
        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)
320
327
 
321
328
        return tv
322
329
 
344
351
        button.set_sensitive(False)
345
352
        return button
346
353
 
 
354
    def _create_find_button(self):
 
355
        button = gtk.Button()
 
356
        button.set_use_stock(True)
 
357
        button.set_label("gtk-find")
 
358
        button.set_tooltip_text("Search for text (Ctrl+F)")
 
359
        button.connect("clicked", self._search_by_text)
 
360
        button.set_relief(gtk.RELIEF_NONE)
 
361
        button.show()
 
362
        button.set_sensitive(True)
 
363
        return button
 
364
 
 
365
    def _create_goto_button(self):
 
366
        button = gtk.Button()
 
367
        button.set_label("Goto Line")
 
368
        button.set_tooltip_text("Scroll to a line by entering its number (Ctrl+G)")
 
369
        button.connect("clicked", self._search_by_line)
 
370
        button.set_relief(gtk.RELIEF_NONE)
 
371
        button.show()
 
372
        button.set_sensitive(True)
 
373
        return button
 
374
 
347
375
    def go_back(self):
348
376
        last_tree = self.tree
349
377
        rev_id = self._selected_revision()
389
417
                return j - i
390
418
 
391
419
 
392
 
class FakeRevision:
 
420
class FakeRevision(object):
393
421
    """ A fake revision.
394
422
 
395
423
    For when a revision is referenced but not present.
404
432
        self.timezone = 0
405
433
        self.properties = {}
406
434
 
407
 
    def get_apparent_author(self):
408
 
        return self.committer
 
435
    def get_apparent_authors(self):
 
436
        return [self.committer]
409
437
 
410
438
 
411
439
class RevisionCache(object):
412
440
    """A caching revision source"""
 
441
 
413
442
    def __init__(self, real_source, seed_cache=None):
414
443
        self.__real_source = real_source
415
444
        if seed_cache is None:
506
535
 
507
536
    def _match(self, model, iterator, column):
508
537
        matching_case = self._match_case.get_active()
509
 
        string, = model.get(iterator, column)
 
538
        cell_value, = model.get(iterator, column)
510
539
        key = self._entry.get_text()
511
 
        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():
512
545
            if matching_case:
513
 
                match = re.compile(key).search(string, 1)
 
546
                match = re.compile(key).search(cell_value, 1)
514
547
            else:
515
 
                match = re.compile(key, re.I).search(string, 1)
 
548
                match = re.compile(key, re.I).search(cell_value, 1)
516
549
        else:
517
550
            if not matching_case:
518
 
                string = string.lower()
 
551
                cell_value = cell_value.lower()
519
552
                key = key.lower()
520
 
            match = string.find(key) != -1
 
553
            match = cell_value.find(key) != -1
521
554
 
522
555
        return match
523
556