/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
724 by Jelmer Vernooij
Fix formatting, imports.
29
from bzrlib.plugins.loom import (
30
    branch as loom_branch,
31
    tree as loom_tree,
32
    )
33
580.1.1 by Jelmer Vernooij
Add gloom command.
34
35
class LoomDialog(gtk.Dialog):
36
    """Simple Loom browse dialog."""
37
580.1.3 by Jelmer Vernooij
Show diffs of threads, allow switching to different threads.
38
    def __init__(self, branch, tree=None, parent=None):
580.1.1 by Jelmer Vernooij
Add gloom command.
39
        gtk.Dialog.__init__(self, title="Threads",
40
                                  parent=parent,
41
                                  flags=0,
42
                                  buttons=(gtk.STOCK_CLOSE,gtk.RESPONSE_OK))
43
        self.branch = branch
580.1.3 by Jelmer Vernooij
Show diffs of threads, allow switching to different threads.
44
        if tree is not None:
45
            self.tree = loom_tree.LoomTreeDecorator(tree)
46
        else:
47
            self.tree = None
580.1.1 by Jelmer Vernooij
Add gloom command.
48
49
        self._construct()
50
51
    def run(self):
52
        try:
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?"),
58
                parent=self)
59
                # Doesn't set a parent for the dialog..
60
            if response == gtk.RESPONSE_NO:
61
                return
580.1.2 by Jelmer Vernooij
Show threads in loom dialog.
62
            assert self.branch.nick is not None
580.1.1 by Jelmer Vernooij
Add gloom command.
63
            loom_branch.loomify(self.branch)
580.1.6 by Jelmer Vernooij
Avoid making assumptions about a branch being a loom until we've checked.
64
        self._load_threads()
580.1.1 by Jelmer Vernooij
Add gloom command.
65
        return super(LoomDialog, self).run()
66
67
    def _construct(self):
580.1.3 by Jelmer Vernooij
Show diffs of threads, allow switching to different threads.
68
        hbox = gtk.HBox()
69
580.1.2 by Jelmer Vernooij
Show threads in loom dialog.
70
        self._threads_scroller = gtk.ScrolledWindow()
71
        self._threads_scroller.set_policy(gtk.POLICY_AUTOMATIC, gtk.POLICY_AUTOMATIC)
580.1.1 by Jelmer Vernooij
Add gloom command.
72
        self._threads_view = gtk.TreeView()
580.1.2 by Jelmer Vernooij
Show threads in loom dialog.
73
        self._threads_scroller.add(self._threads_view)
74
        self._threads_scroller.set_shadow_type(gtk.SHADOW_IN)
580.1.3 by Jelmer Vernooij
Show diffs of threads, allow switching to different threads.
75
        hbox.pack_start(self._threads_scroller)
580.1.2 by Jelmer Vernooij
Show threads in loom dialog.
76
77
        self._threads_store = gtk.ListStore(
580.1.3 by Jelmer Vernooij
Show diffs of threads, allow switching to different threads.
78
                gobject.TYPE_STRING, gobject.TYPE_STRING, gobject.TYPE_PYOBJECT, gobject.TYPE_STRING)
580.1.2 by Jelmer Vernooij
Show threads in loom dialog.
79
        self._threads_view.set_model(self._threads_store)
80
        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.
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)
84
85
        self._diff = DiffWidget()
86
        self._diff.show()
87
        hbox.pack_end(self._diff)
88
89
        hbox.show_all()
90
        self.vbox.pack_start(hbox)
580.1.1 by Jelmer Vernooij
Add gloom command.
91
580.1.4 by Jelmer Vernooij
Update FIXME, add news entry.
92
        # FIXME: Buttons: combine-thread, revert-loom, record
580.1.3 by Jelmer Vernooij
Show diffs of threads, allow switching to different threads.
93
        self.set_default_size(500, 350)
94
95
    def _on_view_thread(self, treeview):
96
        treeselection = treeview.get_selection()
97
        (model, selection) = treeselection.get_selected()
98
        if selection is None:
99
            return
100
        revid, parent_revid = model.get(selection, 1, 3)
101
        if parent_revid is None:
102
            return
103
        self.branch.lock_read()
104
        try:
105
            (rev_tree, parent_tree) = tuple(self.branch.repository.revision_trees([revid, parent_revid]))
106
            self._diff.set_diff(rev_tree, parent_tree)
107
        finally:
108
            self.branch.unlock()
109
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)
580.1.2 by Jelmer Vernooij
Show threads in loom dialog.
113
114
    def _load_threads(self):
115
        self._threads_store.clear()
116
        
117
        self.branch.lock_read()
118
        try:
119
            threads = self.branch.get_loom_state().get_threads()
580.1.3 by Jelmer Vernooij
Show diffs of threads, allow switching to different threads.
120
            last_revid = None
121
            for name, revid, parent_ids in reversed(threads):
122
                self._threads_store.append([name, revid, parent_ids, last_revid])
123
                last_revid = revid
580.1.2 by Jelmer Vernooij
Show threads in loom dialog.
124
        finally:
125
            self.branch.unlock()