37
34
# Use three-quarters of the screen by default
38
35
screen = self.get_screen()
39
width = int(screen.get_width() * 0.75)
40
height = int(screen.get_height() * 0.75)
36
monitor = screen.get_monitor_geometry(0)
37
width = int(monitor.width * 0.75)
38
height = int(monitor.height * 0.75)
41
39
self.set_default_size(width, height)
52
50
def construct(self):
53
51
"""Construct the window contents."""
52
vbox = gtk.VBox(spacing=0)
55
vbox.pack_start(self.construct_navigation(), expand=False, fill=True)
54
57
paned = gtk.VPaned()
55
58
paned.pack1(self.construct_top(), resize=True, shrink=False)
56
paned.pack2(self.construct_bottom(), resize=True, shrink=True)
59
paned.pack2(self.construct_bottom(), resize=False, shrink=True)
61
vbox.pack_start(paned, expand=True, fill=True)
62
vbox.set_focus_child(paned)
60
66
def construct_top(self):
61
67
"""Construct the top-half of the window."""
62
vbox = gtk.VBox(spacing=6)
63
vbox.set_border_width(12)
66
68
scrollwin = gtk.ScrolledWindow()
67
69
scrollwin.set_policy(gtk.POLICY_NEVER, gtk.POLICY_AUTOMATIC)
68
70
scrollwin.set_shadow_type(gtk.SHADOW_IN)
69
#scrollwin.set_border_width(12)
70
vbox.pack_start(scrollwin, expand=True, fill=True)
73
73
self.treeview = gtk.TreeView()
74
74
self.treeview.set_rules_hint(True)
75
75
self.treeview.set_search_column(4)
76
76
self.treeview.connect("cursor-changed", self._treeview_cursor_cb)
77
self.treeview.connect("row-activated", self._treeview_row_activated_cb)
77
78
scrollwin.add(self.treeview)
78
79
self.treeview.show()
80
81
cell = CellRendererGraph()
81
82
column = gtk.TreeViewColumn()
82
column.set_resizable(False)
83
column.set_resizable(True)
83
84
column.pack_start(cell, expand=False)
84
85
column.add_attribute(cell, "node", 1)
85
86
column.add_attribute(cell, "in-lines", 2)
112
113
column.add_attribute(cell, "text", 6)
113
114
self.treeview.append_column(column)
115
hbox = gtk.HBox(False, spacing=6)
116
vbox.pack_start(hbox, expand=False, fill=False)
118
def construct_navigation(self):
119
"""Construct the navigation buttons."""
121
frame.set_shadow_type(gtk.SHADOW_OUT)
124
hbox = gtk.HBox(spacing=12)
119
128
self.back_button = gtk.Button(stock=gtk.STOCK_GO_BACK)
129
self.back_button.set_relief(gtk.RELIEF_NONE)
120
130
self.back_button.add_accelerator("clicked", self.accel_group, ord('['),
122
132
self.back_button.connect("clicked", self._back_clicked_cb)
124
134
self.back_button.show()
126
136
self.fwd_button = gtk.Button(stock=gtk.STOCK_GO_FORWARD)
137
self.fwd_button.set_relief(gtk.RELIEF_NONE)
127
138
self.fwd_button.add_accelerator("clicked", self.accel_group, ord(']'),
129
140
self.fwd_button.connect("clicked", self._fwd_clicked_cb)
130
141
hbox.pack_start(self.fwd_button, expand=False, fill=True)
131
142
self.fwd_button.show()
135
146
def construct_bottom(self):
136
147
"""Construct the bottom half of the window."""
137
label = gtk.Label("test")
142
def set_branch(self, branch, start):
148
from bzrlib.plugins.gtk.logview import LogView
149
self.logview = LogView()
150
(width, height) = self.get_size()
151
self.logview.set_size_request(width, int(height / 2.5))
153
self.logview.set_show_callback(self._show_clicked_cb)
154
self.logview.set_go_callback(self._go_clicked_cb)
157
def set_branch(self, branch, start, maxnum):
143
158
"""Set the branch and start position for this window.
145
160
Creates a new TreeModel and populates it with information about
146
161
the new branch before updating the window title and model of the
149
166
# [ revision, node, last_lines, lines, message, committer, timestamp ]
150
167
self.model = gtk.ListStore(gobject.TYPE_PYOBJECT,
151
168
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):
176
(self.revisions, colours, self.children, self.parent_ids,
177
merge_sorted) = distances(branch, start)
178
for (index, (revision, node, lines)) in enumerate(graph(
179
self.revisions, colours, merge_sorted)):
180
# FIXME: at this point we should be able to show the graph order
181
# and lines with no message or commit data - and then incrementally
182
# fill the timestamp, committer etc data as desired.
162
183
message = revision.message.split("\n")[0]
163
184
if revision.committer is not None:
164
185
timestamp = format_date(revision.timestamp, revision.timezone)
168
self.model.append([ revision, node, last_lines, lines,
169
message, revision.committer, timestamp ])
188
self.model.append([revision, node, last_lines, lines,
189
message, revision.committer, timestamp])
170
190
self.index[revision] = index
173
191
last_lines = lines
192
if maxnum is not None and index > maxnum:
175
self.set_title(os.path.basename(branch.base) + " - bzrk")
195
self.set_title(branch.nick + " - bzrk")
176
196
self.treeview.set_model(self.model)
178
198
def _treeview_cursor_cb(self, *args):
180
200
(path, col) = self.treeview.get_cursor()
181
201
revision = self.model[path][0]
183
self.back_button.set_sensitive(len(self.children[revision]) > 0)
184
self.fwd_button.set_sensitive(len(revision.parent_ids) > 0)
203
self.back_button.set_sensitive(len(self.parent_ids[revision]) > 0)
204
self.fwd_button.set_sensitive(len(self.children[revision]) > 0)
205
self.logview.set_revision(revision)
186
207
def _back_clicked_cb(self, *args):
187
208
"""Callback for when the back button is clicked."""
188
209
(path, col) = self.treeview.get_cursor()
189
210
revision = self.model[path][0]
211
if not len(self.parent_ids[revision]):
214
for parent_id in self.parent_ids[revision]:
215
parent = self.revisions[parent_id]
216
if same_branch(revision, parent):
217
self.treeview.set_cursor(self.index[parent])
220
next = self.revisions[self.parent_ids[revision][0]]
221
self.treeview.set_cursor(self.index[next])
222
self.treeview.grab_focus()
224
def _fwd_clicked_cb(self, *args):
225
"""Callback for when the forward button is clicked."""
226
(path, col) = self.treeview.get_cursor()
227
revision = self.model[path][0]
190
228
if not len(self.children[revision]):
198
236
prev = list(self.children[revision])[0]
199
237
self.treeview.set_cursor(self.index[prev])
201
def _fwd_clicked_cb(self, *args):
202
"""Callback for when the forward button is clicked."""
203
(path, col) = self.treeview.get_cursor()
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[self.revisions[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
rev_tree = branch.repository.revision_tree(revid)
250
parent_tree = branch.repository.revision_tree(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_activated_cb(self, widget, path, col):
261
# TODO: more than one parent
262
"""Callback for when a treeview row gets activated."""
204
263
revision = self.model[path][0]
205
if not len(revision.parent_ids):
264
if len(self.parent_ids[revision]) == 0:
265
# Ignore revisions without parent
208
for parent_id in revision.parent_ids:
209
parent = self.revisions[parent_id]
210
if same_branch(revision, parent):
211
self.treeview.set_cursor(self.index[parent])
214
next = self.revisions[revision.parent_ids[0]]
215
self.treeview.set_cursor(self.index[next])
267
parent_id = self.parent_ids[revision][0]
268
self.show_diff(self.branch, revision.revision_id, parent_id)
269
self.treeview.grab_focus()