/b-gtk/fix-viz

To get this branch, use:
bzr branch http://gegoxaren.bato24.eu/bzr/b-gtk/fix-viz
580.1.1 by Jelmer Vernooij
Add gloom command.
1
# Copyright (C) 2008 Jelmer Vernooij <jelmer@samba.org>
2
#
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.
7
#
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.
12
#
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
16
17
try:
18
    import pygtk
19
    pygtk.require("2.0")
20
except:
21
    pass
22
23
import gtk
24
import gobject
25
26
from bzrlib.plugins.gtk import _i18n
580.1.3 by Jelmer Vernooij
Show diffs of threads, allow switching to different threads.
27
from bzrlib.plugins.gtk.diff import DiffWidget
580.1.1 by Jelmer Vernooij
Add gloom command.
28
from bzrlib.plugins.gtk.dialog import question_dialog
29
from bzrlib.plugins.loom import branch as loom_branch
580.1.3 by Jelmer Vernooij
Show diffs of threads, allow switching to different threads.
30
from bzrlib.plugins.loom import tree as loom_tree
580.1.1 by Jelmer Vernooij
Add gloom command.
31
32
class LoomDialog(gtk.Dialog):
33
    """Simple Loom browse dialog."""
34
580.1.3 by Jelmer Vernooij
Show diffs of threads, allow switching to different threads.
35
    def __init__(self, branch, tree=None, parent=None):
580.1.1 by Jelmer Vernooij
Add gloom command.
36
        gtk.Dialog.__init__(self, title="Threads",
37
                                  parent=parent,
38
                                  flags=0,
39
                                  buttons=(gtk.STOCK_CLOSE,gtk.RESPONSE_OK))
40
        self.branch = branch
580.1.3 by Jelmer Vernooij
Show diffs of threads, allow switching to different threads.
41
        if tree is not None:
42
            self.tree = loom_tree.LoomTreeDecorator(tree)
43
        else:
44
            self.tree = None
580.1.1 by Jelmer Vernooij
Add gloom command.
45
46
        self._construct()
47
48
    def run(self):
49
        try:
50
            loom_branch.require_loom_branch(self.branch)
51
        except loom_branch.NotALoom:
52
            response = question_dialog(
53
                _i18n("Upgrade to Loom branch?"),
54
                _i18n("Branch is not a loom branch. Upgrade to Loom format?"),
55
                parent=self)
56
                # Doesn't set a parent for the dialog..
57
            if response == gtk.RESPONSE_NO:
58
                return
580.1.2 by Jelmer Vernooij
Show threads in loom dialog.
59
            assert self.branch.nick is not None
580.1.1 by Jelmer Vernooij
Add gloom command.
60
            loom_branch.loomify(self.branch)
580.1.6 by Jelmer Vernooij
Avoid making assumptions about a branch being a loom until we've checked.
61
        self._load_threads()
580.1.1 by Jelmer Vernooij
Add gloom command.
62
        return super(LoomDialog, self).run()
63
64
    def _construct(self):
580.1.3 by Jelmer Vernooij
Show diffs of threads, allow switching to different threads.
65
        hbox = gtk.HBox()
66
580.1.2 by Jelmer Vernooij
Show threads in loom dialog.
67
        self._threads_scroller = gtk.ScrolledWindow()
68
        self._threads_scroller.set_policy(gtk.POLICY_AUTOMATIC, gtk.POLICY_AUTOMATIC)
580.1.1 by Jelmer Vernooij
Add gloom command.
69
        self._threads_view = gtk.TreeView()
580.1.2 by Jelmer Vernooij
Show threads in loom dialog.
70
        self._threads_scroller.add(self._threads_view)
71
        self._threads_scroller.set_shadow_type(gtk.SHADOW_IN)
580.1.3 by Jelmer Vernooij
Show diffs of threads, allow switching to different threads.
72
        hbox.pack_start(self._threads_scroller)
580.1.2 by Jelmer Vernooij
Show threads in loom dialog.
73
74
        self._threads_store = gtk.ListStore(
580.1.3 by Jelmer Vernooij
Show diffs of threads, allow switching to different threads.
75
                gobject.TYPE_STRING, gobject.TYPE_STRING, gobject.TYPE_PYOBJECT, gobject.TYPE_STRING)
580.1.2 by Jelmer Vernooij
Show threads in loom dialog.
76
        self._threads_view.set_model(self._threads_store)
77
        self._threads_view.append_column(gtk.TreeViewColumn("Name", gtk.CellRendererText(), text=0))
580.1.3 by Jelmer Vernooij
Show diffs of threads, allow switching to different threads.
78
        self._threads_view.connect('cursor-changed', self._on_view_thread)
79
        if self.tree is not None:
80
            self._threads_view.connect('row-activated', self._on_switch_thread)
81
82
        self._diff = DiffWidget()
83
        self._diff.show()
84
        hbox.pack_end(self._diff)
85
86
        hbox.show_all()
87
        self.vbox.pack_start(hbox)
580.1.1 by Jelmer Vernooij
Add gloom command.
88
580.1.4 by Jelmer Vernooij
Update FIXME, add news entry.
89
        # FIXME: Buttons: combine-thread, revert-loom, record
580.1.3 by Jelmer Vernooij
Show diffs of threads, allow switching to different threads.
90
        self.set_default_size(500, 350)
91
92
    def _on_view_thread(self, treeview):
93
        treeselection = treeview.get_selection()
94
        (model, selection) = treeselection.get_selected()
95
        if selection is None:
96
            return
97
        revid, parent_revid = model.get(selection, 1, 3)
98
        if parent_revid is None:
99
            return
100
        self.branch.lock_read()
101
        try:
102
            (rev_tree, parent_tree) = tuple(self.branch.repository.revision_trees([revid, parent_revid]))
103
            self._diff.set_diff(rev_tree, parent_tree)
104
        finally:
105
            self.branch.unlock()
106
107
    def _on_switch_thread(self, treeview, path, view_column):
108
        new_thread = self._threads_store.get_value(self._threads_store.get_iter(path), 0)
109
        self.tree.down_thread(new_thread)
580.1.2 by Jelmer Vernooij
Show threads in loom dialog.
110
111
    def _load_threads(self):
112
        self._threads_store.clear()
113
        
114
        self.branch.lock_read()
115
        try:
116
            threads = self.branch.get_loom_state().get_threads()
580.1.3 by Jelmer Vernooij
Show diffs of threads, allow switching to different threads.
117
            last_revid = None
118
            for name, revid, parent_ids in reversed(threads):
119
                self._threads_store.append([name, revid, parent_ids, last_revid])
120
                last_revid = revid
580.1.2 by Jelmer Vernooij
Show threads in loom dialog.
121
        finally:
122
            self.branch.unlock()