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