/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-08-01 14:46:23 UTC
  • mto: This revision was merged to the branch mainline in revision 741.
  • Revision ID: sinzui.is@verizon.net-20110801144623-ldjf0bu7kyi5bxzu
Updated commit to gtk3.

Show diffs side-by-side

added added

removed removed

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