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
58
def __init__(self, branch=None):
59
gtk.Notebook.__init__(self)
60
self.show_children = False
62
self._create_general()
63
self._create_relations()
64
self._create_file_info_view()
66
self.set_current_page(0)
68
self._show_callback = None
69
self._clicked_callback = None
74
if self._branch is not None and self._branch.supports_tags():
75
self._tagdict = self._branch.tags.get_reverse_tag_dict()
79
self.set_file_id(None)
81
def do_get_property(self, property):
82
if property.name == 'branch':
84
elif property.name == 'revision':
86
elif property.name == 'file-id':
89
raise AttributeError, 'unknown property %s' % property.name
91
def do_set_property(self, property, value):
92
if property.name == 'branch':
94
elif property.name == 'revision':
95
self._set_revision(value)
96
elif property.name == 'file-id':
99
raise AttributeError, 'unknown property %s' % property.name
101
def set_show_callback(self, callback):
102
self._show_callback = callback
104
def set_file_id(self, file_id):
105
"""Set a specific file id that we want to track.
107
This just effects the display of a per-file commit message.
108
If it is set to None, then all commit messages will be shown.
110
self.set_property('file-id', file_id)
112
def set_revision(self, revision, children=[]):
113
if revision != self._revision:
114
self.set_property('revision', revision)
116
def get_revision(self):
117
return self.get_property('revision')
119
def _set_revision(self, revision, children=[]):
120
if revision is None: return
122
self._revision = revision
123
if revision.committer is not None:
124
self.committer.set_text(revision.committer)
126
self.committer.set_text("")
127
author = revision.properties.get('author', '')
129
self.author.set_text(author)
131
self.author_label.show()
134
self.author_label.hide()
136
if revision.timestamp is not None:
137
self.timestamp.set_text(format_date(revision.timestamp,
140
self.branchnick_label.set_text(revision.properties['branch-nick'])
142
self.branchnick_label.set_text("")
144
self._add_parents_or_children(revision.parent_ids,
145
self.parents_widgets,
148
if self.show_children:
149
self._add_parents_or_children(children,
150
self.children_widgets,
154
file_info = revision.properties.get('file-info', None)
155
if file_info is not None:
156
file_info = bdecode(file_info.encode('UTF-8'))
159
if self._file_id is None:
162
text.append('%(path)s\n%(message)s' % fi)
163
self.file_info_buffer.set_text('\n'.join(text))
164
self.file_info_box.show()
168
if fi['file_id'] == self._file_id:
169
text.append(fi['message'])
171
self.file_info_buffer.set_text('\n'.join(text))
172
self.file_info_box.show()
174
self.file_info_box.hide()
176
self.file_info_box.hide()
178
def _show_clicked_cb(self, widget, revid, parentid):
179
"""Callback for when the show button for a parent is clicked."""
180
self._show_callback(revid, parentid)
182
def _go_clicked_cb(self, widget, revid):
183
"""Callback for when the go button for a parent is clicked."""
185
def _add_tags(self, *args):
186
if self._tagdict.has_key(self._revision.revision_id):
187
tags = self._tagdict[self._revision.revision_id]
192
self.tags_list.hide()
193
self.tags_label.hide()
196
for widget in self.tags_widgets:
197
self.tags_list.remove(widget)
199
self.tags_widgets = []
202
widget = gtk.Label(tag)
203
widget.set_selectable(True)
204
self.tags_widgets.append(widget)
205
self.tags_list.add(widget)
206
self.tags_list.show_all()
207
self.tags_label.show_all()
209
def _add_parents_or_children(self, revids, widgets, table):
210
while len(widgets) > 0:
211
widget = widgets.pop()
214
table.resize(max(len(revids), 1), 2)
216
for idx, revid in enumerate(revids):
217
align = gtk.Alignment(0.0, 0.0)
218
widgets.append(align)
219
table.attach(align, 1, 2, idx, idx + 1,
220
gtk.EXPAND | gtk.FILL, gtk.FILL)
223
hbox = gtk.HBox(False, spacing=6)
228
image.set_from_stock(
229
gtk.STOCK_FIND, gtk.ICON_SIZE_SMALL_TOOLBAR)
232
if self._show_callback is not None:
233
button = gtk.Button()
235
button.connect("clicked", self._show_clicked_cb,
236
self._revision.revision_id, revid)
237
hbox.pack_start(button, expand=False, fill=True)
240
button = gtk.Button(revid)
241
button.connect("clicked",
242
lambda w, r: self.set_revision(self._branch.repository.get_revision(revid)), revid)
243
button.set_use_underline(False)
244
hbox.pack_start(button, expand=False, fill=True)
247
def _create_general(self):
248
vbox = gtk.VBox(False, 6)
249
vbox.set_border_width(6)
250
vbox.pack_start(self._create_headers(), expand=False, fill=True)
251
vbox.pack_start(self._create_message_view())
252
self.append_page(vbox, tab_label=gtk.Label("General"))
255
def _create_relations(self):
256
vbox = gtk.VBox(False, 6)
257
vbox.set_border_width(6)
258
vbox.pack_start(self._create_parents(), expand=False, fill=True)
259
if self.show_children:
260
vbox.pack_start(self._create_children(), expand=False, fill=True)
261
self.append_page(vbox, tab_label=gtk.Label("Relations"))
264
def _create_headers(self):
265
self.table = gtk.Table(rows=5, columns=2)
266
self.table.set_row_spacings(6)
267
self.table.set_col_spacings(6)
270
align = gtk.Alignment(1.0, 0.5)
272
label.set_markup("<b>Revision Id:</b>")
274
self.table.attach(align, 0, 1, 0, 1, gtk.FILL, gtk.FILL)
278
align = gtk.Alignment(0.0, 0.5)
279
revision_id = gtk.Label()
280
revision_id.set_selectable(True)
281
self.connect('notify::revision',
282
lambda w, p: revision_id.set_text(self._revision.revision_id))
283
align.add(revision_id)
284
self.table.attach(align, 1, 2, 0, 1, gtk.EXPAND | gtk.FILL, gtk.FILL)
288
align = gtk.Alignment(1.0, 0.5)
289
self.author_label = gtk.Label()
290
self.author_label.set_markup("<b>Author:</b>")
291
align.add(self.author_label)
292
self.table.attach(align, 0, 1, 1, 2, gtk.FILL, gtk.FILL)
294
self.author_label.show()
296
align = gtk.Alignment(0.0, 0.5)
297
self.author = gtk.Label()
298
self.author.set_selectable(True)
299
align.add(self.author)
300
self.table.attach(align, 1, 2, 1, 2, gtk.EXPAND | gtk.FILL, gtk.FILL)
305
align = gtk.Alignment(1.0, 0.5)
307
label.set_markup("<b>Committer:</b>")
309
self.table.attach(align, 0, 1, 2, 3, gtk.FILL, gtk.FILL)
313
align = gtk.Alignment(0.0, 0.5)
314
self.committer = gtk.Label()
315
self.committer.set_selectable(True)
316
align.add(self.committer)
317
self.table.attach(align, 1, 2, 2, 3, gtk.EXPAND | gtk.FILL, gtk.FILL)
319
self.committer.show()
321
align = gtk.Alignment(0.0, 0.5)
323
label.set_markup("<b>Branch nick:</b>")
325
self.table.attach(align, 0, 1, 3, 4, gtk.FILL, gtk.FILL)
329
align = gtk.Alignment(0.0, 0.5)
330
self.branchnick_label = gtk.Label()
331
self.branchnick_label.set_selectable(True)
332
align.add(self.branchnick_label)
333
self.table.attach(align, 1, 2, 3, 4, gtk.EXPAND | gtk.FILL, gtk.FILL)
334
self.branchnick_label.show()
337
align = gtk.Alignment(1.0, 0.5)
339
label.set_markup("<b>Timestamp:</b>")
341
self.table.attach(align, 0, 1, 4, 5, gtk.FILL, gtk.FILL)
345
align = gtk.Alignment(0.0, 0.5)
346
self.timestamp = gtk.Label()
347
self.timestamp.set_selectable(True)
348
align.add(self.timestamp)
349
self.table.attach(align, 1, 2, 4, 5, gtk.EXPAND | gtk.FILL, gtk.FILL)
351
self.timestamp.show()
353
align = gtk.Alignment(1.0, 0.5)
354
self.tags_label = gtk.Label()
355
self.tags_label.set_markup("<b>Tags:</b>")
356
align.add(self.tags_label)
358
self.table.attach(align, 0, 1, 5, 6, gtk.FILL, gtk.FILL)
359
self.tags_label.show()
361
align = gtk.Alignment(0.0, 0.5)
362
self.tags_list = gtk.VBox()
363
align.add(self.tags_list)
364
self.table.attach(align, 1, 2, 5, 6, gtk.EXPAND | gtk.FILL, gtk.FILL)
366
self.tags_list.show()
367
self.tags_widgets = []
369
self.connect('notify::revision', self._add_tags)
374
def _create_parents(self):
375
hbox = gtk.HBox(True, 3)
377
self.parents_table = self._create_parents_or_children_table(
379
self.parents_widgets = []
380
hbox.pack_start(self.parents_table)
385
def _create_children(self):
386
hbox = gtk.HBox(True, 3)
387
self.children_table = self._create_parents_or_children_table(
389
self.children_widgets = []
390
hbox.pack_start(self.children_table)
394
def _create_parents_or_children_table(self, text):
395
table = gtk.Table(rows=1, columns=2)
396
table.set_row_spacings(3)
397
table.set_col_spacings(6)
401
label.set_markup(text)
402
align = gtk.Alignment(0.0, 0.5)
404
table.attach(align, 0, 1, 0, 1, gtk.FILL, gtk.FILL)
410
def _create_message_view(self):
411
msg_buffer = gtk.TextBuffer()
412
self.connect('notify::revision',
413
lambda w, p: msg_buffer.set_text(self._revision.message))
414
window = gtk.ScrolledWindow()
415
window.set_policy(gtk.POLICY_NEVER, gtk.POLICY_AUTOMATIC)
416
window.set_shadow_type(gtk.SHADOW_IN)
417
tv = gtk.TextView(msg_buffer)
418
tv.set_editable(False)
419
tv.set_wrap_mode(gtk.WRAP_WORD)
420
tv.modify_font(pango.FontDescription("Monospace"))
426
def _create_file_info_view(self):
427
self.file_info_box = gtk.VBox(False, 6)
428
self.file_info_box.set_border_width(6)
429
self.file_info_buffer = gtk.TextBuffer()
430
window = gtk.ScrolledWindow()
431
window.set_policy(gtk.POLICY_NEVER, gtk.POLICY_AUTOMATIC)
432
window.set_shadow_type(gtk.SHADOW_IN)
433
tv = gtk.TextView(self.file_info_buffer)
434
tv.set_editable(False)
435
tv.set_wrap_mode(gtk.WRAP_WORD)
436
tv.modify_font(pango.FontDescription("Monospace"))
440
self.file_info_box.pack_start(window)
441
self.file_info_box.hide() # Only shown when there are per-file messages
442
self.append_page(self.file_info_box, tab_label=gtk.Label('Per-file'))