/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-03-14 02:13:27 UTC
  • mto: (452.2.2 trunk)
  • mto: This revision was merged to the branch mainline in revision 453.
  • Revision ID: jelmer@samba.org-20080314021327-q1pabtpneeasz8qv
Fix support for default value in BranchSelectionDialog.

Show diffs side-by-side

added added

removed removed

Lines of Context:
30
30
except ImportError:
31
31
    have_gconf = False
32
32
 
33
 
from bzrlib import merge as _mod_merge, osutils, progress, workingtree
 
33
from bzrlib import (
 
34
    merge as _mod_merge,
 
35
    osutils,
 
36
    progress,
 
37
    urlutils,
 
38
    workingtree,
 
39
)
34
40
from bzrlib.diff import show_diff_trees, internal_diff
35
41
from bzrlib.errors import NoSuchFile
36
42
from bzrlib.patches import parse_patches
45
51
 
46
52
 
47
53
class DiffFileView(gtk.ScrolledWindow):
 
54
    """Window for displaying diffs from a diff file"""
48
55
 
49
56
    def __init__(self):
50
57
        gtk.ScrolledWindow.__init__(self)
259
266
        self.parent_tree = None
260
267
 
261
268
    def show_diff(self, specific_files):
 
269
        """Show the diff for the specified files"""
262
270
        s = StringIO()
263
271
        show_diff_trees(self.parent_tree, self.rev_tree, s, specific_files,
264
272
                        old_label='', new_label='',
313
321
        self.treeview.append_column(column)
314
322
 
315
323
    def set_diff_text(self, lines):
 
324
        """Set the current diff from a list of lines
 
325
 
 
326
        :param lines: The diff to show, in unified diff format
 
327
        """
316
328
        # The diffs of the  selected file: a scrollable source or
317
329
        # text view
318
330
        self.diff_view = DiffFileView()
369
381
        self.treeview.expand_all()
370
382
 
371
383
    def set_file(self, file_path):
 
384
        """Select the current file to display"""
372
385
        tv_path = None
373
386
        for data in self.model:
374
387
            for child in data.iterchildren():
426
439
        self.diff.show_all()
427
440
 
428
441
    def _get_button_bar(self):
 
442
        """Return a button bar to use.
 
443
 
 
444
        :return: None, meaning that no button bar will be used.
 
445
        """
429
446
        return None
430
447
 
431
448
    def set_diff_text(self, description, lines):
 
449
        """Set the diff from a text.
 
450
 
 
451
        The diff must be in unified diff format, and will be parsed to
 
452
        determine filenames.
 
453
        """
432
454
        self.diff.set_diff_text(lines)
433
455
        self.set_title(description + " - bzrk diff")
434
456
 
447
469
 
448
470
class MergeDirectiveWindow(DiffWindow):
449
471
 
450
 
    def __init__(self, directive, parent=None):
451
 
        DiffWindow.__init__(self, parent)
 
472
    def __init__(self, directive, path):
 
473
        DiffWindow.__init__(self, None)
452
474
        self._merge_target = None
453
475
        self.directive = directive
 
476
        self.path = path
454
477
 
455
478
    def _get_button_bar(self):
 
479
        """The button bar has only the Merge button"""
456
480
        merge_button = gtk.Button('Merge')
457
481
        merge_button.show()
458
482
        merge_button.set_relief(gtk.RELIEF_NONE)
459
483
        merge_button.connect("clicked", self.perform_merge)
460
484
 
 
485
        save_button = gtk.Button('Save')
 
486
        save_button.show()
 
487
        save_button.set_relief(gtk.RELIEF_NONE)
 
488
        save_button.connect("clicked", self.perform_save)
 
489
 
461
490
        hbox = gtk.HButtonBox()
462
491
        hbox.set_layout(gtk.BUTTONBOX_START)
463
492
        hbox.pack_start(merge_button, expand=False, fill=True)
 
493
        hbox.pack_start(save_button, expand=False, fill=True)
464
494
        hbox.show()
465
495
        return hbox
466
496
 
503
533
                                           gtk.RESPONSE_CANCEL,))
504
534
        try:
505
535
            result = d.run()
506
 
            if result == gtk.RESPONSE_OK:
507
 
                uri = d.get_current_folder_uri()
508
 
                return workingtree.WorkingTree.open(uri)
509
 
            else:
 
536
            if result != gtk.RESPONSE_OK:
510
537
                raise SelectCancelled()
 
538
            uri = d.get_current_folder_uri()
511
539
        finally:
512
540
            d.destroy()
 
541
        return workingtree.WorkingTree.open(uri)
 
542
 
 
543
    def perform_save(self, window):
 
544
        d = gtk.FileChooserDialog('Save As', self,
 
545
                                  gtk.FILE_CHOOSER_ACTION_SAVE,
 
546
                                  buttons=(gtk.STOCK_OK, gtk.RESPONSE_OK,
 
547
                                           gtk.STOCK_CANCEL,
 
548
                                           gtk.RESPONSE_CANCEL,))
 
549
        d.set_current_name(osutils.basename(self.path))
 
550
        try:
 
551
            try:
 
552
                result = d.run()
 
553
                if result != gtk.RESPONSE_OK:
 
554
                    raise SelectCancelled()
 
555
                uri = d.get_uri()
 
556
            finally:
 
557
                d.destroy()
 
558
        except SelectCancelled:
 
559
            return
 
560
        source = open(self.path, 'rb')
 
561
        try:
 
562
            target = open(urlutils.local_path_from_url(uri), 'wb')
 
563
            try:
 
564
                target.write(source.read())
 
565
            finally:
 
566
                target.close()
 
567
        finally:
 
568
            source.close()
513
569
 
514
570
 
515
571
def _iter_changes_to_status(source, target):