27
28
from bzrlib.branch import Branch
28
29
import bzrlib.errors as errors
30
from bzrlib.plugins.gtk import icon_path
31
from bzrlib.plugins.gtk.dialog import (
36
from bzrlib.plugins.gtk.errors import show_bzr_error
37
from bzrlib.plugins.gtk.i18n import _i18n
40
class MergeDialog(gtk.Dialog):
31
from dialog import error_dialog, info_dialog, warning_dialog
32
from errors import show_bzr_error
33
from olive.guifiles import GLADEFILENAME
41
37
""" Display the Merge dialog and perform the needed actions. """
43
def __init__(self, wt, wtpath, default_branch_path=None, parent=None):
38
def __init__(self, wt, wtpath):
44
39
""" Initialize the Merge dialog. """
45
gtk.Dialog.__init__(self, title="Merge changes",
48
buttons=(gtk.STOCK_CANCEL, gtk.RESPONSE_CANCEL))
49
self.set_icon_from_file(icon_path("bzr-icon-64.png"))
40
self.glade = gtk.glade.XML(GLADEFILENAME, 'window_merge', 'olive-gtk')
42
self.window = self.glade.get_widget('window_merge')
44
# Dictionary for signal_autoconnect
45
dic = { "on_button_merge_merge_clicked": self.merge,
46
"on_button_merge_cancel_clicked": self.close,
47
"on_button_merge_open_clicked": self.open }
49
# Connect the signals to the handlers
50
self.glade.signal_autoconnect(dic)
52
53
self.wtpath = wtpath
53
self.default_branch_path = default_branch_path
54
self.parent_window = parent
57
self._hbox = gtk.HBox()
58
self._source = gtk.HBox()
59
self._label_merge_from = gtk.Label(_i18n("Merge from"))
60
self._combo_source = gtk.combo_box_new_text()
61
for entry in [_i18n("Folder"),_i18n("Custom Location")]:
62
self._combo_source.append_text(entry)
63
self._combo_source.connect("changed", self._on_combo_changed)
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)
68
self._button_merge.connect('clicked', self._on_merge_clicked)
70
# Add widgets to dialog
71
self.vbox.pack_start(self._hbox, False, False, 0)
72
self._hbox.add(self._label_merge_from)
73
self._hbox.add(self._combo_source)
74
self._hbox.set_spacing(5)
75
self.action_area.pack_end(self._button_merge)
77
if self.default_branch_path and os.path.isdir(
78
self.default_branch_path.partition('file://')[2]):
79
self.directory = self.default_branch_path.partition('file://')[2]
80
self._combo_source.set_active(0)
81
elif self.default_branch_path:
82
self._combo_source.set_active(1)
84
# If no default_branch_path give, default to folder source with current folder
85
self._combo_source.set_active(0)
88
def _on_folder_source(self):
89
""" Merge from folder, create a filechooser dialog and button """
90
self._source = gtk.HBox()
91
self._filechooser_dialog = gtk.FileChooserDialog(title="Please select a folder",
92
parent=self.parent_window,
93
action=gtk.FILE_CHOOSER_ACTION_SELECT_FOLDER,
94
buttons=(gtk.STOCK_CANCEL, gtk.RESPONSE_CANCEL,
95
gtk.STOCK_OPEN, gtk.RESPONSE_OK))
96
self._filechooser_dialog.set_default_response(gtk.RESPONSE_OK)
97
self._filechooser = gtk.FileChooserButton(self._filechooser_dialog)
98
self._filechooser.show()
99
directory = getattr(self, 'directory', None)
101
directory = os.path.dirname(self.wt.abspath(self.wtpath))
102
self._filechooser_dialog.set_current_folder(directory)
103
self._source.pack_start(self._filechooser, True, True, 0)
104
self.vbox.pack_start(self._source, True, True, 5)
107
def _on_custom_source(self):
108
""" Merge from a custom source (can be folder, remote, etc), create entry """
109
self._source = gtk.HBox()
110
self._custom_entry = gtk.Entry()
111
if self.default_branch_path:
112
self._custom_entry.set_text(self.default_branch_path)
113
self._custom_entry.connect("activate", self._on_merge_clicked)
114
self._custom_entry.show()
115
self._source.pack_start(self._custom_entry, True, True, 0)
116
self.vbox.pack_start(self._source, True, True, 5)
119
def _on_combo_changed(self, widget):
120
merge_source = self._combo_source.get_active()
121
self._source.destroy()
122
if merge_source == 0:
124
self._on_folder_source()
125
elif merge_source == 1:
127
self._on_custom_source()
56
self.entry = self.glade.get_widget('entry_merge')
59
""" Display the Add file(s) dialog. """
60
self.window.show_all()
130
def _on_merge_clicked(self, widget):
131
merge_source = self._combo_source.get_active()
132
if merge_source == 0:
133
branch = self._filechooser.get_filename()
134
elif merge_source == 1:
135
branch = self._custom_entry.get_text()
63
def merge(self, widget):
64
branch = self.entry.get_text()
137
error_dialog(_i18n('Branch not given'),
138
_i18n('Please specify a branch to merge from.'))
66
error_dialog(_('Branch not given'),
67
_('Please specify a branch to merge from.'))
141
70
other_branch = Branch.open_containing(branch)[0]
144
73
conflicts = self.wt.merge_from_branch(other_branch)
145
74
except errors.BzrCommandError, errmsg:
146
error_dialog(_i18n('Bazaar command error'), str(errmsg))
75
error_dialog(_('Bazaar command error'), str(errmsg))
149
79
if conflicts == 0:
150
80
# No conflicts found.
151
info_dialog(_i18n('Merge successful'),
152
_i18n('All changes applied successfully.'))
81
info_dialog(_('Merge successful'),
82
_('All changes applied successfully.'))
154
84
# There are conflicts to be resolved.
155
warning_dialog(_i18n('Conflicts encountered'),
156
_i18n('Please resolve the conflicts manually before committing.'))
158
self.response(gtk.RESPONSE_OK)
85
warning_dialog(_('Conflicts encountered'),
86
_('Please resolve the conflicts manually before committing.'))
88
def open(self, widget):
89
fcd = gtk.FileChooserDialog(title="Please select a folder",
91
action=gtk.FILE_CHOOSER_ACTION_SELECT_FOLDER,
92
buttons=(gtk.STOCK_CANCEL, gtk.RESPONSE_CANCEL,
93
gtk.STOCK_OPEN, gtk.RESPONSE_OK))
94
fcd.set_default_response(gtk.RESPONSE_OK)
96
if fcd.run() == gtk.RESPONSE_OK:
97
self.entry.set_text(fcd.get_filename())
101
def close(self, widget=None):
102
self.window.destroy()