115 """ |
117 """ |
116 Private method to generate the popup menus for a Python project. |
118 Private method to generate the popup menus for a Python project. |
117 """ |
119 """ |
118 self.checksMenu = QMenu(self.tr('Check')) |
120 self.checksMenu = QMenu(self.tr('Check')) |
119 self.checksMenu.aboutToShow.connect(self.__showContextMenuCheck) |
121 self.checksMenu.aboutToShow.connect(self.__showContextMenuCheck) |
|
122 |
|
123 self.formattingMenu = QMenu(self.tr("Code Formatting")) |
|
124 self.formattingMenu.addAction( |
|
125 self.tr("Format Code"), |
|
126 lambda: self.__performFormatWithBlack(BlackFormattingAction.Format) |
|
127 ) |
|
128 self.formattingMenu.addAction( |
|
129 self.tr("Check Formatting"), |
|
130 lambda: self.__performFormatWithBlack(BlackFormattingAction.Check) |
|
131 ) |
|
132 self.formattingMenu.addAction( |
|
133 self.tr("Formatting Diff"), |
|
134 lambda: self.__performFormatWithBlack(BlackFormattingAction.Diff) |
|
135 ) |
|
136 self.formattingMenu.aboutToShow.connect(self.__showContextMenuFormatting) |
120 |
137 |
121 self.menuShow = QMenu(self.tr('Show')) |
138 self.menuShow = QMenu(self.tr('Show')) |
122 self.menuShow.addAction( |
139 self.menuShow.addAction( |
123 self.tr('Code metrics...'), self.__showCodeMetrics) |
140 self.tr('Code metrics...'), self.__showCodeMetrics) |
124 self.coverageMenuAction = self.menuShow.addAction( |
141 self.coverageMenuAction = self.menuShow.addAction( |
179 self.sourceMenu.addAction( |
196 self.sourceMenu.addAction( |
180 self.tr('Add source files...'), self.__addSourceFiles) |
197 self.tr('Add source files...'), self.__addSourceFiles) |
181 self.sourceMenu.addAction( |
198 self.sourceMenu.addAction( |
182 self.tr('Add source directory...'), self.__addSourceDirectory) |
199 self.tr('Add source directory...'), self.__addSourceDirectory) |
183 self.sourceMenu.addSeparator() |
200 self.sourceMenu.addSeparator() |
184 act = self.sourceMenu.addMenu(self.graphicsMenu) |
201 self.sourceMenu.addMenu(self.graphicsMenu) |
185 self.sourceMenu.addSeparator() |
|
186 self.sourceMenu.addMenu(self.checksMenu) |
202 self.sourceMenu.addMenu(self.checksMenu) |
187 self.sourceMenu.addSeparator() |
203 self.sourceMenu.addMenu(self.formattingMenu) |
188 self.sourceMenuActions["Show"] = self.sourceMenu.addMenu(self.menuShow) |
204 self.sourceMenuActions["Show"] = self.sourceMenu.addMenu(self.menuShow) |
189 self.sourceMenu.addSeparator() |
205 self.sourceMenu.addSeparator() |
190 self.__startAct = self.sourceMenu.addMenu(self.__startMenu) |
206 self.__startAct = self.sourceMenu.addMenu(self.__startMenu) |
191 self.sourceMenu.addSeparator() |
207 self.sourceMenu.addSeparator() |
192 self.sourceMenu.addAction( |
208 self.sourceMenu.addAction( |
260 act = self.multiMenu.addAction( |
276 act = self.multiMenu.addAction( |
261 self.tr('Delete'), self.__deleteFile) |
277 self.tr('Delete'), self.__deleteFile) |
262 self.multiMenuActions.append(act) |
278 self.multiMenuActions.append(act) |
263 self.multiMenu.addSeparator() |
279 self.multiMenu.addSeparator() |
264 self.multiMenu.addMenu(self.checksMenu) |
280 self.multiMenu.addMenu(self.checksMenu) |
|
281 self.multiMenu.addMenu(self.formattingMenu) |
265 self.multiMenu.addSeparator() |
282 self.multiMenu.addSeparator() |
266 self.multiMenu.addAction( |
283 self.multiMenu.addAction( |
267 self.tr('Expand all directories'), self._expandAllDirs) |
284 self.tr('Expand all directories'), self._expandAllDirs) |
268 self.multiMenu.addAction( |
285 self.multiMenu.addAction( |
269 self.tr('Collapse all directories'), self._collapseAllDirs) |
286 self.tr('Collapse all directories'), self._collapseAllDirs) |
284 self.tr('Add source files...'), self.__addSourceFiles) |
301 self.tr('Add source files...'), self.__addSourceFiles) |
285 self.dirMenu.addAction( |
302 self.dirMenu.addAction( |
286 self.tr('Add source directory...'), self.__addSourceDirectory) |
303 self.tr('Add source directory...'), self.__addSourceDirectory) |
287 self.dirMenu.addSeparator() |
304 self.dirMenu.addSeparator() |
288 act = self.dirMenu.addMenu(self.graphicsMenu) |
305 act = self.dirMenu.addMenu(self.graphicsMenu) |
289 self.dirMenu.addSeparator() |
|
290 self.dirMenu.addMenu(self.checksMenu) |
306 self.dirMenu.addMenu(self.checksMenu) |
291 self.dirMenu.addSeparator() |
307 self.dirMenu.addSeparator() |
292 self.dirMenu.addAction( |
308 self.dirMenu.addAction( |
293 self.tr('Copy Path to Clipboard'), self._copyToClipboard) |
309 self.tr('Copy Path to Clipboard'), self._copyToClipboard) |
294 self.dirMenu.addSeparator() |
310 self.dirMenu.addSeparator() |
1173 """ |
1189 """ |
1174 Private method to run a coverage test of the editor script. |
1190 Private method to run a coverage test of the editor script. |
1175 """ |
1191 """ |
1176 fn = self.model().item(self.currentIndex()).fileName() |
1192 fn = self.model().item(self.currentIndex()).fileName() |
1177 ericApp().getObject("DebugUI").doCoverage(False, script=fn) |
1193 ericApp().getObject("DebugUI").doCoverage(False, script=fn) |
|
1194 |
|
1195 ########################################################################### |
|
1196 ## Methods for the Code Formatting submenu |
|
1197 ########################################################################### |
|
1198 |
|
1199 def __showContextMenuFormatting(self): |
|
1200 """ |
|
1201 Private slot called before the Code Formatting menu is shown. |
|
1202 """ |
|
1203 self.showMenu.emit("Formatting", self.formattingMenu) |
|
1204 |
|
1205 def __performFormatWithBlack(self, action): |
|
1206 """ |
|
1207 Private method to format the selected project sources using the 'Black' tool. |
|
1208 |
|
1209 Following actions are supported. |
|
1210 <ul> |
|
1211 <li>BlackFormattingAction.Format - the code reformatting is performed</li> |
|
1212 <li>BlackFormattingAction.Check - a check is performed, if code formatting |
|
1213 is necessary</li> |
|
1214 <li>BlackFormattingAction.Diff - a unified diff of potential code formatting |
|
1215 changes is generated</li> |
|
1216 </ul> |
|
1217 |
|
1218 @param action formatting operation to be performed |
|
1219 @type BlackFormattingAction |
|
1220 """ |
|
1221 from CodeFormatting.BlackConfigurationDialog import BlackConfigurationDialog |
|
1222 from CodeFormatting.BlackFormattingDialog import BlackFormattingDialog |
|
1223 |
|
1224 files = [ |
|
1225 itm.fileName() |
|
1226 for itm in self.getSelectedItems( |
|
1227 [BrowserFileItem, BrowserClassItem, BrowserMethodItem, |
|
1228 BrowserClassAttributeItem, BrowserImportItem] |
|
1229 ) |
|
1230 if itm.isPython3File() |
|
1231 ] |
|
1232 |
|
1233 if ericApp().getObject("ViewManager").checkAllDirty(): |
|
1234 dlg = BlackConfigurationDialog(withProject=True) |
|
1235 if dlg.exec() == QDialog.DialogCode.Accepted: |
|
1236 config = dlg.getConfiguration() |
|
1237 |
|
1238 formattingDialog = BlackFormattingDialog( |
|
1239 config, |
|
1240 files, |
|
1241 project=self.project, |
|
1242 action=action |
|
1243 ) |
|
1244 formattingDialog.exec() |