示例#1
0
文件: push.py 项目: jelmer/bzr-gtk
    def __init__(self, repository=None, revid=None, branch=None, parent=None):
        """Initialize the Push dialog. """
        super(PushDialog, self).__init__(
            title="Push", parent=parent, flags=0, border_width=6,
            buttons=(Gtk.STOCK_CLOSE, Gtk.ResponseType.CLOSE))
        if repository is None:
            repository = branch.repository
        self.branch = branch

        # Unused arguments
        self.repository = repository
        if revid is None:
            revid = branch.last_revision()
        self.revid = revid

        # Create the widgets
        self._label_location = Gtk.Label(label=_i18n("Location:"))
        self._combo = Gtk.ComboBox.new_with_entry()
        self._button_push = Gtk.Button(_i18n("_Push"), use_underline=True)
        self._hbox_location = Gtk.Box(Gtk.Orientation.HORIZONTAL, 6)
        self._push_message = Gtk.Label(xalign=0)
        self._progress_widget = ProgressPanel()

        # Set callbacks
        ui.ui_factory.set_progress_bar_widget(self._progress_widget)
        self.connect('close', self._on_close_clicked)
        self._button_push.connect('clicked', self._on_push_clicked)

        # Set properties
        content_area = self.get_content_area()
        content_area.set_spacing(6)

        # Pack widgets
        self._hbox_location.pack_start(self._label_location, False, False, 0)
        self._hbox_location.pack_start(self._combo, False, False, 0)
        content_area.pack_start(self._hbox_location, True, True, 0)
        content_area.pack_start(self._progress_widget, True, True, 0)
        content_area.pack_start(self._push_message, True, True, 0)
        self.get_action_area().pack_end(self._button_push, True, True, 0)

        # Show the dialog
        content_area.show_all()
        self._progress_widget.hide()
        self._push_message.hide()

        # Build location history
        self._history = UrlHistory(self.branch.get_config(), 'push_history')
        self._build_history()
示例#2
0
文件: push.py 项目: jelmer/bzr-gtk
class PushDialog(Gtk.Dialog):
    """New implementation of the Push dialog."""

    def __init__(self, repository=None, revid=None, branch=None, parent=None):
        """Initialize the Push dialog. """
        super(PushDialog, self).__init__(
            title="Push", parent=parent, flags=0, border_width=6,
            buttons=(Gtk.STOCK_CLOSE, Gtk.ResponseType.CLOSE))
        if repository is None:
            repository = branch.repository
        self.branch = branch

        # Unused arguments
        self.repository = repository
        if revid is None:
            revid = branch.last_revision()
        self.revid = revid

        # Create the widgets
        self._label_location = Gtk.Label(label=_i18n("Location:"))
        self._combo = Gtk.ComboBox.new_with_entry()
        self._button_push = Gtk.Button(_i18n("_Push"), use_underline=True)
        self._hbox_location = Gtk.Box(Gtk.Orientation.HORIZONTAL, 6)
        self._push_message = Gtk.Label(xalign=0)
        self._progress_widget = ProgressPanel()

        # Set callbacks
        ui.ui_factory.set_progress_bar_widget(self._progress_widget)
        self.connect('close', self._on_close_clicked)
        self._button_push.connect('clicked', self._on_push_clicked)

        # Set properties
        content_area = self.get_content_area()
        content_area.set_spacing(6)

        # Pack widgets
        self._hbox_location.pack_start(self._label_location, False, False, 0)
        self._hbox_location.pack_start(self._combo, False, False, 0)
        content_area.pack_start(self._hbox_location, True, True, 0)
        content_area.pack_start(self._progress_widget, True, True, 0)
        content_area.pack_start(self._push_message, True, True, 0)
        self.get_action_area().pack_end(self._button_push, True, True, 0)

        # Show the dialog
        content_area.show_all()
        self._progress_widget.hide()
        self._push_message.hide()

        # Build location history
        self._history = UrlHistory(self.branch.get_config(), 'push_history')
        self._build_history()

    def _build_history(self):
        """Build up the location history. """
        self._combo_model = Gtk.ListStore(str)
        for item in self._history.get_entries():
            self._combo_model.append([item])
        self._combo.set_model(self._combo_model)
        self._combo.set_entry_text_column(0)

        if self.branch is not None:
            location = self.branch.get_push_location()
            if location is not None:
                self._combo.get_child().set_text(location)

    def _on_close_clicked(self, widget):
        """Close dialog handler."""
        ui.ui_factory.set_progress_bar_widget(None)

    @show_bzr_error
    def _on_push_clicked(self, widget):
        """Push button clicked handler. """
        self._push_message.hide()
        self._progress_widget.tick()
        location = self._combo.get_child().get_text()

        try:
            message = do_push(self.branch, location, overwrite=False)
        except errors.DivergedBranches:
            response = question_dialog(
                _i18n('Branches have been diverged'),
                _i18n('You cannot push if branches have diverged.\n'
                      'Overwrite?'))
            if response == Gtk.ResponseType.YES:
                message = do_push(self.branch, location, overwrite=True)
            else:
                return
        self._history.add_entry(location)
        if (self.branch is not None
            and self.branch.get_push_location() is None):
            self.branch.set_push_location(location)
        if message:
            self._progress_widget.finished()
            self._push_message.props.label = message
            self._push_message.show()