/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 19:07:23 UTC
  • mto: This revision was merged to the branch mainline in revision 515.
  • Revision ID: jelmer@samba.org-20080629190723-l8mzg9x4oec0lhsl
Return cleartext from seahorse module

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
# -*- coding: UTF-8 -*-
1
2
"""Difference window.
2
3
 
3
4
This module contains the code to manage the diff window which shows
4
5
the changes made between two revisions on a branch.
5
6
"""
6
7
 
7
 
__copyright__ = "Copyright 2005 Canonical Ltd."
 
8
__copyright__ = "Copyright © 2005 Canonical Ltd."
8
9
__author__    = "Scott James Remnant <scott@ubuntu.com>"
9
10
 
10
11
 
72
73
            self.buffer.set_language(gsl)
73
74
            self.buffer.set_highlight(True)
74
75
 
75
 
            self.sourceview = gtksourceview.SourceView(self.buffer)
 
76
            sourceview = gtksourceview.SourceView(self.buffer)
76
77
        else:
77
78
            self.buffer = gtk.TextBuffer()
78
 
            self.sourceview = gtk.TextView(self.buffer)
 
79
            sourceview = gtk.TextView(self.buffer)
79
80
 
80
 
        self.sourceview.set_editable(False)
81
 
        self.sourceview.modify_font(pango.FontDescription("Monospace"))
82
 
        self.add(self.sourceview)
83
 
        self.sourceview.show()
 
81
        sourceview.set_editable(False)
 
82
        sourceview.modify_font(pango.FontDescription("Monospace"))
 
83
        self.add(sourceview)
 
84
        sourceview.show()
84
85
 
85
86
    @staticmethod
86
87
    def apply_gedit_colors(lang):
304
305
        scrollwin.set_shadow_type(gtk.SHADOW_IN)
305
306
        self.pack1(scrollwin)
306
307
        scrollwin.show()
307
 
        
 
308
 
308
309
        self.model = gtk.TreeStore(str, str)
309
310
        self.treeview = gtk.TreeView(self.model)
310
311
        self.treeview.set_headers_visible(False)
329
330
        # text view
330
331
 
331
332
    def set_diff_text_sections(self, sections):
332
 
        if getattr(self, 'diff_view', None) is None:
333
 
            self.diff_view = DiffFileView()
334
 
            self.pack2(self.diff_view)
 
333
        self.diff_view = DiffFileView()
335
334
        self.diff_view.show()
 
335
        self.pack2(self.diff_view)
336
336
        for oldname, newname, patch in sections:
337
337
            self.diff_view._diffs[newname] = str(patch)
338
338
            if newname is None:
346
346
        Compares the two trees and populates the window with the
347
347
        differences.
348
348
        """
349
 
        if getattr(self, 'diff_view', None) is None:
350
 
            self.diff_view = DiffView()
351
 
            self.pack2(self.diff_view)
 
349
        self.diff_view = DiffView()
 
350
        self.pack2(self.diff_view)
352
351
        self.diff_view.show()
353
352
        self.diff_view.set_trees(rev_tree, parent_tree)
354
353
        self.rev_tree = rev_tree
381
380
                self.model.append(titer, [ path, path ])
382
381
 
383
382
        self.treeview.expand_all()
384
 
        self.diff_view.show_diff(None)
385
383
 
386
384
    def set_file(self, file_path):
387
385
        """Select the current file to display"""
404
402
            return
405
403
        elif specific_files == [ "" ]:
406
404
            specific_files = None
407
 
        
 
405
 
408
406
        self.diff_view.show_diff(specific_files)
409
 
    
410
 
    def _on_wraplines_toggled(self, widget=None, wrap=False):
411
 
        """Callback for when the wrap lines checkbutton is toggled"""
412
 
        if wrap or widget.get_active():
413
 
            self.diff_view.sourceview.set_wrap_mode(gtk.WRAP_WORD)
414
 
        else:
415
 
            self.diff_view.sourceview.set_wrap_mode(gtk.WRAP_NONE)
 
407
 
416
408
 
417
409
class DiffWindow(Window):
418
410
    """Diff window.
439
431
        self.vbox = gtk.VBox()
440
432
        self.add(self.vbox)
441
433
        self.vbox.show()
 
434
        hbox = self._get_button_bar(operations)
 
435
        if hbox is not None:
 
436
            self.vbox.pack_start(hbox, expand=False, fill=True)
442
437
        self.diff = DiffWidget()
443
 
        self.vbox.pack_end(self.diff, True, True, 0)
 
438
        self.vbox.add(self.diff)
444
439
        self.diff.show_all()
445
 
        # Build after DiffWidget to connect signals
446
 
        menubar = self._get_menu_bar()
447
 
        self.vbox.pack_start(menubar, False, False, 0)
448
 
        hbox = self._get_button_bar(operations)
449
 
        if hbox is not None:
450
 
            self.vbox.pack_start(hbox, False, True, 0)
451
 
        
452
 
    
453
 
    def _get_menu_bar(self):
454
 
        menubar = gtk.MenuBar()
455
 
        # View menu
456
 
        mb_view = gtk.MenuItem(_i18n("_View"))
457
 
        mb_view_menu = gtk.Menu()
458
 
        mb_view_wrapsource = gtk.CheckMenuItem(_i18n("Wrap _Long Lines"))
459
 
        mb_view_wrapsource.connect('activate', self.diff._on_wraplines_toggled)
460
 
        mb_view_wrapsource.show()
461
 
        mb_view_menu.append(mb_view_wrapsource)
462
 
        mb_view.show()
463
 
        mb_view.set_submenu(mb_view_menu)
464
 
        mb_view.show()
465
 
        menubar.append(mb_view)
466
 
        menubar.show()
467
 
        return menubar
468
 
    
 
440
 
469
441
    def _get_button_bar(self, operations):
470
442
        """Return a button bar to use.
471
443
 
634
606
    renamed_and_modified = 'renamed and modified'
635
607
    modified = 'modified'
636
608
    kind_changed = 'kind changed'
637
 
    missing = 'missing'
638
609
 
639
610
    # TODO: Handle metadata changes
640
611
 
655
626
                    source_marker = ''
656
627
                else:
657
628
                    source_marker = osutils.kind_marker(kinds[0])
658
 
 
659
629
                if kinds[1] is None:
660
 
                    if kinds[0] is None:
661
 
                        # We assume bzr will flag only files in that case,
662
 
                        # there may be a bzr bug there as only files seems to
663
 
                        # not receive any kind.
664
 
                        marker = osutils.kind_marker('file')
665
 
                    else:
666
 
                        marker = osutils.kind_marker(kinds[0])
 
630
                    assert kinds[0] is not None
 
631
                    marker = osutils.kind_marker(kinds[0])
667
632
                else:
668
633
                    marker = osutils.kind_marker(kinds[1])
669
634
 
671
636
                if real_path is None:
672
637
                    real_path = paths[0]
673
638
                assert real_path is not None
 
639
                display_path = real_path + marker
674
640
 
675
641
                present_source = versioned[0] and kinds[0] is not None
676
642
                present_target = versioned[1] and kinds[1] is not None
677
643
 
678
 
                if kinds[0] is None and kinds[1] is None:
679
 
                    change_type = missing
680
 
                    display_path = real_path + marker
681
 
                elif present_source != present_target:
 
644
                if present_source != present_target:
682
645
                    if present_target:
683
646
                        change_type = added
684
647
                    else:
685
648
                        assert present_source
686
649
                        change_type = removed
687
 
                    display_path = real_path + marker
688
650
                elif names[0] != names[1] or parent_ids[0] != parent_ids[1]:
689
651
                    # Renamed
690
652
                    if changed_content or executables[0] != executables[1]:
698
660
                    change_type = kind_changed
699
661
                    display_path = (paths[0] + source_marker
700
662
                                    + ' => ' + paths[1] + marker)
701
 
                elif changed_content or executables[0] != executables[1]:
 
663
                elif changed_content is True or executables[0] != executables[1]:
702
664
                    change_type = modified
703
 
                    display_path = real_path + marker
704
665
                else:
705
666
                    assert False, "How did we get here?"
706
667