6
6
__copyright__ = "Copyright © 2005 Canonical Ltd."
7
7
__author__ = "Daniel Schierbeck <daniel.schierbeck@gmail.com>"
9
from gi.repository import Gtk
10
from gi.repository import GObject
11
from gi.repository import Pango
16
13
from bzrlib import ui
18
from bzrlib.plugins.gtk import _i18n
19
from bzrlib.plugins.gtk.ui import GtkProgressBar, ProgressPanel
20
from linegraph import linegraph, same_branch
21
from graphcell import CellRendererGraph
22
from treemodel import TreeModel
23
14
from bzrlib.revision import NULL_REVISION
26
class TreeView(gtk.VBox):
16
from bzrlib.plugins.gtk import lock
17
from bzrlib.plugins.gtk.ui import ProgressPanel
18
from bzrlib.plugins.gtk.branchview import treemodel
19
from bzrlib.plugins.gtk.branchview.linegraph import linegraph, same_branch
20
from bzrlib.plugins.gtk.branchview.graphcell import CellRendererGraph
23
class TreeView(Gtk.VBox):
28
25
__gproperties__ = {
29
'branch': (gobject.TYPE_PYOBJECT,
26
'branch': (GObject.TYPE_PYOBJECT,
31
28
'The Bazaar branch being visualized',
32
gobject.PARAM_CONSTRUCT_ONLY | gobject.PARAM_WRITABLE),
29
GObject.PARAM_CONSTRUCT_ONLY | GObject.PARAM_WRITABLE),
34
'revision': (gobject.TYPE_PYOBJECT,
31
'revision': (GObject.TYPE_PYOBJECT,
36
33
'The currently selected revision',
37
gobject.PARAM_READWRITE),
34
GObject.PARAM_READWRITE),
39
'revision-number': (gobject.TYPE_STRING,
36
'revision-number': (GObject.TYPE_STRING,
41
38
'The number of the selected revision',
43
gobject.PARAM_READABLE),
40
GObject.PARAM_READABLE),
45
'children': (gobject.TYPE_PYOBJECT,
42
'children': (GObject.TYPE_PYOBJECT,
47
44
'Children of the currently selected revision',
48
gobject.PARAM_READABLE),
45
GObject.PARAM_READABLE),
50
'parents': (gobject.TYPE_PYOBJECT,
47
'parents': (GObject.TYPE_PYOBJECT,
51
48
'Parent revisions',
52
49
'Parents to the currently selected revision',
53
gobject.PARAM_READABLE),
50
GObject.PARAM_READABLE),
55
'revno-column-visible': (gobject.TYPE_BOOLEAN,
52
'revno-column-visible': (GObject.TYPE_BOOLEAN,
56
53
'Revision number column',
57
54
'Show revision number column',
59
gobject.PARAM_READWRITE),
56
GObject.PARAM_READWRITE),
61
'graph-column-visible': (gobject.TYPE_BOOLEAN,
58
'graph-column-visible': (GObject.TYPE_BOOLEAN,
63
60
'Show graph column',
65
gobject.PARAM_READWRITE),
62
GObject.PARAM_READWRITE),
67
'date-column-visible': (gobject.TYPE_BOOLEAN,
64
'date-column-visible': (GObject.TYPE_BOOLEAN,
69
66
'Show date column',
71
gobject.PARAM_READWRITE),
68
GObject.PARAM_READWRITE),
73
'compact': (gobject.TYPE_BOOLEAN,
70
'compact': (GObject.TYPE_BOOLEAN,
75
72
'Break ancestry lines to save space',
77
gobject.PARAM_CONSTRUCT | gobject.PARAM_READWRITE),
74
GObject.PARAM_CONSTRUCT | GObject.PARAM_READWRITE),
79
'mainline-only': (gobject.TYPE_BOOLEAN,
76
'mainline-only': (GObject.TYPE_BOOLEAN,
81
78
'Only show the mainline history.',
83
gobject.PARAM_CONSTRUCT | gobject.PARAM_READWRITE),
80
GObject.PARAM_CONSTRUCT | GObject.PARAM_READWRITE),
88
'revision-selected': (gobject.SIGNAL_RUN_FIRST,
85
'revision-selected': (GObject.SignalFlags.RUN_FIRST,
91
'revision-activated': (gobject.SIGNAL_RUN_FIRST,
93
(gobject.TYPE_PYOBJECT, gobject.TYPE_PYOBJECT)),
94
'tag-added': (gobject.SIGNAL_RUN_FIRST,
96
(gobject.TYPE_STRING, gobject.TYPE_STRING)),
97
'refreshed': (gobject.SIGNAL_RUN_FIRST, gobject.TYPE_NONE,
88
'revision-activated': (GObject.SignalFlags.RUN_FIRST,
90
(GObject.TYPE_PYOBJECT, GObject.TYPE_PYOBJECT)),
91
'tag-added': (GObject.SignalFlags.RUN_FIRST,
93
(GObject.TYPE_STRING, GObject.TYPE_STRING)),
94
'refreshed': (GObject.SignalFlags.RUN_FIRST, None,
337
340
self.progress_bar.finished()
339
342
def construct_treeview(self):
340
self.treeview = gtk.TreeView()
343
self.treeview = Gtk.TreeView()
342
345
self.treeview.set_rules_hint(True)
343
self.treeview.set_search_column(treemodel.REVNO)
345
# Fix old PyGTK bug - by JAM
346
set_tooltip = getattr(self.treeview, 'set_tooltip_column', None)
347
if set_tooltip is not None:
348
set_tooltip(treemodel.MESSAGE)
346
# combined revno/summary interactive search
348
# the row in a treemodel is considered "matched" if a REVNO *starts*
349
# from the key (that is the key is found in a REVNO at the offset 0)
350
# or if a MESSAGE *contains* the key anywhere (that is, the key is
351
# found case insensitively in a MESSAGE at any offset)
352
def search_equal_func(model, column, key, iter):
353
return (model.get_value(iter, treemodel.REVNO).find(key) != 0
354
and model.get_value(iter, treemodel.MESSAGE).lower().find(key.lower()) == -1)
356
self.treeview.set_search_equal_func(search_equal_func)
357
self.treeview.set_enable_search(True)
359
set_tooltip(treemodel.MESSAGE)
350
361
self._prev_cursor_path = None
351
362
self.treeview.connect("cursor-changed",
362
373
self.treeview.show()
364
cell = gtk.CellRendererText()
375
cell = Gtk.CellRendererText()
365
376
cell.set_property("width-chars", 15)
366
cell.set_property("ellipsize", pango.ELLIPSIZE_END)
367
self.revno_column = gtk.TreeViewColumn("Revision No")
368
self.revno_column.set_resizable(False)
369
self.revno_column.set_sizing(gtk.TREE_VIEW_COLUMN_FIXED)
377
cell.set_property("ellipsize", Pango.EllipsizeMode.END)
378
self.revno_column = Gtk.TreeViewColumn("Revision No")
379
self.revno_column.set_resizable(True)
380
self.revno_column.set_sizing(Gtk.TreeViewColumnSizing.FIXED)
370
381
self.revno_column.set_fixed_width(cell.get_size(self.treeview)[2])
371
self.revno_column.pack_start(cell, expand=True)
382
self.revno_column.pack_start(cell, True, True, 0)
372
383
self.revno_column.add_attribute(cell, "text", treemodel.REVNO)
373
384
self.treeview.append_column(self.revno_column)
375
386
self.graph_cell = CellRendererGraph()
376
self.graph_column = gtk.TreeViewColumn()
377
self.graph_column.set_resizable(False)
378
self.graph_column.set_sizing(gtk.TREE_VIEW_COLUMN_FIXED)
379
self.graph_column.pack_start(self.graph_cell, expand=True)
387
self.graph_column = Gtk.TreeViewColumn()
388
self.graph_column.set_resizable(True)
389
self.graph_column.set_sizing(Gtk.TreeViewColumnSizing.FIXED)
390
self.graph_column.pack_start(self.graph_cell, True, True, 0)
380
391
self.graph_column.add_attribute(self.graph_cell, "node", treemodel.NODE)
381
392
self.graph_column.add_attribute(self.graph_cell, "tags", treemodel.TAGS)
382
393
self.graph_column.add_attribute(self.graph_cell, "in-lines", treemodel.LAST_LINES)
383
394
self.graph_column.add_attribute(self.graph_cell, "out-lines", treemodel.LINES)
384
395
self.treeview.append_column(self.graph_column)
386
cell = gtk.CellRendererText()
397
cell = Gtk.CellRendererText()
387
398
cell.set_property("width-chars", 65)
388
cell.set_property("ellipsize", pango.ELLIPSIZE_END)
389
self.summary_column = gtk.TreeViewColumn("Summary")
390
self.summary_column.set_resizable(False)
399
cell.set_property("ellipsize", Pango.EllipsizeMode.END)
400
self.summary_column = Gtk.TreeViewColumn("Summary")
401
self.summary_column.set_resizable(True)
391
402
self.summary_column.set_expand(True)
392
self.summary_column.set_sizing(gtk.TREE_VIEW_COLUMN_FIXED)
403
self.summary_column.set_sizing(Gtk.TreeViewColumnSizing.FIXED)
393
404
self.summary_column.set_fixed_width(cell.get_size(self.treeview)[2])
394
self.summary_column.pack_start(cell, expand=True)
405
self.summary_column.pack_start(cell, True, True, 0)
395
406
self.summary_column.add_attribute(cell, "markup", treemodel.SUMMARY)
396
407
self.treeview.append_column(self.summary_column)
398
cell = gtk.CellRendererText()
409
cell = Gtk.CellRendererText()
399
410
cell.set_property("width-chars", 15)
400
cell.set_property("ellipsize", pango.ELLIPSIZE_END)
401
self.committer_column = gtk.TreeViewColumn("Committer")
402
self.committer_column.set_resizable(False)
403
self.committer_column.set_sizing(gtk.TREE_VIEW_COLUMN_FIXED)
404
self.committer_column.set_fixed_width(200)
405
self.committer_column.pack_start(cell, expand=True)
406
self.committer_column.add_attribute(cell, "text", treemodel.COMMITTER)
407
self.treeview.append_column(self.committer_column)
411
cell.set_property("ellipsize", Pango.EllipsizeMode.END)
412
self.authors_column = Gtk.TreeViewColumn("Author(s)")
413
self.authors_column.set_resizable(False)
414
self.authors_column.set_sizing(Gtk.TreeViewColumnSizing.FIXED)
415
self.authors_column.set_fixed_width(200)
416
self.authors_column.pack_start(cell, True, True, 0)
417
self.authors_column.add_attribute(cell, "text", treemodel.AUTHORS)
418
self.treeview.append_column(self.authors_column)
409
cell = gtk.CellRendererText()
420
cell = Gtk.CellRendererText()
410
421
cell.set_property("width-chars", 20)
411
cell.set_property("ellipsize", pango.ELLIPSIZE_END)
412
self.date_column = gtk.TreeViewColumn("Date")
422
cell.set_property("ellipsize", Pango.EllipsizeMode.END)
423
self.date_column = Gtk.TreeViewColumn("Date")
413
424
self.date_column.set_visible(False)
414
self.date_column.set_resizable(False)
415
self.date_column.set_sizing(gtk.TREE_VIEW_COLUMN_FIXED)
425
self.date_column.set_resizable(True)
426
self.date_column.set_sizing(Gtk.TreeViewColumnSizing.FIXED)
416
427
self.date_column.set_fixed_width(130)
417
self.date_column.pack_start(cell, expand=True)
428
self.date_column.pack_start(cell, True, True, 0)
418
429
self.date_column.add_attribute(cell, "text", treemodel.TIMESTAMP)
419
430
self.treeview.append_column(self.date_column)
421
432
return self.treeview
423
434
def _on_selection_changed(self, treeview):
424
435
"""callback for when the treeview changes."""
425
436
(path, focus) = treeview.get_cursor()