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
82
self.set_file_id(None)
84
def do_get_property(self, property):
85
if property.name == 'branch':
87
elif property.name == 'revision':
89
elif property.name == 'children':
91
elif property.name == 'file-id':
94
raise AttributeError, 'unknown property %s' % property.name
96
def do_set_property(self, property, value):
97
if property.name == 'branch':
99
elif property.name == 'revision':
100
self._set_revision(value)
101
elif property.name == 'children':
102
self.set_children(value)
103
elif property.name == 'file-id':
104
self._file_id = value
106
raise AttributeError, 'unknown property %s' % property.name
108
def set_show_callback(self, callback):
109
self._show_callback = callback
111
def set_file_id(self, file_id):
112
"""Set a specific file id that we want to track.
114
This just effects the display of a per-file commit message.
115
If it is set to None, then all commit messages will be shown.
117
self.set_property('file-id', file_id)
119
def set_revision(self, revision):
120
if revision != self._revision:
121
self.set_property('revision', revision)
123
def get_revision(self):
124
return self.get_property('revision')
126
def _set_revision(self, revision):
127
if revision is None: return
129
self._revision = revision
130
if revision.committer is not None:
131
self.committer.set_text(revision.committer)
133
self.committer.set_text("")
134
author = revision.properties.get('author', '')
136
self.author.set_text(author)
138
self.author_label.show()
141
self.author_label.hide()
143
if revision.timestamp is not None:
144
self.timestamp.set_text(format_date(revision.timestamp,
147
self.branchnick_label.set_text(revision.properties['branch-nick'])
149
self.branchnick_label.set_text("")
151
self._add_parents_or_children(revision.parent_ids,
152
self.parents_widgets,
155
file_info = revision.properties.get('file-info', None)
156
if file_info is not None:
157
file_info = bdecode(file_info.encode('UTF-8'))
160
if self._file_id is None:
163
text.append('%(path)s\n%(message)s' % fi)
164
self.file_info_buffer.set_text('\n'.join(text))
165
self.file_info_box.show()
169
if fi['file_id'] == self._file_id:
170
text.append(fi['message'])
172
self.file_info_buffer.set_text('\n'.join(text))
173
self.file_info_box.show()
175
self.file_info_box.hide()
177
self.file_info_box.hide()
179
def update_tags(self):
180
if self._branch is not None and self._branch.supports_tags():
181
self._tagdict = self._branch.tags.get_reverse_tag_dict()
187
def set_children(self, children):
188
self._add_parents_or_children(children,
189
self.children_widgets,
192
def _show_clicked_cb(self, widget, revid, parentid):
193
"""Callback for when the show button for a parent is clicked."""
194
self._show_callback(revid, parentid)
196
def _go_clicked_cb(self, widget, revid):
197
"""Callback for when the go button for a parent is clicked."""
199
def _add_tags(self, *args):
200
if self._revision is None: return
202
if self._tagdict.has_key(self._revision.revision_id):
203
tags = self._tagdict[self._revision.revision_id]
208
self.tags_list.hide()
209
self.tags_label.hide()
212
self.tags_list.set_text(", ".join(tags))
214
self.tags_list.show_all()
215
self.tags_label.show_all()
217
def _add_parents_or_children(self, revids, widgets, table):
218
while len(widgets) > 0:
219
widget = widgets.pop()
222
table.resize(max(len(revids), 1), 2)
224
for idx, revid in enumerate(revids):
225
align = gtk.Alignment(0.0, 0.0)
226
widgets.append(align)
227
table.attach(align, 1, 2, idx, idx + 1,
228
gtk.EXPAND | gtk.FILL, gtk.FILL)
231
hbox = gtk.HBox(False, spacing=6)
236
image.set_from_stock(
237
gtk.STOCK_FIND, gtk.ICON_SIZE_SMALL_TOOLBAR)
240
if self._show_callback is not None:
241
button = gtk.Button()
243
button.connect("clicked", self._show_clicked_cb,
244
self._revision.revision_id, revid)
245
hbox.pack_start(button, expand=False, fill=True)
248
button = gtk.Button(revid)
249
button.connect("clicked",
250
lambda w, r: self.set_revision(self._branch.repository.get_revision(r)), revid)
251
button.set_use_underline(False)
252
hbox.pack_start(button, expand=False, fill=True)
255
def _create_general(self):
256
vbox = gtk.VBox(False, 6)
257
vbox.set_border_width(6)
258
vbox.pack_start(self._create_headers(), expand=False, fill=True)
259
vbox.pack_start(self._create_message_view())
260
self.append_page(vbox, tab_label=gtk.Label("General"))
263
def _create_relations(self):
264
vbox = gtk.VBox(False, 6)
265
vbox.set_border_width(6)
266
vbox.pack_start(self._create_parents(), expand=False, fill=True)
267
vbox.pack_start(self._create_children(), expand=False, fill=True)
268
self.append_page(vbox, tab_label=gtk.Label("Relations"))
271
def _create_headers(self):
272
self.table = gtk.Table(rows=5, columns=2)
273
self.table.set_row_spacings(6)
274
self.table.set_col_spacings(6)
277
align = gtk.Alignment(1.0, 0.5)
279
label.set_markup("<b>Revision Id:</b>")
281
self.table.attach(align, 0, 1, 0, 1, gtk.FILL, gtk.FILL)
285
align = gtk.Alignment(0.0, 0.5)
286
revision_id = gtk.Label()
287
revision_id.set_selectable(True)
288
self.connect('notify::revision',
289
lambda w, p: revision_id.set_text(self._revision.revision_id))
290
align.add(revision_id)
291
self.table.attach(align, 1, 2, 0, 1, gtk.EXPAND | gtk.FILL, gtk.FILL)
295
align = gtk.Alignment(1.0, 0.5)
296
self.author_label = gtk.Label()
297
self.author_label.set_markup("<b>Author:</b>")
298
align.add(self.author_label)
299
self.table.attach(align, 0, 1, 1, 2, gtk.FILL, gtk.FILL)
301
self.author_label.show()
303
align = gtk.Alignment(0.0, 0.5)
304
self.author = gtk.Label()
305
self.author.set_selectable(True)
306
align.add(self.author)
307
self.table.attach(align, 1, 2, 1, 2, gtk.EXPAND | gtk.FILL, gtk.FILL)
312
align = gtk.Alignment(1.0, 0.5)
314
label.set_markup("<b>Committer:</b>")
316
self.table.attach(align, 0, 1, 2, 3, gtk.FILL, gtk.FILL)
320
align = gtk.Alignment(0.0, 0.5)
321
self.committer = gtk.Label()
322
self.committer.set_selectable(True)
323
align.add(self.committer)
324
self.table.attach(align, 1, 2, 2, 3, gtk.EXPAND | gtk.FILL, gtk.FILL)
326
self.committer.show()
328
align = gtk.Alignment(0.0, 0.5)
330
label.set_markup("<b>Branch nick:</b>")
332
self.table.attach(align, 0, 1, 3, 4, gtk.FILL, gtk.FILL)
336
align = gtk.Alignment(0.0, 0.5)
337
self.branchnick_label = gtk.Label()
338
self.branchnick_label.set_selectable(True)
339
align.add(self.branchnick_label)
340
self.table.attach(align, 1, 2, 3, 4, gtk.EXPAND | gtk.FILL, gtk.FILL)
341
self.branchnick_label.show()
344
align = gtk.Alignment(1.0, 0.5)
346
label.set_markup("<b>Timestamp:</b>")
348
self.table.attach(align, 0, 1, 4, 5, gtk.FILL, gtk.FILL)
352
align = gtk.Alignment(0.0, 0.5)
353
self.timestamp = gtk.Label()
354
self.timestamp.set_selectable(True)
355
align.add(self.timestamp)
356
self.table.attach(align, 1, 2, 4, 5, gtk.EXPAND | gtk.FILL, gtk.FILL)
358
self.timestamp.show()
360
align = gtk.Alignment(1.0, 0.5)
361
self.tags_label = gtk.Label()
362
self.tags_label.set_markup("<b>Tags:</b>")
363
align.add(self.tags_label)
365
self.table.attach(align, 0, 1, 5, 6, gtk.FILL, gtk.FILL)
366
self.tags_label.show()
368
align = gtk.Alignment(0.0, 0.5)
369
self.tags_list = gtk.Label()
370
align.add(self.tags_list)
371
self.table.attach(align, 1, 2, 5, 6, gtk.EXPAND | gtk.FILL, gtk.FILL)
373
self.tags_list.show()
375
self.connect('notify::revision', self._add_tags)
380
def _create_parents(self):
381
hbox = gtk.HBox(True, 3)
383
self.parents_table = self._create_parents_or_children_table(
385
self.parents_widgets = []
386
hbox.pack_start(self.parents_table)
391
def _create_children(self):
392
hbox = gtk.HBox(True, 3)
393
self.children_table = self._create_parents_or_children_table(
395
self.children_widgets = []
396
hbox.pack_start(self.children_table)
400
def _create_parents_or_children_table(self, text):
401
table = gtk.Table(rows=1, columns=2)
402
table.set_row_spacings(3)
403
table.set_col_spacings(6)
407
label.set_markup(text)
408
align = gtk.Alignment(0.0, 0.5)
410
table.attach(align, 0, 1, 0, 1, gtk.FILL, gtk.FILL)
416
def _create_message_view(self):
417
msg_buffer = gtk.TextBuffer()
418
self.connect('notify::revision',
419
lambda w, p: msg_buffer.set_text(self._revision.message))
420
window = gtk.ScrolledWindow()
421
window.set_policy(gtk.POLICY_NEVER, gtk.POLICY_AUTOMATIC)
422
window.set_shadow_type(gtk.SHADOW_IN)
423
tv = gtk.TextView(msg_buffer)
424
tv.set_editable(False)
425
tv.set_wrap_mode(gtk.WRAP_WORD)
426
tv.modify_font(pango.FontDescription("Monospace"))
432
def _create_file_info_view(self):
433
self.file_info_box = gtk.VBox(False, 6)
434
self.file_info_box.set_border_width(6)
435
self.file_info_buffer = gtk.TextBuffer()
436
window = gtk.ScrolledWindow()
437
window.set_policy(gtk.POLICY_NEVER, gtk.POLICY_AUTOMATIC)
438
window.set_shadow_type(gtk.SHADOW_IN)
439
tv = gtk.TextView(self.file_info_buffer)
440
tv.set_editable(False)
441
tv.set_wrap_mode(gtk.WRAP_WORD)
442
tv.modify_font(pango.FontDescription("Monospace"))
446
self.file_info_box.pack_start(window)
447
self.file_info_box.hide() # Only shown when there are per-file messages
448
self.append_page(self.file_info_box, tab_label=gtk.Label('Per-file'))