237
248
# self.parent_tree.unlock()
239
250
def show_diff(self, specific_files):
252
if specific_files is None:
253
self.buffer.set_text(self._diffs[None])
255
for specific_file in specific_files:
256
sections.append(self._diffs[specific_file])
257
self.buffer.set_text(''.join(sections))
260
class DiffView(DiffFileView):
261
"""This is the soft and chewy filling for a DiffWindow."""
264
DiffFileView.__init__(self)
266
self.parent_tree = None
268
def show_diff(self, specific_files):
269
"""Show the diff for the specified files"""
241
271
show_diff_trees(self.parent_tree, self.rev_tree, s, specific_files,
242
272
old_label='', new_label='',
261
291
self.buffer.set_text(decoded.encode('UTF-8'))
264
class DiffWindow(Window):
294
class DiffWidget(gtk.HPaned):
267
This object represents and manages a single window containing the
268
differences between two revisions on a branch.
271
def __init__(self, parent=None):
272
Window.__init__(self, parent)
273
self.set_border_width(0)
274
self.set_title("bzrk diff")
276
# Use two thirds of the screen by default
277
screen = self.get_screen()
278
monitor = screen.get_monitor_geometry(0)
279
width = int(monitor.width * 0.66)
280
height = int(monitor.height * 0.66)
281
self.set_default_size(width, height)
286
"""Construct the window contents."""
287
# The window consists of a pane containing: the
288
# hierarchical list of files on the left, and the diff
289
# for the currently selected file on the right.
299
super(DiffWidget, self).__init__()
294
301
# The file hierarchy: a scrollable treeview
295
302
scrollwin = gtk.ScrolledWindow()
296
303
scrollwin.set_policy(gtk.POLICY_NEVER, gtk.POLICY_AUTOMATIC)
297
304
scrollwin.set_shadow_type(gtk.SHADOW_IN)
298
pane.pack1(scrollwin)
305
self.pack1(scrollwin)
301
308
self.model = gtk.TreeStore(str, str)
313
320
column.add_attribute(cell, "text", 0)
314
321
self.treeview.append_column(column)
323
def set_diff_text(self, lines):
324
"""Set the current diff from a list of lines
326
:param lines: The diff to show, in unified diff format
316
328
# The diffs of the selected file: a scrollable source or
330
self.diff_view = DiffFileView()
331
self.diff_view.show()
332
self.pack2(self.diff_view)
333
self.model.append(None, [ "Complete Diff", "" ])
334
self.diff_view._diffs[None] = ''.join(lines)
335
for patch in parse_patches(lines):
336
oldname = patch.oldname.split('\t')[0]
337
newname = patch.newname.split('\t')[0]
338
self.model.append(None, [oldname, newname])
339
self.diff_view._diffs[newname] = str(patch)
340
self.diff_view.show_diff(None)
342
def set_diff(self, rev_tree, parent_tree):
343
"""Set the differences showed by this window.
345
Compares the two trees and populates the window with the
318
348
self.diff_view = DiffView()
319
pane.pack2(self.diff_view)
349
self.pack2(self.diff_view)
320
350
self.diff_view.show()
322
def set_diff(self, description, rev_tree, parent_tree):
323
"""Set the differences showed by this window.
325
Compares the two trees and populates the window with the
328
351
self.diff_view.set_trees(rev_tree, parent_tree)
329
352
self.rev_tree = rev_tree
330
353
self.parent_tree = parent_tree
382
405
self.diff_view.show_diff(specific_files)
385
def _iter_changes_to_status(source, target):
408
class DiffWindow(Window):
411
This object represents and manages a single window containing the
412
differences between two revisions on a branch.
415
def __init__(self, parent=None):
416
Window.__init__(self, parent)
417
self.set_border_width(0)
418
self.set_title("bzrk diff")
420
# Use two thirds of the screen by default
421
screen = self.get_screen()
422
monitor = screen.get_monitor_geometry(0)
423
width = int(monitor.width * 0.66)
424
height = int(monitor.height * 0.66)
425
self.set_default_size(width, height)
430
"""Construct the window contents."""
431
self.vbox = gtk.VBox()
434
hbox = self._get_button_bar()
436
self.vbox.pack_start(hbox, expand=False, fill=True)
437
self.diff = DiffWidget()
438
self.vbox.add(self.diff)
441
def _get_button_bar(self):
442
"""Return a button bar to use.
444
:return: None, meaning that no button bar will be used.
448
def set_diff_text(self, description, lines):
449
"""Set the diff from a text.
451
The diff must be in unified diff format, and will be parsed to
454
self.diff.set_diff_text(lines)
455
self.set_title(description + " - bzrk diff")
457
def set_diff(self, description, rev_tree, parent_tree):
458
"""Set the differences showed by this window.
460
Compares the two trees and populates the window with the
463
self.diff.set_diff(rev_tree, parent_tree)
464
self.set_title(description + " - bzrk diff")
466
def set_file(self, file_path):
467
self.diff.set_file(file_path)
470
class MergeDirectiveWindow(DiffWindow):
472
def __init__(self, directive, path):
473
DiffWindow.__init__(self, None)
474
self._merge_target = None
475
self.directive = directive
478
def _get_button_bar(self):
479
"""The button bar has only the Merge button"""
480
merge_button = gtk.Button('Merge')
482
merge_button.set_relief(gtk.RELIEF_NONE)
483
merge_button.connect("clicked", self.perform_merge)
485
save_button = gtk.Button('Save')
487
save_button.set_relief(gtk.RELIEF_NONE)
488
save_button.connect("clicked", self.perform_save)
490
hbox = gtk.HButtonBox()
491
hbox.set_layout(gtk.BUTTONBOX_START)
492
hbox.pack_start(merge_button, expand=False, fill=True)
493
hbox.pack_start(save_button, expand=False, fill=True)
497
def perform_merge(self, window):
499
tree = self._get_merge_target()
500
except SelectCancelled:
505
merger, verified = _mod_merge.Merger.from_mergeable(tree,
506
self.directive, progress.DummyProgress())
507
merger.check_basis(True)
508
merger.merge_type = _mod_merge.Merge3Merger
509
conflict_count = merger.do_merge()
511
if conflict_count == 0:
512
# No conflicts found.
513
info_dialog(_('Merge successful'),
514
_('All changes applied successfully.'))
516
# There are conflicts to be resolved.
517
warning_dialog(_('Conflicts encountered'),
518
_('Please resolve the conflicts manually'
519
' before committing.'))
522
error_dialog('Error', str(e))
526
def _get_merge_target(self):
527
if self._merge_target is not None:
528
return self._merge_target
529
d = gtk.FileChooserDialog('Merge branch', self,
530
gtk.FILE_CHOOSER_ACTION_SELECT_FOLDER,
531
buttons=(gtk.STOCK_OK, gtk.RESPONSE_OK,
533
gtk.RESPONSE_CANCEL,))
536
if result != gtk.RESPONSE_OK:
537
raise SelectCancelled()
538
uri = d.get_current_folder_uri()
541
return workingtree.WorkingTree.open(uri)
543
def perform_save(self, window):
544
d = gtk.FileChooserDialog('Save As', self,
545
gtk.FILE_CHOOSER_ACTION_SAVE,
546
buttons=(gtk.STOCK_OK, gtk.RESPONSE_OK,
548
gtk.RESPONSE_CANCEL,))
549
d.set_current_name(osutils.basename(self.path))
553
if result != gtk.RESPONSE_OK:
554
raise SelectCancelled()
558
except SelectCancelled:
560
source = open(self.path, 'rb')
562
target = open(urlutils.local_path_from_url(uri), 'wb')
564
target.write(source.read())
571
def iter_changes_to_status(source, target):
386
572
"""Determine the differences between trees.
388
This is a wrapper around _iter_changes which just yields more
574
This is a wrapper around iter_changes which just yields more
389
575
understandable results.
391
577
:param source: The source tree (basis tree)