/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
734.1.1 by Curtis Hovey
Mechanical changes made by pygi.convert.sh.
17
from gi.repository import Gtk
18
from gi.repository import GObject
580.1.1 by Jelmer Vernooij
Add gloom command.
19
580.1.3 by Jelmer Vernooij
Show diffs of threads, allow switching to different threads.
20
from bzrlib.plugins.gtk.diff import DiffWidget
580.1.1 by Jelmer Vernooij
Add gloom command.
21
from bzrlib.plugins.gtk.dialog import question_dialog
724 by Jelmer Vernooij
Fix formatting, imports.
22
from bzrlib.plugins.loom import (
23
    branch as loom_branch,
24
    tree as loom_tree,
25
    )
729.1.1 by Jelmer Vernooij
Move i18n support to a separate file, so gettext files aren't loaded unless bzr-gtk is used.
26
from bzrlib.plugins.gtk.i18n import _i18n
724 by Jelmer Vernooij
Fix formatting, imports.
27
580.1.1 by Jelmer Vernooij
Add gloom command.
28
734.1.1 by Curtis Hovey
Mechanical changes made by pygi.convert.sh.
29
class LoomDialog(Gtk.Dialog):
580.1.1 by Jelmer Vernooij
Add gloom command.
30
    """Simple Loom browse dialog."""
31
580.1.3 by Jelmer Vernooij
Show diffs of threads, allow switching to different threads.
32
    def __init__(self, branch, tree=None, parent=None):
734.1.1 by Curtis Hovey
Mechanical changes made by pygi.convert.sh.
33
        GObject.GObject.__init__(self, title="Threads",
580.1.1 by Jelmer Vernooij
Add gloom command.
34
                                  parent=parent,
35
                                  flags=0,
734.1.1 by Curtis Hovey
Mechanical changes made by pygi.convert.sh.
36
                                  buttons=(Gtk.STOCK_CLOSE,Gtk.ResponseType.OK))
580.1.1 by Jelmer Vernooij
Add gloom command.
37
        self.branch = branch
580.1.3 by Jelmer Vernooij
Show diffs of threads, allow switching to different threads.
38
        if tree is not None:
39
            self.tree = loom_tree.LoomTreeDecorator(tree)
40
        else:
41
            self.tree = None
580.1.1 by Jelmer Vernooij
Add gloom command.
42
43
        self._construct()
44
45
    def run(self):
46
        try:
47
            loom_branch.require_loom_branch(self.branch)
48
        except loom_branch.NotALoom:
49
            response = question_dialog(
50
                _i18n("Upgrade to Loom branch?"),
51
                _i18n("Branch is not a loom branch. Upgrade to Loom format?"),
52
                parent=self)
53
                # Doesn't set a parent for the dialog..
734.1.1 by Curtis Hovey
Mechanical changes made by pygi.convert.sh.
54
            if response == Gtk.ResponseType.NO:
580.1.1 by Jelmer Vernooij
Add gloom command.
55
                return
580.1.2 by Jelmer Vernooij
Show threads in loom dialog.
56
            assert self.branch.nick is not None
580.1.1 by Jelmer Vernooij
Add gloom command.
57
            loom_branch.loomify(self.branch)
580.1.6 by Jelmer Vernooij
Avoid making assumptions about a branch being a loom until we've checked.
58
        self._load_threads()
580.1.1 by Jelmer Vernooij
Add gloom command.
59
        return super(LoomDialog, self).run()
60
61
    def _construct(self):
734.1.1 by Curtis Hovey
Mechanical changes made by pygi.convert.sh.
62
        hbox = Gtk.HBox()
580.1.3 by Jelmer Vernooij
Show diffs of threads, allow switching to different threads.
63
734.1.1 by Curtis Hovey
Mechanical changes made by pygi.convert.sh.
64
        self._threads_scroller = Gtk.ScrolledWindow()
65
        self._threads_scroller.set_policy(Gtk.PolicyType.AUTOMATIC, Gtk.PolicyType.AUTOMATIC)
66
        self._threads_view = Gtk.TreeView()
580.1.2 by Jelmer Vernooij
Show threads in loom dialog.
67
        self._threads_scroller.add(self._threads_view)
734.1.1 by Curtis Hovey
Mechanical changes made by pygi.convert.sh.
68
        self._threads_scroller.set_shadow_type(Gtk.ShadowType.IN)
69
        hbox.pack_start(self._threads_scroller, True, True, 0)
580.1.2 by Jelmer Vernooij
Show threads in loom dialog.
70
734.1.1 by Curtis Hovey
Mechanical changes made by pygi.convert.sh.
71
        self._threads_store = Gtk.ListStore(
72
                GObject.TYPE_STRING, GObject.TYPE_STRING, GObject.TYPE_PYOBJECT, GObject.TYPE_STRING)
580.1.2 by Jelmer Vernooij
Show threads in loom dialog.
73
        self._threads_view.set_model(self._threads_store)
734.1.1 by Curtis Hovey
Mechanical changes made by pygi.convert.sh.
74
        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.
75
        self._threads_view.connect('cursor-changed', self._on_view_thread)
76
        if self.tree is not None:
77
            self._threads_view.connect('row-activated', self._on_switch_thread)
78
79
        self._diff = DiffWidget()
80
        self._diff.show()
81
        hbox.pack_end(self._diff)
82
83
        hbox.show_all()
734.1.1 by Curtis Hovey
Mechanical changes made by pygi.convert.sh.
84
        self.vbox.pack_start(hbox, True, True, 0)
580.1.1 by Jelmer Vernooij
Add gloom command.
85
580.1.4 by Jelmer Vernooij
Update FIXME, add news entry.
86
        # FIXME: Buttons: combine-thread, revert-loom, record
580.1.3 by Jelmer Vernooij
Show diffs of threads, allow switching to different threads.
87
        self.set_default_size(500, 350)
88
89
    def _on_view_thread(self, treeview):
90
        treeselection = treeview.get_selection()
91
        (model, selection) = treeselection.get_selected()
92
        if selection is None:
93
            return
94
        revid, parent_revid = model.get(selection, 1, 3)
95
        if parent_revid is None:
96
            return
97
        self.branch.lock_read()
98
        try:
99
            (rev_tree, parent_tree) = tuple(self.branch.repository.revision_trees([revid, parent_revid]))
100
            self._diff.set_diff(rev_tree, parent_tree)
101
        finally:
102
            self.branch.unlock()
103
104
    def _on_switch_thread(self, treeview, path, view_column):
105
        new_thread = self._threads_store.get_value(self._threads_store.get_iter(path), 0)
106
        self.tree.down_thread(new_thread)
580.1.2 by Jelmer Vernooij
Show threads in loom dialog.
107
108
    def _load_threads(self):
109
        self._threads_store.clear()
110
        
111
        self.branch.lock_read()
112
        try:
113
            threads = self.branch.get_loom_state().get_threads()
580.1.3 by Jelmer Vernooij
Show diffs of threads, allow switching to different threads.
114
            last_revid = None
115
            for name, revid, parent_ids in reversed(threads):
116
                self._threads_store.append([name, revid, parent_ids, last_revid])
117
                last_revid = revid
580.1.2 by Jelmer Vernooij
Show threads in loom dialog.
118
        finally:
119
            self.branch.unlock()