19
from gi.repository import GObject
20
from gi.repository import Gtk
27
22
from bzrlib.branch import Branch
28
23
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
25
from bzrlib.plugins.gtk import icon_path
26
from bzrlib.plugins.gtk.dialog import (
32
31
from bzrlib.plugins.gtk.errors import show_bzr_error
35
class MergeDialog(gtk.Dialog):
32
from bzrlib.plugins.gtk.i18n import _i18n
35
class MergeDialog(Gtk.Dialog):
36
36
""" Display the Merge dialog and perform the needed actions. """
38
38
def __init__(self, wt, wtpath, default_branch_path=None, parent=None):
39
39
""" Initialize the Merge dialog. """
40
gtk.Dialog.__init__(self, title="Merge changes",
40
Gtk.Dialog.__init__(self, title="Merge changes",
43
buttons=(gtk.STOCK_CANCEL, gtk.RESPONSE_CANCEL))
43
buttons=(Gtk.STOCK_CANCEL, Gtk.ResponseType.CANCEL))
44
44
self.set_icon_from_file(icon_path("bzr-icon-64.png"))
49
49
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()
52
self._hbox = Gtk.HBox()
53
self._source = Gtk.HBox()
54
self._label_merge_from = Gtk.Label(label=_i18n("Merge from"))
55
self._combo_source = Gtk.ComboBoxText()
56
56
for entry in [_i18n("Folder"),_i18n("Custom Location")]:
57
57
self._combo_source.append_text(entry)
58
58
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)
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.IconSize.BUTTON)
62
62
self._button_merge.set_image(self._button_merge_icon)
63
63
self._button_merge.connect('clicked', self._on_merge_clicked)
65
65
# Add widgets to dialog
66
self.vbox.pack_start(self._hbox, False, False, 0)
66
self.get_content_area().pack_start(self._hbox, False, False, 0)
67
67
self._hbox.add(self._label_merge_from)
68
68
self._hbox.add(self._combo_source)
69
69
self._hbox.set_spacing(5)
79
79
# If no default_branch_path give, default to folder source with current folder
80
80
self._combo_source.set_active(0)
81
self.get_content_area().show_all()
83
83
def _on_folder_source(self):
84
84
""" 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",
85
self._source = Gtk.HBox()
86
self._filechooser_dialog = Gtk.FileChooserDialog(title="Please select a folder",
87
87
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)
88
action=Gtk.FileChooserAction.SELECT_FOLDER,
89
buttons=(Gtk.STOCK_CANCEL, Gtk.ResponseType.CANCEL,
90
Gtk.STOCK_OPEN, Gtk.ResponseType.OK))
91
self._filechooser_dialog.set_default_response(Gtk.ResponseType.OK)
92
self._filechooser = Gtk.FileChooserButton(self._filechooser_dialog)
93
93
self._filechooser.show()
94
94
directory = getattr(self, 'directory', None)
96
96
directory = os.path.dirname(self.wt.abspath(self.wtpath))
97
97
self._filechooser_dialog.set_current_folder(directory)
98
98
self._source.pack_start(self._filechooser, True, True, 0)
99
self.vbox.pack_start(self._source, True, True, 5)
99
self.get_content_area().pack_start(self._source, True, True, 5)
100
100
self._source.show()
102
102
def _on_custom_source(self):
103
103
""" Merge from a custom source (can be folder, remote, etc), create entry """
104
self._source = gtk.HBox()
105
self._custom_entry = gtk.Entry()
104
self._source = Gtk.HBox()
105
self._custom_entry = Gtk.Entry()
106
106
if self.default_branch_path:
107
107
self._custom_entry.set_text(self.default_branch_path)
108
108
self._custom_entry.connect("activate", self._on_merge_clicked)
109
109
self._custom_entry.show()
110
110
self._source.pack_start(self._custom_entry, True, True, 0)
111
self.vbox.pack_start(self._source, True, True, 5)
111
self.get_content_area().pack_start(self._source, True, True, 5)
112
112
self._source.show()
114
114
def _on_combo_changed(self, widget):