/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 09:56:34 UTC
  • mto: This revision was merged to the branch mainline in revision 492.
  • Revision ID: aaron@aaronbentley.com-20080508095634-mxdov4qryx2stow3
Much refactoring

Show diffs side-by-side

added added

removed removed

Lines of Context:
327
327
        """
328
328
        # The diffs of the  selected file: a scrollable source or
329
329
        # text view
 
330
 
 
331
    def set_diff_text_sections(self, sections):
330
332
        self.diff_view = DiffFileView()
331
333
        self.diff_view.show()
332
334
        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]
 
335
        for oldname, newname, patch in sections:
 
336
            self.diff_view._diffs[newname] = str(patch)
 
337
            if newname is None:
 
338
                newname = ''
338
339
            self.model.append(None, [oldname, newname])
339
 
            self.diff_view._diffs[newname] = str(patch)
340
340
        self.diff_view.show_diff(None)
341
341
 
342
342
    def set_diff(self, rev_tree, parent_tree):
423
423
        width = int(monitor.width * 0.66)
424
424
        height = int(monitor.height * 0.66)
425
425
        self.set_default_size(width, height)
426
 
        self.operations = operations
427
 
        self.construct()
 
426
        self.construct(operations)
428
427
 
429
 
    def construct(self):
 
428
    def construct(self, operations):
430
429
        """Construct the window contents."""
431
430
        self.vbox = gtk.VBox()
432
431
        self.add(self.vbox)
433
432
        self.vbox.show()
434
 
        hbox = self._get_button_bar()
 
433
        hbox = self._get_button_bar(operations)
435
434
        if hbox is not None:
436
435
            self.vbox.pack_start(hbox, expand=False, fill=True)
437
436
        self.diff = DiffWidget()
438
437
        self.vbox.add(self.diff)
439
438
        self.diff.show_all()
440
439
 
441
 
    def _get_button_bar(self):
 
440
    def _get_button_bar(self, operations):
442
441
        """Return a button bar to use.
443
442
 
444
443
        :return: None, meaning that no button bar will be used.
445
444
        """
446
 
        if self.operations is None:
 
445
        if operations is None:
447
446
            return None
448
447
        hbox = gtk.HButtonBox()
449
448
        hbox.set_layout(gtk.BUTTONBOX_START)
450
 
        for title, method in self.operations:
 
449
        for title, method in operations:
451
450
            merge_button = gtk.Button(title)
452
451
            merge_button.show()
453
452
            merge_button.set_relief(gtk.RELIEF_NONE)
485
484
        finally:
486
485
            d.destroy()
487
486
 
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
487
    def set_diff(self, description, rev_tree, parent_tree):
498
488
        """Set the differences showed by this window.
499
489
 
511
501
 
512
502
    def __init__(self, path, patch, window=None):
513
503
        self.path = path
514
 
        self.window = None
515
504
        self.patch = patch
516
505
        if window is None:
517
506
            window = DiffWindow(operations=self._provide_operations())
518
507
            self.initialize_window(window)
 
508
        self.window = window
519
509
 
520
510
    def initialize_window(self, window):
521
 
        self.window = window
522
 
        window.set_diff_text(self.path, self.patch)
 
511
        window.diff.set_diff_text_sections(self.get_diff_sections())
 
512
        window.set_title(self.path + " - diff")
 
513
 
 
514
    def get_diff_sections(self):
 
515
        yield "Complete Diff", None, ''.join(self.patch)
 
516
        for patch in parse_patches(self.patch):
 
517
            oldname = patch.oldname.split('\t')[0]
 
518
            newname = patch.newname.split('\t')[0]
 
519
            yield oldname, newname, str(patch)
523
520
 
524
521
    def perform_save(self, window):
525
522
        try: