/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-12 20:21:45 UTC
  • mto: This revision was merged to the branch mainline in revision 492.
  • Revision ID: aaron@aaronbentley.com-20080512202145-7dh7wm8avi3ud47q
Update error handling to use window

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
 
73
72
            self.buffer.set_language(gsl)
74
73
            self.buffer.set_highlight(True)
75
74
 
76
 
            self.sourceview = gtksourceview.SourceView(self.buffer)
 
75
            sourceview = gtksourceview.SourceView(self.buffer)
77
76
        else:
78
77
            self.buffer = gtk.TextBuffer()
79
 
            self.sourceview = gtk.TextView(self.buffer)
 
78
            sourceview = gtk.TextView(self.buffer)
80
79
 
81
 
        self.sourceview.set_editable(False)
82
 
        self.sourceview.modify_font(pango.FontDescription("Monospace"))
83
 
        self.add(self.sourceview)
84
 
        self.sourceview.show()
 
80
        sourceview.set_editable(False)
 
81
        sourceview.modify_font(pango.FontDescription("Monospace"))
 
82
        self.add(sourceview)
 
83
        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
 
        if getattr(self, 'diff_view', None) is None:
334
 
            self.diff_view = DiffFileView()
335
 
            self.pack2(self.diff_view)
 
332
        self.diff_view = DiffFileView()
336
333
        self.diff_view.show()
 
334
        self.pack2(self.diff_view)
337
335
        for oldname, newname, patch in sections:
338
336
            self.diff_view._diffs[newname] = str(patch)
339
337
            if newname is None:
347
345
        Compares the two trees and populates the window with the
348
346
        differences.
349
347
        """
350
 
        if getattr(self, 'diff_view', None) is None:
351
 
            self.diff_view = DiffView()
352
 
            self.pack2(self.diff_view)
 
348
        self.diff_view = DiffView()
 
349
        self.pack2(self.diff_view)
353
350
        self.diff_view.show()
354
351
        self.diff_view.set_trees(rev_tree, parent_tree)
355
352
        self.rev_tree = rev_tree
382
379
                self.model.append(titer, [ path, path ])
383
380
 
384
381
        self.treeview.expand_all()
385
 
        self.diff_view.show_diff(None)
386
382
 
387
383
    def set_file(self, file_path):
388
384
        """Select the current file to display"""
405
401
            return
406
402
        elif specific_files == [ "" ]:
407
403
            specific_files = None
408
 
        
 
404
 
409
405
        self.diff_view.show_diff(specific_files)
410
 
    
411
 
    def _on_wraplines_toggled(self, widget=None, wrap=False):
412
 
        """Callback for when the wrap lines checkbutton is toggled"""
413
 
        if wrap or widget.get_active():
414
 
            self.diff_view.sourceview.set_wrap_mode(gtk.WRAP_WORD)
415
 
        else:
416
 
            self.diff_view.sourceview.set_wrap_mode(gtk.WRAP_NONE)
 
406
 
417
407
 
418
408
class DiffWindow(Window):
419
409
    """Diff window.
440
430
        self.vbox = gtk.VBox()
441
431
        self.add(self.vbox)
442
432
        self.vbox.show()
 
433
        hbox = self._get_button_bar(operations)
 
434
        if hbox is not None:
 
435
            self.vbox.pack_start(hbox, expand=False, fill=True)
443
436
        self.diff = DiffWidget()
444
 
        self.vbox.pack_end(self.diff, True, True, 0)
 
437
        self.vbox.add(self.diff)
445
438
        self.diff.show_all()
446
 
        # Build after DiffWidget to connect signals
447
 
        menubar = self._get_menu_bar()
448
 
        self.vbox.pack_start(menubar, False, False, 0)
449
 
        hbox = self._get_button_bar(operations)
450
 
        if hbox is not None:
451
 
            self.vbox.pack_start(hbox, False, True, 0)
452
 
        
453
 
    
454
 
    def _get_menu_bar(self):
455
 
        menubar = gtk.MenuBar()
456
 
        # View menu
457
 
        mb_view = gtk.MenuItem(_i18n("_View"))
458
 
        mb_view_menu = gtk.Menu()
459
 
        mb_view_wrapsource = gtk.CheckMenuItem(_i18n("Wrap _Long Lines"))
460
 
        mb_view_wrapsource.connect('activate', self.diff._on_wraplines_toggled)
461
 
        mb_view_wrapsource.show()
462
 
        mb_view_menu.append(mb_view_wrapsource)
463
 
        mb_view.show()
464
 
        mb_view.set_submenu(mb_view_menu)
465
 
        mb_view.show()
466
 
        menubar.append(mb_view)
467
 
        menubar.show()
468
 
        return menubar
469
 
    
 
439
 
470
440
    def _get_button_bar(self, operations):
471
441
        """Return a button bar to use.
472
442
 
501
471
 
502
472
    def _merge_successful(self):
503
473
        # No conflicts found.
504
 
        info_dialog(_i18n('Merge successful'),
505
 
                    _i18n('All changes applied successfully.'))
 
474
        info_dialog(_('Merge successful'),
 
475
                    _('All changes applied successfully.'))
506
476
 
507
477
    def _conflicts(self):
508
 
        warning_dialog(_i18n('Conflicts encountered'),
509
 
                       _i18n('Please resolve the conflicts manually'
510
 
                             ' before committing.'))
 
478
        warning_dialog(_('Conflicts encountered'),
 
479
                       _('Please resolve the conflicts manually'
 
480
                         ' before committing.'))
511
481
 
512
482
    def _handle_error(self, e):
513
483
        error_dialog('Error', str(e))