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