/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 branchview/treeview.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:
3
3
 
4
4
"""
5
5
 
6
 
__copyright__ = "Copyright � 2005 Canonical Ltd."
 
6
__copyright__ = "Copyright © 2005 Canonical Ltd."
7
7
__author__    = "Daniel Schierbeck <daniel.schierbeck@gmail.com>"
8
8
 
9
 
import sys
10
 
import string
11
 
import gtk
12
 
import gobject
13
 
import pango
14
 
import re
15
 
import treemodel
 
9
from gi.repository import Gtk
 
10
from gi.repository import GObject
 
11
from gi.repository import Pango
16
12
 
17
 
from linegraph import linegraph, same_branch
18
 
from graphcell import CellRendererGraph
19
 
from treemodel import TreeModel
 
13
from bzrlib import ui
20
14
from bzrlib.revision import NULL_REVISION
21
15
 
22
 
class TreeView(gtk.ScrolledWindow):
 
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
 
21
 
 
22
 
 
23
class TreeView(Gtk.VBox):
23
24
 
24
25
    __gproperties__ = {
25
 
        'branch': (gobject.TYPE_PYOBJECT,
 
26
        'branch': (GObject.TYPE_PYOBJECT,
26
27
                   'Branch',
27
28
                   'The Bazaar branch being visualized',
28
 
                   gobject.PARAM_CONSTRUCT_ONLY | gobject.PARAM_WRITABLE),
 
29
                   GObject.PARAM_CONSTRUCT_ONLY | GObject.PARAM_WRITABLE),
29
30
 
30
 
        'revision': (gobject.TYPE_PYOBJECT,
 
31
        'revision': (GObject.TYPE_PYOBJECT,
31
32
                     'Revision',
32
33
                     'The currently selected revision',
33
 
                     gobject.PARAM_READWRITE),
34
 
 
35
 
        'revno-column-visible': (gobject.TYPE_BOOLEAN,
36
 
                                 'Revision number',
 
34
                     GObject.PARAM_READWRITE),
 
35
 
 
36
        'revision-number': (GObject.TYPE_STRING,
 
37
                            'Revision number',
 
38
                            'The number of the selected revision',
 
39
                            '',
 
40
                            GObject.PARAM_READABLE),
 
41
 
 
42
        'children': (GObject.TYPE_PYOBJECT,
 
43
                     'Child revisions',
 
44
                     'Children of the currently selected revision',
 
45
                     GObject.PARAM_READABLE),
 
46
 
 
47
        'parents': (GObject.TYPE_PYOBJECT,
 
48
                    'Parent revisions',
 
49
                    'Parents to the currently selected revision',
 
50
                    GObject.PARAM_READABLE),
 
51
 
 
52
        'revno-column-visible': (GObject.TYPE_BOOLEAN,
 
53
                                 'Revision number column',
37
54
                                 'Show revision number column',
38
55
                                 True,
39
 
                                 gobject.PARAM_READWRITE),
40
 
 
41
 
        'date-column-visible': (gobject.TYPE_BOOLEAN,
 
56
                                 GObject.PARAM_READWRITE),
 
57
 
 
58
        'graph-column-visible': (GObject.TYPE_BOOLEAN,
 
59
                                 'Graph column',
 
60
                                 'Show graph column',
 
61
                                 True,
 
62
                                 GObject.PARAM_READWRITE),
 
63
 
 
64
        'date-column-visible': (GObject.TYPE_BOOLEAN,
42
65
                                 'Date',
43
66
                                 'Show date column',
44
67
                                 False,
45
 
                                 gobject.PARAM_READWRITE)
 
68
                                 GObject.PARAM_READWRITE),
 
69
 
 
70
        'compact': (GObject.TYPE_BOOLEAN,
 
71
                    'Compact view',
 
72
                    'Break ancestry lines to save space',
 
73
                    True,
 
74
                    GObject.PARAM_CONSTRUCT | GObject.PARAM_READWRITE),
 
75
 
 
76
        'mainline-only': (GObject.TYPE_BOOLEAN,
 
77
                    'Mainline only',
 
78
                    'Only show the mainline history.',
 
79
                    False,
 
80
                    GObject.PARAM_CONSTRUCT | GObject.PARAM_READWRITE),
46
81
 
47
82
    }
48
83
 
49
84
    __gsignals__ = {
50
 
        'revisions-loaded': (gobject.SIGNAL_RUN_FIRST, 
51
 
                             gobject.TYPE_NONE,
52
 
                             ()),
53
 
        'revision-selected': (gobject.SIGNAL_RUN_FIRST,
54
 
                              gobject.TYPE_NONE,
 
85
        'revision-selected': (GObject.SignalFlags.RUN_FIRST,
 
86
                              None,
 
87
                              ()),
 
88
        'revision-activated': (GObject.SignalFlags.RUN_FIRST,
 
89
                              None,
 
90
                              (GObject.TYPE_PYOBJECT, GObject.TYPE_PYOBJECT)),
 
91
        'tag-added': (GObject.SignalFlags.RUN_FIRST,
 
92
                              None,
 
93
                              (GObject.TYPE_STRING, GObject.TYPE_STRING)),
 
94
        'refreshed': (GObject.SignalFlags.RUN_FIRST, None,
55
95
                              ())
56
96
    }
57
97
 
58
 
    def __init__(self, branch, start, maxnum, broken_line_length=None):
 
98
    def __init__(self, branch, start, maxnum, compact=True):
59
99
        """Create a new TreeView.
60
100
 
61
101
        :param branch: Branch object for branch to show.
65
105
        :param broken_line_length: After how much lines to break 
66
106
                                   branches.
67
107
        """
68
 
        gtk.ScrolledWindow.__init__(self)
69
 
 
70
 
        self.set_policy(gtk.POLICY_NEVER, gtk.POLICY_AUTOMATIC)
71
 
        self.set_shadow_type(gtk.SHADOW_IN)
72
 
 
73
 
        self.construct_treeview()
74
 
 
 
108
        super(TreeView, self).__init__(homogeneous=False, spacing=0)
 
109
 
 
110
        self.progress_widget = ProgressPanel()
 
111
        self.pack_start(self.progress_widget, False, True, 0)
 
112
        if getattr(ui.ui_factory, "set_progress_bar_widget", None) is not None:
 
113
            # We'are using our own ui, let's tell it to use our widget.
 
114
            ui.ui_factory.set_progress_bar_widget(self.progress_widget)
 
115
 
 
116
        self.scrolled_window = Gtk.ScrolledWindow()
 
117
        self.scrolled_window.set_policy(Gtk.PolicyType.AUTOMATIC,
 
118
                                        Gtk.PolicyType.AUTOMATIC)
 
119
        self.scrolled_window.set_shadow_type(Gtk.ShadowType.IN)
 
120
        self.scrolled_window.show()
 
121
        self.pack_start(self.scrolled_window, True, True, 0)
 
122
 
 
123
        self.scrolled_window.add(self.construct_treeview())
 
124
 
 
125
        self.path = None
75
126
        self.branch = branch
76
 
 
77
 
        gobject.idle_add(self.populate, start, maxnum, 
78
 
                         broken_line_length)
79
 
 
80
127
        self.revision = None
81
 
        self.children = None
82
 
        self.parents  = None
83
 
 
84
 
        self.connect("destroy", lambda x: self.branch.unlock())
 
128
        self.index = {}
 
129
 
 
130
        self.start = start
 
131
        self.maxnum = maxnum
 
132
        self.compact = compact
 
133
 
 
134
        self.model = treemodel.BranchTreeModel(self.branch, [])
 
135
        GObject.idle_add(self.populate)
 
136
 
 
137
        self.connect("destroy", self._on_destroy)
 
138
 
 
139
    def _on_destroy(self, *ignored):
 
140
        self.branch.unlock()
 
141
        if getattr(ui.ui_factory, "set_progress_bar_widget", None) is not None:
 
142
            # We'are using our own ui, let's tell it to stop using our widget.
 
143
            ui.ui_factory.set_progress_bar_widget(None)
85
144
 
86
145
    def do_get_property(self, property):
87
146
        if property.name == 'revno-column-visible':
88
147
            return self.revno_column.get_visible()
 
148
        elif property.name == 'graph-column-visible':
 
149
            return self.graph_column.get_visible()
89
150
        elif property.name == 'date-column-visible':
90
151
            return self.date_column.get_visible()
 
152
        elif property.name == 'compact':
 
153
            return self.compact
 
154
        elif property.name == 'mainline-only':
 
155
            return self.mainline_only
91
156
        elif property.name == 'branch':
92
157
            return self.branch
93
158
        elif property.name == 'revision':
94
 
            return self.revision
 
159
            if self.path is None:
 
160
                return None
 
161
            return self.model.get_value(self.model.get_iter(self.path),
 
162
                                        treemodel.REVISION)
 
163
        elif property.name == 'revision-number':
 
164
            if self.path is None:
 
165
                return None
 
166
            return self.model.get_value(self.model.get_iter(self.path),
 
167
                                        treemodel.REVNO)
 
168
        elif property.name == 'children':
 
169
            if self.path is None:
 
170
                return None
 
171
            return self.model.get_value(self.model.get_iter(self.path),
 
172
                                        treemodel.CHILDREN)
 
173
        elif property.name == 'parents':
 
174
            if self.path is None:
 
175
                return None
 
176
            return self.model.get_value(self.model.get_iter(self.path),
 
177
                                        treemodel.PARENTS)
95
178
        else:
96
179
            raise AttributeError, 'unknown property %s' % property.name
97
180
 
98
181
    def do_set_property(self, property, value):
99
182
        if property.name == 'revno-column-visible':
100
183
            self.revno_column.set_visible(value)
 
184
        elif property.name == 'graph-column-visible':
 
185
            self.graph_column.set_visible(value)
101
186
        elif property.name == 'date-column-visible':
102
187
            self.date_column.set_visible(value)
 
188
        elif property.name == 'compact':
 
189
            self.compact = value
 
190
        elif property.name == 'mainline-only':
 
191
            self.mainline_only = value
103
192
        elif property.name == 'branch':
104
193
            self.branch = value
105
194
        elif property.name == 'revision':
109
198
 
110
199
    def get_revision(self):
111
200
        """Return revision id of currently selected revision, or None."""
112
 
        return self.revision
 
201
        return self.get_property('revision')
 
202
 
 
203
    def has_revision_id(self, revision_id):
 
204
        return (revision_id in self.index)
 
205
 
 
206
    def set_revision(self, revision):
 
207
        self.set_property('revision', revision)
113
208
 
114
209
    def set_revision_id(self, revid):
115
210
        """Change the currently selected revision.
116
211
 
117
212
        :param revid: Revision id of revision to display.
118
213
        """
119
 
        self.treeview.set_cursor(self.index[revid])
 
214
        self.treeview.set_cursor(
 
215
            Gtk.TreePath(path=self.index[revid]), None, False)
120
216
        self.treeview.grab_focus()
121
217
 
122
218
    def get_children(self):
124
220
 
125
221
        :return: list of revision ids.
126
222
        """
127
 
        return self.children
 
223
        return self.get_property('children')
128
224
 
129
225
    def get_parents(self):
130
226
        """Return the parents of the currently selected revision.
131
227
 
132
228
        :return: list of revision ids.
133
229
        """
134
 
        return self.parents
135
 
        
 
230
        return self.get_property('parents')
 
231
 
 
232
    def add_tag(self, tag, revid=None):
 
233
        if revid is None: revid = self.revision.revision_id
 
234
 
 
235
        if lock.release(self.branch):
 
236
            try:
 
237
                lock.acquire(self.branch, lock.WRITE)
 
238
                self.model.add_tag(tag, revid)
 
239
            finally:
 
240
                lock.release(self.branch)
 
241
 
 
242
            lock.acquire(self.branch, lock.READ)
 
243
 
 
244
            self.emit('tag-added', tag, revid)
 
245
 
 
246
    def refresh(self):
 
247
        GObject.idle_add(self.populate, self.get_revision())
 
248
 
 
249
    def update(self):
 
250
        try:
 
251
            self.branch.unlock()
 
252
            try:
 
253
                self.branch.lock_write()
 
254
                self.branch.update()
 
255
            finally:
 
256
                self.branch.unlock()
 
257
        finally:
 
258
            self.branch.lock_read()
 
259
 
136
260
    def back(self):
137
261
        """Signal handler for the Back button."""
138
 
        (path, col) = self.treeview.get_cursor()
139
 
        revision = self.model[path][treemodel.REVISION]
140
 
        parents = self.model[path][treemodel.PARENTS]
141
 
        if not len(parents):
 
262
        parents = self.get_parents()
 
263
        if not parents:
142
264
            return
143
265
 
144
266
        for parent_id in parents:
145
267
            parent_index = self.index[parent_id]
146
268
            parent = self.model[parent_index][treemodel.REVISION]
147
 
            if same_branch(revision, parent):
148
 
                self.treeview.set_cursor(parent_index)
 
269
            if same_branch(self.get_revision(), parent):
 
270
                self.set_revision(parent)
149
271
                break
150
272
        else:
151
 
            self.treeview.set_cursor(self.index[parents[0]])
152
 
        self.treeview.grab_focus()
 
273
            self.set_revision_id(parents[0])
153
274
 
154
275
    def forward(self):
155
276
        """Signal handler for the Forward button."""
156
 
        (path, col) = self.treeview.get_cursor()
157
 
        revision = self.model[path][treemodel.REVISION]
158
 
        children = self.model[path][treemodel.CHILDREN]
159
 
        if not len(children):
 
277
        children = self.get_children()
 
278
        if not children:
160
279
            return
161
280
 
162
281
        for child_id in children:
163
282
            child_index = self.index[child_id]
164
283
            child = self.model[child_index][treemodel.REVISION]
165
 
            if same_branch(child, revision):
166
 
                self.treeview.set_cursor(child_index)
 
284
            if same_branch(child, self.get_revision()):
 
285
                self.set_revision(child)
167
286
                break
168
287
        else:
169
 
            self.treeview.set_cursor(self.index[children[0]])
170
 
        self.treeview.grab_focus()
 
288
            self.set_revision_id(children[0])
171
289
 
172
 
    def populate(self, start, maxnum, broken_line_length=None):
 
290
    def populate(self, revision=None):
173
291
        """Fill the treeview with contents.
174
292
 
175
293
        :param start: Revision id of revision to start with.
178
296
        :param broken_line_length: After how much lines branches \
179
297
                       should be broken.
180
298
        """
181
 
        self.branch.lock_read()
182
 
        (linegraphdata, index, columns_len) = linegraph(self.branch.repository,
183
 
                                                        start,
184
 
                                                        maxnum, 
185
 
                                                        broken_line_length)
186
 
 
187
 
        self.model = TreeModel(self.branch.repository, linegraphdata)
188
 
        self.graph_cell.columns_len = columns_len
189
 
        width = self.graph_cell.get_size(self.treeview)[2]
190
 
        self.graph_column.set_fixed_width(width)
191
 
        self.graph_column.set_max_width(width)
192
 
        self.index = index
193
 
        self.treeview.set_model(self.model)
194
 
        self.treeview.set_cursor(0)
195
 
        self.emit('revisions-loaded')
196
 
 
197
 
        return False
198
 
 
199
 
    def show_diff(self, revid=None, parentid=None):
200
 
        """Open a new window to show a diff between the given revisions."""
201
 
        from bzrlib.plugins.gtk.diff import DiffWindow
202
 
        window = DiffWindow(parent=self)
203
 
 
204
 
        if revid is None:
205
 
            revid = self.revision.revision_id
206
 
 
207
 
            if parentid is None and len(self.parents) > 0:
208
 
                parentid = self.parents[0]
209
 
 
210
 
        if parentid is None:
211
 
            parentid = NULL_REVISION
212
 
 
213
 
        rev_tree    = self.branch.repository.revision_tree(revid)
214
 
        parent_tree = self.branch.repository.revision_tree(parentid)
215
 
 
216
 
        description = revid + " - " + self.branch.nick
217
 
        window.set_diff(description, rev_tree, parent_tree)
218
 
        window.show()
 
299
 
 
300
        if getattr(ui.ui_factory, "set_progress_bar_widget", None) is not None:
 
301
            # We'are using our own ui, let's tell it to use our widget.
 
302
            ui.ui_factory.set_progress_bar_widget(self.progress_widget)
 
303
        self.progress_bar = ui.ui_factory.nested_progress_bar()
 
304
        self.progress_bar.update("Loading ancestry graph", 0, 5)
 
305
 
 
306
        try:
 
307
            if self.compact:
 
308
                broken_line_length = 32
 
309
            else:
 
310
                broken_line_length = None
 
311
 
 
312
            show_graph = self.graph_column.get_visible()
 
313
 
 
314
            self.branch.lock_read()
 
315
            (linegraphdata, index, columns_len) = linegraph(
 
316
                self.branch.repository.get_graph(),
 
317
                self.start,
 
318
                self.maxnum, 
 
319
                broken_line_length,
 
320
                show_graph,
 
321
                self.mainline_only,
 
322
                self.progress_bar)
 
323
 
 
324
            self.model.set_line_graph_data(linegraphdata)
 
325
            self.graph_cell.columns_len = columns_len
 
326
            width = self.graph_cell.get_preferred_width(self.treeview)[1]
 
327
            if width > 500:
 
328
                width = 500
 
329
            elif width == 0:
 
330
                # The get_preferred_width() call got an insane value.
 
331
                width = 200
 
332
            self.graph_column.set_fixed_width(width)
 
333
            self.graph_column.set_max_width(width)
 
334
            self.index = index
 
335
            self.treeview.set_model(self.model)
 
336
 
 
337
            if not revision or revision == NULL_REVISION:
 
338
                self.treeview.set_cursor(Gtk.TreePath(path=0), None, False)
 
339
            else:
 
340
                self.set_revision(revision)
 
341
 
 
342
            self.emit('refreshed')
 
343
            return False
 
344
        finally:
 
345
            self.progress_bar.finished()
219
346
 
220
347
    def construct_treeview(self):
221
 
        self.treeview = gtk.TreeView()
 
348
        self.treeview = Gtk.TreeView()
222
349
 
223
350
        self.treeview.set_rules_hint(True)
224
 
        self.treeview.set_search_column(treemodel.REVNO)
225
 
        
226
 
        # Fix old PyGTK bug - by JAM
227
 
        set_tooltip = getattr(self.treeview, 'set_tooltip_column', None)
228
 
        if set_tooltip is not None:
229
 
            set_tooltip(treemodel.MESSAGE)
230
 
 
 
351
        # combined revno/summary interactive search
 
352
        #
 
353
        # the row in a treemodel is considered "matched" if a REVNO *starts*
 
354
        # from the key (that is the key is found in a REVNO at the offset 0)
 
355
        # or if a MESSAGE *contains* the key anywhere (that is, the key is
 
356
        # found case insensitively in a MESSAGE at any offset)
 
357
        def search_equal_func(model, column, key, iter, ignored):
 
358
            return (model.get_value(iter, treemodel.REVNO).find(key) != 0
 
359
                and model.get_value(iter, treemodel.MESSAGE).lower().find(key.lower()) == -1)
 
360
 
 
361
        self.treeview.set_search_equal_func(search_equal_func, None)
 
362
        self.treeview.set_enable_search(True)
 
363
 
 
364
        self.treeview.set_tooltip_column(treemodel.MESSAGE)
 
365
        self.treeview.set_headers_visible(True)
 
366
 
 
367
        self._prev_cursor_path = None
231
368
        self.treeview.connect("cursor-changed",
232
369
                self._on_selection_changed)
233
370
 
239
376
 
240
377
        self.treeview.set_property('fixed-height-mode', True)
241
378
 
242
 
        self.add(self.treeview)
243
379
        self.treeview.show()
244
380
 
245
 
        cell = gtk.CellRendererText()
 
381
        cell = Gtk.CellRendererText()
246
382
        cell.set_property("width-chars", 15)
247
 
        cell.set_property("ellipsize", pango.ELLIPSIZE_END)
248
 
        self.revno_column = gtk.TreeViewColumn("Revision No")
 
383
        cell.set_property("ellipsize", Pango.EllipsizeMode.END)
 
384
        self.revno_column = Gtk.TreeViewColumn("Revision No")
249
385
        self.revno_column.set_resizable(True)
250
 
        self.revno_column.set_sizing(gtk.TREE_VIEW_COLUMN_FIXED)
251
 
        self.revno_column.set_fixed_width(cell.get_size(self.treeview)[2])
252
 
        self.revno_column.pack_start(cell, expand=True)
 
386
        self.revno_column.set_sizing(Gtk.TreeViewColumnSizing.FIXED)
 
387
        self.revno_column.set_fixed_width(
 
388
            cell.get_preferred_width(self.treeview)[1])
 
389
        self.revno_column.pack_start(cell, True)
253
390
        self.revno_column.add_attribute(cell, "text", treemodel.REVNO)
254
391
        self.treeview.append_column(self.revno_column)
255
392
 
256
393
        self.graph_cell = CellRendererGraph()
257
 
        self.graph_column = gtk.TreeViewColumn()
 
394
        self.graph_column = Gtk.TreeViewColumn()
258
395
        self.graph_column.set_resizable(True)
259
 
        self.graph_column.set_sizing(gtk.TREE_VIEW_COLUMN_FIXED)
260
 
        self.graph_column.pack_start(self.graph_cell, expand=False)
261
 
        self.graph_column.add_attribute(self.graph_cell, "node", treemodel.NODE)
262
 
        self.graph_column.add_attribute(self.graph_cell, "in-lines", treemodel.LAST_LINES)
263
 
        self.graph_column.add_attribute(self.graph_cell, "out-lines", treemodel.LINES)
 
396
        self.graph_column.set_sizing(Gtk.TreeViewColumnSizing.FIXED)
 
397
        self.graph_column.pack_start(self.graph_cell, True)
 
398
        self.graph_column.add_attribute(
 
399
            self.graph_cell, "node", treemodel.NODE)
 
400
        self.graph_column.add_attribute(
 
401
            self.graph_cell, "tags", treemodel.TAGS)
 
402
        self.graph_column.add_attribute(
 
403
            self.graph_cell, "in-lines", treemodel.LAST_LINES)
 
404
        self.graph_column.add_attribute(
 
405
            self.graph_cell, "out-lines", treemodel.LINES)
264
406
        self.treeview.append_column(self.graph_column)
265
407
 
266
 
        cell = gtk.CellRendererText()
 
408
        cell = Gtk.CellRendererText()
267
409
        cell.set_property("width-chars", 65)
268
 
        cell.set_property("ellipsize", pango.ELLIPSIZE_END)
269
 
        self.msg_column = gtk.TreeViewColumn("Message")
270
 
        self.msg_column.set_resizable(True)
271
 
        self.msg_column.set_sizing(gtk.TREE_VIEW_COLUMN_FIXED)
272
 
        self.msg_column.set_fixed_width(cell.get_size(self.treeview)[2])
273
 
        self.msg_column.pack_start(cell, expand=True)
274
 
        self.msg_column.add_attribute(cell, "text", treemodel.MESSAGE)
275
 
        self.treeview.append_column(self.msg_column)
 
410
        cell.set_property("ellipsize", Pango.EllipsizeMode.END)
 
411
        self.summary_column = Gtk.TreeViewColumn("Summary")
 
412
        self.summary_column.set_resizable(True)
 
413
        self.summary_column.set_expand(True)
 
414
        self.summary_column.set_sizing(Gtk.TreeViewColumnSizing.FIXED)
 
415
        self.summary_column.set_fixed_width(
 
416
            cell.get_preferred_width(self.treeview)[1])
 
417
        self.summary_column.pack_start(cell, True)
 
418
        self.summary_column.add_attribute(cell, "markup", treemodel.SUMMARY)
 
419
        self.treeview.append_column(self.summary_column)
276
420
 
277
 
        cell = gtk.CellRendererText()
 
421
        cell = Gtk.CellRendererText()
278
422
        cell.set_property("width-chars", 15)
279
 
        cell.set_property("ellipsize", pango.ELLIPSIZE_END)
280
 
        self.committer_column = gtk.TreeViewColumn("Committer")
281
 
        self.committer_column.set_resizable(True)
282
 
        self.committer_column.set_sizing(gtk.TREE_VIEW_COLUMN_FIXED)
283
 
        self.committer_column.set_fixed_width(cell.get_size(self.treeview)[2])
284
 
        self.committer_column.pack_start(cell, expand=True)
285
 
        self.committer_column.add_attribute(cell, "text", treemodel.COMMITER)
286
 
        self.treeview.append_column(self.committer_column)
 
423
        cell.set_property("ellipsize", Pango.EllipsizeMode.END)
 
424
        self.authors_column = Gtk.TreeViewColumn("Author(s)")
 
425
        self.authors_column.set_resizable(False)
 
426
        self.authors_column.set_sizing(Gtk.TreeViewColumnSizing.FIXED)
 
427
        self.authors_column.set_fixed_width(200)
 
428
        self.authors_column.pack_start(cell, True)
 
429
        self.authors_column.add_attribute(cell, "text", treemodel.AUTHORS)
 
430
        self.treeview.append_column(self.authors_column)
287
431
 
288
 
        cell = gtk.CellRendererText()
 
432
        cell = Gtk.CellRendererText()
289
433
        cell.set_property("width-chars", 20)
290
 
        cell.set_property("ellipsize", pango.ELLIPSIZE_END)
291
 
        self.date_column = gtk.TreeViewColumn("Date")
 
434
        cell.set_property("ellipsize", Pango.EllipsizeMode.END)
 
435
        self.date_column = Gtk.TreeViewColumn("Date")
292
436
        self.date_column.set_visible(False)
293
437
        self.date_column.set_resizable(True)
294
 
        self.date_column.set_sizing(gtk.TREE_VIEW_COLUMN_FIXED)
295
 
        self.date_column.set_fixed_width(cell.get_size(self.treeview)[2])
296
 
        self.date_column.pack_start(cell, expand=True)
 
438
        self.date_column.set_sizing(Gtk.TreeViewColumnSizing.FIXED)
 
439
        self.date_column.set_fixed_width(130)
 
440
        self.date_column.pack_start(cell, True)
297
441
        self.date_column.add_attribute(cell, "text", treemodel.TIMESTAMP)
298
442
        self.treeview.append_column(self.date_column)
299
443
 
 
444
        return self.treeview
 
445
 
300
446
    def _on_selection_changed(self, treeview):
301
447
        """callback for when the treeview changes."""
302
448
        (path, focus) = treeview.get_cursor()
303
 
        if path is not None:
304
 
            iter = self.model.get_iter(path)
305
 
            self.revision = self.model.get_value(iter, treemodel.REVISION)
306
 
            self.parents = self.model.get_value(iter, treemodel.PARENTS)
307
 
            self.children = self.model.get_value(iter, treemodel.CHILDREN)
308
 
 
 
449
        if (path is not None) and (path != self._prev_cursor_path):
 
450
            self._prev_cursor_path = path # avoid emitting twice per click
 
451
            self.path = path
309
452
            self.emit('revision-selected')
310
453
 
311
454
    def _on_revision_selected(self, widget, event):
312
 
        from bzrlib.plugins.gtk.revisionmenu import RevisionPopupMenu
 
455
        from bzrlib.plugins.gtk.revisionmenu import RevisionMenu
313
456
        if event.button == 3:
314
 
            menu = RevisionPopupMenu(self.branch.repository, 
315
 
                [self.get_revision().revision_id],
316
 
                self.branch)
317
 
            menu.popup(None, None, None, event.button, event.get_time())
 
457
            revs = []
 
458
            rev = self.get_revision()
 
459
            if rev is not None:
 
460
                revs.append(rev.revision_id)
 
461
            menu = RevisionMenu(self.branch.repository, revs, self.branch)
 
462
            menu.connect('tag-added', lambda w, t, r: self.add_tag(t, r))
 
463
            menu.popup(None, None, None, None, event.button, event.get_time())
318
464
 
319
465
    def _on_revision_activated(self, widget, path, col):
320
 
        # TODO: more than one parent
321
 
        """Callback for when a treeview row gets activated."""
322
 
        revision_id = self.model[path][treemodel.REVID]
323
 
        parents = self.model[path][treemodel.PARENTS]
324
 
 
325
 
        if len(parents) == 0:
326
 
            parent_id = None
327
 
        else:
328
 
            parent_id = parents[0]
329
 
 
330
 
        self.show_diff(revision_id, parent_id)
331
 
        self.treeview.grab_focus()
 
466
        self.emit('revision-activated', path, col)