20
21
from errors import show_bzr_error
22
import bzrlib.errors as errors
27
from bzrlib.bzrdir import BzrDir
28
from bzrlib.transport import get_transport
24
30
from bzrlib.plugins.gtk.dialog import (
29
33
from bzrlib.plugins.gtk.history import UrlHistory
30
34
from bzrlib.plugins.gtk.i18n import _i18n
35
from bzrlib.plugins.gtk.ui import ProgressPanel
33
38
class PushDialog(Gtk.Dialog):
34
39
"""New implementation of the Push dialog."""
36
def __init__(self, repository, revid, branch=None, parent=None):
41
def __init__(self, repository=None, revid=None, branch=None, parent=None):
37
42
"""Initialize the Push dialog. """
38
GObject.GObject.__init__(self, title="Push",
41
buttons=(Gtk.STOCK_CANCEL, Gtk.ResponseType.CANCEL))
43
super(PushDialog, self).__init__(
44
title="Push", parent=parent, flags=0, border_width=6,
45
buttons=(Gtk.STOCK_CLOSE, Gtk.ResponseType.CLOSE))
46
if repository is None:
47
repository = branch.repository
44
51
self.repository = repository
53
revid = branch.last_revision()
48
56
# Create the widgets
49
57
self._label_location = Gtk.Label(label=_i18n("Location:"))
50
self._combo = Gtk.ComboBoxEntry()
58
self._combo = Gtk.ComboBox.new_with_entry()
51
59
self._button_push = Gtk.Button(_i18n("_Push"), use_underline=True)
52
self._hbox_location = Gtk.HBox()
60
self._hbox_location = Gtk.Box(Gtk.Orientation.HORIZONTAL, 6)
61
self._push_message = Gtk.Label(xalign=0)
62
self._progress_widget = ProgressPanel()
65
ui.ui_factory.set_progress_bar_widget(self._progress_widget)
66
self.connect('close', self._on_close_clicked)
55
67
self._button_push.connect('clicked', self._on_push_clicked)
58
self._label_location.set_alignment(0, 0.5)
59
self._hbox_location.set_spacing(3)
60
self.vbox.set_spacing(3)
70
content_area = self.get_content_area()
71
content_area.set_spacing(6)
63
self._hbox_location.pack_start(self._label_location, False, False)
64
self._hbox_location.pack_start(self._combo, True, True)
65
self.vbox.pack_start(self._hbox_location, True, True, 0)
66
self.action_area.pack_end(self._button_push)
74
self._hbox_location.pack_start(self._label_location, False, False, 0)
75
self._hbox_location.pack_start(self._combo, False, False, 0)
76
content_area.pack_start(self._hbox_location, True, True, 0)
77
content_area.pack_start(self._progress_widget, True, True, 0)
78
content_area.pack_start(self._push_message, True, True, 0)
79
self.get_action_area().pack_end(self._button_push, True, True, 0)
82
content_area.show_all()
83
self._progress_widget.hide()
84
self._push_message.hide()
71
86
# Build location history
72
87
self._history = UrlHistory(self.branch.get_config(), 'push_history')
76
91
"""Build up the location history. """
77
92
self._combo_model = Gtk.ListStore(str)
78
93
for item in self._history.get_entries():
79
self._combo_model.append([ item ])
94
self._combo_model.append([item])
80
95
self._combo.set_model(self._combo_model)
81
self._combo.set_text_column(0)
96
self._combo.set_entry_text_column(0)
83
98
if self.branch is not None:
84
99
location = self.branch.get_push_location()
85
100
if location is not None:
86
101
self._combo.get_child().set_text(location)
103
def _on_close_clicked(self, widget):
104
"""Close dialog handler."""
105
ui.ui_factory.set_progress_bar_widget(None)
89
108
def _on_push_clicked(self, widget):
90
109
"""Push button clicked handler. """
110
self._push_message.hide()
111
self._progress_widget.tick()
91
112
location = self._combo.get_child().get_text()
95
revs = do_push(self.branch, location=location, overwrite=False)
115
message = do_push(self.branch, location, overwrite=False)
96
116
except errors.DivergedBranches:
97
response = question_dialog(_i18n('Branches have been diverged'),
98
_i18n('You cannot push if branches have diverged.\nOverwrite?'))
117
response = question_dialog(
118
_i18n('Branches have been diverged'),
119
_i18n('You cannot push if branches have diverged.\n'
99
121
if response == Gtk.ResponseType.YES:
100
revs = do_push(self.branch, location=location, overwrite=True)
102
if self.branch is not None and self.branch.get_push_location() is None:
122
message = do_push(self.branch, location, overwrite=True)
125
self._history.add_entry(location)
126
if (self.branch is not None
127
and self.branch.get_push_location() is None):
103
128
self.branch.set_push_location(location)
105
self._history.add_entry(location)
106
info_dialog(_i18n('Push successful'),
107
_i18n("%d revision(s) pushed.") % revs)
109
self.response(Gtk.ResponseType.OK)
130
self._progress_widget.finished()
131
self._push_message.props.label = message
132
self._push_message.show()
112
135
def do_push(br_from, location, overwrite):