| 1 |
|
| 2 |
|
| 3 |
|
| 4 |
|
| 5 |
|
| 6 |
|
| 7 |
|
| 8 |
|
| 9 |
|
| 10 |
|
| 11 |
|
| 12 |
|
| 13 |
|
| 14 |
|
| 15 |
|
| 16 |
|
| 17 |
|
| 18 |
|
| 19 |
|
| 20 |
|
| 21 |
|
| 22 |
import os |
| 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 |
QBzrDialog, |
| 32 |
runs_in_loading_queue, |
| 33 |
ThrobberWidget |
| 34 |
) |
| 35 |
from breezy.plugins.qbrz.lib.uifactory import ui_current_widget |
| 36 |
from breezy.plugins.qbrz.lib.trace import ( |
| 37 |
reports_exception, |
| 38 |
SUB_LOAD_METHOD) |
| 39 |
|
| 40 |
|
| 41 |
class QBzrSwitchWindow(SubProcessDialog): |
| 42 |
|
| 43 |
def __init__(self, branch, controldir, location, ui_mode = None): |
| 44 |
|
| 45 |
super(QBzrSwitchWindow, self).__init__( |
| 46 |
gettext("Switch"), |
| 47 |
name = "switch", |
| 48 |
default_size = (400, 400), |
| 49 |
ui_mode = ui_mode, |
| 50 |
dialog = True, |
| 51 |
parent = None, |
| 52 |
hide_progress=False, |
| 53 |
) |
| 54 |
|
| 55 |
self.branch = branch |
| 56 |
|
| 57 |
gbSwitch = QtWidgets.QGroupBox(gettext("Switch checkout"), self) |
| 58 |
|
| 59 |
switch_box = QtWidgets.QFormLayout(gbSwitch) |
| 60 |
|
| 61 |
branchbase = None |
| 62 |
|
| 63 |
boundloc = branch.get_bound_location() |
| 64 |
if boundloc is not None: |
| 65 |
label = gettext("Heavyweight checkout:") |
| 66 |
branchbase = branch.base |
| 67 |
else: |
| 68 |
if controldir.root_transport.base != branch.controldir.root_transport.base: |
| 69 |
label = gettext("Lightweight checkout:") |
| 70 |
boundloc = branch.controldir.root_transport.base |
| 71 |
branchbase = controldir.root_transport.base |
| 72 |
else: |
| 73 |
raise errors.BzrError("This branch is not checkout.") |
| 74 |
|
| 75 |
switch_box.addRow(label, QtWidgets.QLabel(url_for_display(branchbase))) |
| 76 |
switch_box.addRow(gettext("Checkout of branch:"), |
| 77 |
QtWidgets.QLabel(url_for_display(boundloc))) |
| 78 |
self.boundloc = url_for_display(boundloc) |
| 79 |
|
| 80 |
throb_hbox = QtWidgets.QHBoxLayout() |
| 81 |
|
| 82 |
self.throbber = ThrobberWidget(self) |
| 83 |
throb_hbox.addWidget(self.throbber) |
| 84 |
self.throbber.hide() |
| 85 |
switch_box.addRow(throb_hbox) |
| 86 |
|
| 87 |
switch_hbox = QtWidgets.QHBoxLayout() |
| 88 |
|
| 89 |
branch_label = QtWidgets.QLabel(gettext("Switch to branch:")) |
| 90 |
branch_combo = QtWidgets.QComboBox() |
| 91 |
branch_combo.setEditable(True) |
| 92 |
|
| 93 |
self.branch_combo = branch_combo |
| 94 |
|
| 95 |
if location is not None: |
| 96 |
branch_combo.addItem(osutils.abspath(location)) |
| 97 |
elif boundloc is not None: |
| 98 |
branch_combo.addItem(url_for_display(boundloc)) |
| 99 |
|
| 100 |
browse_button = QtWidgets.QPushButton(gettext("Browse")) |
| 101 |
browse_button.clicked[bool].connect(self.browse_clicked) |
| 102 |
|
| 103 |
switch_hbox.addWidget(branch_label) |
| 104 |
switch_hbox.addWidget(branch_combo) |
| 105 |
switch_hbox.addWidget(browse_button) |
| 106 |
|
| 107 |
switch_hbox.setStretchFactor(branch_label,0) |
| 108 |
switch_hbox.setStretchFactor(branch_combo,1) |
| 109 |
switch_hbox.setStretchFactor(browse_button,0) |
| 110 |
|
| 111 |
switch_box.addRow(switch_hbox) |
| 112 |
|
| 113 |
create_branch_box = QtWidgets.QCheckBox(gettext("Create Branch before switching")) |
| 114 |
create_branch_box.setChecked(False) |
| 115 |
switch_box.addRow(create_branch_box) |
| 116 |
self.create_branch_box = create_branch_box |
| 117 |
|
| 118 |
layout = QtWidgets.QVBoxLayout(self) |
| 119 |
|
| 120 |
layout.addWidget(gbSwitch) |
| 121 |
|
| 122 |
layout.addWidget(self.make_default_status_box()) |
| 123 |
layout.addWidget(self.buttonbox) |
| 124 |
self.branch_combo.setFocus() |
| 125 |
|
| 126 |
def show(self): |
| 127 |
QBzrDialog.show(self) |
| 128 |
QtCore.QTimer.singleShot(0, self.initial_load) |
| 129 |
|
| 130 |
def exec_(self): |
| 131 |
QtCore.QTimer.singleShot(0, self.initial_load) |
| 132 |
return QBzrDialog.exec_(self) |
| 133 |
|
| 134 |
def _load_branch_names(self): |
| 135 |
branch_combo = self.branch_combo |
| 136 |
repo = self.branch.controldir.find_repository() |
| 137 |
if repo is not None: |
| 138 |
if getattr(repo, "iter_branches", None): |
| 139 |
for br in repo.iter_branches(): |
| 140 |
self.processEvents() |
| 141 |
branch_combo.addItem(url_for_display(br.base)) |
| 142 |
|
| 143 |
@runs_in_loading_queue |
| 144 |
@ui_current_widget |
| 145 |
@reports_exception(type=SUB_LOAD_METHOD) |
| 146 |
def initial_load(self): |
| 147 |
|
| 148 |
self.throbber.show() |
| 149 |
self._load_branch_names() |
| 150 |
self.throbber.hide() |
| 151 |
|
| 152 |
def browse_clicked(self): |
| 153 |
if os.path.exists(self.boundloc): |
| 154 |
directory = self.boundloc |
| 155 |
else: |
| 156 |
directory = os.getcwd() |
| 157 |
fileName = QtWidgets.QFileDialog.getExistingDirectory(self, |
| 158 |
gettext("Select branch location"), |
| 159 |
directory, |
| 160 |
) |
| 161 |
if fileName: |
| 162 |
self.branch_combo.insertItem(0,fileName) |
| 163 |
self.branch_combo.setCurrentIndex(0) |
| 164 |
|
| 165 |
def validate(self): |
| 166 |
location = str(self.branch_combo.currentText()) |
| 167 |
if not location: |
| 168 |
self.operation_blocked(gettext("Branch location not specified.")) |
| 169 |
return False |
| 170 |
return True |
| 171 |
|
| 172 |
def do_start(self): |
| 173 |
location = str(self.branch_combo.currentText()) |
| 174 |
if self.create_branch_box.isChecked(): |
| 175 |
self.process_widget.do_start(None, 'switch', '--create-branch', location) |
| 176 |
else: |
| 177 |
self.process_widget.do_start(None, 'switch', location) |