/b-gtk/fix-viz

To get this branch, use:
bzr branch http://gegoxaren.bato24.eu/bzr/b-gtk/fix-viz
301 by Daniel Schierbeck
Initial work on extracting the TreeView from the branch window.
1
# -*- coding: UTF-8 -*-
2
"""Revision history view.
3
4
"""
5
6
__copyright__ = "Copyright © 2005 Canonical Ltd."
7
__author__    = "Daniel Schierbeck <daniel.schierbeck@gmail.com>"
8
314 by Daniel Schierbeck
Moved branch locking into treeview.
9
import sys
10
import string
301 by Daniel Schierbeck
Initial work on extracting the TreeView from the branch window.
11
import gtk
12
import gobject
13
import pango
14
import re
303 by Daniel Schierbeck
Made basic signaling work.
15
import treemodel
301 by Daniel Schierbeck
Initial work on extracting the TreeView from the branch window.
16
17
from linegraph import linegraph, same_branch
18
from graphcell import CellRendererGraph
19
from treemodel import TreeModel
330.4.3 by Daniel Schierbeck
Switched to using NULL_REVISION instead of None.
20
from bzrlib.revision import NULL_REVISION
301 by Daniel Schierbeck
Initial work on extracting the TreeView from the branch window.
21
423.1.13 by Gary van der Merwe
Move viz loading msg from branchwin to treeview.
22
class TreeView(gtk.VBox):
301 by Daniel Schierbeck
Initial work on extracting the TreeView from the branch window.
23
346 by Daniel Schierbeck
Added revno-column-visible property to treeview.
24
    __gproperties__ = {
352 by Daniel Schierbeck
Added branch property to treeview.
25
        'branch': (gobject.TYPE_PYOBJECT,
26
                   'Branch',
27
                   'The Bazaar branch being visualized',
28
                   gobject.PARAM_CONSTRUCT_ONLY | gobject.PARAM_WRITABLE),
29
356 by Daniel Schierbeck
Made revision a property on TreeView.
30
        'revision': (gobject.TYPE_PYOBJECT,
31
                     'Revision',
32
                     'The currently selected revision',
33
                     gobject.PARAM_READWRITE),
34
395.1.2 by Daniel Schierbeck
Added revision-number property to the TreeView.
35
        'revision-number': (gobject.TYPE_STRING,
36
                            'Revision number',
37
                            'The number of the selected revision',
38
                            '',
39
                            gobject.PARAM_READABLE),
40
395.1.1 by Daniel Schierbeck
Cleaned up code in the TreeView, removing instance variables.
41
        'children': (gobject.TYPE_PYOBJECT,
42
                     'Child revisions',
43
                     'Children of the currently selected revision',
44
                     gobject.PARAM_READABLE),
45
46
        'parents': (gobject.TYPE_PYOBJECT,
47
                    'Parent revisions',
48
                    'Parents to the currently selected revision',
49
                    gobject.PARAM_READABLE),
50
346 by Daniel Schierbeck
Added revno-column-visible property to treeview.
51
        'revno-column-visible': (gobject.TYPE_BOOLEAN,
423.1.18 by Gary van der Merwe
Add options to viz treeview to not show the line graph, and to only show the main line.
52
                                 'Revision number column',
346 by Daniel Schierbeck
Added revno-column-visible property to treeview.
53
                                 'Show revision number column',
54
                                 True,
357 by Daniel Schierbeck
Added support for showing the date column in the viz.
55
                                 gobject.PARAM_READWRITE),
56
423.1.18 by Gary van der Merwe
Add options to viz treeview to not show the line graph, and to only show the main line.
57
        'graph-column-visible': (gobject.TYPE_BOOLEAN,
58
                                 'Graph column',
59
                                 'Show graph column',
60
                                 True,
61
                                 gobject.PARAM_READWRITE),
62
357 by Daniel Schierbeck
Added support for showing the date column in the viz.
63
        'date-column-visible': (gobject.TYPE_BOOLEAN,
360 by Daniel Schierbeck
Fixed wrong text in date property.
64
                                 'Date',
65
                                 'Show date column',
357 by Daniel Schierbeck
Added support for showing the date column in the viz.
66
                                 False,
401.1.3 by Daniel Schierbeck
Made the compact view toggling cleaner.
67
                                 gobject.PARAM_READWRITE),
68
69
        'compact': (gobject.TYPE_BOOLEAN,
70
                    'Compact view',
71
                    'Break ancestry lines to save space',
72
                    True,
423.1.18 by Gary van der Merwe
Add options to viz treeview to not show the line graph, and to only show the main line.
73
                    gobject.PARAM_CONSTRUCT | gobject.PARAM_READWRITE),
74
75
        'mainline-only': (gobject.TYPE_BOOLEAN,
76
                    'Mainline only',
77
                    'Only show the mainline history.',
78
                    False,
79
                    gobject.PARAM_CONSTRUCT | gobject.PARAM_READWRITE),
357 by Daniel Schierbeck
Added support for showing the date column in the viz.
80
346 by Daniel Schierbeck
Added revno-column-visible property to treeview.
81
    }
82
307 by Daniel Schierbeck
Made load notification work again.
83
    __gsignals__ = {
345 by Daniel Schierbeck
Made treeview columns instance variables.
84
        'revisions-loaded': (gobject.SIGNAL_RUN_FIRST, 
85
                             gobject.TYPE_NONE,
86
                             ()),
87
        'revision-selected': (gobject.SIGNAL_RUN_FIRST,
88
                              gobject.TYPE_NONE,
423.7.4 by Daniel Schierbeck
Made revisionview and branchview update when a tag is added.
89
                              ()),
423.1.17 by Gary van der Merwe
Reuse the viz treeview in the revision browser.
90
        'revision-activated': (gobject.SIGNAL_RUN_FIRST,
91
                              gobject.TYPE_NONE,
92
                              (gobject.TYPE_PYOBJECT, gobject.TYPE_PYOBJECT)),
423.7.4 by Daniel Schierbeck
Made revisionview and branchview update when a tag is added.
93
        'tag-added': (gobject.SIGNAL_RUN_FIRST,
94
                              gobject.TYPE_NONE,
95
                              (gobject.TYPE_STRING, gobject.TYPE_STRING))
307 by Daniel Schierbeck
Made load notification work again.
96
    }
97
401.1.3 by Daniel Schierbeck
Made the compact view toggling cleaner.
98
    def __init__(self, branch, start, maxnum, compact=True):
322 by Jelmer Vernooij
Add docstrings.
99
        """Create a new TreeView.
100
101
        :param branch: Branch object for branch to show.
102
        :param start: Revision id of top revision.
103
        :param maxnum: Maximum number of revisions to display, 
104
                       None for no limit.
329 by Jelmer Vernooij
Make broken_line_length setting from higher up.
105
        :param broken_line_length: After how much lines to break 
106
                                   branches.
322 by Jelmer Vernooij
Add docstrings.
107
        """
423.1.13 by Gary van der Merwe
Move viz loading msg from branchwin to treeview.
108
        gtk.VBox.__init__(self, spacing=0)
109
110
        self.pack_start(self.construct_loading_msg(), expand=False, fill=True)
111
        self.connect('revisions-loaded', 
112
                lambda x: self.loading_msg_box.hide())
113
114
        self.scrolled_window = gtk.ScrolledWindow()
423.1.18 by Gary van der Merwe
Add options to viz treeview to not show the line graph, and to only show the main line.
115
        self.scrolled_window.set_policy(gtk.POLICY_AUTOMATIC,
116
                                        gtk.POLICY_AUTOMATIC)
423.1.13 by Gary van der Merwe
Move viz loading msg from branchwin to treeview.
117
        self.scrolled_window.set_shadow_type(gtk.SHADOW_IN)
118
        self.scrolled_window.show()
119
        self.pack_start(self.scrolled_window, expand=True, fill=True)
120
121
        self.scrolled_window.add(self.construct_treeview())
122
        
303 by Daniel Schierbeck
Made basic signaling work.
123
423.7.3 by Daniel Schierbeck
Moved tag writing logic inside the branchview treemodel.
124
        self.iter = None
316 by Daniel Schierbeck
Removed viz.TreeView.set_branch()
125
        self.branch = branch
423.7.3 by Daniel Schierbeck
Moved tag writing logic inside the branchview treemodel.
126
        self.revision = None
316 by Daniel Schierbeck
Removed viz.TreeView.set_branch()
127
401.1.1 by Daniel Schierbeck
Added update() method to TreeView.
128
        self.start = start
129
        self.maxnum = maxnum
401.1.3 by Daniel Schierbeck
Made the compact view toggling cleaner.
130
        self.compact = compact
401.1.1 by Daniel Schierbeck
Added update() method to TreeView.
131
132
        gobject.idle_add(self.populate)
316 by Daniel Schierbeck
Removed viz.TreeView.set_branch()
133
392 by Daniel Schierbeck
Fixed performance issue by only releasing the branch lock when the treeview is destroyed. This will surely fuck up the tagging code.
134
        self.connect("destroy", lambda x: self.branch.unlock())
135
347 by Daniel Schierbeck
Added property getter and setter method to the treeview.
136
    def do_get_property(self, property):
137
        if property.name == 'revno-column-visible':
352 by Daniel Schierbeck
Added branch property to treeview.
138
            return self.revno_column.get_visible()
423.1.18 by Gary van der Merwe
Add options to viz treeview to not show the line graph, and to only show the main line.
139
        elif property.name == 'graph-column-visible':
140
            return self.graph_column.get_visible()
357 by Daniel Schierbeck
Added support for showing the date column in the viz.
141
        elif property.name == 'date-column-visible':
142
            return self.date_column.get_visible()
401.1.3 by Daniel Schierbeck
Made the compact view toggling cleaner.
143
        elif property.name == 'compact':
144
            return self.compact
423.1.18 by Gary van der Merwe
Add options to viz treeview to not show the line graph, and to only show the main line.
145
        elif property.name == 'mainline-only':
146
            return self.mainline_only
352 by Daniel Schierbeck
Added branch property to treeview.
147
        elif property.name == 'branch':
148
            return self.branch
356 by Daniel Schierbeck
Made revision a property on TreeView.
149
        elif property.name == 'revision':
395.1.1 by Daniel Schierbeck
Cleaned up code in the TreeView, removing instance variables.
150
            return self.model.get_value(self.iter, treemodel.REVISION)
395.1.2 by Daniel Schierbeck
Added revision-number property to the TreeView.
151
        elif property.name == 'revision-number':
152
            return self.model.get_value(self.iter, treemodel.REVNO)
395.1.1 by Daniel Schierbeck
Cleaned up code in the TreeView, removing instance variables.
153
        elif property.name == 'children':
154
            return self.model.get_value(self.iter, treemodel.CHILDREN)
155
        elif property.name == 'parents':
156
            return self.model.get_value(self.iter, treemodel.PARENTS)
347 by Daniel Schierbeck
Added property getter and setter method to the treeview.
157
        else:
158
            raise AttributeError, 'unknown property %s' % property.name
159
160
    def do_set_property(self, property, value):
161
        if property.name == 'revno-column-visible':
162
            self.revno_column.set_visible(value)
423.1.18 by Gary van der Merwe
Add options to viz treeview to not show the line graph, and to only show the main line.
163
        elif property.name == 'graph-column-visible':
164
            self.graph_column.set_visible(value)
357 by Daniel Schierbeck
Added support for showing the date column in the viz.
165
        elif property.name == 'date-column-visible':
166
            self.date_column.set_visible(value)
401.1.3 by Daniel Schierbeck
Made the compact view toggling cleaner.
167
        elif property.name == 'compact':
168
            self.compact = value
423.1.18 by Gary van der Merwe
Add options to viz treeview to not show the line graph, and to only show the main line.
169
        elif property.name == 'mainline-only':
170
            self.mainline_only = value
352 by Daniel Schierbeck
Added branch property to treeview.
171
        elif property.name == 'branch':
172
            self.branch = value
356 by Daniel Schierbeck
Made revision a property on TreeView.
173
        elif property.name == 'revision':
174
            self.set_revision_id(value.revision_id)
347 by Daniel Schierbeck
Added property getter and setter method to the treeview.
175
        else:
176
            raise AttributeError, 'unknown property %s' % property.name
177
303 by Daniel Schierbeck
Made basic signaling work.
178
    def get_revision(self):
322 by Jelmer Vernooij
Add docstrings.
179
        """Return revision id of currently selected revision, or None."""
395.1.1 by Daniel Schierbeck
Cleaned up code in the TreeView, removing instance variables.
180
        return self.get_property('revision')
181
182
    def set_revision(self, revision):
183
        self.set_property('revision', revision)
303 by Daniel Schierbeck
Made basic signaling work.
184
356 by Daniel Schierbeck
Made revision a property on TreeView.
185
    def set_revision_id(self, revid):
322 by Jelmer Vernooij
Add docstrings.
186
        """Change the currently selected revision.
187
188
        :param revid: Revision id of revision to display.
189
        """
305 by Daniel Schierbeck
Moved revision selection to the new view.
190
        self.treeview.set_cursor(self.index[revid])
191
        self.treeview.grab_focus()
192
303 by Daniel Schierbeck
Made basic signaling work.
193
    def get_children(self):
322 by Jelmer Vernooij
Add docstrings.
194
        """Return the children of the currently selected revision.
195
196
        :return: list of revision ids.
197
        """
395.1.1 by Daniel Schierbeck
Cleaned up code in the TreeView, removing instance variables.
198
        return self.get_property('children')
303 by Daniel Schierbeck
Made basic signaling work.
199
200
    def get_parents(self):
322 by Jelmer Vernooij
Add docstrings.
201
        """Return the parents of the currently selected revision.
202
203
        :return: list of revision ids.
204
        """
395.1.1 by Daniel Schierbeck
Cleaned up code in the TreeView, removing instance variables.
205
        return self.get_property('parents')
423.7.3 by Daniel Schierbeck
Moved tag writing logic inside the branchview treemodel.
206
207
    def add_tag(self, tag, revid=None):
208
        if revid is None: revid = self.revision.revision_id
209
210
        try:
211
            self.branch.unlock()
212
213
            try:
214
                self.branch.lock_write()
215
                self.model.add_tag(tag, revid)
216
            finally:
217
                self.branch.unlock()
218
219
        finally:
220
            self.branch.lock_read()
423.7.4 by Daniel Schierbeck
Made revisionview and branchview update when a tag is added.
221
222
        self.emit('tag-added', tag, revid)
316 by Daniel Schierbeck
Removed viz.TreeView.set_branch()
223
        
401.1.2 by Daniel Schierbeck
Allowed the treeview to be refreshed.
224
    def refresh(self):
423.1.13 by Gary van der Merwe
Move viz loading msg from branchwin to treeview.
225
        self.loading_msg_box.show()
401.1.2 by Daniel Schierbeck
Allowed the treeview to be refreshed.
226
        gobject.idle_add(self.populate, self.get_revision())
401.1.1 by Daniel Schierbeck
Added update() method to TreeView.
227
404 by Daniel Schierbeck
Made the refresh use proper locking.
228
    def update(self):
229
        try:
230
            self.branch.unlock()
231
            try:
232
                self.branch.lock_write()
233
                self.branch.update()
234
            finally:
235
                self.branch.unlock()
236
        finally:
237
            self.branch.lock_read()
238
304 by Daniel Schierbeck
Made forward/back buttons work again.
239
    def back(self):
322 by Jelmer Vernooij
Add docstrings.
240
        """Signal handler for the Back button."""
395.1.1 by Daniel Schierbeck
Cleaned up code in the TreeView, removing instance variables.
241
        parents = self.get_parents()
304 by Daniel Schierbeck
Made forward/back buttons work again.
242
        if not len(parents):
243
            return
244
245
        for parent_id in parents:
246
            parent_index = self.index[parent_id]
247
            parent = self.model[parent_index][treemodel.REVISION]
395.1.1 by Daniel Schierbeck
Cleaned up code in the TreeView, removing instance variables.
248
            if same_branch(self.get_revision(), parent):
395.1.2 by Daniel Schierbeck
Added revision-number property to the TreeView.
249
                self.set_revision(parent)
304 by Daniel Schierbeck
Made forward/back buttons work again.
250
                break
251
        else:
395.1.2 by Daniel Schierbeck
Added revision-number property to the TreeView.
252
            self.set_revision_id(parents[0])
304 by Daniel Schierbeck
Made forward/back buttons work again.
253
254
    def forward(self):
322 by Jelmer Vernooij
Add docstrings.
255
        """Signal handler for the Forward button."""
395.1.1 by Daniel Schierbeck
Cleaned up code in the TreeView, removing instance variables.
256
        children = self.get_children()
304 by Daniel Schierbeck
Made forward/back buttons work again.
257
        if not len(children):
258
            return
259
260
        for child_id in children:
261
            child_index = self.index[child_id]
262
            child = self.model[child_index][treemodel.REVISION]
395.1.1 by Daniel Schierbeck
Cleaned up code in the TreeView, removing instance variables.
263
            if same_branch(child, self.get_revision()):
395.1.2 by Daniel Schierbeck
Added revision-number property to the TreeView.
264
                self.set_revision(child)
304 by Daniel Schierbeck
Made forward/back buttons work again.
265
                break
266
        else:
395.1.2 by Daniel Schierbeck
Added revision-number property to the TreeView.
267
            self.set_revision_id(children[0])
304 by Daniel Schierbeck
Made forward/back buttons work again.
268
401.1.2 by Daniel Schierbeck
Allowed the treeview to be refreshed.
269
    def populate(self, revision=None):
322 by Jelmer Vernooij
Add docstrings.
270
        """Fill the treeview with contents.
271
272
        :param start: Revision id of revision to start with.
273
        :param maxnum: Maximum number of revisions to display, or None 
274
                       for no limit.
329 by Jelmer Vernooij
Make broken_line_length setting from higher up.
275
        :param broken_line_length: After how much lines branches \
276
                       should be broken.
322 by Jelmer Vernooij
Add docstrings.
277
        """
401.1.3 by Daniel Schierbeck
Made the compact view toggling cleaner.
278
279
        if self.compact:
280
            broken_line_length = 32
281
        else:
282
            broken_line_length = None
423.1.18 by Gary van der Merwe
Add options to viz treeview to not show the line graph, and to only show the main line.
283
        
284
        show_graph = self.graph_column.get_visible()
401.1.3 by Daniel Schierbeck
Made the compact view toggling cleaner.
285
392 by Daniel Schierbeck
Fixed performance issue by only releasing the branch lock when the treeview is destroyed. This will surely fuck up the tagging code.
286
        self.branch.lock_read()
287
        (linegraphdata, index, columns_len) = linegraph(self.branch.repository,
401.1.1 by Daniel Schierbeck
Added update() method to TreeView.
288
                                                        self.start,
289
                                                        self.maxnum, 
423.1.18 by Gary van der Merwe
Add options to viz treeview to not show the line graph, and to only show the main line.
290
                                                        broken_line_length,
291
                                                        show_graph,
292
                                                        self.mainline_only)
392 by Daniel Schierbeck
Fixed performance issue by only releasing the branch lock when the treeview is destroyed. This will surely fuck up the tagging code.
293
423.5.1 by Ali Sabil
Added tags visualization in the graph
294
        self.model = TreeModel(self.branch, linegraphdata)
392 by Daniel Schierbeck
Fixed performance issue by only releasing the branch lock when the treeview is destroyed. This will surely fuck up the tagging code.
295
        self.graph_cell.columns_len = columns_len
296
        width = self.graph_cell.get_size(self.treeview)[2]
403 by Daniel Schierbeck
Set a maximum width on the graph column.
297
        if width > 500:
298
            width = 500
392 by Daniel Schierbeck
Fixed performance issue by only releasing the branch lock when the treeview is destroyed. This will surely fuck up the tagging code.
299
        self.graph_column.set_fixed_width(width)
300
        self.graph_column.set_max_width(width)
301
        self.index = index
302
        self.treeview.set_model(self.model)
401.1.2 by Daniel Schierbeck
Allowed the treeview to be refreshed.
303
304
        if revision is None:
305
            self.treeview.set_cursor(0)
306
        else:
307
            self.set_revision(revision)
308
392 by Daniel Schierbeck
Fixed performance issue by only releasing the branch lock when the treeview is destroyed. This will surely fuck up the tagging code.
309
        self.emit('revisions-loaded')
304 by Daniel Schierbeck
Made forward/back buttons work again.
310
311
        return False
312
301 by Daniel Schierbeck
Initial work on extracting the TreeView from the branch window.
313
    def construct_treeview(self):
314
        self.treeview = gtk.TreeView()
315
316
        self.treeview.set_rules_hint(True)
330.1.2 by Daniel Schierbeck
Replaced literal column index with equivalent symbol.
317
        self.treeview.set_search_column(treemodel.REVNO)
330.5.2 by Szilveszter Farkas (Phanatic)
Fixed set_tooltip_column() related issue.
318
        
330.5.5 by Szilveszter Farkas (Phanatic)
Use better fix by John.
319
        # Fix old PyGTK bug - by JAM
320
        set_tooltip = getattr(self.treeview, 'set_tooltip_column', None)
321
        if set_tooltip is not None:
423.4.3 by Daniel Schierbeck
Made the MESSAGE column be the tooltip column.
322
            set_tooltip(treemodel.MESSAGE)
301 by Daniel Schierbeck
Initial work on extracting the TreeView from the branch window.
323
391 by Daniel Schierbeck
Moved away from the changed signal on the treeview.
324
        self.treeview.connect("cursor-changed",
301 by Daniel Schierbeck
Initial work on extracting the TreeView from the branch window.
325
                self._on_selection_changed)
326
327
        self.treeview.connect("row-activated", 
328
                self._on_revision_activated)
329
330
        self.treeview.connect("button-release-event", 
331
                self._on_revision_selected)
332
333
        self.treeview.set_property('fixed-height-mode', True)
334
335
        self.treeview.show()
336
337
        cell = gtk.CellRendererText()
338
        cell.set_property("width-chars", 15)
339
        cell.set_property("ellipsize", pango.ELLIPSIZE_END)
345 by Daniel Schierbeck
Made treeview columns instance variables.
340
        self.revno_column = gtk.TreeViewColumn("Revision No")
341
        self.revno_column.set_resizable(True)
342
        self.revno_column.set_sizing(gtk.TREE_VIEW_COLUMN_FIXED)
343
        self.revno_column.set_fixed_width(cell.get_size(self.treeview)[2])
344
        self.revno_column.pack_start(cell, expand=True)
345
        self.revno_column.add_attribute(cell, "text", treemodel.REVNO)
346
        self.treeview.append_column(self.revno_column)
301 by Daniel Schierbeck
Initial work on extracting the TreeView from the branch window.
347
348
        self.graph_cell = CellRendererGraph()
349
        self.graph_column = gtk.TreeViewColumn()
350
        self.graph_column.set_resizable(True)
351
        self.graph_column.set_sizing(gtk.TREE_VIEW_COLUMN_FIXED)
352
        self.graph_column.pack_start(self.graph_cell, expand=False)
353
        self.graph_column.add_attribute(self.graph_cell, "node", treemodel.NODE)
423.5.1 by Ali Sabil
Added tags visualization in the graph
354
        self.graph_column.add_attribute(self.graph_cell, "tags", treemodel.TAGS)
301 by Daniel Schierbeck
Initial work on extracting the TreeView from the branch window.
355
        self.graph_column.add_attribute(self.graph_cell, "in-lines", treemodel.LAST_LINES)
356
        self.graph_column.add_attribute(self.graph_cell, "out-lines", treemodel.LINES)
357
        self.treeview.append_column(self.graph_column)
358
359
        cell = gtk.CellRendererText()
360
        cell.set_property("width-chars", 65)
361
        cell.set_property("ellipsize", pango.ELLIPSIZE_END)
423.4.1 by Daniel Schierbeck
Renamed the MESSAGE column to SUMMARY.
362
        self.summary_column = gtk.TreeViewColumn("Summary")
363
        self.summary_column.set_resizable(True)
364
        self.summary_column.set_sizing(gtk.TREE_VIEW_COLUMN_FIXED)
365
        self.summary_column.set_fixed_width(cell.get_size(self.treeview)[2])
366
        self.summary_column.pack_start(cell, expand=True)
367
        self.summary_column.add_attribute(cell, "markup", treemodel.SUMMARY)
368
        self.treeview.append_column(self.summary_column)
301 by Daniel Schierbeck
Initial work on extracting the TreeView from the branch window.
369
370
        cell = gtk.CellRendererText()
371
        cell.set_property("width-chars", 15)
372
        cell.set_property("ellipsize", pango.ELLIPSIZE_END)
345 by Daniel Schierbeck
Made treeview columns instance variables.
373
        self.committer_column = gtk.TreeViewColumn("Committer")
374
        self.committer_column.set_resizable(True)
375
        self.committer_column.set_sizing(gtk.TREE_VIEW_COLUMN_FIXED)
376
        self.committer_column.set_fixed_width(cell.get_size(self.treeview)[2])
377
        self.committer_column.pack_start(cell, expand=True)
423.4.4 by Daniel Schierbeck
Renamed COMMITER column into the correct COMMITTER.
378
        self.committer_column.add_attribute(cell, "text", treemodel.COMMITTER)
345 by Daniel Schierbeck
Made treeview columns instance variables.
379
        self.treeview.append_column(self.committer_column)
301 by Daniel Schierbeck
Initial work on extracting the TreeView from the branch window.
380
357 by Daniel Schierbeck
Added support for showing the date column in the viz.
381
        cell = gtk.CellRendererText()
359 by Daniel Schierbeck
Simplified date format.
382
        cell.set_property("width-chars", 20)
357 by Daniel Schierbeck
Added support for showing the date column in the viz.
383
        cell.set_property("ellipsize", pango.ELLIPSIZE_END)
384
        self.date_column = gtk.TreeViewColumn("Date")
385
        self.date_column.set_visible(False)
386
        self.date_column.set_resizable(True)
387
        self.date_column.set_sizing(gtk.TREE_VIEW_COLUMN_FIXED)
388
        self.date_column.set_fixed_width(cell.get_size(self.treeview)[2])
389
        self.date_column.pack_start(cell, expand=True)
390
        self.date_column.add_attribute(cell, "text", treemodel.TIMESTAMP)
391
        self.treeview.append_column(self.date_column)
423.1.13 by Gary van der Merwe
Move viz loading msg from branchwin to treeview.
392
        
393
        return self.treeview
394
    
395
    def construct_loading_msg(self):
396
        image_loading = gtk.image_new_from_stock(gtk.STOCK_REFRESH,
397
                                                 gtk.ICON_SIZE_BUTTON)
398
        image_loading.show()
399
        
400
        label_loading = gtk.Label(_("Please wait, loading ancestral graph..."))
401
        label_loading.set_alignment(0.0, 0.5)
402
        label_loading.show()
403
        
404
        self.loading_msg_box = gtk.HBox()
405
        self.loading_msg_box.set_spacing(5)
406
        self.loading_msg_box.set_border_width(5)        
407
        self.loading_msg_box.pack_start(image_loading, False, False)
408
        self.loading_msg_box.pack_start(label_loading, True, True)
409
        self.loading_msg_box.show()
410
        
411
        return self.loading_msg_box
357 by Daniel Schierbeck
Added support for showing the date column in the viz.
412
391 by Daniel Schierbeck
Moved away from the changed signal on the treeview.
413
    def _on_selection_changed(self, treeview):
303 by Daniel Schierbeck
Made basic signaling work.
414
        """callback for when the treeview changes."""
391 by Daniel Schierbeck
Moved away from the changed signal on the treeview.
415
        (path, focus) = treeview.get_cursor()
416
        if path is not None:
395.1.1 by Daniel Schierbeck
Cleaned up code in the TreeView, removing instance variables.
417
            self.iter = self.model.get_iter(path)
310 by Daniel Schierbeck
Moved to using custom signal for handling revision selections.
418
            self.emit('revision-selected')
419
301 by Daniel Schierbeck
Initial work on extracting the TreeView from the branch window.
420
    def _on_revision_selected(self, widget, event):
421
        from bzrlib.plugins.gtk.revisionmenu import RevisionPopupMenu
422
        if event.button == 3:
423
            menu = RevisionPopupMenu(self.branch.repository, 
312 by Daniel Schierbeck
Made right-clicking work again.
424
                [self.get_revision().revision_id],
301 by Daniel Schierbeck
Initial work on extracting the TreeView from the branch window.
425
                self.branch)
423.7.8 by Daniel Schierbeck
Made the revision popup menu correctly add tags.
426
            menu.connect('tag-added', lambda w, t, r: self.add_tag(t, r))
301 by Daniel Schierbeck
Initial work on extracting the TreeView from the branch window.
427
            menu.popup(None, None, None, event.button, event.get_time())
428
429
    def _on_revision_activated(self, widget, path, col):
423.1.17 by Gary van der Merwe
Reuse the viz treeview in the revision browser.
430
        self.emit('revision-activated', path, col)