/b-gtk/fix-viz

To get this branch, use:
bzr branch http://gegoxaren.bato24.eu/bzr/b-gtk/fix-viz

« back to all changes in this revision

Viewing changes to loom.py

  • Committer: Jelmer Vernooij
  • Date: 2008-07-31 01:09:01 UTC
  • mto: (580.2.1 gtk.gloom)
  • mto: This revision was merged to the branch mainline in revision 581.
  • Revision ID: jelmer@samba.org-20080731010901-2wbyaorsf4wbukrx
Show diffs of threads, allow switching to different threads.

Show diffs side-by-side

added added

removed removed

Lines of Context:
24
24
import gobject
25
25
 
26
26
from bzrlib.plugins.gtk import _i18n
 
27
from bzrlib.plugins.gtk.diff import DiffWidget
27
28
from bzrlib.plugins.gtk.dialog import question_dialog
28
29
from bzrlib.plugins.loom import branch as loom_branch
 
30
from bzrlib.plugins.loom import tree as loom_tree
29
31
 
30
32
class LoomDialog(gtk.Dialog):
31
33
    """Simple Loom browse dialog."""
32
34
 
33
 
    def __init__(self, branch, parent=None):
 
35
    def __init__(self, branch, tree=None, parent=None):
34
36
        gtk.Dialog.__init__(self, title="Threads",
35
37
                                  parent=parent,
36
38
                                  flags=0,
37
39
                                  buttons=(gtk.STOCK_CLOSE,gtk.RESPONSE_OK))
38
40
        self.branch = branch
 
41
        if tree is not None:
 
42
            self.tree = loom_tree.LoomTreeDecorator(tree)
 
43
        else:
 
44
            self.tree = None
39
45
 
40
46
        self._construct()
 
47
        self._load_threads()
41
48
 
42
49
    def run(self):
43
50
        try:
55
62
        return super(LoomDialog, self).run()
56
63
 
57
64
    def _construct(self):
 
65
        hbox = gtk.HBox()
 
66
 
58
67
        self._threads_scroller = gtk.ScrolledWindow()
59
68
        self._threads_scroller.set_policy(gtk.POLICY_AUTOMATIC, gtk.POLICY_AUTOMATIC)
60
69
        self._threads_view = gtk.TreeView()
61
 
        self._threads_view.show()
62
70
        self._threads_scroller.add(self._threads_view)
63
71
        self._threads_scroller.set_shadow_type(gtk.SHADOW_IN)
64
 
        self._threads_scroller.show()
65
 
        self.vbox.pack_start(self._threads_scroller)
 
72
        hbox.pack_start(self._threads_scroller)
66
73
 
67
74
        self._threads_store = gtk.ListStore(
68
 
                gobject.TYPE_STRING, gobject.TYPE_STRING, gobject.TYPE_PYOBJECT)
 
75
                gobject.TYPE_STRING, gobject.TYPE_STRING, gobject.TYPE_PYOBJECT, gobject.TYPE_STRING)
69
76
        self._threads_view.set_model(self._threads_store)
70
77
        self._threads_view.append_column(gtk.TreeViewColumn("Name", gtk.CellRendererText(), text=0))
 
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)
71
88
 
72
89
        # Buttons: combine-thread, export-loom, revert-loom, up-thread
73
 
        self.set_default_size(200, 350)
74
 
 
75
 
        self._load_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)
76
110
 
77
111
    def _load_threads(self):
78
112
        self._threads_store.clear()
80
114
        self.branch.lock_read()
81
115
        try:
82
116
            threads = self.branch.get_loom_state().get_threads()
83
 
            for thread in reversed(threads):
84
 
                self._threads_store.append(thread)
 
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
85
121
        finally:
86
122
            self.branch.unlock()