| 1 |
|
| 2 |
|
| 3 |
|
| 4 |
|
| 5 |
|
| 6 |
|
| 7 |
|
| 8 |
|
| 9 |
|
| 10 |
|
| 11 |
|
| 12 |
|
| 13 |
|
| 14 |
|
| 15 |
|
| 16 |
|
| 17 |
|
| 18 |
from PyQt5 import QtCore |
| 19 |
import os |
| 20 |
|
| 21 |
from breezy.commands import get_cmd_object |
| 22 |
|
| 23 |
from breezy.plugins.qbrz.lib.i18n import gettext |
| 24 |
from breezy.plugins.qbrz.lib.subprocess import SubProcessDialog |
| 25 |
from breezy.plugins.qbrz.lib.ui_init import Ui_InitForm |
| 26 |
|
| 27 |
from breezy.plugins.qbrz.lib.util import ( |
| 28 |
hookup_directory_picker, |
| 29 |
DIRECTORYPICKER_TARGET, |
| 30 |
) |
| 31 |
|
| 32 |
|
| 33 |
class QBzrInitWindow(SubProcessDialog): |
| 34 |
|
| 35 |
def __init__(self, localdir=".", parent=None, ui_mode=False): |
| 36 |
super(QBzrInitWindow, self).__init__( |
| 37 |
gettext("Initialize"), |
| 38 |
name = "init", |
| 39 |
ui_mode = ui_mode, |
| 40 |
dialog = True, |
| 41 |
parent = parent, |
| 42 |
hide_progress=True) |
| 43 |
|
| 44 |
self.ui = Ui_InitForm() |
| 45 |
self.ui.setupUi(self) |
| 46 |
|
| 47 |
for w in self.make_default_layout_widgets(): |
| 48 |
self.layout().addWidget(w) |
| 49 |
|
| 50 |
|
| 51 |
self.ui.location.setText(os.path.abspath(localdir)) |
| 52 |
hookup_directory_picker(self, |
| 53 |
self.ui.location_picker, |
| 54 |
self.ui.location, |
| 55 |
DIRECTORYPICKER_TARGET) |
| 56 |
|
| 57 |
|
| 58 |
cmd = get_cmd_object('init') |
| 59 |
opt = cmd.options()['format'] |
| 60 |
fill_option_combo(self.ui.combo_format, opt, 'default', |
| 61 |
self.ui.format_desc) |
| 62 |
|
| 63 |
self.ui.but_append_only.setToolTip(cmd.options()['append-revisions-only'].help) |
| 64 |
|
| 65 |
cmd = get_cmd_object('init-repo') |
| 66 |
opt = cmd.options()['no-trees'] |
| 67 |
self.ui.but_no_trees.setToolTip(opt.help) |
| 68 |
|
| 69 |
def _get_location(self): |
| 70 |
return str(self.ui.location.text()) |
| 71 |
|
| 72 |
def validate(self): |
| 73 |
if not self._get_location(): |
| 74 |
self.operation_blocked(gettext("You should specify a location")) |
| 75 |
return False |
| 76 |
return True |
| 77 |
|
| 78 |
def do_start(self): |
| 79 |
if self.ui.but_init.isChecked(): |
| 80 |
args = ['init'] |
| 81 |
if self.ui.but_append_only.isChecked(): |
| 82 |
args.append('--append-revisions-only') |
| 83 |
else: |
| 84 |
args = ['init-repo'] |
| 85 |
if self.ui.but_no_trees.isChecked(): |
| 86 |
args.append('--no-trees') |
| 87 |
args.append('--format=' + self.ui.combo_format.currentText()) |
| 88 |
|
| 89 |
args.append(self._get_location()) |
| 90 |
|
| 91 |
self.process_widget.do_start(None, *args) |
| 92 |
|
| 93 |
|
| 94 |
|
| 95 |
|
| 96 |
|
| 97 |
def fill_option_combo(combo, option, default, desc_widget=None): |
| 98 |
"""Fill a widget with the values specified in a bzr.options.Option object. |
| 99 |
|
| 100 |
If default is specified, a string match is made. Otherwise, the first |
| 101 |
option is the default. |
| 102 |
|
| 103 |
If desc_widget is specified, it is a widget which will be updated with |
| 104 |
the help text for the option as each option is selected. |
| 105 |
""" |
| 106 |
|
| 107 |
def index_changed(index, combo=combo, desc_widget=desc_widget): |
| 108 |
help = combo.itemData(index) |
| 109 |
desc_widget.setText(help) |
| 110 |
|
| 111 |
default_index = 0 |
| 112 |
for i, info in enumerate(option.iter_switches()): |
| 113 |
if i==0: |
| 114 |
|
| 115 |
continue |
| 116 |
name, short_name, argname, help = info |
| 117 |
if option.is_hidden(name): |
| 118 |
continue |
| 119 |
user_data = help or '' |
| 120 |
combo.addItem(name, user_data) |
| 121 |
if name == default: |
| 122 |
default_index = combo.count() - 1 |
| 123 |
if desc_widget is not None: |
| 124 |
combo.currentIndexChanged[int].connect(index_changed) |
| 125 |
|
| 126 |
combo.setCurrentIndex(default_index) |