37
37
from bzrlib.trace import warning
40
class DiffWindow(gtk.Window):
43
This object represents and manages a single window containing the
44
differences between two revisions on a branch.
40
class DiffDisplay(gtk.ScrolledWindow):
41
"""This is the soft and chewy filling for a DiffWindow."""
47
43
def __init__(self):
48
gtk.Window.__init__(self, gtk.WINDOW_TOPLEVEL)
49
self.set_border_width(0)
50
self.set_title("bzrk diff")
52
# Use two thirds of the screen by default
53
screen = self.get_screen()
54
monitor = screen.get_monitor_geometry(0)
55
width = int(monitor.width * 0.66)
56
height = int(monitor.height * 0.66)
57
self.set_default_size(width, height)
44
gtk.ScrolledWindow.__init__(self)
48
self.parent_tree = None
61
50
def construct(self):
62
"""Construct the window contents."""
63
# The window consists of a pane containing: the
64
# hierarchical list of files on the left, and the diff
65
# for the currently selected file on the right.
70
# The file hierarchy: a scrollable treeview
71
scrollwin = gtk.ScrolledWindow()
72
scrollwin.set_policy(gtk.POLICY_NEVER, gtk.POLICY_AUTOMATIC)
73
scrollwin.set_shadow_type(gtk.SHADOW_IN)
77
self.model = gtk.TreeStore(str, str)
78
self.treeview = gtk.TreeView(self.model)
79
self.treeview.set_headers_visible(False)
80
self.treeview.set_search_column(1)
81
self.treeview.connect("cursor-changed", self._treeview_cursor_cb)
82
scrollwin.add(self.treeview)
85
cell = gtk.CellRendererText()
86
cell.set_property("width-chars", 20)
87
column = gtk.TreeViewColumn()
88
column.pack_start(cell, expand=True)
89
column.add_attribute(cell, "text", 0)
90
self.treeview.append_column(column)
92
# The diffs of the selected file: a scrollable source or
94
scrollwin = gtk.ScrolledWindow()
95
scrollwin.set_policy(gtk.POLICY_AUTOMATIC, gtk.POLICY_AUTOMATIC)
96
scrollwin.set_shadow_type(gtk.SHADOW_IN)
51
self.set_policy(gtk.POLICY_AUTOMATIC, gtk.POLICY_AUTOMATIC)
52
self.set_shadow_type(gtk.SHADOW_IN)
100
54
if have_gtksourceview:
101
55
self.buffer = gtksourceview.SourceBuffer()
115
69
sourceview.set_editable(False)
116
70
sourceview.modify_font(pango.FontDescription("Monospace"))
117
scrollwin.add(sourceview)
120
def set_diff(self, description, rev_tree, parent_tree):
121
"""Set the differences showed by this window.
123
Compares the two trees and populates the window with the
126
self.rev_tree = rev_tree
127
self.parent_tree = parent_tree
130
delta = self.rev_tree.changes_from(self.parent_tree)
132
self.model.append(None, [ "Complete Diff", "" ])
135
titer = self.model.append(None, [ "Added", None ])
136
for path, id, kind in delta.added:
137
self.model.append(titer, [ path, path ])
139
if len(delta.removed):
140
titer = self.model.append(None, [ "Removed", None ])
141
for path, id, kind in delta.removed:
142
self.model.append(titer, [ path, path ])
144
if len(delta.renamed):
145
titer = self.model.append(None, [ "Renamed", None ])
146
for oldpath, newpath, id, kind, text_modified, meta_modified \
148
self.model.append(titer, [ oldpath, newpath ])
150
if len(delta.modified):
151
titer = self.model.append(None, [ "Modified", None ])
152
for path, id, kind, text_modified, meta_modified in delta.modified:
153
self.model.append(titer, [ path, path ])
155
self.treeview.expand_all()
156
self.set_title(description + " - bzrk diff")
158
def set_file(self, file_path):
160
for data in self.model:
161
for child in data.iterchildren():
162
if child[0] == file_path or child[1] == file_path:
166
raise NoSuchFile(file_path)
167
self.treeview.set_cursor(tv_path)
168
self.treeview.scroll_to_cell(tv_path)
170
def _treeview_cursor_cb(self, *args):
171
"""Callback for when the treeview cursor changes."""
172
(path, col) = self.treeview.get_cursor()
173
specific_files = [ self.model[path][1] ]
174
if specific_files == [ None ]:
176
elif specific_files == [ "" ]:
177
specific_files = None
180
show_diff_trees(self.parent_tree, self.rev_tree, s, specific_files)
181
self.buffer.set_text(s.getvalue().decode(sys.getdefaultencoding(), 'replace'))
184
75
def apply_gedit_colors(lang):
185
76
"""Set style for lang to that specified in gedit configuration.
187
78
This method needs the gconf module.
189
80
:param lang: a gtksourceview.SourceLanguage object.
191
82
GEDIT_SYNTAX_PATH = '/apps/gedit-2/preferences/syntax_highlighting'
316
207
colors[key.strip()] = val.strip()
210
def set_trees(self, rev_tree, parent_tree):
211
self.rev_tree = rev_tree
212
self.parent_tree = parent_tree
214
def show_diff(self, specific_files):
216
show_diff_trees(self.parent_tree, self.rev_tree, s, specific_files)
217
self.buffer.set_text(s.getvalue().decode(sys.getdefaultencoding(), 'replace'))
220
class DiffWindow(gtk.Window):
223
This object represents and manages a single window containing the
224
differences between two revisions on a branch.
228
gtk.Window.__init__(self, gtk.WINDOW_TOPLEVEL)
229
self.set_border_width(0)
230
self.set_title("bzrk diff")
232
# Use two thirds of the screen by default
233
screen = self.get_screen()
234
monitor = screen.get_monitor_geometry(0)
235
width = int(monitor.width * 0.66)
236
height = int(monitor.height * 0.66)
237
self.set_default_size(width, height)
242
"""Construct the window contents."""
243
# The window consists of a pane containing: the
244
# hierarchical list of files on the left, and the diff
245
# for the currently selected file on the right.
250
# The file hierarchy: a scrollable treeview
251
scrollwin = gtk.ScrolledWindow()
252
scrollwin.set_policy(gtk.POLICY_NEVER, gtk.POLICY_AUTOMATIC)
253
scrollwin.set_shadow_type(gtk.SHADOW_IN)
254
pane.pack1(scrollwin)
257
self.model = gtk.TreeStore(str, str)
258
self.treeview = gtk.TreeView(self.model)
259
self.treeview.set_headers_visible(False)
260
self.treeview.set_search_column(1)
261
self.treeview.connect("cursor-changed", self._treeview_cursor_cb)
262
scrollwin.add(self.treeview)
265
cell = gtk.CellRendererText()
266
cell.set_property("width-chars", 20)
267
column = gtk.TreeViewColumn()
268
column.pack_start(cell, expand=True)
269
column.add_attribute(cell, "text", 0)
270
self.treeview.append_column(column)
272
# The diffs of the selected file: a scrollable source or
274
self.diff_win = DiffDisplay()
275
pane.pack2(self.diff_win)
278
def set_diff(self, description, rev_tree, parent_tree):
279
"""Set the differences showed by this window.
281
Compares the two trees and populates the window with the
284
self.diff_win.set_trees(rev_tree, parent_tree)
285
self.rev_tree = rev_tree
286
self.parent_tree = parent_tree
289
delta = self.rev_tree.changes_from(self.parent_tree)
291
self.model.append(None, [ "Complete Diff", "" ])
294
titer = self.model.append(None, [ "Added", None ])
295
for path, id, kind in delta.added:
296
self.model.append(titer, [ path, path ])
298
if len(delta.removed):
299
titer = self.model.append(None, [ "Removed", None ])
300
for path, id, kind in delta.removed:
301
self.model.append(titer, [ path, path ])
303
if len(delta.renamed):
304
titer = self.model.append(None, [ "Renamed", None ])
305
for oldpath, newpath, id, kind, text_modified, meta_modified \
307
self.model.append(titer, [ oldpath, newpath ])
309
if len(delta.modified):
310
titer = self.model.append(None, [ "Modified", None ])
311
for path, id, kind, text_modified, meta_modified in delta.modified:
312
self.model.append(titer, [ path, path ])
314
self.treeview.expand_all()
315
self.set_title(description + " - bzrk diff")
317
def set_file(self, file_path):
319
for data in self.model:
320
for child in data.iterchildren():
321
if child[0] == file_path or child[1] == file_path:
325
raise NoSuchFile(file_path)
326
self.treeview.set_cursor(tv_path)
327
self.treeview.scroll_to_cell(tv_path)
329
def _treeview_cursor_cb(self, *args):
330
"""Callback for when the treeview cursor changes."""
331
(path, col) = self.treeview.get_cursor()
332
specific_files = [ self.model[path][1] ]
333
if specific_files == [ None ]:
335
elif specific_files == [ "" ]:
336
specific_files = None
338
self.diff_win.show_diff(specific_files)