/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 merge.py

  • Committer: Jasper Groenewegen
  • Date: 2008-07-22 19:46:47 UTC
  • mfrom: (560.2.1 LP151818-no-push-Q)
  • Revision ID: colbrac@xs4all.nl-20080722194647-25sbnnkj9wdt2v00
Merge removal of question to set default push location

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
# Copyright (C) 2006 by Szilveszter Farkas (Phanatic) <szilveszter.farkas@gmail.com>
 
2
#
 
3
# This program is free software; you can redistribute it and/or modify
 
4
# it under the terms of the GNU General Public License as published by
 
5
# the Free Software Foundation; either version 2 of the License, or
 
6
# (at your option) any later version.
 
7
#
 
8
# This program is distributed in the hope that it will be useful,
 
9
# but WITHOUT ANY WARRANTY; without even the implied warranty of
 
10
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 
11
# GNU General Public License for more details.
 
12
#
 
13
# You should have received a copy of the GNU General Public License
 
14
# along with this program; if not, write to the Free Software
 
15
# Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
 
16
 
 
17
import os
 
18
 
 
19
try:
 
20
    import pygtk
 
21
    pygtk.require("2.0")
 
22
except:
 
23
    pass
 
24
 
 
25
import gtk
 
26
 
 
27
from bzrlib.branch import Branch
 
28
import bzrlib.errors as errors
 
29
 
 
30
from bzrlib.plugins.gtk import _i18n
 
31
from bzrlib.plugins.gtk.dialog import error_dialog, info_dialog, warning_dialog
 
32
from bzrlib.plugins.gtk.errors import show_bzr_error
 
33
 
 
34
 
 
35
class MergeDialog(gtk.Dialog):
 
36
    """ Display the Merge dialog and perform the needed actions. """
 
37
    
 
38
    def __init__(self, wt, wtpath, default_branch_path=None, parent=None):
 
39
        """ Initialize the Merge dialog. """
 
40
        gtk.Dialog.__init__(self, title="Olive - Merge",
 
41
                                  parent=parent,
 
42
                                  flags=0,
 
43
                                  buttons=(gtk.STOCK_CANCEL, gtk.RESPONSE_CANCEL))
 
44
        
 
45
        # Get arguments
 
46
        self.wt = wt
 
47
        self.wtpath = wtpath
 
48
        
 
49
        directory = os.path.dirname(self.wt.abspath(self.wtpath))
 
50
        
 
51
        # Create widgets
 
52
        self._hbox = gtk.HBox()
 
53
        self._label_merge_from = gtk.Label(_i18n("Merge from"))
 
54
        self._filechooser_dialog = gtk.FileChooserDialog(title="Please select a folder",
 
55
                                    parent=self.window,
 
56
                                    action=gtk.FILE_CHOOSER_ACTION_SELECT_FOLDER,
 
57
                                    buttons=(gtk.STOCK_CANCEL, gtk.RESPONSE_CANCEL,
 
58
                                             gtk.STOCK_OPEN, gtk.RESPONSE_OK))
 
59
        self._filechooser_dialog.set_default_response(gtk.RESPONSE_OK)
 
60
        self._filechooser = gtk.FileChooserButton(self._filechooser_dialog)
 
61
        self._button_merge = gtk.Button(_i18n("_Merge"))
 
62
        self._button_merge_icon = gtk.Image()
 
63
        self._button_merge_icon.set_from_stock(gtk.STOCK_APPLY, gtk.ICON_SIZE_BUTTON)
 
64
        self._button_merge.set_image(self._button_merge_icon)
 
65
        
 
66
        self._button_merge.connect('clicked', self._on_merge_clicked)
 
67
        
 
68
        # Set location
 
69
        self._filechooser_dialog.set_current_folder(directory)
 
70
        
 
71
        # Add widgets to dialog
 
72
        self.vbox.add(self._hbox)
 
73
        self._hbox.add(self._label_merge_from)
 
74
        self._hbox.add(self._filechooser)
 
75
        self._hbox.set_spacing(5)
 
76
        self.action_area.pack_end(self._button_merge)
 
77
        
 
78
        self.vbox.show_all()
 
79
 
 
80
    @show_bzr_error
 
81
    def _on_merge_clicked(self, widget):
 
82
        branch = self._filechooser.get_filename()
 
83
        if branch == "":
 
84
            error_dialog(_i18n('Branch not given'),
 
85
                         _i18n('Please specify a branch to merge from.'))
 
86
            return
 
87
 
 
88
        other_branch = Branch.open_containing(branch)[0]
 
89
 
 
90
        try:
 
91
            conflicts = self.wt.merge_from_branch(other_branch)
 
92
        except errors.BzrCommandError, errmsg:
 
93
            error_dialog(_i18n('Bazaar command error'), str(errmsg))
 
94
            return
 
95
        
 
96
        if conflicts == 0:
 
97
            # No conflicts found.
 
98
            info_dialog(_i18n('Merge successful'),
 
99
                        _i18n('All changes applied successfully.'))
 
100
        else:
 
101
            # There are conflicts to be resolved.
 
102
            warning_dialog(_i18n('Conflicts encountered'),
 
103
                           _i18n('Please resolve the conflicts manually before committing.'))
 
104
        
 
105
        self.response(gtk.RESPONSE_OK)