1
# Copyright (C) 2005 Dan Loda <danloda@gmail.com>
2
# Copyright (C) 2007 Jelmer Vernooij <jelmer@samba.org>
4
# This program is free software; you can redistribute it and/or modify
5
# it under the terms of the GNU General Public License as published by
6
# the Free Software Foundation; either version 2 of the License, or
7
# (at your option) any later version.
9
# This program is distributed in the hope that it will be useful,
10
# but WITHOUT ANY WARRANTY; without even the implied warranty of
11
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12
# GNU General Public License for more details.
14
# You should have received a copy of the GNU General Public License
15
# along with this program; if not, write to the Free Software
16
# Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
24
from bzrlib.osutils import format_date
25
from bzrlib.util.bencode import bdecode
27
class RevisionView(gtk.Notebook):
28
""" Custom widget for commit log details.
30
A variety of bzr tools may need to implement such a thing. This is a
36
gobject.TYPE_PYOBJECT,
38
'The branch holding the revision being displayed',
39
gobject.PARAM_CONSTRUCT_ONLY | gobject.PARAM_WRITABLE
43
gobject.TYPE_PYOBJECT,
45
'The revision being displayed',
46
gobject.PARAM_READWRITE
50
gobject.TYPE_PYOBJECT,
53
gobject.PARAM_READWRITE
57
gobject.TYPE_PYOBJECT,
60
gobject.PARAM_READWRITE
65
def __init__(self, branch=None):
66
gtk.Notebook.__init__(self)
68
self._create_general()
69
self._create_relations()
70
self._create_file_info_view()
72
self.set_current_page(0)
74
self._show_callback = None
75
self._clicked_callback = None
80
if self._branch is not None and self._branch.supports_tags():
81
self._tagdict = self._branch.tags.get_reverse_tag_dict()
85
self.set_file_id(None)
87
def do_get_property(self, property):
88
if property.name == 'branch':
90
elif property.name == 'revision':
92
elif property.name == 'children':
94
elif property.name == 'file-id':
97
raise AttributeError, 'unknown property %s' % property.name
99
def do_set_property(self, property, value):
100
if property.name == 'branch':
102
elif property.name == 'revision':
103
self._set_revision(value)
104
elif property.name == 'children':
105
self.set_children(value)
106
elif property.name == 'file-id':
107
self._file_id = value
109
raise AttributeError, 'unknown property %s' % property.name
111
def set_show_callback(self, callback):
112
self._show_callback = callback
114
def set_file_id(self, file_id):
115
"""Set a specific file id that we want to track.
117
This just effects the display of a per-file commit message.
118
If it is set to None, then all commit messages will be shown.
120
self.set_property('file-id', file_id)
122
def set_revision(self, revision):
123
if revision != self._revision:
124
self.set_property('revision', revision)
126
def get_revision(self):
127
return self.get_property('revision')
129
def _set_revision(self, revision):
130
if revision is None: return
132
self._revision = revision
133
if revision.committer is not None:
134
self.committer.set_text(revision.committer)
136
self.committer.set_text("")
137
author = revision.properties.get('author', '')
139
self.author.set_text(author)
141
self.author_label.show()
144
self.author_label.hide()
146
if revision.timestamp is not None:
147
self.timestamp.set_text(format_date(revision.timestamp,
150
self.branchnick_label.set_text(revision.properties['branch-nick'])
152
self.branchnick_label.set_text("")
154
self._add_parents_or_children(revision.parent_ids,
155
self.parents_widgets,
158
file_info = revision.properties.get('file-info', None)
159
if file_info is not None:
160
file_info = bdecode(file_info.encode('UTF-8'))
163
if self._file_id is None:
166
text.append('%(path)s\n%(message)s' % fi)
167
self.file_info_buffer.set_text('\n'.join(text))
168
self.file_info_box.show()
172
if fi['file_id'] == self._file_id:
173
text.append(fi['message'])
175
self.file_info_buffer.set_text('\n'.join(text))
176
self.file_info_box.show()
178
self.file_info_box.hide()
180
self.file_info_box.hide()
182
def set_children(self, children):
183
self._add_parents_or_children(children,
184
self.children_widgets,
187
def _show_clicked_cb(self, widget, revid, parentid):
188
"""Callback for when the show button for a parent is clicked."""
189
self._show_callback(revid, parentid)
191
def _go_clicked_cb(self, widget, revid):
192
"""Callback for when the go button for a parent is clicked."""
194
def _add_tags(self, *args):
195
if self._tagdict.has_key(self._revision.revision_id):
196
tags = self._tagdict[self._revision.revision_id]
201
self.tags_list.hide()
202
self.tags_label.hide()
205
for widget in self.tags_widgets:
206
self.tags_list.remove(widget)
208
self.tags_widgets = []
211
widget = gtk.Label(tag)
212
widget.set_selectable(True)
213
self.tags_widgets.append(widget)
214
self.tags_list.add(widget)
215
self.tags_list.show_all()
216
self.tags_label.show_all()
218
def _add_parents_or_children(self, revids, widgets, table):
219
while len(widgets) > 0:
220
widget = widgets.pop()
223
table.resize(max(len(revids), 1), 2)
225
for idx, revid in enumerate(revids):
226
align = gtk.Alignment(0.0, 0.0)
227
widgets.append(align)
228
table.attach(align, 1, 2, idx, idx + 1,
229
gtk.EXPAND | gtk.FILL, gtk.FILL)
232
hbox = gtk.HBox(False, spacing=6)
237
image.set_from_stock(
238
gtk.STOCK_FIND, gtk.ICON_SIZE_SMALL_TOOLBAR)
241
if self._show_callback is not None:
242
button = gtk.Button()
244
button.connect("clicked", self._show_clicked_cb,
245
self._revision.revision_id, revid)
246
hbox.pack_start(button, expand=False, fill=True)
249
button = gtk.Button(revid)
250
button.connect("clicked",
251
lambda w, r: self.set_revision(self._branch.repository.get_revision(r)), revid)
252
button.set_use_underline(False)
253
hbox.pack_start(button, expand=False, fill=True)
256
def _create_general(self):
257
vbox = gtk.VBox(False, 6)
258
vbox.set_border_width(6)
259
vbox.pack_start(self._create_headers(), expand=False, fill=True)
260
vbox.pack_start(self._create_message_view())
261
self.append_page(vbox, tab_label=gtk.Label("General"))
264
def _create_relations(self):
265
vbox = gtk.VBox(False, 6)
266
vbox.set_border_width(6)
267
vbox.pack_start(self._create_parents(), expand=False, fill=True)
268
vbox.pack_start(self._create_children(), expand=False, fill=True)
269
self.append_page(vbox, tab_label=gtk.Label("Relations"))
272
def _create_headers(self):
273
self.table = gtk.Table(rows=5, columns=2)
274
self.table.set_row_spacings(6)
275
self.table.set_col_spacings(6)
278
align = gtk.Alignment(1.0, 0.5)
280
label.set_markup("<b>Revision Id:</b>")
282
self.table.attach(align, 0, 1, 0, 1, gtk.FILL, gtk.FILL)
286
align = gtk.Alignment(0.0, 0.5)
287
revision_id = gtk.Label()
288
revision_id.set_selectable(True)
289
self.connect('notify::revision',
290
lambda w, p: revision_id.set_text(self._revision.revision_id))
291
align.add(revision_id)
292
self.table.attach(align, 1, 2, 0, 1, gtk.EXPAND | gtk.FILL, gtk.FILL)
296
align = gtk.Alignment(1.0, 0.5)
297
self.author_label = gtk.Label()
298
self.author_label.set_markup("<b>Author:</b>")
299
align.add(self.author_label)
300
self.table.attach(align, 0, 1, 1, 2, gtk.FILL, gtk.FILL)
302
self.author_label.show()
304
align = gtk.Alignment(0.0, 0.5)
305
self.author = gtk.Label()
306
self.author.set_selectable(True)
307
align.add(self.author)
308
self.table.attach(align, 1, 2, 1, 2, gtk.EXPAND | gtk.FILL, gtk.FILL)
313
align = gtk.Alignment(1.0, 0.5)
315
label.set_markup("<b>Committer:</b>")
317
self.table.attach(align, 0, 1, 2, 3, gtk.FILL, gtk.FILL)
321
align = gtk.Alignment(0.0, 0.5)
322
self.committer = gtk.Label()
323
self.committer.set_selectable(True)
324
align.add(self.committer)
325
self.table.attach(align, 1, 2, 2, 3, gtk.EXPAND | gtk.FILL, gtk.FILL)
327
self.committer.show()
329
align = gtk.Alignment(0.0, 0.5)
331
label.set_markup("<b>Branch nick:</b>")
333
self.table.attach(align, 0, 1, 3, 4, gtk.FILL, gtk.FILL)
337
align = gtk.Alignment(0.0, 0.5)
338
self.branchnick_label = gtk.Label()
339
self.branchnick_label.set_selectable(True)
340
align.add(self.branchnick_label)
341
self.table.attach(align, 1, 2, 3, 4, gtk.EXPAND | gtk.FILL, gtk.FILL)
342
self.branchnick_label.show()
345
align = gtk.Alignment(1.0, 0.5)
347
label.set_markup("<b>Timestamp:</b>")
349
self.table.attach(align, 0, 1, 4, 5, gtk.FILL, gtk.FILL)
353
align = gtk.Alignment(0.0, 0.5)
354
self.timestamp = gtk.Label()
355
self.timestamp.set_selectable(True)
356
align.add(self.timestamp)
357
self.table.attach(align, 1, 2, 4, 5, gtk.EXPAND | gtk.FILL, gtk.FILL)
359
self.timestamp.show()
361
align = gtk.Alignment(1.0, 0.5)
362
self.tags_label = gtk.Label()
363
self.tags_label.set_markup("<b>Tags:</b>")
364
align.add(self.tags_label)
366
self.table.attach(align, 0, 1, 5, 6, gtk.FILL, gtk.FILL)
367
self.tags_label.show()
369
align = gtk.Alignment(0.0, 0.5)
370
self.tags_list = gtk.VBox()
371
align.add(self.tags_list)
372
self.table.attach(align, 1, 2, 5, 6, gtk.EXPAND | gtk.FILL, gtk.FILL)
374
self.tags_list.show()
375
self.tags_widgets = []
377
self.connect('notify::revision', self._add_tags)
382
def _create_parents(self):
383
hbox = gtk.HBox(True, 3)
385
self.parents_table = self._create_parents_or_children_table(
387
self.parents_widgets = []
388
hbox.pack_start(self.parents_table)
393
def _create_children(self):
394
hbox = gtk.HBox(True, 3)
395
self.children_table = self._create_parents_or_children_table(
397
self.children_widgets = []
398
hbox.pack_start(self.children_table)
402
def _create_parents_or_children_table(self, text):
403
table = gtk.Table(rows=1, columns=2)
404
table.set_row_spacings(3)
405
table.set_col_spacings(6)
409
label.set_markup(text)
410
align = gtk.Alignment(0.0, 0.5)
412
table.attach(align, 0, 1, 0, 1, gtk.FILL, gtk.FILL)
418
def _create_message_view(self):
419
msg_buffer = gtk.TextBuffer()
420
self.connect('notify::revision',
421
lambda w, p: msg_buffer.set_text(self._revision.message))
422
window = gtk.ScrolledWindow()
423
window.set_policy(gtk.POLICY_NEVER, gtk.POLICY_AUTOMATIC)
424
window.set_shadow_type(gtk.SHADOW_IN)
425
tv = gtk.TextView(msg_buffer)
426
tv.set_editable(False)
427
tv.set_wrap_mode(gtk.WRAP_WORD)
428
tv.modify_font(pango.FontDescription("Monospace"))
434
def _create_file_info_view(self):
435
self.file_info_box = gtk.VBox(False, 6)
436
self.file_info_box.set_border_width(6)
437
self.file_info_buffer = gtk.TextBuffer()
438
window = gtk.ScrolledWindow()
439
window.set_policy(gtk.POLICY_NEVER, gtk.POLICY_AUTOMATIC)
440
window.set_shadow_type(gtk.SHADOW_IN)
441
tv = gtk.TextView(self.file_info_buffer)
442
tv.set_editable(False)
443
tv.set_wrap_mode(gtk.WRAP_WORD)
444
tv.modify_font(pango.FontDescription("Monospace"))
448
self.file_info_box.pack_start(window)
449
self.file_info_box.hide() # Only shown when there are per-file messages
450
self.append_page(self.file_info_box, tab_label=gtk.Label('Per-file'))