/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: Aaron Bentley
  • Date: 2008-05-08 08:45:15 UTC
  • mto: This revision was merged to the branch mainline in revision 492.
  • Revision ID: aaron@aaronbentley.com-20080508084515-0h1ge28g39mqab5s
Unify MergeDirectiveWindow and DiffWindow

Show diffs side-by-side

added added

removed removed

Lines of Context:
41
41
from bzrlib.errors import NoSuchFile
42
42
from bzrlib.patches import parse_patches
43
43
from bzrlib.trace import warning
44
 
from bzrlib.plugins.gtk import _i18n
45
44
from bzrlib.plugins.gtk.window import Window
46
45
from dialog import error_dialog, info_dialog, warning_dialog
47
46
 
328
327
        """
329
328
        # The diffs of the  selected file: a scrollable source or
330
329
        # text view
331
 
 
332
 
    def set_diff_text_sections(self, sections):
333
330
        self.diff_view = DiffFileView()
334
331
        self.diff_view.show()
335
332
        self.pack2(self.diff_view)
336
 
        for oldname, newname, patch in sections:
 
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])
337
339
            self.diff_view._diffs[newname] = str(patch)
338
 
            if newname is None:
339
 
                newname = ''
340
 
            self.model.append(None, [oldname, newname])
341
340
        self.diff_view.show_diff(None)
342
341
 
343
342
    def set_diff(self, rev_tree, parent_tree):
424
423
        width = int(monitor.width * 0.66)
425
424
        height = int(monitor.height * 0.66)
426
425
        self.set_default_size(width, height)
427
 
        self.construct(operations)
 
426
        self.operations = operations
 
427
        self.construct()
428
428
 
429
 
    def construct(self, operations):
 
429
    def construct(self):
430
430
        """Construct the window contents."""
431
431
        self.vbox = gtk.VBox()
432
432
        self.add(self.vbox)
433
433
        self.vbox.show()
434
 
        hbox = self._get_button_bar(operations)
 
434
        hbox = self._get_button_bar()
435
435
        if hbox is not None:
436
436
            self.vbox.pack_start(hbox, expand=False, fill=True)
437
437
        self.diff = DiffWidget()
438
438
        self.vbox.add(self.diff)
439
439
        self.diff.show_all()
440
440
 
441
 
    def _get_button_bar(self, operations):
 
441
    def _get_button_bar(self):
442
442
        """Return a button bar to use.
443
443
 
444
444
        :return: None, meaning that no button bar will be used.
445
445
        """
446
 
        if operations is None:
 
446
        if self.operations is None:
447
447
            return None
448
448
        hbox = gtk.HButtonBox()
449
449
        hbox.set_layout(gtk.BUTTONBOX_START)
450
 
        for title, method in operations:
 
450
        for title, method in self.operations:
451
451
            merge_button = gtk.Button(title)
452
452
            merge_button.show()
453
453
            merge_button.set_relief(gtk.RELIEF_NONE)
470
470
        finally:
471
471
            d.destroy()
472
472
 
473
 
    def _merge_successful(self):
474
 
        # No conflicts found.
475
 
        info_dialog(_i18n('Merge successful'),
476
 
                    _i18n('All changes applied successfully.'))
477
 
 
478
 
    def _conflicts(self):
479
 
        warning_dialog(_i18n('Conflicts encountered'),
480
 
                       _i18n('Please resolve the conflicts manually'
481
 
                             ' before committing.'))
482
 
 
483
 
    def _handle_error(self, e):
484
 
        error_dialog('Error', str(e))
485
 
 
486
473
    def _get_save_path(self, basename):
487
474
        d = gtk.FileChooserDialog('Save As', self,
488
475
                                  gtk.FILE_CHOOSER_ACTION_SAVE,
498
485
        finally:
499
486
            d.destroy()
500
487
 
 
488
    def set_diff_text(self, description, lines):
 
489
        """Set the diff from a text.
 
490
 
 
491
        The diff must be in unified diff format, and will be parsed to
 
492
        determine filenames.
 
493
        """
 
494
        self.diff.set_diff_text(lines)
 
495
        self.set_title(description + " - bzrk diff")
 
496
 
501
497
    def set_diff(self, description, rev_tree, parent_tree):
502
498
        """Set the differences showed by this window.
503
499
 
515
511
 
516
512
    def __init__(self, path, patch, window=None):
517
513
        self.path = path
 
514
        self.window = None
518
515
        self.patch = patch
519
516
        if window is None:
520
517
            window = DiffWindow(operations=self._provide_operations())
521
518
            self.initialize_window(window)
 
519
 
 
520
    def initialize_window(self, window):
522
521
        self.window = window
523
 
 
524
 
    def initialize_window(self, window):
525
 
        window.diff.set_diff_text_sections(self.get_diff_sections())
526
 
        window.set_title(self.path + " - diff")
527
 
 
528
 
    def get_diff_sections(self):
529
 
        yield "Complete Diff", None, ''.join(self.patch)
530
 
        for patch in parse_patches(self.patch):
531
 
            oldname = patch.oldname.split('\t')[0]
532
 
            newname = patch.newname.split('\t')[0]
533
 
            yield oldname, newname, str(patch)
 
522
        window.set_diff_text(self.path, self.patch)
534
523
 
535
524
    def perform_save(self, window):
536
525
        try:
553
542
 
554
543
class MergeDirectiveController(DiffController):
555
544
 
556
 
    def __init__(self, path, directive, window=None):
557
 
        DiffController.__init__(self, path, directive.patch.splitlines(True),
558
 
                                window)
 
545
    def __init__(self, path, directive):
 
546
        DiffController.__init__(self, path, directive.patch.splitlines(True))
559
547
        self.directive = directive
560
548
        self.merge_target = None
561
549
 
579
567
                conflict_count = merger.do_merge()
580
568
                merger.set_pending()
581
569
                if conflict_count == 0:
582
 
                    self.window._merge_successful()
 
570
                    # No conflicts found.
 
571
                    info_dialog(_('Merge successful'),
 
572
                                _('All changes applied successfully.'))
583
573
                else:
584
 
                    self.window._conflicts()
585
574
                    # There are conflicts to be resolved.
 
575
                    warning_dialog(_('Conflicts encountered'),
 
576
                                   _('Please resolve the conflicts manually'
 
577
                                     ' before committing.'))
586
578
                self.window.destroy()
587
579
            except Exception, e:
588
 
                self.window._handle_error(e)
 
580
                error_dialog('Error', str(e))
589
581
        finally:
590
582
            tree.unlock()
591
583