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
23
from bzrlib.osutils import format_date
26
class LogView(gtk.ScrolledWindow):
27
""" Custom widget for commit log details.
29
A variety of bzr tools may need to implement such a thing. This is a
33
def __init__(self, revision=None, scroll=True, tags=[],
35
super(LogView, self).__init__()
37
self.set_policy(gtk.POLICY_NEVER, gtk.POLICY_AUTOMATIC)
39
self.set_policy(gtk.POLICY_NEVER, gtk.POLICY_NEVER)
40
self.set_shadow_type(gtk.SHADOW_NONE)
41
self.show_children = show_children
43
self._show_callback = None
44
self._go_callback = None
45
self._clicked_callback = None
47
if revision is not None:
48
self.set_revision(revision, tags=tags)
50
def set_show_callback(self, callback):
51
self._show_callback = callback
53
def set_go_callback(self, callback):
54
self._go_callback = callback
56
def set_revision(self, revision, tags=[], children=[]):
57
self._revision = revision
58
self.revision_id.set_text(revision.revision_id)
59
if revision.committer is not None:
60
self.committer.set_text(revision.committer)
62
self.committer.set_text("")
63
author = revision.properties.get('author', '')
65
self.author.set_text(author)
67
self.author_label.show()
70
self.author_label.hide()
72
if revision.timestamp is not None:
73
self.timestamp.set_text(format_date(revision.timestamp,
75
self.message_buffer.set_text(revision.message)
77
self.branchnick_label.set_text(revision.properties['branch-nick'])
79
self.branchnick_label.set_text("")
81
self._add_parents_or_children(revision.parent_ids,
85
if self.show_children:
86
self._add_parents_or_children(children,
87
self.children_widgets,
92
def _show_clicked_cb(self, widget, revid, parentid):
93
"""Callback for when the show button for a parent is clicked."""
94
self._show_callback(revid, parentid)
96
def _go_clicked_cb(self, widget, revid):
97
"""Callback for when the go button for a parent is clicked."""
98
self._go_callback(revid)
100
def _add_tags(self, tags):
102
self.tags_list.hide()
103
self.tags_label.hide()
106
for widget in self.tags_widgets:
107
self.tags_list.remove(widget)
109
self.tags_widgets = []
112
widget = gtk.Label(tag)
113
widget.set_selectable(True)
114
self.tags_widgets.append(widget)
115
self.tags_list.add(widget)
116
self.tags_list.show_all()
117
self.tags_label.show_all()
119
def _add_parents_or_children(self, revids, widgets, table):
120
while len(widgets) > 0:
121
widget = widgets.pop()
124
table.resize(max(len(revids), 1), 2)
126
for idx, revid in enumerate(revids):
127
align = gtk.Alignment(0.0, 0.0)
128
widgets.append(align)
129
table.attach(align, 1, 2, idx, idx + 1,
130
gtk.EXPAND | gtk.FILL, gtk.FILL)
133
hbox = gtk.HBox(False, spacing=6)
138
image.set_from_stock(
139
gtk.STOCK_FIND, gtk.ICON_SIZE_SMALL_TOOLBAR)
142
if self._show_callback is not None:
143
button = gtk.Button()
145
button.connect("clicked", self._show_clicked_cb,
146
self._revision.revision_id, revid)
147
hbox.pack_start(button, expand=False, fill=True)
150
if self._go_callback is not None:
151
button = gtk.Button(revid)
152
button.connect("clicked", self._go_clicked_cb, revid)
154
button = gtk.Label(revid)
155
button.set_use_underline(False)
156
hbox.pack_start(button, expand=False, fill=True)
160
vbox = gtk.VBox(False, 6)
161
vbox.set_border_width(6)
162
vbox.pack_start(self._create_headers(), expand=False, fill=True)
163
vbox.pack_start(self._create_parents(), expand=False, fill=True)
164
if self.show_children:
165
vbox.pack_start(self._create_children(), expand=False, fill=True)
166
vbox.pack_start(self._create_message_view())
167
self.add_with_viewport(vbox)
170
def _create_headers(self):
171
self.table = gtk.Table(rows=5, columns=2)
172
self.table.set_row_spacings(6)
173
self.table.set_col_spacings(6)
176
align = gtk.Alignment(1.0, 0.5)
178
label.set_markup("<b>Revision Id:</b>")
180
self.table.attach(align, 0, 1, 0, 1, gtk.FILL, gtk.FILL)
184
align = gtk.Alignment(0.0, 0.5)
185
self.revision_id = gtk.Label()
186
self.revision_id.set_selectable(True)
187
align.add(self.revision_id)
188
self.table.attach(align, 1, 2, 0, 1, gtk.EXPAND | gtk.FILL, gtk.FILL)
190
self.revision_id.show()
192
align = gtk.Alignment(1.0, 0.5)
193
self.author_label = gtk.Label()
194
self.author_label.set_markup("<b>Author:</b>")
195
align.add(self.author_label)
196
self.table.attach(align, 0, 1, 1, 2, gtk.FILL, gtk.FILL)
198
self.author_label.show()
200
align = gtk.Alignment(0.0, 0.5)
201
self.author = gtk.Label()
202
self.author.set_selectable(True)
203
align.add(self.author)
204
self.table.attach(align, 1, 2, 1, 2, gtk.EXPAND | gtk.FILL, gtk.FILL)
209
align = gtk.Alignment(1.0, 0.5)
211
label.set_markup("<b>Committer:</b>")
213
self.table.attach(align, 0, 1, 2, 3, gtk.FILL, gtk.FILL)
217
align = gtk.Alignment(0.0, 0.5)
218
self.committer = gtk.Label()
219
self.committer.set_selectable(True)
220
align.add(self.committer)
221
self.table.attach(align, 1, 2, 2, 3, gtk.EXPAND | gtk.FILL, gtk.FILL)
223
self.committer.show()
225
align = gtk.Alignment(0.0, 0.5)
227
label.set_markup("<b>Branch nick:</b>")
229
self.table.attach(align, 0, 1, 3, 4, gtk.FILL, gtk.FILL)
233
align = gtk.Alignment(0.0, 0.5)
234
self.branchnick_label = gtk.Label()
235
self.branchnick_label.set_selectable(True)
236
align.add(self.branchnick_label)
237
self.table.attach(align, 1, 2, 3, 4, gtk.EXPAND | gtk.FILL, gtk.FILL)
238
self.branchnick_label.show()
241
align = gtk.Alignment(1.0, 0.5)
243
label.set_markup("<b>Timestamp:</b>")
245
self.table.attach(align, 0, 1, 4, 5, gtk.FILL, gtk.FILL)
249
align = gtk.Alignment(0.0, 0.5)
250
self.timestamp = gtk.Label()
251
self.timestamp.set_selectable(True)
252
align.add(self.timestamp)
253
self.table.attach(align, 1, 2, 4, 5, gtk.EXPAND | gtk.FILL, gtk.FILL)
255
self.timestamp.show()
257
align = gtk.Alignment(1.0, 0.5)
258
self.tags_label = gtk.Label()
259
self.tags_label.set_markup("<b>Tags:</b>")
260
align.add(self.tags_label)
262
self.table.attach(align, 0, 1, 5, 6, gtk.FILL, gtk.FILL)
263
self.tags_label.show()
265
align = gtk.Alignment(0.0, 0.5)
266
self.tags_list = gtk.VBox()
267
align.add(self.tags_list)
268
self.table.attach(align, 1, 2, 5, 6, gtk.EXPAND | gtk.FILL, gtk.FILL)
270
self.tags_list.show()
271
self.tags_widgets = []
276
def _create_parents(self):
277
hbox = gtk.HBox(True, 3)
279
self.parents_table = self._create_parents_or_children_table(
281
self.parents_widgets = []
282
hbox.pack_start(self.parents_table)
287
def _create_children(self):
288
hbox = gtk.HBox(True, 3)
289
self.children_table = self._create_parents_or_children_table(
291
self.children_widgets = []
292
hbox.pack_start(self.children_table)
296
def _create_parents_or_children_table(self, text):
297
table = gtk.Table(rows=1, columns=2)
298
table.set_row_spacings(3)
299
table.set_col_spacings(6)
303
label.set_markup(text)
304
align = gtk.Alignment(0.0, 0.5)
306
table.attach(align, 0, 1, 0, 1, gtk.FILL, gtk.FILL)
314
def _create_message_view(self):
315
self.message_buffer = gtk.TextBuffer()
316
tv = gtk.TextView(self.message_buffer)
317
tv.set_editable(False)
318
tv.set_wrap_mode(gtk.WRAP_WORD)
319
tv.modify_font(pango.FontDescription("Monospace"))