25 class GitNewProjectOptionsDialog(QDialog, Ui_GitNewProjectOptionsDialog): |
25 class GitNewProjectOptionsDialog(QDialog, Ui_GitNewProjectOptionsDialog): |
26 """ |
26 """ |
27 Class implementing the Options Dialog for a new project from the |
27 Class implementing the Options Dialog for a new project from the |
28 repository. |
28 repository. |
29 """ |
29 """ |
|
30 |
30 def __init__(self, vcs, parent=None): |
31 def __init__(self, vcs, parent=None): |
31 """ |
32 """ |
32 Constructor |
33 Constructor |
33 |
34 |
34 @param vcs reference to the version control object |
35 @param vcs reference to the version control object |
35 @param parent parent widget (QWidget) |
36 @param parent parent widget (QWidget) |
36 """ |
37 """ |
37 super().__init__(parent) |
38 super().__init__(parent) |
38 self.setupUi(self) |
39 self.setupUi(self) |
39 |
40 |
40 self.__vcs = vcs |
41 self.__vcs = vcs |
41 |
42 |
42 self.projectDirButton.setIcon(UI.PixmapCache.getIcon("open")) |
43 self.projectDirButton.setIcon(UI.PixmapCache.getIcon("open")) |
43 self.vcsUrlButton.setIcon(UI.PixmapCache.getIcon("open")) |
44 self.vcsUrlButton.setIcon(UI.PixmapCache.getIcon("open")) |
44 self.vcsUrlClearHistoryButton.setIcon( |
45 self.vcsUrlClearHistoryButton.setIcon(UI.PixmapCache.getIcon("editDelete")) |
45 UI.PixmapCache.getIcon("editDelete")) |
46 |
46 |
47 vcsUrlHistory = self.__vcs.getPlugin().getPreferences("RepositoryUrlHistory") |
47 vcsUrlHistory = self.__vcs.getPlugin().getPreferences( |
|
48 "RepositoryUrlHistory") |
|
49 self.vcsUrlCombo.addItems(vcsUrlHistory) |
48 self.vcsUrlCombo.addItems(vcsUrlHistory) |
50 self.vcsUrlCombo.setEditText("") |
49 self.vcsUrlCombo.setEditText("") |
51 |
50 |
52 self.vcsDirectoryCompleter = EricDirCompleter(self.vcsUrlCombo) |
51 self.vcsDirectoryCompleter = EricDirCompleter(self.vcsUrlCombo) |
53 self.vcsProjectDirCompleter = EricDirCompleter(self.vcsProjectDirEdit) |
52 self.vcsProjectDirCompleter = EricDirCompleter(self.vcsProjectDirEdit) |
54 |
53 |
55 ipath = ( |
54 ipath = Preferences.getMultiProject("Workspace") or Utilities.getHomeDir() |
56 Preferences.getMultiProject("Workspace") or |
|
57 Utilities.getHomeDir() |
|
58 ) |
|
59 self.__initPaths = [ |
55 self.__initPaths = [ |
60 Utilities.fromNativeSeparators(ipath), |
56 Utilities.fromNativeSeparators(ipath), |
61 Utilities.fromNativeSeparators(ipath) + "/", |
57 Utilities.fromNativeSeparators(ipath) + "/", |
62 ] |
58 ] |
63 self.vcsProjectDirEdit.setText( |
59 self.vcsProjectDirEdit.setText( |
64 Utilities.toNativeSeparators(self.__initPaths[0])) |
60 Utilities.toNativeSeparators(self.__initPaths[0]) |
65 |
61 ) |
66 self.buttonBox.button( |
62 |
67 QDialogButtonBox.StandardButton.Ok).setEnabled(False) |
63 self.buttonBox.button(QDialogButtonBox.StandardButton.Ok).setEnabled(False) |
68 |
64 |
69 msh = self.minimumSizeHint() |
65 msh = self.minimumSizeHint() |
70 self.resize(max(self.width(), msh.width()), msh.height()) |
66 self.resize(max(self.width(), msh.width()), msh.height()) |
71 |
67 |
72 @pyqtSlot(str) |
68 @pyqtSlot(str) |
73 def on_vcsProjectDirEdit_textChanged(self, txt): |
69 def on_vcsProjectDirEdit_textChanged(self, txt): |
74 """ |
70 """ |
75 Private slot to handle a change of the project directory. |
71 Private slot to handle a change of the project directory. |
76 |
72 |
77 @param txt name of the project directory (string) |
73 @param txt name of the project directory (string) |
78 """ |
74 """ |
79 self.buttonBox.button(QDialogButtonBox.StandardButton.Ok).setEnabled( |
75 self.buttonBox.button(QDialogButtonBox.StandardButton.Ok).setEnabled( |
80 bool(txt) and |
76 bool(txt) and Utilities.fromNativeSeparators(txt) not in self.__initPaths |
81 Utilities.fromNativeSeparators(txt) not in self.__initPaths) |
77 ) |
82 |
78 |
83 @pyqtSlot() |
79 @pyqtSlot() |
84 def on_vcsUrlButton_clicked(self): |
80 def on_vcsUrlButton_clicked(self): |
85 """ |
81 """ |
86 Private slot to display a selection dialog. |
82 Private slot to display a selection dialog. |
87 """ |
83 """ |
88 directory = EricFileDialog.getExistingDirectory( |
84 directory = EricFileDialog.getExistingDirectory( |
89 self, |
85 self, |
90 self.tr("Select Repository-Directory"), |
86 self.tr("Select Repository-Directory"), |
91 self.vcsUrlCombo.currentText(), |
87 self.vcsUrlCombo.currentText(), |
92 EricFileDialog.ShowDirsOnly) |
88 EricFileDialog.ShowDirsOnly, |
93 |
89 ) |
|
90 |
94 if directory: |
91 if directory: |
95 self.vcsUrlCombo.setEditText( |
92 self.vcsUrlCombo.setEditText(Utilities.toNativeSeparators(directory)) |
96 Utilities.toNativeSeparators(directory)) |
93 |
97 |
|
98 @pyqtSlot() |
94 @pyqtSlot() |
99 def on_projectDirButton_clicked(self): |
95 def on_projectDirButton_clicked(self): |
100 """ |
96 """ |
101 Private slot to display a directory selection dialog. |
97 Private slot to display a directory selection dialog. |
102 """ |
98 """ |
103 directory = EricFileDialog.getExistingDirectory( |
99 directory = EricFileDialog.getExistingDirectory( |
104 self, |
100 self, |
105 self.tr("Select Project Directory"), |
101 self.tr("Select Project Directory"), |
106 self.vcsProjectDirEdit.text(), |
102 self.vcsProjectDirEdit.text(), |
107 EricFileDialog.ShowDirsOnly) |
103 EricFileDialog.ShowDirsOnly, |
108 |
104 ) |
|
105 |
109 if directory: |
106 if directory: |
110 self.vcsProjectDirEdit.setText( |
107 self.vcsProjectDirEdit.setText(Utilities.toNativeSeparators(directory)) |
111 Utilities.toNativeSeparators(directory)) |
108 |
112 |
|
113 @pyqtSlot(str) |
109 @pyqtSlot(str) |
114 def on_vcsUrlCombo_editTextChanged(self, txt): |
110 def on_vcsUrlCombo_editTextChanged(self, txt): |
115 """ |
111 """ |
116 Private slot to handle changes of the URL. |
112 Private slot to handle changes of the URL. |
117 |
113 |
118 @param txt current text of the combo box |
114 @param txt current text of the combo box |
119 @type str |
115 @type str |
120 """ |
116 """ |
121 enable = False |
117 enable = False |
122 vcsUrlEnable = False |
118 vcsUrlEnable = False |
123 |
119 |
124 if txt: |
120 if txt: |
125 url = QUrl.fromUserInput(txt) |
121 url = QUrl.fromUserInput(txt) |
126 if url.isValid(): |
122 if url.isValid(): |
127 if url.scheme() in ConfigGitSchemes: |
123 if url.scheme() in ConfigGitSchemes: |
128 enable = True |
124 enable = True |
129 vcsUrlEnable = url.scheme() == "file" |
125 vcsUrlEnable = url.scheme() == "file" |
130 elif ':' in txt: |
126 elif ":" in txt: |
131 # assume scp like repository URL |
127 # assume scp like repository URL |
132 enable = True |
128 enable = True |
133 else: |
129 else: |
134 vcsUrlEnable = True |
130 vcsUrlEnable = True |
135 |
131 |
136 self.buttonBox.button( |
132 self.buttonBox.button(QDialogButtonBox.StandardButton.Ok).setEnabled(enable) |
137 QDialogButtonBox.StandardButton.Ok).setEnabled(enable) |
|
138 self.vcsUrlButton.setEnabled(vcsUrlEnable) |
133 self.vcsUrlButton.setEnabled(vcsUrlEnable) |
139 |
134 |
140 @pyqtSlot() |
135 @pyqtSlot() |
141 def on_vcsUrlClearHistoryButton_clicked(self): |
136 def on_vcsUrlClearHistoryButton_clicked(self): |
142 """ |
137 """ |
143 Private slot to clear the history of entered repository URLs. |
138 Private slot to clear the history of entered repository URLs. |
144 """ |
139 """ |
145 currentVcsUrl = self.vcsUrlCombo.currentText() |
140 currentVcsUrl = self.vcsUrlCombo.currentText() |
146 self.vcsUrlCombo.clear() |
141 self.vcsUrlCombo.clear() |
147 self.vcsUrlCombo.setEditText(currentVcsUrl) |
142 self.vcsUrlCombo.setEditText(currentVcsUrl) |
148 |
143 |
149 self.__saveHistory() |
144 self.__saveHistory() |
150 |
145 |
151 def getData(self): |
146 def getData(self): |
152 """ |
147 """ |
153 Public slot to retrieve the data entered into the dialog. |
148 Public slot to retrieve the data entered into the dialog. |
154 |
149 |
155 @return a tuple of a string (project directory) and a dictionary |
150 @return a tuple of a string (project directory) and a dictionary |
156 containing the data entered. |
151 containing the data entered. |
157 """ |
152 """ |
158 self.__saveHistory() |
153 self.__saveHistory() |
159 |
154 |
160 vcsdatadict = { |
155 vcsdatadict = { |
161 "url": self.vcsUrlCombo.currentText().replace("\\", "/"), |
156 "url": self.vcsUrlCombo.currentText().replace("\\", "/"), |
162 } |
157 } |
163 return (self.vcsProjectDirEdit.text(), vcsdatadict) |
158 return (self.vcsProjectDirEdit.text(), vcsdatadict) |
164 |
159 |
165 def __saveHistory(self): |
160 def __saveHistory(self): |
166 """ |
161 """ |
167 Private method to save the repository URL history. |
162 Private method to save the repository URL history. |
168 """ |
163 """ |
169 url = self.vcsUrlCombo.currentText() |
164 url = self.vcsUrlCombo.currentText() |
170 vcsUrlHistory = [] |
165 vcsUrlHistory = [] |
171 for index in range(self.vcsUrlCombo.count()): |
166 for index in range(self.vcsUrlCombo.count()): |
172 vcsUrlHistory.append(self.vcsUrlCombo.itemText(index)) |
167 vcsUrlHistory.append(self.vcsUrlCombo.itemText(index)) |
173 if url not in vcsUrlHistory: |
168 if url not in vcsUrlHistory: |
174 vcsUrlHistory.insert(0, url) |
169 vcsUrlHistory.insert(0, url) |
175 |
170 |
176 # max. list sizes is hard coded to 20 entries |
171 # max. list sizes is hard coded to 20 entries |
177 newVcsUrlHistory = [url for url in vcsUrlHistory if url] |
172 newVcsUrlHistory = [url for url in vcsUrlHistory if url] |
178 if len(newVcsUrlHistory) > 20: |
173 if len(newVcsUrlHistory) > 20: |
179 newVcsUrlHistory = newVcsUrlHistory[:20] |
174 newVcsUrlHistory = newVcsUrlHistory[:20] |
180 |
175 |
181 self.__vcs.getPlugin().setPreferences( |
176 self.__vcs.getPlugin().setPreferences("RepositoryUrlHistory", newVcsUrlHistory) |
182 "RepositoryUrlHistory", newVcsUrlHistory) |
|