19
from gi.repository import Gtk
21
27
from bzrlib.branch import Branch
22
28
import bzrlib.errors as errors
24
from bzrlib.plugins.gtk import icon_path
25
from bzrlib.plugins.gtk.dialog import (
30
from bzrlib.plugins.gtk import _i18n
31
from bzrlib.plugins.gtk.dialog import error_dialog, info_dialog, warning_dialog
30
32
from bzrlib.plugins.gtk.errors import show_bzr_error
31
from bzrlib.plugins.gtk.i18n import _i18n
34
class MergeDialog(Gtk.Dialog):
35
class MergeDialog(gtk.Dialog):
35
36
""" Display the Merge dialog and perform the needed actions. """
37
38
def __init__(self, wt, wtpath, default_branch_path=None, parent=None):
38
39
""" Initialize the Merge dialog. """
39
super(MergeDialog, self).__init__(
40
title="Merge changes", parent=parent, flags=0,
41
buttons=(Gtk.STOCK_CANCEL, Gtk.ResponseType.CANCEL))
42
self.set_icon_from_file(icon_path("bzr-icon-64.png"))
40
gtk.Dialog.__init__(self, title="Olive - Merge",
43
buttons=(gtk.STOCK_CANCEL, gtk.RESPONSE_CANCEL))
45
47
self.wtpath = wtpath
46
self.default_branch_path = default_branch_path
47
self.parent_window = parent
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))
50
self._hbox = Gtk.HBox()
51
self._source = Gtk.HBox()
52
self._label_merge_from = Gtk.Label(label=_i18n("Merge from"))
53
self._combo_source = Gtk.ComboBoxText()
54
for entry in [_i18n("Folder"),_i18n("Custom Location")]:
55
self._combo_source.append_text(entry)
56
self._combo_source.connect("changed", self._on_combo_changed)
57
self._button_merge = Gtk.Button(_i18n("_Merge"), use_underline=True)
58
self._button_merge_icon = Gtk.Image()
59
self._button_merge_icon.set_from_stock(Gtk.STOCK_APPLY, Gtk.IconSize.BUTTON)
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)
60
67
self._button_merge.set_image(self._button_merge_icon)
61
69
self._button_merge.connect('clicked', self._on_merge_clicked)
72
self._filechooser_dialog.set_current_folder(directory)
63
74
# Add widgets to dialog
64
self.get_content_area().pack_start(self._hbox, False, False, 0)
75
self.vbox.add(self._hbox)
65
76
self._hbox.add(self._label_merge_from)
66
self._hbox.add(self._combo_source)
77
self._hbox.add(self._filechooser)
67
78
self._hbox.set_spacing(5)
68
self.action_area.pack_end(self._button_merge, False, False, 0)
79
self.action_area.pack_end(self._button_merge)
70
if self.default_branch_path and os.path.isdir(
71
self.default_branch_path.partition('file://')[2]):
72
self.directory = self.default_branch_path.partition('file://')[2]
73
self._combo_source.set_active(0)
74
elif self.default_branch_path:
75
self._combo_source.set_active(1)
77
# If no default_branch_path give, default to folder source with current folder
78
self._combo_source.set_active(0)
79
self.get_content_area().show_all()
81
def _on_folder_source(self):
82
""" Merge from folder, create a filechooser dialog and button """
83
self._source = Gtk.HBox()
84
self._filechooser_dialog = Gtk.FileChooserDialog(title="Please select a folder",
85
parent=self.parent_window,
86
action=Gtk.FileChooserAction.SELECT_FOLDER,
87
buttons=(Gtk.STOCK_CANCEL, Gtk.ResponseType.CANCEL,
88
Gtk.STOCK_OPEN, Gtk.ResponseType.OK))
89
self._filechooser_dialog.set_default_response(Gtk.ResponseType.OK)
90
self._filechooser = Gtk.FileChooserButton(self._filechooser_dialog)
91
self._filechooser.show()
92
directory = getattr(self, 'directory', None)
94
directory = os.path.dirname(self.wt.abspath(self.wtpath))
95
self._filechooser_dialog.set_current_folder(directory)
96
self._source.pack_start(self._filechooser, True, True, 0)
97
self.get_content_area().pack_start(self._source, True, True, 5)
100
def _on_custom_source(self):
101
""" Merge from a custom source (can be folder, remote, etc), create entry """
102
self._source = Gtk.HBox()
103
self._custom_entry = Gtk.Entry()
104
if self.default_branch_path:
105
self._custom_entry.set_text(self.default_branch_path)
106
self._custom_entry.connect("activate", self._on_merge_clicked)
107
self._custom_entry.show()
108
self._source.pack_start(self._custom_entry, True, True, 0)
109
self.get_content_area().pack_start(self._source, True, True, 5)
112
def _on_combo_changed(self, widget):
113
merge_source = self._combo_source.get_active()
114
self._source.destroy()
115
if merge_source == 0:
117
self._on_folder_source()
118
elif merge_source == 1:
120
self._on_custom_source()
123
84
def _on_merge_clicked(self, widget):
124
merge_source = self._combo_source.get_active()
125
if merge_source == 0:
126
branch = self._filechooser.get_filename()
127
elif merge_source == 1:
128
branch = self._custom_entry.get_text()
85
branch = self._filechooser.get_filename()
130
87
error_dialog(_i18n('Branch not given'),
131
88
_i18n('Please specify a branch to merge from.'))