1
# Copyright (C) 2006 by Szilveszter Farkas (Phanatic) <szilveszter.farkas@gmail.com>
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.
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.
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
27
from bzrlib.branch import Branch
28
import bzrlib.errors as errors
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
35
class MergeDialog(gtk.Dialog):
36
""" Display the Merge dialog and perform the needed actions. """
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",
43
buttons=(gtk.STOCK_CANCEL, gtk.RESPONSE_CANCEL))
49
if default_branch_path and os.path.isdir(default_branch_path.partition('file://')[2]):
50
directory = default_branch_path.partition('file://')[2]
52
directory = os.path.dirname(self.wt.abspath(self.wtpath))
55
self._hbox = gtk.HBox()
56
self._label_merge_from = gtk.Label(_i18n("Merge from"))
57
self._filechooser_dialog = gtk.FileChooserDialog(title="Please select a folder",
59
action=gtk.FILE_CHOOSER_ACTION_SELECT_FOLDER,
60
buttons=(gtk.STOCK_CANCEL, gtk.RESPONSE_CANCEL,
61
gtk.STOCK_OPEN, gtk.RESPONSE_OK))
62
self._filechooser_dialog.set_default_response(gtk.RESPONSE_OK)
63
self._filechooser = gtk.FileChooserButton(self._filechooser_dialog)
64
self._button_merge = gtk.Button(_i18n("_Merge"))
65
self._button_merge_icon = gtk.Image()
66
self._button_merge_icon.set_from_stock(gtk.STOCK_APPLY, gtk.ICON_SIZE_BUTTON)
67
self._button_merge.set_image(self._button_merge_icon)
69
self._button_merge.connect('clicked', self._on_merge_clicked)
72
self._filechooser_dialog.set_current_folder(directory)
74
# Add widgets to dialog
75
self.vbox.add(self._hbox)
76
self._hbox.add(self._label_merge_from)
77
self._hbox.add(self._filechooser)
78
self._hbox.set_spacing(5)
79
self.action_area.pack_end(self._button_merge)
84
def _on_merge_clicked(self, widget):
85
branch = self._filechooser.get_filename()
87
error_dialog(_i18n('Branch not given'),
88
_i18n('Please specify a branch to merge from.'))
91
other_branch = Branch.open_containing(branch)[0]
94
conflicts = self.wt.merge_from_branch(other_branch)
95
except errors.BzrCommandError, errmsg:
96
error_dialog(_i18n('Bazaar command error'), str(errmsg))
100
# No conflicts found.
101
info_dialog(_i18n('Merge successful'),
102
_i18n('All changes applied successfully.'))
104
# There are conflicts to be resolved.
105
warning_dialog(_i18n('Conflicts encountered'),
106
_i18n('Please resolve the conflicts manually before committing.'))
108
self.response(gtk.RESPONSE_OK)