8 repository. |
8 repository. |
9 """ |
9 """ |
10 |
10 |
11 from __future__ import unicode_literals |
11 from __future__ import unicode_literals |
12 |
12 |
13 import os |
13 from PyQt5.QtCore import pyqtSlot, QUrl |
14 |
|
15 from PyQt5.QtCore import pyqtSlot, QDir |
|
16 from PyQt5.QtWidgets import QDialog, QDialogButtonBox |
14 from PyQt5.QtWidgets import QDialog, QDialogButtonBox |
17 |
15 |
18 from E5Gui.E5PathPicker import E5PathPickerModes |
16 from E5Gui.E5PathPicker import E5PathPickerModes |
19 |
17 |
20 from .Ui_HgNewProjectOptionsDialog import Ui_HgNewProjectOptionsDialog |
18 from .Ui_HgNewProjectOptionsDialog import Ui_HgNewProjectOptionsDialog |
21 from .Config import ConfigHgProtocols |
19 from .Config import ConfigHgSchemes |
22 |
20 |
23 import Utilities |
21 import Utilities |
24 import Preferences |
22 import Preferences |
25 |
23 |
26 |
24 |
40 self.setupUi(self) |
38 self.setupUi(self) |
41 |
39 |
42 self.vcsProjectDirPicker.setMode(E5PathPickerModes.DirectoryMode) |
40 self.vcsProjectDirPicker.setMode(E5PathPickerModes.DirectoryMode) |
43 self.vcsUrlPicker.setMode(E5PathPickerModes.DirectoryMode) |
41 self.vcsUrlPicker.setMode(E5PathPickerModes.DirectoryMode) |
44 |
42 |
45 self.protocolCombo.addItems(ConfigHgProtocols) |
|
46 |
|
47 hd = Utilities.toNativeSeparators(QDir.homePath()) |
|
48 hd = os.path.join(hd, 'hgroot') |
|
49 self.vcsUrlPicker.setText(hd) |
|
50 |
|
51 self.vcs = vcs |
|
52 |
|
53 self.localPath = hd |
|
54 self.networkPath = "localhost/" |
|
55 self.localProtocol = True |
|
56 |
|
57 ipath = Preferences.getMultiProject("Workspace") or \ |
43 ipath = Preferences.getMultiProject("Workspace") or \ |
58 Utilities.getHomeDir() |
44 Utilities.getHomeDir() |
59 self.__initPaths = [ |
45 self.__initPaths = [ |
60 Utilities.fromNativeSeparators(ipath), |
46 Utilities.fromNativeSeparators(ipath), |
61 Utilities.fromNativeSeparators(ipath) + "/", |
47 Utilities.fromNativeSeparators(ipath) + "/", |
62 ] |
48 ] |
63 self.vcsProjectDirPicker.setText(self.__initPaths[0]) |
49 self.vcsProjectDirPicker.setText(self.__initPaths[0]) |
64 |
50 |
65 self.lfNoteLabel.setVisible(self.vcs.isExtensionActive("largefiles")) |
51 self.lfNoteLabel.setVisible(vcs.isExtensionActive("largefiles")) |
66 self.largeCheckBox.setVisible(self.vcs.isExtensionActive("largefiles")) |
52 self.largeCheckBox.setVisible(vcs.isExtensionActive("largefiles")) |
67 |
|
68 self.resize(self.width(), self.minimumSizeHint().height()) |
|
69 |
53 |
70 self.buttonBox.button(QDialogButtonBox.Ok).setEnabled(False) |
54 self.buttonBox.button(QDialogButtonBox.Ok).setEnabled(False) |
71 |
55 |
72 msh = self.minimumSizeHint() |
56 msh = self.minimumSizeHint() |
73 self.resize(max(self.width(), msh.width()), msh.height()) |
57 self.resize(max(self.width(), msh.width()), msh.height()) |
82 self.buttonBox.button(QDialogButtonBox.Ok).setEnabled( |
66 self.buttonBox.button(QDialogButtonBox.Ok).setEnabled( |
83 bool(txt) and |
67 bool(txt) and |
84 Utilities.fromNativeSeparators(txt) not in self.__initPaths) |
68 Utilities.fromNativeSeparators(txt) not in self.__initPaths) |
85 |
69 |
86 @pyqtSlot(str) |
70 @pyqtSlot(str) |
87 def on_protocolCombo_activated(self, protocol): |
|
88 """ |
|
89 Private slot to switch the status of the directory selection button. |
|
90 |
|
91 @param protocol name of the selected protocol (string) |
|
92 """ |
|
93 self.vcsUrlPicker.setPickerEnabled(protocol == "file://") |
|
94 if protocol == "file://": |
|
95 self.networkPath = self.vcsUrlPicker.text() |
|
96 self.vcsUrlPicker.setText(self.localPath) |
|
97 self.localProtocol = True |
|
98 else: |
|
99 if self.localProtocol: |
|
100 self.localPath = self.vcsUrlPicker.text() |
|
101 self.vcsUrlPicker.setText(self.networkPath) |
|
102 self.localProtocol = False |
|
103 |
|
104 @pyqtSlot(str) |
|
105 def on_vcsUrlPicker_textChanged(self, txt): |
71 def on_vcsUrlPicker_textChanged(self, txt): |
106 """ |
72 """ |
107 Private slot to handle changes of the URL. |
73 Private slot to handle changes of the URL. |
108 |
74 |
109 @param txt current text of the line edit (string) |
75 @param txt current text of the line edit (string) |
110 """ |
76 """ |
111 enable = "://" not in txt |
77 url = QUrl.fromUserInput(txt) |
|
78 enable = url.isValid() and url.scheme() in ConfigHgSchemes |
112 self.buttonBox.button(QDialogButtonBox.Ok).setEnabled(enable) |
79 self.buttonBox.button(QDialogButtonBox.Ok).setEnabled(enable) |
|
80 |
|
81 self.vcsUrlPicker.setPickerEnabled(url.scheme() == "file") |
113 |
82 |
114 def getData(self): |
83 def getData(self): |
115 """ |
84 """ |
116 Public slot to retrieve the data entered into the dialog. |
85 Public slot to retrieve the data entered into the dialog. |
117 |
86 |
118 @return a tuple of a string (project directory) and a dictionary |
87 @return a tuple of a string (project directory) and a dictionary |
119 containing the data entered. |
88 containing the data entered. |
120 """ |
89 """ |
121 scheme = self.protocolCombo.currentText() |
90 url = QUrl.fromUserInput(self.vcsUrlPicker.text().replace("\\", "/")) |
122 url = self.vcsUrlPicker.text() |
|
123 if scheme == "file://" and url[0] not in ["\\", "/"]: |
|
124 url = "/{0}".format(url) |
|
125 vcsdatadict = { |
91 vcsdatadict = { |
126 "url": '{0}{1}'.format(scheme, url), |
92 "url": url.toString(QUrl.None_), |
127 "revision": self.vcsRevisionEdit.text(), |
93 "revision": self.vcsRevisionEdit.text(), |
128 "largefiles": self.largeCheckBox.isChecked(), |
94 "largefiles": self.largeCheckBox.isChecked(), |
129 } |
95 } |
130 return (self.vcsProjectDirPicker.text(), vcsdatadict) |
96 return (self.vcsProjectDirPicker.text(), vcsdatadict) |