237
249
# self.parent_tree.unlock()
239
251
def show_diff(self, specific_files):
253
if specific_files is None:
254
self.buffer.set_text(self._diffs[None])
256
for specific_file in specific_files:
257
sections.append(self._diffs[specific_file])
258
self.buffer.set_text(''.join(sections))
261
class DiffView(DiffFileView):
262
"""This is the soft and chewy filling for a DiffWindow."""
265
DiffFileView.__init__(self)
267
self.parent_tree = None
269
def show_diff(self, specific_files):
270
"""Show the diff for the specified files"""
241
272
show_diff_trees(self.parent_tree, self.rev_tree, s, specific_files,
242
273
old_label='', new_label='',
261
292
self.buffer.set_text(decoded.encode('UTF-8'))
264
class DiffWindow(Window):
295
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.
300
super(DiffWidget, self).__init__()
294
302
# The file hierarchy: a scrollable treeview
295
303
scrollwin = gtk.ScrolledWindow()
296
304
scrollwin.set_policy(gtk.POLICY_NEVER, gtk.POLICY_AUTOMATIC)
297
305
scrollwin.set_shadow_type(gtk.SHADOW_IN)
298
pane.pack1(scrollwin)
306
self.pack1(scrollwin)
301
309
self.model = gtk.TreeStore(str, str)
313
321
column.add_attribute(cell, "text", 0)
314
322
self.treeview.append_column(column)
324
def set_diff_text(self, lines):
325
"""Set the current diff from a list of lines
327
:param lines: The diff to show, in unified diff format
316
329
# The diffs of the selected file: a scrollable source or
331
self.diff_view = DiffFileView()
332
self.diff_view.show()
333
self.pack2(self.diff_view)
334
self.model.append(None, [ "Complete Diff", "" ])
335
self.diff_view._diffs[None] = ''.join(lines)
336
for patch in parse_patches(lines):
337
oldname = patch.oldname.split('\t')[0]
338
newname = patch.newname.split('\t')[0]
339
self.model.append(None, [oldname, newname])
340
self.diff_view._diffs[newname] = str(patch)
341
self.diff_view.show_diff(None)
343
def set_diff(self, rev_tree, parent_tree):
344
"""Set the differences showed by this window.
346
Compares the two trees and populates the window with the
318
349
self.diff_view = DiffView()
319
pane.pack2(self.diff_view)
350
self.pack2(self.diff_view)
320
351
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
352
self.diff_view.set_trees(rev_tree, parent_tree)
329
353
self.rev_tree = rev_tree
330
354
self.parent_tree = parent_tree
382
406
self.diff_view.show_diff(specific_files)
385
def _iter_changes_to_status(source, target):
409
class DiffWindow(Window):
412
This object represents and manages a single window containing the
413
differences between two revisions on a branch.
416
def __init__(self, parent=None):
417
Window.__init__(self, parent)
418
self.set_border_width(0)
419
self.set_title("bzrk diff")
421
# Use two thirds of the screen by default
422
screen = self.get_screen()
423
monitor = screen.get_monitor_geometry(0)
424
width = int(monitor.width * 0.66)
425
height = int(monitor.height * 0.66)
426
self.set_default_size(width, height)
431
"""Construct the window contents."""
432
self.vbox = gtk.VBox()
435
hbox = self._get_button_bar()
437
self.vbox.pack_start(hbox, expand=False, fill=True)
438
self.diff = DiffWidget()
439
self.vbox.add(self.diff)
442
def _get_button_bar(self):
443
"""Return a button bar to use.
445
:return: None, meaning that no button bar will be used.
449
def set_diff_text(self, description, lines):
450
"""Set the diff from a text.
452
The diff must be in unified diff format, and will be parsed to
455
self.diff.set_diff_text(lines)
456
self.set_title(description + " - bzrk diff")
458
def set_diff(self, description, rev_tree, parent_tree):
459
"""Set the differences showed by this window.
461
Compares the two trees and populates the window with the
464
self.diff.set_diff(rev_tree, parent_tree)
465
self.set_title(description + " - bzrk diff")
467
def set_file(self, file_path):
468
self.diff.set_file(file_path)
471
class MergeDirectiveWindow(DiffWindow):
473
def __init__(self, directive, path):
474
DiffWindow.__init__(self, None)
475
self._merge_target = None
476
self.directive = directive
479
def _get_button_bar(self):
480
"""The button bar has only the Merge button"""
481
merge_button = gtk.Button('Merge')
483
merge_button.set_relief(gtk.RELIEF_NONE)
484
merge_button.connect("clicked", self.perform_merge)
486
save_button = gtk.Button('Save')
488
save_button.set_relief(gtk.RELIEF_NONE)
489
save_button.connect("clicked", self.perform_save)
491
hbox = gtk.HButtonBox()
492
hbox.set_layout(gtk.BUTTONBOX_START)
493
hbox.pack_start(merge_button, expand=False, fill=True)
494
hbox.pack_start(save_button, expand=False, fill=True)
498
def perform_merge(self, window):
500
tree = self._get_merge_target()
501
except SelectCancelled:
506
merger, verified = _mod_merge.Merger.from_mergeable(tree,
507
self.directive, progress.DummyProgress())
508
merger.check_basis(True)
509
merger.merge_type = _mod_merge.Merge3Merger
510
conflict_count = merger.do_merge()
512
if conflict_count == 0:
513
# No conflicts found.
514
info_dialog(_i18n('Merge successful'),
515
_i18n('All changes applied successfully.'))
517
# There are conflicts to be resolved.
518
warning_dialog(_i18n('Conflicts encountered'),
519
_i18n('Please resolve the conflicts manually'
520
' before committing.'))
523
error_dialog('Error', str(e))
527
def _get_merge_target(self):
528
if self._merge_target is not None:
529
return self._merge_target
530
d = gtk.FileChooserDialog('Merge branch', self,
531
gtk.FILE_CHOOSER_ACTION_SELECT_FOLDER,
532
buttons=(gtk.STOCK_OK, gtk.RESPONSE_OK,
534
gtk.RESPONSE_CANCEL,))
537
if result != gtk.RESPONSE_OK:
538
raise SelectCancelled()
539
uri = d.get_current_folder_uri()
542
return workingtree.WorkingTree.open(uri)
544
def perform_save(self, window):
545
d = gtk.FileChooserDialog('Save As', self,
546
gtk.FILE_CHOOSER_ACTION_SAVE,
547
buttons=(gtk.STOCK_OK, gtk.RESPONSE_OK,
549
gtk.RESPONSE_CANCEL,))
550
d.set_current_name(osutils.basename(self.path))
554
if result != gtk.RESPONSE_OK:
555
raise SelectCancelled()
559
except SelectCancelled:
561
source = open(self.path, 'rb')
563
target = open(urlutils.local_path_from_url(uri), 'wb')
565
target.write(source.read())
572
def iter_changes_to_status(source, target):
386
573
"""Determine the differences between trees.
388
This is a wrapper around _iter_changes which just yields more
575
This is a wrapper around iter_changes which just yields more
389
576
understandable results.
391
578
:param source: The source tree (basis tree)