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.plugins.gtk.window import Window
18
from bzrlib.osutils import format_date
20
from linegraph import linegraph, same_branch
21
from graphcell import CellRendererGraph
22
from treemodel import TreeModel
23
from treeview import TreeView
25
class BranchWindow(Window):
28
This object represents and manages a single window containing information
29
for a particular branch.
32
def __init__(self, branch, start, maxnum, parent=None):
33
Window.__init__(self, parent=parent)
34
self.set_border_width(0)
40
self.set_title(branch.nick + " - revision history")
42
# Use three-quarters of the screen by default
43
screen = self.get_screen()
44
monitor = screen.get_monitor_geometry(0)
45
width = int(monitor.width * 0.75)
46
height = int(monitor.height * 0.75)
47
self.set_default_size(width, height)
50
icon = self.render_icon(gtk.STOCK_INDEX, gtk.ICON_SIZE_BUTTON)
53
self.accel_group = gtk.AccelGroup()
54
self.add_accel_group(self.accel_group)
59
"""Construct the window contents."""
60
vbox = gtk.VBox(spacing=0)
63
vbox.pack_start(self.construct_navigation(), expand=False, fill=True)
64
vbox.pack_start(self.construct_loading_msg(), expand=False, fill=True)
67
paned.pack1(self.construct_top(), resize=True, shrink=False)
68
paned.pack2(self.construct_bottom(), resize=False, shrink=True)
70
vbox.pack_start(paned, expand=True, fill=True)
71
vbox.set_focus_child(paned)
75
def construct_loading_msg(self):
76
image_loading = gtk.image_new_from_stock(gtk.STOCK_REFRESH,
80
label_loading = gtk.Label(_("Please wait, loading ancestral graph..."))
81
label_loading.set_alignment(0.0, 0.5)
84
self.loading_msg_box = gtk.HBox()
85
self.loading_msg_box.set_spacing(5)
86
self.loading_msg_box.set_border_width(5)
87
self.loading_msg_box.pack_start(image_loading, False, False)
88
self.loading_msg_box.pack_start(label_loading, True, True)
89
self.loading_msg_box.show()
91
return self.loading_msg_box
93
def construct_top(self):
94
"""Construct the top-half of the window."""
95
self.treeview = TreeView(self.branch, self.start, self.maxnum)
97
self.treeview.connect("revision-selected",
98
self._treeselection_changed_cb)
100
self.treeview.connect('revisions-loaded',
101
lambda x: self.loading_msg_box.hide())
107
def construct_navigation(self):
108
"""Construct the navigation buttons."""
110
frame.set_shadow_type(gtk.SHADOW_OUT)
113
hbox = gtk.HBox(spacing=12)
117
self.back_button = gtk.Button(stock=gtk.STOCK_GO_BACK)
118
self.back_button.set_relief(gtk.RELIEF_NONE)
119
self.back_button.add_accelerator("clicked", self.accel_group, ord('['),
121
self.back_button.connect("clicked", self._back_clicked_cb)
122
hbox.pack_start(self.back_button, expand=False, fill=True)
123
self.back_button.show()
125
self.fwd_button = gtk.Button(stock=gtk.STOCK_GO_FORWARD)
126
self.fwd_button.set_relief(gtk.RELIEF_NONE)
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
from bzrlib.plugins.gtk.logview import LogView
138
self.logview = LogView(None, True, [], True)
139
(width, height) = self.get_size()
140
self.logview.set_size_request(width, int(height / 2.5))
142
self.logview.set_show_callback(self._show_clicked_cb)
143
self.logview.set_go_callback(self._go_clicked_cb)
146
def _treeselection_changed_cb(self, selection, *args):
147
"""callback for when the treeview changes."""
148
revision = self.treeview.get_revision()
149
parents = self.treeview.get_parents()
150
children = self.treeview.get_children()
152
if revision is not None:
153
self.back_button.set_sensitive(len(parents) > 0)
154
self.fwd_button.set_sensitive(len(children) > 0)
156
if self.branch.supports_tags():
157
tagdict = self.branch.tags.get_reverse_tag_dict()
158
if tagdict.has_key(revision.revision_id):
159
tags = tagdict[revision.revision_id]
160
self.logview.set_revision(revision, tags, children)
162
def _back_clicked_cb(self, *args):
163
"""Callback for when the back button is clicked."""
166
def _fwd_clicked_cb(self, *args):
167
"""Callback for when the forward button is clicked."""
168
self.treeview.forward()
170
def _go_clicked_cb(self, revid):
171
"""Callback for when the go button for a parent is clicked."""
172
self.treeview.set_revision(revid)
174
def _show_clicked_cb(self, revid, parentid):
175
"""Callback for when the show button for a parent is clicked."""
176
self.treeview.show_diff(self.branch, revid, parentid)
177
self.treeview.grab_focus()