1
# Copyright (C) 2008 Jelmer Vernooij <jelmer@samba.org>
3
# This program is free software; you can redistribute it and/or modify
4
# it under the terms of the GNU General Public License as published by
5
# the Free Software Foundation; either version 2 of the License, or
6
# (at your option) any later version.
8
# This program is distributed in the hope that it will be useful,
9
# but WITHOUT ANY WARRANTY; without even the implied warranty of
10
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
11
# GNU General Public License for more details.
13
# You should have received a copy of the GNU General Public License
14
# along with this program; if not, write to the Free Software
15
# Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
26
from bzrlib.plugins.gtk.diff import DiffWidget
27
from bzrlib.plugins.gtk.dialog import question_dialog
28
from bzrlib.plugins.loom import (
29
branch as loom_branch,
32
from bzrlib.plugins.gtk.i18n import _i18n
35
class LoomDialog(gtk.Dialog):
36
"""Simple Loom browse dialog."""
38
def __init__(self, branch, tree=None, parent=None):
39
gtk.Dialog.__init__(self, title="Threads",
42
buttons=(gtk.STOCK_CLOSE,gtk.RESPONSE_OK))
45
self.tree = loom_tree.LoomTreeDecorator(tree)
53
loom_branch.require_loom_branch(self.branch)
54
except loom_branch.NotALoom:
55
response = question_dialog(
56
_i18n("Upgrade to Loom branch?"),
57
_i18n("Branch is not a loom branch. Upgrade to Loom format?"),
59
# Doesn't set a parent for the dialog..
60
if response == gtk.RESPONSE_NO:
62
assert self.branch.nick is not None
63
loom_branch.loomify(self.branch)
65
return super(LoomDialog, self).run()
70
self._threads_scroller = gtk.ScrolledWindow()
71
self._threads_scroller.set_policy(gtk.POLICY_AUTOMATIC, gtk.POLICY_AUTOMATIC)
72
self._threads_view = gtk.TreeView()
73
self._threads_scroller.add(self._threads_view)
74
self._threads_scroller.set_shadow_type(gtk.SHADOW_IN)
75
hbox.pack_start(self._threads_scroller)
77
self._threads_store = gtk.ListStore(
78
gobject.TYPE_STRING, gobject.TYPE_STRING, gobject.TYPE_PYOBJECT, gobject.TYPE_STRING)
79
self._threads_view.set_model(self._threads_store)
80
self._threads_view.append_column(gtk.TreeViewColumn("Name", gtk.CellRendererText(), text=0))
81
self._threads_view.connect('cursor-changed', self._on_view_thread)
82
if self.tree is not None:
83
self._threads_view.connect('row-activated', self._on_switch_thread)
85
self._diff = DiffWidget()
87
hbox.pack_end(self._diff)
90
self.vbox.pack_start(hbox)
92
# FIXME: Buttons: combine-thread, revert-loom, record
93
self.set_default_size(500, 350)
95
def _on_view_thread(self, treeview):
96
treeselection = treeview.get_selection()
97
(model, selection) = treeselection.get_selected()
100
revid, parent_revid = model.get(selection, 1, 3)
101
if parent_revid is None:
103
self.branch.lock_read()
105
(rev_tree, parent_tree) = tuple(self.branch.repository.revision_trees([revid, parent_revid]))
106
self._diff.set_diff(rev_tree, parent_tree)
110
def _on_switch_thread(self, treeview, path, view_column):
111
new_thread = self._threads_store.get_value(self._threads_store.get_iter(path), 0)
112
self.tree.down_thread(new_thread)
114
def _load_threads(self):
115
self._threads_store.clear()
117
self.branch.lock_read()
119
threads = self.branch.get_loom_state().get_threads()
121
for name, revid, parent_ids in reversed(threads):
122
self._threads_store.append([name, revid, parent_ids, last_revid])