13 import os |
13 import os |
14 |
14 |
15 from PyQt5.QtCore import pyqtSlot, QDir |
15 from PyQt5.QtCore import pyqtSlot, QDir |
16 from PyQt5.QtWidgets import QDialog, QDialogButtonBox |
16 from PyQt5.QtWidgets import QDialog, QDialogButtonBox |
17 |
17 |
18 from E5Gui.E5Completers import E5DirCompleter |
18 from E5Gui.E5PathPicker import E5PathPickerModes |
19 from E5Gui import E5FileDialog |
|
20 |
19 |
21 from .Ui_HgNewProjectOptionsDialog import Ui_HgNewProjectOptionsDialog |
20 from .Ui_HgNewProjectOptionsDialog import Ui_HgNewProjectOptionsDialog |
22 from .Config import ConfigHgProtocols |
21 from .Config import ConfigHgProtocols |
23 |
22 |
24 import Utilities |
23 import Utilities |
25 import Preferences |
24 import Preferences |
26 import UI.PixmapCache |
|
27 |
25 |
28 |
26 |
29 class HgNewProjectOptionsDialog(QDialog, Ui_HgNewProjectOptionsDialog): |
27 class HgNewProjectOptionsDialog(QDialog, Ui_HgNewProjectOptionsDialog): |
30 """ |
28 """ |
31 Class implementing the Options Dialog for a new project from the |
29 Class implementing the Options Dialog for a new project from the |
39 @param parent parent widget (QWidget) |
37 @param parent parent widget (QWidget) |
40 """ |
38 """ |
41 super(HgNewProjectOptionsDialog, self).__init__(parent) |
39 super(HgNewProjectOptionsDialog, self).__init__(parent) |
42 self.setupUi(self) |
40 self.setupUi(self) |
43 |
41 |
44 self.projectDirButton.setIcon(UI.PixmapCache.getIcon("open.png")) |
42 self.vcsProjectDirPicker.setMode(E5PathPickerModes.DirectoryMode) |
45 self.vcsUrlButton.setIcon(UI.PixmapCache.getIcon("open.png")) |
43 self.vcsUrlPicker.setMode(E5PathPickerModes.DirectoryMode) |
46 |
|
47 self.vcsDirectoryCompleter = E5DirCompleter(self.vcsUrlEdit) |
|
48 self.vcsProjectDirCompleter = E5DirCompleter(self.vcsProjectDirEdit) |
|
49 |
44 |
50 self.protocolCombo.addItems(ConfigHgProtocols) |
45 self.protocolCombo.addItems(ConfigHgProtocols) |
51 |
46 |
52 hd = Utilities.toNativeSeparators(QDir.homePath()) |
47 hd = Utilities.toNativeSeparators(QDir.homePath()) |
53 hd = os.path.join(hd, 'hgroot') |
48 hd = os.path.join(hd, 'hgroot') |
54 self.vcsUrlEdit.setText(hd) |
49 self.vcsUrlPicker.setText(hd) |
55 |
50 |
56 self.vcs = vcs |
51 self.vcs = vcs |
57 |
52 |
58 self.localPath = hd |
53 self.localPath = hd |
59 self.networkPath = "localhost/" |
54 self.networkPath = "localhost/" |
63 Utilities.getHomeDir() |
58 Utilities.getHomeDir() |
64 self.__initPaths = [ |
59 self.__initPaths = [ |
65 Utilities.fromNativeSeparators(ipath), |
60 Utilities.fromNativeSeparators(ipath), |
66 Utilities.fromNativeSeparators(ipath) + "/", |
61 Utilities.fromNativeSeparators(ipath) + "/", |
67 ] |
62 ] |
68 self.vcsProjectDirEdit.setText( |
63 self.vcsProjectDirPicker.setText(self.__initPaths[0]) |
69 Utilities.toNativeSeparators(self.__initPaths[0])) |
|
70 |
64 |
71 self.lfNoteLabel.setVisible(self.vcs.isExtensionActive("largefiles")) |
65 self.lfNoteLabel.setVisible(self.vcs.isExtensionActive("largefiles")) |
72 self.largeCheckBox.setVisible(self.vcs.isExtensionActive("largefiles")) |
66 self.largeCheckBox.setVisible(self.vcs.isExtensionActive("largefiles")) |
73 |
67 |
74 self.resize(self.width(), self.minimumSizeHint().height()) |
68 self.resize(self.width(), self.minimumSizeHint().height()) |
77 |
71 |
78 msh = self.minimumSizeHint() |
72 msh = self.minimumSizeHint() |
79 self.resize(max(self.width(), msh.width()), msh.height()) |
73 self.resize(max(self.width(), msh.width()), msh.height()) |
80 |
74 |
81 @pyqtSlot(str) |
75 @pyqtSlot(str) |
82 def on_vcsProjectDirEdit_textChanged(self, txt): |
76 def on_vcsProjectDirPicker_textChanged(self, txt): |
83 """ |
77 """ |
84 Private slot to handle a change of the project directory. |
78 Private slot to handle a change of the project directory. |
85 |
79 |
86 @param txt name of the project directory (string) |
80 @param txt name of the project directory (string) |
87 """ |
81 """ |
88 self.buttonBox.button(QDialogButtonBox.Ok).setEnabled( |
82 self.buttonBox.button(QDialogButtonBox.Ok).setEnabled( |
89 bool(txt) and |
83 bool(txt) and |
90 Utilities.fromNativeSeparators(txt) not in self.__initPaths) |
84 Utilities.fromNativeSeparators(txt) not in self.__initPaths) |
91 |
85 |
92 @pyqtSlot() |
|
93 def on_vcsUrlButton_clicked(self): |
|
94 """ |
|
95 Private slot to display a selection dialog. |
|
96 """ |
|
97 if self.protocolCombo.currentText() == "file://": |
|
98 directory = E5FileDialog.getExistingDirectory( |
|
99 self, |
|
100 self.tr("Select Repository-Directory"), |
|
101 self.vcsUrlEdit.text(), |
|
102 E5FileDialog.Options(E5FileDialog.ShowDirsOnly)) |
|
103 |
|
104 if directory: |
|
105 self.vcsUrlEdit.setText( |
|
106 Utilities.toNativeSeparators(directory)) |
|
107 |
|
108 @pyqtSlot() |
|
109 def on_projectDirButton_clicked(self): |
|
110 """ |
|
111 Private slot to display a directory selection dialog. |
|
112 """ |
|
113 directory = E5FileDialog.getExistingDirectory( |
|
114 self, |
|
115 self.tr("Select Project Directory"), |
|
116 self.vcsProjectDirEdit.text(), |
|
117 E5FileDialog.Options(E5FileDialog.ShowDirsOnly)) |
|
118 |
|
119 if directory: |
|
120 self.vcsProjectDirEdit.setText( |
|
121 Utilities.toNativeSeparators(directory)) |
|
122 |
|
123 @pyqtSlot(str) |
86 @pyqtSlot(str) |
124 def on_protocolCombo_activated(self, protocol): |
87 def on_protocolCombo_activated(self, protocol): |
125 """ |
88 """ |
126 Private slot to switch the status of the directory selection button. |
89 Private slot to switch the status of the directory selection button. |
127 |
90 |
128 @param protocol name of the selected protocol (string) |
91 @param protocol name of the selected protocol (string) |
129 """ |
92 """ |
130 self.vcsUrlButton.setEnabled(protocol == "file://") |
93 self.vcsUrlPicker.setPickerEnabled(protocol == "file://") |
131 if protocol == "file://": |
94 if protocol == "file://": |
132 self.networkPath = self.vcsUrlEdit.text() |
95 self.networkPath = self.vcsUrlPicker.text() |
133 self.vcsUrlEdit.setText(self.localPath) |
96 self.vcsUrlPicker.setText(self.localPath) |
134 self.localProtocol = True |
97 self.localProtocol = True |
135 else: |
98 else: |
136 if self.localProtocol: |
99 if self.localProtocol: |
137 self.localPath = self.vcsUrlEdit.text() |
100 self.localPath = self.vcsUrlPicker.text() |
138 self.vcsUrlEdit.setText(self.networkPath) |
101 self.vcsUrlPicker.setText(self.networkPath) |
139 self.localProtocol = False |
102 self.localProtocol = False |
140 |
103 |
141 @pyqtSlot(str) |
104 @pyqtSlot(str) |
142 def on_vcsUrlEdit_textChanged(self, txt): |
105 def on_vcsUrlPicker_textChanged(self, txt): |
143 """ |
106 """ |
144 Private slot to handle changes of the URL. |
107 Private slot to handle changes of the URL. |
145 |
108 |
146 @param txt current text of the line edit (string) |
109 @param txt current text of the line edit (string) |
147 """ |
110 """ |
154 |
117 |
155 @return a tuple of a string (project directory) and a dictionary |
118 @return a tuple of a string (project directory) and a dictionary |
156 containing the data entered. |
119 containing the data entered. |
157 """ |
120 """ |
158 scheme = self.protocolCombo.currentText() |
121 scheme = self.protocolCombo.currentText() |
159 url = self.vcsUrlEdit.text() |
122 url = self.vcsUrlPicker.text() |
160 if scheme == "file://" and url[0] not in ["\\", "/"]: |
123 if scheme == "file://" and url[0] not in ["\\", "/"]: |
161 url = "/{0}".format(url) |
124 url = "/{0}".format(url) |
162 vcsdatadict = { |
125 vcsdatadict = { |
163 "url": '{0}{1}'.format(scheme, url), |
126 "url": '{0}{1}'.format(scheme, url), |
164 "revision": self.vcsRevisionEdit.text(), |
127 "revision": self.vcsRevisionEdit.text(), |
165 "largefiles": self.largeCheckBox.isChecked(), |
128 "largefiles": self.largeCheckBox.isChecked(), |
166 } |
129 } |
167 return (self.vcsProjectDirEdit.text(), vcsdatadict) |
130 return (self.vcsProjectDirPicker.text(), vcsdatadict) |