/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

Merged with mainline.

Show diffs side-by-side

added added

removed removed

Lines of Context:
19
19
from treemodel import TreeModel
20
20
from bzrlib.revision import NULL_REVISION
21
21
 
22
 
class TreeView(gtk.ScrolledWindow):
 
22
class TreeView(gtk.VBox):
23
23
 
24
24
    __gproperties__ = {
25
25
        'branch': (gobject.TYPE_PYOBJECT,
49
49
                    gobject.PARAM_READABLE),
50
50
 
51
51
        'revno-column-visible': (gobject.TYPE_BOOLEAN,
52
 
                                 'Revision number',
 
52
                                 'Revision number column',
53
53
                                 'Show revision number column',
54
54
                                 True,
55
55
                                 gobject.PARAM_READWRITE),
56
56
 
 
57
        'graph-column-visible': (gobject.TYPE_BOOLEAN,
 
58
                                 'Graph column',
 
59
                                 'Show graph column',
 
60
                                 True,
 
61
                                 gobject.PARAM_READWRITE),
 
62
 
57
63
        'date-column-visible': (gobject.TYPE_BOOLEAN,
58
64
                                 'Date',
59
65
                                 'Show date column',
64
70
                    'Compact view',
65
71
                    'Break ancestry lines to save space',
66
72
                    True,
67
 
                    gobject.PARAM_CONSTRUCT | gobject.PARAM_READWRITE)
 
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),
68
80
 
69
81
    }
70
82
 
74
86
                             ()),
75
87
        'revision-selected': (gobject.SIGNAL_RUN_FIRST,
76
88
                              gobject.TYPE_NONE,
77
 
                              ())
 
89
                              ()),
 
90
        'revision-activated': (gobject.SIGNAL_RUN_FIRST,
 
91
                              gobject.TYPE_NONE,
 
92
                              (gobject.TYPE_PYOBJECT, gobject.TYPE_PYOBJECT)),
 
93
        'tag-added': (gobject.SIGNAL_RUN_FIRST,
 
94
                              gobject.TYPE_NONE,
 
95
                              (gobject.TYPE_STRING, gobject.TYPE_STRING))
78
96
    }
79
97
 
80
98
    def __init__(self, branch, start, maxnum, compact=True):
87
105
        :param broken_line_length: After how much lines to break 
88
106
                                   branches.
89
107
        """
90
 
        gtk.ScrolledWindow.__init__(self)
91
 
 
92
 
        self.set_policy(gtk.POLICY_NEVER, gtk.POLICY_AUTOMATIC)
93
 
        self.set_shadow_type(gtk.SHADOW_IN)
94
 
 
95
 
        self.construct_treeview()
96
 
 
97
 
        self.iter   = None
 
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()
 
115
        self.scrolled_window.set_policy(gtk.POLICY_AUTOMATIC,
 
116
                                        gtk.POLICY_AUTOMATIC)
 
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
        
 
123
 
 
124
        self.iter = None
98
125
        self.branch = branch
 
126
        self.revision = None
99
127
 
100
128
        self.start = start
101
129
        self.maxnum = maxnum
108
136
    def do_get_property(self, property):
109
137
        if property.name == 'revno-column-visible':
110
138
            return self.revno_column.get_visible()
 
139
        elif property.name == 'graph-column-visible':
 
140
            return self.graph_column.get_visible()
111
141
        elif property.name == 'date-column-visible':
112
142
            return self.date_column.get_visible()
113
143
        elif property.name == 'compact':
114
144
            return self.compact
 
145
        elif property.name == 'mainline-only':
 
146
            return self.mainline_only
115
147
        elif property.name == 'branch':
116
148
            return self.branch
117
149
        elif property.name == 'revision':
128
160
    def do_set_property(self, property, value):
129
161
        if property.name == 'revno-column-visible':
130
162
            self.revno_column.set_visible(value)
 
163
        elif property.name == 'graph-column-visible':
 
164
            self.graph_column.set_visible(value)
131
165
        elif property.name == 'date-column-visible':
132
166
            self.date_column.set_visible(value)
133
167
        elif property.name == 'compact':
134
168
            self.compact = value
 
169
        elif property.name == 'mainline-only':
 
170
            self.mainline_only = value
135
171
        elif property.name == 'branch':
136
172
            self.branch = value
137
173
        elif property.name == 'revision':
167
203
        :return: list of revision ids.
168
204
        """
169
205
        return self.get_property('parents')
 
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()
 
221
 
 
222
        self.emit('tag-added', tag, revid)
170
223
        
171
224
    def refresh(self):
 
225
        self.loading_msg_box.show()
172
226
        gobject.idle_add(self.populate, self.get_revision())
173
227
 
174
228
    def update(self):
226
280
            broken_line_length = 32
227
281
        else:
228
282
            broken_line_length = None
 
283
        
 
284
        show_graph = self.graph_column.get_visible()
229
285
 
230
286
        self.branch.lock_read()
231
287
        (linegraphdata, index, columns_len) = linegraph(self.branch.repository,
232
288
                                                        self.start,
233
289
                                                        self.maxnum, 
234
 
                                                        broken_line_length)
 
290
                                                        broken_line_length,
 
291
                                                        show_graph,
 
292
                                                        self.mainline_only)
235
293
 
236
 
        self.model = TreeModel(self.branch.repository, linegraphdata)
 
294
        self.model = TreeModel(self.branch, linegraphdata)
237
295
        self.graph_cell.columns_len = columns_len
238
296
        width = self.graph_cell.get_size(self.treeview)[2]
239
297
        if width > 500:
252
310
 
253
311
        return False
254
312
 
255
 
    def show_diff(self, revid=None, parentid=None):
256
 
        """Open a new window to show a diff between the given revisions."""
257
 
        from bzrlib.plugins.gtk.diff import DiffWindow
258
 
        window = DiffWindow(parent=self)
259
 
 
260
 
        parents = self.get_parents()
261
 
 
262
 
        if revid is None:
263
 
            revid = self.get_revision().revision_id
264
 
 
265
 
            if parentid is None and len(parents) > 0:
266
 
                parentid = parents[0]
267
 
 
268
 
        if parentid is None:
269
 
            parentid = NULL_REVISION
270
 
 
271
 
        rev_tree    = self.branch.repository.revision_tree(revid)
272
 
        parent_tree = self.branch.repository.revision_tree(parentid)
273
 
 
274
 
        description = revid + " - " + self.branch.nick
275
 
        window.set_diff(description, rev_tree, parent_tree)
276
 
        window.show()
277
 
 
278
313
    def construct_treeview(self):
279
314
        self.treeview = gtk.TreeView()
280
315
 
297
332
 
298
333
        self.treeview.set_property('fixed-height-mode', True)
299
334
 
300
 
        self.add(self.treeview)
301
335
        self.treeview.show()
302
336
 
303
337
        cell = gtk.CellRendererText()
317
351
        self.graph_column.set_sizing(gtk.TREE_VIEW_COLUMN_FIXED)
318
352
        self.graph_column.pack_start(self.graph_cell, expand=False)
319
353
        self.graph_column.add_attribute(self.graph_cell, "node", treemodel.NODE)
 
354
        self.graph_column.add_attribute(self.graph_cell, "tags", treemodel.TAGS)
320
355
        self.graph_column.add_attribute(self.graph_cell, "in-lines", treemodel.LAST_LINES)
321
356
        self.graph_column.add_attribute(self.graph_cell, "out-lines", treemodel.LINES)
322
357
        self.treeview.append_column(self.graph_column)
354
389
        self.date_column.pack_start(cell, expand=True)
355
390
        self.date_column.add_attribute(cell, "text", treemodel.TIMESTAMP)
356
391
        self.treeview.append_column(self.date_column)
 
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
412
 
358
413
    def _on_selection_changed(self, treeview):
359
414
        """callback for when the treeview changes."""
368
423
            menu = RevisionPopupMenu(self.branch.repository, 
369
424
                [self.get_revision().revision_id],
370
425
                self.branch)
 
426
            menu.connect('tag-added', lambda w, t, r: self.add_tag(t, r))
371
427
            menu.popup(None, None, None, event.button, event.get_time())
372
428
 
373
429
    def _on_revision_activated(self, widget, path, col):
374
 
        # TODO: more than one parent
375
 
        """Callback for when a treeview row gets activated."""
376
 
        revision_id = self.model[path][treemodel.REVID]
377
 
        parents = self.model[path][treemodel.PARENTS]
378
 
 
379
 
        if len(parents) == 0:
380
 
            parent_id = None
381
 
        else:
382
 
            parent_id = parents[0]
383
 
 
384
 
        self.show_diff(revision_id, parent_id)
385
 
        self.treeview.grab_focus()
 
430
        self.emit('revision-activated', path, col)