|
1 # -*- coding: utf-8 -*- |
|
2 |
|
3 # Copyright (c) 2002 - 2019 Detlev Offenbach <detlev@die-offenbachs.de> |
|
4 # |
|
5 |
|
6 """ |
|
7 Module implementing the Subversion Options Dialog for a new project from the |
|
8 repository. |
|
9 """ |
|
10 |
|
11 from __future__ import unicode_literals |
|
12 |
|
13 import os |
|
14 |
|
15 from PyQt5.QtCore import QDir, pyqtSlot |
|
16 from PyQt5.QtWidgets import QDialog, QDialogButtonBox |
|
17 |
|
18 from E5Gui.E5PathPicker import E5PathPickerModes |
|
19 |
|
20 from .Ui_SvnNewProjectOptionsDialog import Ui_SvnNewProjectOptionsDialog |
|
21 from .Config import ConfigSvnProtocols |
|
22 |
|
23 import Utilities |
|
24 import Preferences |
|
25 |
|
26 |
|
27 class SvnNewProjectOptionsDialog(QDialog, Ui_SvnNewProjectOptionsDialog): |
|
28 """ |
|
29 Class implementing the Options Dialog for a new project from the |
|
30 repository. |
|
31 """ |
|
32 def __init__(self, vcs, parent=None): |
|
33 """ |
|
34 Constructor |
|
35 |
|
36 @param vcs reference to the version control object |
|
37 @param parent parent widget (QWidget) |
|
38 """ |
|
39 super(SvnNewProjectOptionsDialog, self).__init__(parent) |
|
40 self.setupUi(self) |
|
41 |
|
42 self.vcsProjectDirPicker.setMode(E5PathPickerModes.DirectoryMode) |
|
43 self.vcsUrlPicker.setMode(E5PathPickerModes.DirectoryMode) |
|
44 |
|
45 self.protocolCombo.addItems(ConfigSvnProtocols) |
|
46 |
|
47 self.vcs = vcs |
|
48 |
|
49 hd = Utilities.toNativeSeparators(QDir.homePath()) |
|
50 hd = os.path.join(hd, 'subversionroot') |
|
51 self.vcsUrlPicker.setText(hd) |
|
52 |
|
53 self.localPath = hd |
|
54 self.networkPath = "localhost/" |
|
55 self.localProtocol = True |
|
56 |
|
57 ipath = Preferences.getMultiProject("Workspace") or \ |
|
58 Utilities.getHomeDir() |
|
59 self.__initPaths = [ |
|
60 Utilities.fromNativeSeparators(ipath), |
|
61 Utilities.fromNativeSeparators(ipath) + "/", |
|
62 ] |
|
63 self.vcsProjectDirPicker.setText(self.__initPaths[0]) |
|
64 |
|
65 self.resize(self.width(), self.minimumSizeHint().height()) |
|
66 |
|
67 self.buttonBox.button(QDialogButtonBox.Ok).setEnabled(False) |
|
68 |
|
69 msh = self.minimumSizeHint() |
|
70 self.resize(max(self.width(), msh.width()), msh.height()) |
|
71 |
|
72 @pyqtSlot(str) |
|
73 def on_vcsProjectDirPicker_textChanged(self, txt): |
|
74 """ |
|
75 Private slot to handle a change of the project directory. |
|
76 |
|
77 @param txt name of the project directory (string) |
|
78 """ |
|
79 self.buttonBox.button(QDialogButtonBox.Ok).setEnabled( |
|
80 bool(txt) and |
|
81 Utilities.fromNativeSeparators(txt) not in self.__initPaths) |
|
82 |
|
83 def on_vcsUrlPicker_pickerButtonClicked(self): |
|
84 """ |
|
85 Private slot to display a repository browser dialog. |
|
86 """ |
|
87 from .SvnRepoBrowserDialog import SvnRepoBrowserDialog |
|
88 dlg = SvnRepoBrowserDialog(self.vcs, mode="select", parent=self) |
|
89 dlg.start( |
|
90 self.protocolCombo.currentText() + self.vcsUrlPicker.text()) |
|
91 if dlg.exec_() == QDialog.Accepted: |
|
92 url = dlg.getSelectedUrl() |
|
93 if url: |
|
94 protocol = url.split("://")[0] |
|
95 path = url.split("://")[1] |
|
96 self.protocolCombo.setCurrentIndex( |
|
97 self.protocolCombo.findText(protocol + "://")) |
|
98 self.vcsUrlPicker.setText(path) |
|
99 |
|
100 def on_layoutCheckBox_toggled(self, checked): |
|
101 """ |
|
102 Private slot to handle the change of the layout checkbox. |
|
103 |
|
104 @param checked flag indicating the state of the checkbox (boolean) |
|
105 """ |
|
106 self.vcsTagLabel.setEnabled(checked) |
|
107 self.vcsTagEdit.setEnabled(checked) |
|
108 if not checked: |
|
109 self.vcsTagEdit.clear() |
|
110 |
|
111 @pyqtSlot(str) |
|
112 def on_protocolCombo_activated(self, protocol): |
|
113 """ |
|
114 Private slot to switch the status of the directory selection button. |
|
115 |
|
116 @param protocol selected protocol (string) |
|
117 """ |
|
118 if protocol == "file://": |
|
119 self.networkPath = self.vcsUrlPicker.text() |
|
120 self.vcsUrlPicker.setText(self.localPath) |
|
121 self.vcsUrlLabel.setText(self.tr("Pat&h:")) |
|
122 self.localProtocol = True |
|
123 self.vcsUrlPicker.setMode(E5PathPickerModes.DirectoryMode) |
|
124 else: |
|
125 if self.localProtocol: |
|
126 self.localPath = self.vcsUrlPicker.text() |
|
127 self.vcsUrlPicker.setText(self.networkPath) |
|
128 self.vcsUrlLabel.setText(self.tr("&URL:")) |
|
129 self.localProtocol = False |
|
130 self.vcsUrlPicker.setMode(E5PathPickerModes.CustomMode) |
|
131 |
|
132 @pyqtSlot(str) |
|
133 def on_vcsUrlPicker_textChanged(self, txt): |
|
134 """ |
|
135 Private slot to handle changes of the URL. |
|
136 |
|
137 @param txt current text of the line edit (string) |
|
138 """ |
|
139 enable = "://" not in txt |
|
140 self.buttonBox.button(QDialogButtonBox.Ok).setEnabled(enable) |
|
141 |
|
142 def getData(self): |
|
143 """ |
|
144 Public slot to retrieve the data entered into the dialog. |
|
145 |
|
146 @return a tuple of a string (project directory) and a dictionary |
|
147 containing the data entered. |
|
148 """ |
|
149 scheme = self.protocolCombo.currentText() |
|
150 url = self.vcsUrlPicker.text() |
|
151 vcsdatadict = { |
|
152 "url": '{0}{1}'.format(scheme, url), |
|
153 "tag": self.vcsTagEdit.text(), |
|
154 "standardLayout": self.layoutCheckBox.isChecked(), |
|
155 } |
|
156 return (self.vcsProjectDirPicker.text(), vcsdatadict) |