/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: 2012-07-09 15:23:26 UTC
  • mto: This revision was merged to the branch mainline in revision 794.
  • Revision ID: jelmer@samba.org-20120709152326-dzxb8zoz0btull7n
Remove bzr-notify.

Show diffs side-by-side

added added

removed removed

Lines of Context:
16
16
 
17
17
import time
18
18
 
19
 
import pygtk
20
 
pygtk.require("2.0")
21
19
from gi.repository import GObject
 
20
from gi.repository import Gdk
22
21
from gi.repository import Gtk
23
22
from gi.repository import Pango
24
23
import re
28
27
from bzrlib.revision import NULL_REVISION, CURRENT_REVISION
29
28
 
30
29
from bzrlib.plugins.gtk.annotate.colormap import AnnotateColorSaturation
 
30
from bzrlib.plugins.gtk.i18n import _i18n
31
31
from bzrlib.plugins.gtk.revisionview import RevisionView
32
32
from bzrlib.plugins.gtk.window import Window
33
33
 
50
50
        self.plain = plain
51
51
        self._branch = branch
52
52
 
53
 
        Window.__init__(self, parent)
 
53
        super(GAnnotateWindow, self).__init__(parent=parent)
54
54
 
55
 
        self.set_icon(self.render_icon(Gtk.STOCK_FIND, Gtk.IconSize.BUTTON))
 
55
        self.set_icon(
 
56
            self.render_icon_pixbuf(Gtk.STOCK_FIND, Gtk.IconSize.BUTTON))
56
57
        self.annotate_colormap = AnnotateColorSaturation()
57
58
 
58
59
        self._create()
129
130
        else:
130
131
            row = lineno - 1
131
132
 
132
 
        self.annoview.set_cursor(row)
133
 
        self.annoview.scroll_to_cell(row, use_align=True)
134
 
 
 
133
        tree_path = Gtk.TreePath(path=row)
 
134
        self.annoview.set_cursor(tree_path, None, False)
 
135
        self.annoview.scroll_to_cell(tree_path, use_align=True)
135
136
 
136
137
    def _annotate(self, tree, file_id):
137
138
        current_revision = FakeRevision(CURRENT_REVISION)
167
168
    def _highlight_annotation(self, model, path, iter, now):
168
169
        revision_id, = model.get(iter, REVISION_ID_COL)
169
170
        revision = self.revisions[revision_id]
170
 
        model.set(iter, HIGHLIGHT_COLOR_COL,
171
 
                  self.annotate_colormap.get_color(revision, now))
 
171
        # XXX sinzui 2011-08-12: What does get_color return?
 
172
        color = self.annotate_colormap.get_color(revision, now)
 
173
        model.set_value(iter, HIGHLIGHT_COLOR_COL, color)
172
174
 
173
175
    def _selected_revision(self):
174
176
        (path, col) = self.annoview.get_cursor()
193
195
        self.revisionview = self._create_log_view()
194
196
        self.annoview = self._create_annotate_view()
195
197
 
196
 
        vbox = Gtk.VBox(False)
 
198
        vbox = Gtk.VBox(homogeneous=False, spacing=0)
197
199
        vbox.show()
198
200
 
199
201
        sw = Gtk.ScrolledWindow()
207
209
        swbox.pack_start(sw, True, True, 0)
208
210
        swbox.show()
209
211
 
210
 
        hbox = Gtk.HBox(False, 6)
 
212
        hbox = Gtk.HBox(homogeneous=False, spacing=6)
211
213
        self.back_button = self._create_back_button()
212
 
        hbox.pack_start(self.back_button, expand=False, fill=True)
 
214
        hbox.pack_start(self.back_button, False, True, 0)
213
215
        self.forward_button = self._create_forward_button()
214
 
        hbox.pack_start(self.forward_button, expand=False, fill=True)
 
216
        hbox.pack_start(self.forward_button, False, True, 0)
215
217
        self.find_button = self._create_find_button()
216
 
        hbox.pack_start(self.find_button, expand=False, fill=True)
 
218
        hbox.pack_start(self.find_button, False, True, 0)
217
219
        self.goto_button = self._create_goto_button()
218
 
        hbox.pack_start(self.goto_button, expand=False, fill=True)
 
220
        hbox.pack_start(self.goto_button, False, True, 0)
219
221
        hbox.show()
220
 
        vbox.pack_start(hbox, expand=False, fill=True)
 
222
        vbox.pack_start(hbox, False, True, 0)
221
223
 
222
 
        self.pane = pane = Gtk.VPaned()
 
224
        self.pane = pane = Gtk.Paned.new(Gtk.Orientation.VERTICAL)
223
225
        pane.add1(swbox)
224
226
        pane.add2(self.revisionview)
225
227
        pane.show()
226
 
        vbox.pack_start(pane, expand=True, fill=True)
 
228
        vbox.pack_start(pane, True, True, 0)
227
229
 
228
230
        self._search = SearchBox()
229
 
        swbox.pack_start(self._search, expand=False, fill=True)
 
231
        swbox.pack_start(self._search, False, True, 0)
230
232
        accels = Gtk.AccelGroup()
231
 
        accels.connect_group(Gdk.KEY_f, Gdk.EventMask.CONTROL_MASK,
232
 
                             Gtk.ACCEL_LOCKED,
 
233
        accels.connect(Gdk.KEY_f, Gdk.ModifierType.CONTROL_MASK,
 
234
                             Gtk.AccelFlags.LOCKED,
233
235
                             self._search_by_text)
234
 
        accels.connect_group(Gdk.KEY_g, Gdk.EventMask.CONTROL_MASK,
235
 
                             Gtk.ACCEL_LOCKED,
 
236
        accels.connect(Gdk.KEY_g, Gdk.ModifierType.CONTROL_MASK,
 
237
                             Gtk.AccelFlags.LOCKED,
236
238
                             self._search_by_line)
237
239
        self.add_accel_group(accels)
238
240
 
247
249
        self._search.set_target(self.annoview, LINE_NUM_COL)
248
250
 
249
251
    def line_diff(self, tv, path, tvc):
250
 
        row = path[0]
 
252
        row = path.get_indices()[0]
251
253
        revision = self.annotations[row]
252
254
        repository = self.branch.repository
253
255
        if revision.revision_id == CURRENT_REVISION:
281
283
                          tv.get_style().bg[Gtk.StateType.NORMAL])
282
284
        col = Gtk.TreeViewColumn()
283
285
        col.set_resizable(False)
284
 
        col.pack_start(cell, True, True, 0)
 
286
        col.pack_start(cell, True)
285
287
        col.add_attribute(cell, "text", LINE_NUM_COL)
286
288
        tv.append_column(col)
287
289
 
292
294
                          self.get_style().bg[Gtk.StateType.NORMAL])
293
295
        col = Gtk.TreeViewColumn("Committer")
294
296
        col.set_resizable(True)
295
 
        col.pack_start(cell, True, True, 0)
 
297
        col.pack_start(cell, True)
296
298
        col.add_attribute(cell, "text", COMMITTER_COL)
297
299
        tv.append_column(col)
298
300
 
303
305
                          self.get_style().bg[Gtk.StateType.NORMAL])
304
306
        col = Gtk.TreeViewColumn("Revno")
305
307
        col.set_resizable(False)
306
 
        col.pack_start(cell, True, True, 0)
 
308
        col.pack_start(cell, True)
307
309
        col.add_attribute(cell, "markup", REVNO_COL)
308
310
        tv.append_column(col)
309
311
 
312
314
        cell.set_property("family", "Monospace")
313
315
        col = Gtk.TreeViewColumn()
314
316
        col.set_resizable(False)
315
 
        col.pack_start(cell, True, True, 0)
 
317
        col.pack_start(cell, True)
316
318
#        col.add_attribute(cell, "foreground", HIGHLIGHT_COLOR_COL)
317
319
        col.add_attribute(cell, "background", HIGHLIGHT_COLOR_COL)
318
320
        col.add_attribute(cell, "text", TEXT_LINE_COL)
323
325
            return model.get_value(iter, TEXT_LINE_COL).lower().find(key.lower()) == -1
324
326
 
325
327
        tv.set_enable_search(True)
326
 
        tv.set_search_equal_func(search_equal_func)
 
328
        tv.set_search_equal_func(search_equal_func, None)
327
329
 
328
330
        return tv
329
331
 
396
398
        rev_id = self._selected_revision()
397
399
        if self.file_id in target_tree:
398
400
            offset = self.get_scroll_offset(target_tree)
399
 
            (row,), col = self.annoview.get_cursor()
 
401
            path, col = self.annoview.get_cursor()
 
402
            (row,) = path.get_indices()
400
403
            self.annotate(target_tree, self.branch, self.file_id)
401
404
            new_row = row+offset
402
405
            if new_row < 0:
403
406
                new_row = 0
404
 
            self.annoview.set_cursor(new_row)
 
407
            new_path = Gtk.TreePath(path=new_row)
 
408
            self.annoview.set_cursor(new_path, None, False)
405
409
            return True
406
410
        else:
407
411
            return False
409
413
    def get_scroll_offset(self, tree):
410
414
        old = self.tree.get_file(self.file_id)
411
415
        new = tree.get_file(self.file_id)
412
 
        (row,), col = self.annoview.get_cursor()
 
416
        path, col = self.annoview.get_cursor()
 
417
        (row,) = path.get_indices()
413
418
        matcher = patiencediff.PatienceSequenceMatcher(None, old.readlines(),
414
419
                                                       new.readlines())
415
420
        for i, j, n in matcher.get_matching_blocks():
452
457
            self.__cache[revision_id] = revision
453
458
        return self.__cache[revision_id]
454
459
 
 
460
 
455
461
class SearchBox(Gtk.HBox):
456
462
    """A button box for searching in text or lines of annotations"""
457
463
    def __init__(self):
458
 
        GObject.GObject.__init__(self, False, 6)
 
464
        super(SearchBox, self).__init__(homogeneous=False, spacing=6)
459
465
 
460
466
        # Close button
461
467
        button = Gtk.Button()
463
469
        image.set_from_stock('gtk-stop', Gtk.IconSize.BUTTON)
464
470
        button.set_image(image)
465
471
        button.set_relief(Gtk.ReliefStyle.NONE)
466
 
        button.connect("clicked", lambda w: self.hide_all())
467
 
        self.pack_start(button, expand=False, fill=False)
 
472
        button.connect("clicked", lambda w: self.hide())
 
473
        self.pack_start(button, False, False, 0)
468
474
 
469
475
        # Search entry
470
476
        label = Gtk.Label()
471
477
        self._label = label
472
 
        self.pack_start(label, expand=False, fill=False)
 
478
        self.pack_start(label, False, False, 0)
473
479
 
474
480
        entry = Gtk.Entry()
475
481
        self._entry = entry
476
482
        entry.connect("activate", lambda w, d: self._do_search(d),
477
483
                      'forward')
478
 
        self.pack_start(entry, expand=False, fill=False)
 
484
        self.pack_start(entry, False, False, 0)
479
485
 
480
486
        # Next/previous buttons
481
 
        button = Gtk.Button('_Next')
 
487
        button = Gtk.Button(_i18n('_Next'), use_underline=True)
482
488
        image = Gtk.Image()
483
489
        image.set_from_stock('gtk-go-forward', Gtk.IconSize.BUTTON)
484
490
        button.set_image(image)
485
491
        button.connect("clicked", lambda w, d: self._do_search(d),
486
492
                       'forward')
487
 
        self.pack_start(button, expand=False, fill=False)
 
493
        self.pack_start(button, False, False, 0)
488
494
 
489
 
        button = Gtk.Button('_Previous')
 
495
        button = Gtk.Button(_i18n('_Previous'), use_underline=True)
490
496
        image = Gtk.Image()
491
497
        image.set_from_stock('gtk-go-back', Gtk.IconSize.BUTTON)
492
498
        button.set_image(image)
493
499
        button.connect("clicked", lambda w, d: self._do_search(d),
494
500
                       'backward')
495
 
        self.pack_start(button, expand=False, fill=False)
 
501
        self.pack_start(button, False, False, 0)
496
502
 
497
503
        # Search options
498
504
        check = Gtk.CheckButton('Match case')
499
505
        self._match_case = check
500
 
        self.pack_start(check, expand=False, fill=False)
 
506
        self.pack_start(check, False, False, 0)
501
507
 
502
508
        check = Gtk.CheckButton('Regexp')
503
509
        check.connect("toggled", lambda w: self._set_label())
504
510
        self._regexp = check
505
 
        self.pack_start(check, expand=False, fill=False)
 
511
        self.pack_start(check, False, False, 0)
506
512
 
507
513
        self._view = None
508
514
        self._column = None
588
594
        for row in iterate(model, start):
589
595
            if self._match(model, row, self._column):
590
596
                path = model.get_path(row)
591
 
                self._view.set_cursor(path)
 
597
                self._view.set_cursor(path, None, False)
592
598
                self._view.scroll_to_cell(path, use_align=True)
593
599
                break