2
# -*- coding: UTF-8 -*-
5
This module contains the code to manage the branch information window,
6
which contains both the revision graph and details panes.
9
__copyright__ = "Copyright © 2005 Canonical Ltd."
10
__author__ = "Scott James Remnant <scott@ubuntu.com>"
19
from bzrlib.osutils import format_date
21
from graph import distances, graph, same_branch
22
from graphcell import CellRendererGraph
25
class BranchWindow(gtk.Window):
28
This object represents and manages a single window containing information
29
for a particular branch.
33
gtk.Window.__init__(self, gtk.WINDOW_TOPLEVEL)
34
self.set_border_width(0)
35
self.set_title("bzrk")
37
# Use three-quarters of the screen by default
38
screen = self.get_screen()
39
monitor = screen.get_monitor_geometry(0)
40
width = int(monitor.width * 0.75)
41
height = int(monitor.height * 0.75)
42
self.set_default_size(width, height)
45
icon = self.render_icon(gtk.STOCK_INDEX, gtk.ICON_SIZE_BUTTON)
48
self.accel_group = gtk.AccelGroup()
49
self.add_accel_group(self.accel_group)
54
"""Construct the window contents."""
56
paned.pack1(self.construct_top(), resize=True, shrink=False)
57
paned.pack2(self.construct_bottom(), resize=True, shrink=True)
61
def construct_top(self):
62
"""Construct the top-half of the window."""
63
vbox = gtk.VBox(spacing=6)
64
vbox.set_border_width(12)
67
scrollwin = gtk.ScrolledWindow()
68
scrollwin.set_policy(gtk.POLICY_NEVER, gtk.POLICY_AUTOMATIC)
69
scrollwin.set_shadow_type(gtk.SHADOW_IN)
70
vbox.pack_start(scrollwin, expand=True, fill=True)
73
self.treeview = gtk.TreeView()
74
self.treeview.set_rules_hint(True)
75
self.treeview.set_search_column(4)
76
self.treeview.connect("cursor-changed", self._treeview_cursor_cb)
77
scrollwin.add(self.treeview)
80
cell = CellRendererGraph()
81
column = gtk.TreeViewColumn()
82
column.set_resizable(False)
83
column.pack_start(cell, expand=False)
84
column.add_attribute(cell, "node", 1)
85
column.add_attribute(cell, "in-lines", 2)
86
column.add_attribute(cell, "out-lines", 3)
87
self.treeview.append_column(column)
89
cell = gtk.CellRendererText()
90
cell.set_property("width-chars", 40)
91
cell.set_property("ellipsize", pango.ELLIPSIZE_END)
92
column = gtk.TreeViewColumn("Message")
93
column.set_resizable(True)
94
column.pack_start(cell, expand=True)
95
column.add_attribute(cell, "text", 4)
96
self.treeview.append_column(column)
98
cell = gtk.CellRendererText()
99
cell.set_property("width-chars", 40)
100
cell.set_property("ellipsize", pango.ELLIPSIZE_END)
101
column = gtk.TreeViewColumn("Committer")
102
column.set_resizable(True)
103
column.pack_start(cell, expand=True)
104
column.add_attribute(cell, "text", 5)
105
self.treeview.append_column(column)
107
cell = gtk.CellRendererText()
108
cell.set_property("ellipsize", pango.ELLIPSIZE_END)
109
column = gtk.TreeViewColumn("Date")
110
column.set_resizable(True)
111
column.pack_start(cell, expand=True)
112
column.add_attribute(cell, "text", 6)
113
self.treeview.append_column(column)
115
hbox = gtk.HBox(False, spacing=6)
116
vbox.pack_start(hbox, expand=False, fill=False)
119
self.back_button = gtk.Button(stock=gtk.STOCK_GO_BACK)
120
self.back_button.add_accelerator("clicked", self.accel_group, ord('['),
122
self.back_button.connect("clicked", self._back_clicked_cb)
123
hbox.pack_start(self.back_button, expand=False, fill=True)
124
self.back_button.show()
126
self.fwd_button = gtk.Button(stock=gtk.STOCK_GO_FORWARD)
127
self.fwd_button.add_accelerator("clicked", self.accel_group, ord(']'),
129
self.fwd_button.connect("clicked", self._fwd_clicked_cb)
130
hbox.pack_start(self.fwd_button, expand=False, fill=True)
131
self.fwd_button.show()
135
def construct_bottom(self):
136
"""Construct the bottom half of the window."""
137
label = gtk.Label("test")
142
def set_branch(self, branch, start):
143
"""Set the branch and start position for this window.
145
Creates a new TreeModel and populates it with information about
146
the new branch before updating the window title and model of the
149
# [ revision, node, last_lines, lines, message, committer, timestamp ]
150
self.model = gtk.ListStore(gobject.TYPE_PYOBJECT,
151
gobject.TYPE_PYOBJECT,
152
gobject.TYPE_PYOBJECT,
153
gobject.TYPE_PYOBJECT,
159
(revids, self.revisions, colours, self.children) \
160
= distances(branch, start)
161
for revision, node, lines in graph(revids, self.revisions, colours):
162
message = revision.message.split("\n")[0]
163
if revision.committer is not None:
164
timestamp = format_date(revision.timestamp, revision.timezone)
168
self.model.append([ revision, node, last_lines, lines,
169
message, revision.committer, timestamp ])
170
self.index[revision] = index
175
self.set_title(os.path.basename(branch.base) + " - bzrk")
176
self.treeview.set_model(self.model)
178
def _treeview_cursor_cb(self, *args):
179
"""Callback for when the treeview cursor changes."""
180
(path, col) = self.treeview.get_cursor()
181
revision = self.model[path][0]
183
self.back_button.set_sensitive(len(revision.parent_ids) > 0)
184
self.fwd_button.set_sensitive(len(self.children[revision]) > 0)
186
def _back_clicked_cb(self, *args):
187
"""Callback for when the back button is clicked."""
188
(path, col) = self.treeview.get_cursor()
189
revision = self.model[path][0]
190
if not len(revision.parent_ids):
193
for parent_id in revision.parent_ids:
194
parent = self.revisions[parent_id]
195
if same_branch(revision, parent):
196
self.treeview.set_cursor(self.index[parent])
199
next = self.revisions[revision.parent_ids[0]]
200
self.treeview.set_cursor(self.index[next])
202
def _fwd_clicked_cb(self, *args):
203
"""Callback for when the forward button is clicked."""
204
(path, col) = self.treeview.get_cursor()
205
revision = self.model[path][0]
206
if not len(self.children[revision]):
209
for child in self.children[revision]:
210
if same_branch(child, revision):
211
self.treeview.set_cursor(self.index[child])
214
prev = list(self.children[revision])[0]
215
self.treeview.set_cursor(self.index[prev])