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
22
from treeview import TreeView
24
class BranchWindow(gtk.Window):
27
This object represents and manages a single window containing information
28
for a particular branch.
31
def __init__(self, parent=None):
32
gtk.Window.__init__(self, gtk.WINDOW_TOPLEVEL)
33
self.set_border_width(0)
34
self.set_title("Revision history")
38
self.connect('key-press-event', self._on_key_pressed)
39
self.connect("destroy", lambda w: self.branch.unlock())
41
# Use three-quarters of the screen by default
42
screen = self.get_screen()
43
monitor = screen.get_monitor_geometry(0)
44
width = int(monitor.width * 0.75)
45
height = int(monitor.height * 0.75)
46
self.set_default_size(width, height)
49
icon = self.render_icon(gtk.STOCK_INDEX, gtk.ICON_SIZE_BUTTON)
52
self.accel_group = gtk.AccelGroup()
53
self.add_accel_group(self.accel_group)
58
"""Construct the window contents."""
59
vbox = gtk.VBox(spacing=0)
62
vbox.pack_start(self.construct_navigation(), expand=False, fill=True)
63
vbox.pack_start(self.construct_loading_msg(), expand=False, fill=True)
66
paned.pack1(self.construct_top(), resize=True, shrink=False)
67
paned.pack2(self.construct_bottom(), resize=False, shrink=True)
69
vbox.pack_start(paned, expand=True, fill=True)
70
vbox.set_focus_child(paned)
74
def construct_loading_msg(self):
75
image_loading = gtk.image_new_from_stock(gtk.STOCK_REFRESH,
79
label_loading = gtk.Label(_("Please wait, loading ancestral graph..."))
80
label_loading.set_alignment(0.0, 0.5)
83
self.loading_msg_box = gtk.HBox()
84
self.loading_msg_box.set_spacing(5)
85
self.loading_msg_box.set_border_width(5)
86
self.loading_msg_box.pack_start(image_loading, False, False)
87
self.loading_msg_box.pack_start(label_loading, True, True)
88
self.loading_msg_box.show()
90
return self.loading_msg_box
92
def construct_top(self):
93
"""Construct the top-half of the window."""
94
self.treeview = TreeView()
96
self.treeview.connect("revision-selected",
97
self._treeselection_changed_cb)
99
self.treeview.connect('revisions-loaded',
100
lambda x: self.loading_msg_box.hide())
106
def construct_navigation(self):
107
"""Construct the navigation buttons."""
109
frame.set_shadow_type(gtk.SHADOW_OUT)
112
hbox = gtk.HBox(spacing=12)
116
self.back_button = gtk.Button(stock=gtk.STOCK_GO_BACK)
117
self.back_button.set_relief(gtk.RELIEF_NONE)
118
self.back_button.add_accelerator("clicked", self.accel_group, ord('['),
120
self.back_button.connect("clicked", self._back_clicked_cb)
121
hbox.pack_start(self.back_button, expand=False, fill=True)
122
self.back_button.show()
124
self.fwd_button = gtk.Button(stock=gtk.STOCK_GO_FORWARD)
125
self.fwd_button.set_relief(gtk.RELIEF_NONE)
126
self.fwd_button.add_accelerator("clicked", self.accel_group, ord(']'),
128
self.fwd_button.connect("clicked", self._fwd_clicked_cb)
129
hbox.pack_start(self.fwd_button, expand=False, fill=True)
130
self.fwd_button.show()
134
def construct_bottom(self):
135
"""Construct the bottom half of the window."""
136
from bzrlib.plugins.gtk.logview import LogView
137
self.logview = LogView(None, True, [], True)
138
(width, height) = self.get_size()
139
self.logview.set_size_request(width, int(height / 2.5))
141
self.logview.set_show_callback(self._show_clicked_cb)
142
self.logview.set_go_callback(self._go_clicked_cb)
145
def set_branch(self, branch, start, maxnum):
146
"""Set the branch and start position for this window.
148
Creates a new TreeModel and populates it with information about
149
the new branch before updating the window title and model of the
153
self.branch.lock_read()
154
self.set_title(branch.nick + " - revision history")
155
self.treeview.set_branch(branch, start, maxnum)
157
def _on_key_pressed(self, widget, event):
158
""" Key press event handler. """
159
keyname = gtk.gdk.keyval_name(event.keyval)
160
func = getattr(self, '_on_key_press_' + keyname, None)
164
def _on_key_press_w(self, event):
165
if event.state & gtk.gdk.CONTROL_MASK:
167
if self._parent is None:
170
def _on_key_press_q(self, event):
171
if event.state & gtk.gdk.CONTROL_MASK:
174
def _treeselection_changed_cb(self, selection, *args):
175
"""callback for when the treeview changes."""
176
revision = self.treeview.get_revision()
177
parents = self.treeview.get_parents()
178
children = self.treeview.get_children()
180
if revision is not None:
181
self.back_button.set_sensitive(len(parents) > 0)
182
self.fwd_button.set_sensitive(len(children) > 0)
184
if self.branch.supports_tags():
185
tagdict = self.branch.tags.get_reverse_tag_dict()
186
if tagdict.has_key(revision.revision_id):
187
tags = tagdict[revision.revision_id]
188
self.logview.set_revision(revision, tags, children)
190
def _back_clicked_cb(self, *args):
191
"""Callback for when the back button is clicked."""
194
def _fwd_clicked_cb(self, *args):
195
"""Callback for when the forward button is clicked."""
196
self.treeview.forward()
198
def _go_clicked_cb(self, revid):
199
"""Callback for when the go button for a parent is clicked."""
200
self.treeview.set_revision(revid)
202
def _show_clicked_cb(self, revid, parentid):
203
"""Callback for when the show button for a parent is clicked."""
204
self.treeview.show_diff(self.branch, revid, parentid)
205
self.treeview.grab_focus()