/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: 2008-06-29 16:24:24 UTC
  • mto: This revision was merged to the branch mainline in revision 519.
  • Revision ID: jelmer@samba.org-20080629162424-48a6rrjmmpejfcyr
Stop emitting no longer used revisions-loaded message.

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
44
45
from bzrlib.plugins.gtk.window import Window
45
46
from dialog import error_dialog, info_dialog, warning_dialog
46
47
 
327
328
        """
328
329
        # The diffs of the  selected file: a scrollable source or
329
330
        # text view
 
331
 
 
332
    def set_diff_text_sections(self, sections):
330
333
        self.diff_view = DiffFileView()
331
334
        self.diff_view.show()
332
335
        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]
 
336
        for oldname, newname, patch in sections:
 
337
            self.diff_view._diffs[newname] = str(patch)
 
338
            if newname is None:
 
339
                newname = ''
338
340
            self.model.append(None, [oldname, newname])
339
 
            self.diff_view._diffs[newname] = str(patch)
340
341
        self.diff_view.show_diff(None)
341
342
 
342
343
    def set_diff(self, rev_tree, parent_tree):
423
424
        width = int(monitor.width * 0.66)
424
425
        height = int(monitor.height * 0.66)
425
426
        self.set_default_size(width, height)
426
 
        self.operations = operations
427
 
        self.construct()
 
427
        self.construct(operations)
428
428
 
429
 
    def construct(self):
 
429
    def construct(self, operations):
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()
 
434
        hbox = self._get_button_bar(operations)
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):
 
441
    def _get_button_bar(self, operations):
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 self.operations is None:
 
446
        if 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 self.operations:
 
450
        for title, method in 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
 
473
486
    def _get_save_path(self, basename):
474
487
        d = gtk.FileChooserDialog('Save As', self,
475
488
                                  gtk.FILE_CHOOSER_ACTION_SAVE,
485
498
        finally:
486
499
            d.destroy()
487
500
 
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
 
 
497
501
    def set_diff(self, description, rev_tree, parent_tree):
498
502
        """Set the differences showed by this window.
499
503
 
511
515
 
512
516
    def __init__(self, path, patch, window=None):
513
517
        self.path = path
514
 
        self.window = None
515
518
        self.patch = patch
516
519
        if window is None:
517
520
            window = DiffWindow(operations=self._provide_operations())
518
521
            self.initialize_window(window)
 
522
        self.window = window
519
523
 
520
524
    def initialize_window(self, window):
521
 
        self.window = window
522
 
        window.set_diff_text(self.path, self.patch)
 
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)
523
534
 
524
535
    def perform_save(self, window):
525
536
        try:
542
553
 
543
554
class MergeDirectiveController(DiffController):
544
555
 
545
 
    def __init__(self, path, directive):
546
 
        DiffController.__init__(self, path, directive.patch.splitlines(True))
 
556
    def __init__(self, path, directive, window=None):
 
557
        DiffController.__init__(self, path, directive.patch.splitlines(True),
 
558
                                window)
547
559
        self.directive = directive
548
560
        self.merge_target = None
549
561
 
567
579
                conflict_count = merger.do_merge()
568
580
                merger.set_pending()
569
581
                if conflict_count == 0:
570
 
                    # No conflicts found.
571
 
                    info_dialog(_('Merge successful'),
572
 
                                _('All changes applied successfully.'))
 
582
                    self.window._merge_successful()
573
583
                else:
 
584
                    self.window._conflicts()
574
585
                    # There are conflicts to be resolved.
575
 
                    warning_dialog(_('Conflicts encountered'),
576
 
                                   _('Please resolve the conflicts manually'
577
 
                                     ' before committing.'))
578
586
                self.window.destroy()
579
587
            except Exception, e:
580
 
                error_dialog('Error', str(e))
 
588
                self.window._handle_error(e)
581
589
        finally:
582
590
            tree.unlock()
583
591