/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 viz/diffwin.py

  • Committer: Jelmer Vernooij
  • Date: 2006-05-19 16:37:13 UTC
  • Revision ID: jelmer@samba.org-20060519163713-be77b31c72cbc7e8
Move visualisation code to a separate directory, preparing for bundling 
the GTK+ plugins for bzr.

Show diffs side-by-side

added added

removed removed

Lines of Context:
14
14
 
15
15
import gtk
16
16
import pango
17
 
import sys
18
17
 
19
18
try:
20
19
    import gtksourceview
22
21
except ImportError:
23
22
    have_gtksourceview = False
24
23
 
25
 
import bzrlib
26
 
 
 
24
from bzrlib.delta import compare_trees
27
25
from bzrlib.diff import show_diff_trees
28
 
from bzrlib.errors import NoSuchFile
29
26
 
30
27
 
31
28
class DiffWindow(gtk.Window):
35
32
    differences between two revisions on a branch.
36
33
    """
37
34
 
38
 
    def __init__(self):
 
35
    def __init__(self, app=None):
39
36
        gtk.Window.__init__(self, gtk.WINDOW_TOPLEVEL)
40
37
        self.set_border_width(0)
41
38
        self.set_title("bzrk diff")
42
39
 
 
40
        self.app = app
 
41
 
43
42
        # Use two thirds of the screen by default
44
43
        screen = self.get_screen()
45
44
        monitor = screen.get_monitor_geometry(0)
51
50
 
52
51
    def construct(self):
53
52
        """Construct the window contents."""
54
 
        # The   window  consists  of   a  pane   containing:  the
55
 
        # hierarchical list  of files on  the left, and  the diff
56
 
        # for the currently selected file on the right.
57
 
        pane = gtk.HPaned()
58
 
        self.add(pane)
59
 
        pane.show()
 
53
        hbox = gtk.HBox(spacing=6)
 
54
        hbox.set_border_width(12)
 
55
        self.add(hbox)
 
56
        hbox.show()
60
57
 
61
 
        # The file hierarchy: a scrollable treeview
62
58
        scrollwin = gtk.ScrolledWindow()
63
59
        scrollwin.set_policy(gtk.POLICY_NEVER, gtk.POLICY_AUTOMATIC)
64
60
        scrollwin.set_shadow_type(gtk.SHADOW_IN)
65
 
        pane.pack1(scrollwin)
 
61
        hbox.pack_start(scrollwin, expand=False, fill=True)
66
62
        scrollwin.show()
67
63
 
68
64
        self.model = gtk.TreeStore(str, str)
80
76
        column.add_attribute(cell, "text", 0)
81
77
        self.treeview.append_column(column)
82
78
 
83
 
        # The diffs of the  selected file: a scrollable source or
84
 
        # text view
 
79
 
85
80
        scrollwin = gtk.ScrolledWindow()
86
81
        scrollwin.set_policy(gtk.POLICY_AUTOMATIC, gtk.POLICY_AUTOMATIC)
87
82
        scrollwin.set_shadow_type(gtk.SHADOW_IN)
88
 
        pane.pack2(scrollwin)
 
83
        hbox.pack_start(scrollwin, expand=True, fill=True)
89
84
        scrollwin.show()
90
85
 
91
86
        if have_gtksourceview:
105
100
        scrollwin.add(sourceview)
106
101
        sourceview.show()
107
102
 
108
 
    def set_diff(self, description, rev_tree, parent_tree):
 
103
    def set_diff(self, branch, revid, parentid):
109
104
        """Set the differences showed by this window.
110
105
 
111
106
        Compares the two trees and populates the window with the
112
107
        differences.
113
108
        """
114
 
        self.rev_tree = rev_tree
115
 
        self.parent_tree = parent_tree
 
109
        self.rev_tree = branch.repository.revision_tree(revid)
 
110
        self.parent_tree = branch.repository.revision_tree(parentid)
116
111
 
117
112
        self.model.clear()
118
 
        delta = self.rev_tree.changes_from(self.parent_tree)
 
113
        delta = compare_trees(self.parent_tree, self.rev_tree)
119
114
 
120
115
        self.model.append(None, [ "Complete Diff", "" ])
121
116
 
133
128
            titer = self.model.append(None, [ "Renamed", None ])
134
129
            for oldpath, newpath, id, kind, text_modified, meta_modified \
135
130
                    in delta.renamed:
136
 
                self.model.append(titer, [ oldpath, newpath ])
 
131
                self.model.append(titer, [ oldpath, oldpath ])
137
132
 
138
133
        if len(delta.modified):
139
134
            titer = self.model.append(None, [ "Modified", None ])
141
136
                self.model.append(titer, [ path, path ])
142
137
 
143
138
        self.treeview.expand_all()
144
 
        self.set_title(description + " - bzrk diff")
145
 
 
146
 
    def set_file(self, file_path):
147
 
        tv_path = None
148
 
        for data in self.model:
149
 
            for child in data.iterchildren():
150
 
                if child[0] == file_path or child[1] == file_path:
151
 
                    tv_path = child.path
152
 
                    break
153
 
        if tv_path is None:
154
 
            raise NoSuchFile(file_path)
155
 
        self.treeview.set_cursor(tv_path)
156
 
        self.treeview.scroll_to_cell(tv_path)
 
139
        self.set_title(revid + " - " + branch.nick + " - bzrk diff")
157
140
 
158
141
    def _treeview_cursor_cb(self, *args):
159
142
        """Callback for when the treeview cursor changes."""
166
149
 
167
150
        s = StringIO()
168
151
        show_diff_trees(self.parent_tree, self.rev_tree, s, specific_files)
169
 
        self.buffer.set_text(s.getvalue().decode(sys.getdefaultencoding(), 'replace'))
 
152
        self.buffer.set_text(s.getvalue())