| 1 |
|
| 2 |
|
| 3 |
|
| 4 |
|
| 5 |
|
| 6 |
|
| 7 |
|
| 8 |
|
| 9 |
|
| 10 |
|
| 11 |
|
| 12 |
|
| 13 |
|
| 14 |
|
| 15 |
|
| 16 |
|
| 17 |
|
| 18 |
|
| 19 |
|
| 20 |
|
| 21 |
|
| 22 |
|
| 23 |
from PyQt5 import QtCore, QtGui, QtWidgets |
| 24 |
|
| 25 |
from breezy import errors, osutils |
| 26 |
|
| 27 |
from breezy.plugins.qbrz.lib.i18n import gettext |
| 28 |
from breezy.plugins.qbrz.lib.subprocess import SubProcessDialog |
| 29 |
from breezy.plugins.qbrz.lib.util import ( |
| 30 |
url_for_display, |
| 31 |
) |
| 32 |
from breezy.plugins.qbrz.lib.uifactory import ui_current_widget |
| 33 |
from breezy.plugins.qbrz.lib.trace import ( |
| 34 |
reports_exception, |
| 35 |
SUB_LOAD_METHOD, |
| 36 |
) |
| 37 |
|
| 38 |
|
| 39 |
class QBzrBindDialog(SubProcessDialog): |
| 40 |
|
| 41 |
def __init__(self, branch, location=None, ui_mode = None): |
| 42 |
self.branch = branch |
| 43 |
super(QBzrBindDialog, self).__init__( |
| 44 |
gettext("Bind branch"), |
| 45 |
name = "bind", |
| 46 |
default_size = (400, 400), |
| 47 |
ui_mode = ui_mode, |
| 48 |
dialog = True, |
| 49 |
parent = None, |
| 50 |
hide_progress=False, |
| 51 |
) |
| 52 |
|
| 53 |
|
| 54 |
gbBind = QtWidgets.QGroupBox(gettext("Bind"), self) |
| 55 |
bind_box = QtWidgets.QFormLayout(gbBind) |
| 56 |
bind_box.addRow(gettext("Branch location:"), |
| 57 |
QtWidgets.QLabel(url_for_display(branch.base))) |
| 58 |
self.currbound = branch.get_bound_location() |
| 59 |
if self.currbound != None: |
| 60 |
bind_box.addRow(gettext("Currently bound to:"), |
| 61 |
QtWidgets.QLabel(url_for_display(self.currbound))) |
| 62 |
|
| 63 |
|
| 64 |
branch_label = QtWidgets.QLabel(gettext("Bind to:")) |
| 65 |
branch_combo = QtWidgets.QComboBox() |
| 66 |
branch_combo.setEditable(True) |
| 67 |
self.branch_combo = branch_combo |
| 68 |
browse_button = QtWidgets.QPushButton(gettext("Browse")) |
| 69 |
browse_button.clicked[bool].connect(self.browse_clicked) |
| 70 |
|
| 71 |
|
| 72 |
|
| 73 |
|
| 74 |
suggestions = [] |
| 75 |
if location: |
| 76 |
suggestions.append(osutils.abspath(location)) |
| 77 |
self._maybe_add_suggestion(suggestions, branch.get_old_bound_location()) |
| 78 |
self._maybe_add_suggestion(suggestions, branch.get_parent()) |
| 79 |
self._maybe_add_suggestion(suggestions, branch.get_push_location()) |
| 80 |
if suggestions: |
| 81 |
branch_combo.addItems(suggestions) |
| 82 |
|
| 83 |
|
| 84 |
bind_hbox = QtWidgets.QHBoxLayout() |
| 85 |
bind_hbox.addWidget(branch_label) |
| 86 |
bind_hbox.addWidget(branch_combo) |
| 87 |
bind_hbox.addWidget(browse_button) |
| 88 |
bind_hbox.setStretchFactor(branch_label,0) |
| 89 |
bind_hbox.setStretchFactor(branch_combo,1) |
| 90 |
bind_hbox.setStretchFactor(browse_button,0) |
| 91 |
bind_box.addRow(bind_hbox) |
| 92 |
|
| 93 |
|
| 94 |
layout = QtWidgets.QVBoxLayout(self) |
| 95 |
layout.addWidget(gbBind) |
| 96 |
layout.addWidget(self.make_default_status_box()) |
| 97 |
layout.addWidget(self.buttonbox) |
| 98 |
|
| 99 |
branch_combo.setFocus() |
| 100 |
|
| 101 |
def _maybe_add_suggestion(self, suggestions, location): |
| 102 |
if location: |
| 103 |
url = url_for_display(location) |
| 104 |
if url not in suggestions: |
| 105 |
suggestions.append(url) |
| 106 |
|
| 107 |
def browse_clicked(self): |
| 108 |
fileName = QtWidgets.QFileDialog.getExistingDirectory(self, |
| 109 |
gettext("Select branch location")); |
| 110 |
if fileName != '': |
| 111 |
self.branch_combo.insertItem(0,fileName) |
| 112 |
self.branch_combo.setCurrentIndex(0) |
| 113 |
|
| 114 |
def _get_location(self): |
| 115 |
return str(self.branch_combo.currentText()) |
| 116 |
|
| 117 |
def validate(self): |
| 118 |
if not self._get_location(): |
| 119 |
self.operation_blocked(gettext("Master branch location not specified.")) |
| 120 |
return False |
| 121 |
return True |
| 122 |
|
| 123 |
def do_start(self): |
| 124 |
self.process_widget.do_start(None, 'bind', self._get_location()) |