1
# -*- coding: UTF-8 -*-
4
This module contains the code to manage the branch information window,
5
which contains both the revision graph and details panes.
8
__copyright__ = "Copyright © 2005 Canonical Ltd."
9
__author__ = "Scott James Remnant <scott@ubuntu.com>"
17
from bzrlib.osutils import format_date
19
from linegraph import linegraph, same_branch
20
from graphcell import CellRendererGraph
21
from treemodel import TreeModel
24
class BranchWindow(gtk.Window):
27
This object represents and manages a single window containing information
28
for a particular branch.
32
gtk.Window.__init__(self, gtk.WINDOW_TOPLEVEL)
33
self.set_border_width(0)
34
self.set_title("bzrk")
36
# Use three-quarters of the screen by default
37
screen = self.get_screen()
38
monitor = screen.get_monitor_geometry(0)
39
width = int(monitor.width * 0.75)
40
height = int(monitor.height * 0.75)
41
self.set_default_size(width, height)
44
icon = self.render_icon(gtk.STOCK_INDEX, gtk.ICON_SIZE_BUTTON)
47
self.accel_group = gtk.AccelGroup()
48
self.add_accel_group(self.accel_group)
53
"""Construct the window contents."""
54
vbox = gtk.VBox(spacing=0)
57
vbox.pack_start(self.construct_navigation(), expand=False, fill=True)
60
paned.pack1(self.construct_top(), resize=True, shrink=False)
61
paned.pack2(self.construct_bottom(), resize=False, shrink=True)
63
vbox.pack_start(paned, expand=True, fill=True)
64
vbox.set_focus_child(paned)
68
def construct_top(self):
69
"""Construct the top-half of the window."""
70
scrollwin = gtk.ScrolledWindow()
71
scrollwin.set_policy(gtk.POLICY_NEVER, gtk.POLICY_AUTOMATIC)
72
scrollwin.set_shadow_type(gtk.SHADOW_IN)
75
self.treeview = gtk.TreeView()
76
self.treeview.set_rules_hint(True)
77
self.treeview.set_search_column(4)
78
self.treeview.connect("cursor-changed", self._treeview_cursor_cb)
79
self.treeview.connect("row-activated", self._treeview_row_activated_cb)
80
self.treeview.connect("button-release-event",
81
self._treeview_row_mouseclick)
82
scrollwin.add(self.treeview)
85
cell = gtk.CellRendererText()
86
#cell.set_property("width-chars", 40)
87
#cell.set_property("ellipsize", pango.ELLIPSIZE_END)
88
column = gtk.TreeViewColumn("Revision No")
89
column.set_resizable(True)
90
column.pack_start(cell, expand=True)
91
column.add_attribute(cell, "text", treemodel.REVNO)
92
self.treeview.append_column(column)
94
cell = CellRendererGraph()
95
column = gtk.TreeViewColumn()
96
column.set_resizable(True)
97
column.pack_start(cell, expand=False)
98
column.add_attribute(cell, "node", treemodel.NODE)
99
column.add_attribute(cell, "in-lines", treemodel.LAST_LINES)
100
column.add_attribute(cell, "out-lines", treemodel.LINES)
101
self.treeview.append_column(column)
103
cell = gtk.CellRendererText()
104
cell.set_property("width-chars", 40)
105
cell.set_property("ellipsize", pango.ELLIPSIZE_END)
106
column = gtk.TreeViewColumn("Message")
107
column.set_resizable(True)
108
column.pack_start(cell, expand=True)
109
column.add_attribute(cell, "text", treemodel.MESSAGE)
110
self.treeview.append_column(column)
112
cell = gtk.CellRendererText()
113
cell.set_property("width-chars", 40)
114
cell.set_property("ellipsize", pango.ELLIPSIZE_END)
115
column = gtk.TreeViewColumn("Committer")
116
column.set_resizable(True)
117
column.pack_start(cell, expand=True)
118
column.add_attribute(cell, "text", treemodel.COMMITER)
119
self.treeview.append_column(column)
121
cell = gtk.CellRendererText()
122
cell.set_property("ellipsize", pango.ELLIPSIZE_END)
123
column = gtk.TreeViewColumn("Date")
124
column.set_resizable(True)
125
column.pack_start(cell, expand=True)
126
column.add_attribute(cell, "text", treemodel.TIMESTAMP)
127
self.treeview.append_column(column)
131
def construct_navigation(self):
132
"""Construct the navigation buttons."""
134
frame.set_shadow_type(gtk.SHADOW_OUT)
137
hbox = gtk.HBox(spacing=12)
141
self.back_button = gtk.Button(stock=gtk.STOCK_GO_BACK)
142
self.back_button.set_relief(gtk.RELIEF_NONE)
143
self.back_button.add_accelerator("clicked", self.accel_group, ord('['),
145
self.back_button.connect("clicked", self._back_clicked_cb)
146
hbox.pack_start(self.back_button, expand=False, fill=True)
147
self.back_button.show()
149
self.fwd_button = gtk.Button(stock=gtk.STOCK_GO_FORWARD)
150
self.fwd_button.set_relief(gtk.RELIEF_NONE)
151
self.fwd_button.add_accelerator("clicked", self.accel_group, ord(']'),
153
self.fwd_button.connect("clicked", self._fwd_clicked_cb)
154
hbox.pack_start(self.fwd_button, expand=False, fill=True)
155
self.fwd_button.show()
159
def construct_bottom(self):
160
"""Construct the bottom half of the window."""
161
from bzrlib.plugins.gtk.logview import LogView
162
self.logview = LogView(None, True, [], True)
163
(width, height) = self.get_size()
164
self.logview.set_size_request(width, int(height / 2.5))
166
self.logview.set_show_callback(self._show_clicked_cb)
167
self.logview.set_go_callback(self._go_clicked_cb)
170
def set_branch(self, branch, start, maxnum):
171
"""Set the branch and start position for this window.
173
Creates a new TreeModel and populates it with information about
174
the new branch before updating the window title and model of the
178
self.set_title(branch.nick + " - bzrk")
179
gobject.idle_add(self.populate_model, start, maxnum)
181
def populate_model(self, start, maxnum):
182
(linegraphdata, index) = linegraph(self.branch,
185
self.model = TreeModel(self.branch, linegraphdata)
187
self.treeview.set_model(self.model)
189
def _treeview_cursor_cb(self, *args):
190
"""Callback for when the treeview cursor changes."""
191
(path, col) = self.treeview.get_cursor()
192
iter = self.model.get_iter(path)
193
revision = self.model.get_value(iter, treemodel.REVISION)
194
parents = self.model.get_value(iter, treemodel.PARENTS)
195
children = self.model.get_value(iter, treemodel.CHILDREN)
197
self.back_button.set_sensitive(len(parents) > 0)
198
self.fwd_button.set_sensitive(len(children) > 0)
200
if self.branch.supports_tags():
201
tagdict = self.branch.tags.get_reverse_tag_dict()
202
if tagdict.has_key(revision.revision_id):
203
tags = tagdict[revision.revision_id]
204
self.logview.set_revision(revision, tags, children)
206
def _back_clicked_cb(self, *args):
207
"""Callback for when the back button is clicked."""
208
(path, col) = self.treeview.get_cursor()
209
revision = self.model[path][0]
210
parents = self.model[path][4]
214
for parent_id in parents:
215
parent = self.revisions[self.index[parent_id]]
216
if same_branch(revision, parent):
217
self.treeview.set_cursor(self.index[parent_id])
220
self.treeview.set_cursor(self.index[parents[0]])
221
self.treeview.grab_focus()
223
def _fwd_clicked_cb(self, *args):
224
"""Callback for when the forward button is clicked."""
225
(path, col) = self.treeview.get_cursor()
226
revision = self.model[path][0]
227
children = self.model[path][5]
228
if not len(children):
231
for child_id in children:
232
child = self.revisions[self.index[child_id]]
233
if same_branch(child, revision):
234
self.treeview.set_cursor(self.index[child_id])
237
self.treeview.set_cursor(self.index[children[0]])
238
self.treeview.grab_focus()
240
def _go_clicked_cb(self, revid):
241
"""Callback for when the go button for a parent is clicked."""
242
self.treeview.set_cursor(self.index[revid])
243
self.treeview.grab_focus()
245
def show_diff(self, branch, revid, parentid):
246
"""Open a new window to show a diff between the given revisions."""
247
from bzrlib.plugins.gtk.diff import DiffWindow
248
window = DiffWindow()
249
(parent_tree, rev_tree) = branch.repository.revision_trees([parentid,
251
description = revid + " - " + branch.nick
252
window.set_diff(description, rev_tree, parent_tree)
255
def _show_clicked_cb(self, revid, parentid):
256
"""Callback for when the show button for a parent is clicked."""
257
self.show_diff(self.branch, revid, parentid)
258
self.treeview.grab_focus()
260
def _treeview_row_mouseclick(self, widget, event):
261
from bzrlib.plugins.gtk.revisionmenu import RevisionPopupMenu
262
if event.button == 3:
263
menu = RevisionPopupMenu(self.branch.repository,
264
[x.revision_id for x in self.selected_revisions()],
266
menu.popup(None, None, None, event.button, event.get_time())
268
def selected_revision(self, path):
269
return self.model[path][0]
271
def selected_revisions(self):
272
return [self.selected_revision(path) for path in \
273
self.treeview.get_selection().get_selected_rows()[1]]
275
def _treeview_row_activated_cb(self, widget, path, col):
276
# TODO: more than one parent
277
"""Callback for when a treeview row gets activated."""
278
revision = self.selected_revision(path)
279
if len(self.parent_ids[revision]) == 0:
280
# Ignore revisions without parent
282
parent_id = self.parent_ids[revision][0]
283
self.show_diff(self.branch, revision.revision_id, parent_id)
284
self.treeview.grab_focus()