/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: 2009-05-04 20:06:58 UTC
  • Revision ID: jelmer@samba.org-20090504200658-n6hsag1soygn3n1o
Use _get_nick(local=True) rather than .nick to get at a branches' nick, since 
the previous might check the nickname of the master branch, which will be slow.

Show diffs side-by-side

added added

removed removed

Lines of Context:
1
 
# -*- coding: UTF-8 -*-
2
1
"""Difference window.
3
2
 
4
3
This module contains the code to manage the diff window which shows
5
4
the changes made between two revisions on a branch.
6
5
"""
7
6
 
8
 
__copyright__ = "Copyright © 2005 Canonical Ltd."
 
7
__copyright__ = "Copyright 2005 Canonical Ltd."
9
8
__author__    = "Scott James Remnant <scott@ubuntu.com>"
10
9
 
11
10
 
73
72
            self.buffer.set_language(gsl)
74
73
            self.buffer.set_highlight(True)
75
74
 
76
 
            sourceview = gtksourceview.SourceView(self.buffer)
 
75
            self.sourceview = gtksourceview.SourceView(self.buffer)
77
76
        else:
78
77
            self.buffer = gtk.TextBuffer()
79
 
            sourceview = gtk.TextView(self.buffer)
 
78
            self.sourceview = gtk.TextView(self.buffer)
80
79
 
81
 
        sourceview.set_editable(False)
82
 
        sourceview.modify_font(pango.FontDescription("Monospace"))
83
 
        self.add(sourceview)
84
 
        sourceview.show()
 
80
        self.sourceview.set_editable(False)
 
81
        self.sourceview.modify_font(pango.FontDescription("Monospace"))
 
82
        self.add(self.sourceview)
 
83
        self.sourceview.show()
85
84
 
86
85
    @staticmethod
87
86
    def apply_gedit_colors(lang):
305
304
        scrollwin.set_shadow_type(gtk.SHADOW_IN)
306
305
        self.pack1(scrollwin)
307
306
        scrollwin.show()
308
 
 
 
307
        
309
308
        self.model = gtk.TreeStore(str, str)
310
309
        self.treeview = gtk.TreeView(self.model)
311
310
        self.treeview.set_headers_visible(False)
330
329
        # text view
331
330
 
332
331
    def set_diff_text_sections(self, sections):
333
 
        self.diff_view = DiffFileView()
 
332
        if getattr(self, 'diff_view', None) is None:
 
333
            self.diff_view = DiffFileView()
 
334
            self.pack2(self.diff_view)
334
335
        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
 
        self.diff_view = DiffView()
350
 
        self.pack2(self.diff_view)
 
349
        if getattr(self, 'diff_view', None) is None:
 
350
            self.diff_view = DiffView()
 
351
            self.pack2(self.diff_view)
351
352
        self.diff_view.show()
352
353
        self.diff_view.set_trees(rev_tree, parent_tree)
353
354
        self.rev_tree = rev_tree
380
381
                self.model.append(titer, [ path, path ])
381
382
 
382
383
        self.treeview.expand_all()
 
384
        self.diff_view.show_diff(None)
383
385
 
384
386
    def set_file(self, file_path):
385
387
        """Select the current file to display"""
402
404
            return
403
405
        elif specific_files == [ "" ]:
404
406
            specific_files = None
405
 
 
 
407
        
406
408
        self.diff_view.show_diff(specific_files)
407
 
 
 
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)
408
416
 
409
417
class DiffWindow(Window):
410
418
    """Diff window.
431
439
        self.vbox = gtk.VBox()
432
440
        self.add(self.vbox)
433
441
        self.vbox.show()
 
442
        self.diff = DiffWidget()
 
443
        self.vbox.pack_end(self.diff, True, True, 0)
 
444
        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)
434
448
        hbox = self._get_button_bar(operations)
435
449
        if hbox is not None:
436
 
            self.vbox.pack_start(hbox, expand=False, fill=True)
437
 
        self.diff = DiffWidget()
438
 
        self.vbox.add(self.diff)
439
 
        self.diff.show_all()
440
 
 
 
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
    
441
469
    def _get_button_bar(self, operations):
442
470
        """Return a button bar to use.
443
471
 
606
634
    renamed_and_modified = 'renamed and modified'
607
635
    modified = 'modified'
608
636
    kind_changed = 'kind changed'
 
637
    missing = 'missing'
609
638
 
610
639
    # TODO: Handle metadata changes
611
640
 
626
655
                    source_marker = ''
627
656
                else:
628
657
                    source_marker = osutils.kind_marker(kinds[0])
 
658
 
629
659
                if kinds[1] is None:
630
 
                    assert kinds[0] is not None
631
 
                    marker = osutils.kind_marker(kinds[0])
 
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])
632
667
                else:
633
668
                    marker = osutils.kind_marker(kinds[1])
634
669
 
636
671
                if real_path is None:
637
672
                    real_path = paths[0]
638
673
                assert real_path is not None
639
 
                display_path = real_path + marker
640
674
 
641
675
                present_source = versioned[0] and kinds[0] is not None
642
676
                present_target = versioned[1] and kinds[1] is not None
643
677
 
644
 
                if present_source != present_target:
 
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:
645
682
                    if present_target:
646
683
                        change_type = added
647
684
                    else:
648
685
                        assert present_source
649
686
                        change_type = removed
 
687
                    display_path = real_path + marker
650
688
                elif names[0] != names[1] or parent_ids[0] != parent_ids[1]:
651
689
                    # Renamed
652
690
                    if changed_content or executables[0] != executables[1]:
660
698
                    change_type = kind_changed
661
699
                    display_path = (paths[0] + source_marker
662
700
                                    + ' => ' + paths[1] + marker)
663
 
                elif changed_content is True or executables[0] != executables[1]:
 
701
                elif changed_content or executables[0] != executables[1]:
664
702
                    change_type = modified
 
703
                    display_path = real_path + marker
665
704
                else:
666
705
                    assert False, "How did we get here?"
667
706