/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 diff.py

  • Committer: Jelmer Vernooij
  • Date: 2007-07-15 15:22:29 UTC
  • Revision ID: jelmer@samba.org-20070715152229-clmlen0vpd8d2pzx
Add docstrings, remove unused code.

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