43 |
43 |
44 class SyntaxCheckerPlugin(QObject): |
44 class SyntaxCheckerPlugin(QObject): |
45 """ |
45 """ |
46 Class implementing the Syntax Checker plugin. |
46 Class implementing the Syntax Checker plugin. |
47 """ |
47 """ |
|
48 |
48 def __init__(self, ui): |
49 def __init__(self, ui): |
49 """ |
50 """ |
50 Constructor |
51 Constructor |
51 |
52 |
52 @param ui reference to the user interface object (UI.UserInterface) |
53 @param ui reference to the user interface object (UI.UserInterface) |
53 """ |
54 """ |
54 super().__init__(ui) |
55 super().__init__(ui) |
55 self.__ui = ui |
56 self.__ui = ui |
56 self.__initialize() |
57 self.__initialize() |
57 |
58 |
58 from Plugins.CheckerPlugins.SyntaxChecker.SyntaxCheckService import ( |
59 from Plugins.CheckerPlugins.SyntaxChecker.SyntaxCheckService import ( |
59 SyntaxCheckService |
60 SyntaxCheckService, |
60 ) |
61 ) |
|
62 |
61 self.syntaxCheckService = SyntaxCheckService() |
63 self.syntaxCheckService = SyntaxCheckService() |
62 ericApp().registerObject("SyntaxCheckService", self.syntaxCheckService) |
64 ericApp().registerObject("SyntaxCheckService", self.syntaxCheckService) |
63 |
65 |
64 ericPath = getConfig('ericDir') |
66 ericPath = getConfig("ericDir") |
65 path = os.path.join(ericPath, 'Plugins', 'CheckerPlugins', |
67 path = os.path.join(ericPath, "Plugins", "CheckerPlugins", "SyntaxChecker") |
66 'SyntaxChecker') |
68 |
67 |
|
68 self.syntaxCheckService.addLanguage( |
69 self.syntaxCheckService.addLanguage( |
69 'Python3', 'Python3', path, 'SyntaxCheck', |
70 "Python3", |
|
71 "Python3", |
|
72 path, |
|
73 "SyntaxCheck", |
70 self.__getPythonOptions, |
74 self.__getPythonOptions, |
71 lambda: Preferences.getPython("Python3Extensions"), |
75 lambda: Preferences.getPython("Python3Extensions"), |
72 self.__translateSyntaxCheck, |
76 self.__translateSyntaxCheck, |
73 self.syntaxCheckService.serviceErrorPy3) |
77 self.syntaxCheckService.serviceErrorPy3, |
74 |
78 ) |
|
79 |
75 self.syntaxCheckService.addLanguage( |
80 self.syntaxCheckService.addLanguage( |
76 'JavaScript', 'Python3', path, |
81 "JavaScript", |
77 'jsCheckSyntax', |
82 "Python3", |
|
83 path, |
|
84 "jsCheckSyntax", |
78 lambda: [], # No options |
85 lambda: [], # No options |
79 lambda: ['.js'], |
86 lambda: [".js"], |
80 lambda fn, problems: |
87 lambda fn, problems: self.syntaxCheckService.syntaxChecked.emit( |
81 self.syntaxCheckService.syntaxChecked.emit(fn, problems), |
88 fn, problems |
82 self.syntaxCheckService.serviceErrorJavaScript) |
89 ), |
83 |
90 self.syntaxCheckService.serviceErrorJavaScript, |
|
91 ) |
|
92 |
84 # YAML syntax check via Python3 |
93 # YAML syntax check via Python3 |
85 self.syntaxCheckService.addLanguage( |
94 self.syntaxCheckService.addLanguage( |
86 'YAML', 'Python3', path, |
95 "YAML", |
87 'yamlCheckSyntax', |
96 "Python3", |
|
97 path, |
|
98 "yamlCheckSyntax", |
88 lambda: [], # No options |
99 lambda: [], # No options |
89 lambda: ['.yml', '.yaml'], |
100 lambda: [".yml", ".yaml"], |
90 lambda fn, problems: |
101 lambda fn, problems: self.syntaxCheckService.syntaxChecked.emit( |
91 self.syntaxCheckService.syntaxChecked.emit(fn, problems), |
102 fn, problems |
92 self.syntaxCheckService.serviceErrorYAML) |
103 ), |
93 |
104 self.syntaxCheckService.serviceErrorYAML, |
|
105 ) |
|
106 |
94 # JSON syntax check via Python3 |
107 # JSON syntax check via Python3 |
95 self.syntaxCheckService.addLanguage( |
108 self.syntaxCheckService.addLanguage( |
96 'JSON', 'Python3', path, |
109 "JSON", |
97 'jsonCheckSyntax', |
110 "Python3", |
|
111 path, |
|
112 "jsonCheckSyntax", |
98 lambda: [], # No options |
113 lambda: [], # No options |
99 lambda: ['.json'], |
114 lambda: [".json"], |
100 lambda fn, problems: |
115 lambda fn, problems: self.syntaxCheckService.syntaxChecked.emit( |
101 self.syntaxCheckService.syntaxChecked.emit(fn, problems), |
116 fn, problems |
102 self.syntaxCheckService.serviceErrorJSON) |
117 ), |
103 |
118 self.syntaxCheckService.serviceErrorJSON, |
|
119 ) |
|
120 |
104 # TOML syntax check via Python3 |
121 # TOML syntax check via Python3 |
105 self.syntaxCheckService.addLanguage( |
122 self.syntaxCheckService.addLanguage( |
106 'TOML', 'Python3', path, |
123 "TOML", |
107 'tomlCheckSyntax', |
124 "Python3", |
|
125 path, |
|
126 "tomlCheckSyntax", |
108 lambda: [], # No options |
127 lambda: [], # No options |
109 lambda: ['.toml'], |
128 lambda: [".toml"], |
110 lambda fn, problems: |
129 lambda fn, problems: self.syntaxCheckService.syntaxChecked.emit( |
111 self.syntaxCheckService.syntaxChecked.emit(fn, problems), |
130 fn, problems |
112 self.syntaxCheckService.serviceErrorTOML) |
131 ), |
|
132 self.syntaxCheckService.serviceErrorTOML, |
|
133 ) |
113 |
134 |
114 def __initialize(self): |
135 def __initialize(self): |
115 """ |
136 """ |
116 Private slot to (re)initialize the plugin. |
137 Private slot to (re)initialize the plugin. |
117 """ |
138 """ |
118 self.__projectAct = None |
139 self.__projectAct = None |
119 self.__projectSyntaxCheckerDialog = None |
140 self.__projectSyntaxCheckerDialog = None |
120 |
141 |
121 self.__projectBrowserAct = None |
142 self.__projectBrowserAct = None |
122 self.__projectBrowserMenu = None |
143 self.__projectBrowserMenu = None |
123 self.__projectBrowserSyntaxCheckerDialog = None |
144 self.__projectBrowserSyntaxCheckerDialog = None |
124 |
145 |
125 self.__editors = [] |
146 self.__editors = [] |
126 self.__editorAct = None |
147 self.__editorAct = None |
127 self.__editorSyntaxCheckerDialog = None |
148 self.__editorSyntaxCheckerDialog = None |
128 |
149 |
129 def __getPythonOptions(self): |
150 def __getPythonOptions(self): |
130 """ |
151 """ |
131 Private method to determine the syntax check options. |
152 Private method to determine the syntax check options. |
132 |
153 |
133 @return state of checkFlakes and ignoreStarImportWarnings (bool, bool) |
154 @return state of checkFlakes and ignoreStarImportWarnings (bool, bool) |
134 """ |
155 """ |
135 checkFlakes = Preferences.getFlakes("IncludeInSyntaxCheck") |
156 checkFlakes = Preferences.getFlakes("IncludeInSyntaxCheck") |
136 ignoreStarImportWarnings = Preferences.getFlakes( |
157 ignoreStarImportWarnings = Preferences.getFlakes("IgnoreStarImportWarnings") |
137 "IgnoreStarImportWarnings") |
|
138 return checkFlakes, ignoreStarImportWarnings |
158 return checkFlakes, ignoreStarImportWarnings |
139 |
159 |
140 def __translateSyntaxCheck(self, fn, problems): |
160 def __translateSyntaxCheck(self, fn, problems): |
141 """ |
161 """ |
142 Private slot to translate the resulting messages. |
162 Private slot to translate the resulting messages. |
143 |
163 |
144 If checkFlakes is True, warnings contains a list of strings containing |
164 If checkFlakes is True, warnings contains a list of strings containing |
145 the warnings (marker, file name, line number, message) |
165 the warnings (marker, file name, line number, message) |
146 The values are only valid, if nok is False. |
166 The values are only valid, if nok is False. |
147 |
167 |
148 @param fn filename of the checked file (str) |
168 @param fn filename of the checked file (str) |
149 @param problems dictionary with the keys 'error' and 'warnings' which |
169 @param problems dictionary with the keys 'error' and 'warnings' which |
150 hold a list containing details about the error/ warnings |
170 hold a list containing details about the error/ warnings |
151 (file name, line number, column, codestring (only at syntax |
171 (file name, line number, column, codestring (only at syntax |
152 errors), the message, a list with arguments for the message) |
172 errors), the message, a list with arguments for the message) |
153 """ |
173 """ |
154 from CheckerPlugins.SyntaxChecker.pyflakes.translations import ( |
174 from CheckerPlugins.SyntaxChecker.pyflakes.translations import ( |
155 getTranslatedFlakesMessage |
175 getTranslatedFlakesMessage, |
156 ) |
176 ) |
157 warnings = problems.get('warnings', []) |
177 |
|
178 warnings = problems.get("warnings", []) |
158 for warning in warnings: |
179 for warning in warnings: |
159 # Translate messages |
180 # Translate messages |
160 msg_args = warning.pop() |
181 msg_args = warning.pop() |
161 warning[4] = getTranslatedFlakesMessage(warning[4], msg_args) |
182 warning[4] = getTranslatedFlakesMessage(warning[4], msg_args) |
162 |
183 |
163 problems['warnings'] = warnings |
184 problems["warnings"] = warnings |
164 self.syntaxCheckService.syntaxChecked.emit(fn, problems) |
185 self.syntaxCheckService.syntaxChecked.emit(fn, problems) |
165 |
186 |
166 def activate(self): |
187 def activate(self): |
167 """ |
188 """ |
168 Public method to activate this plugin. |
189 Public method to activate this plugin. |
169 |
190 |
170 @return tuple of None and activation status (boolean) |
191 @return tuple of None and activation status (boolean) |
171 """ |
192 """ |
172 menu = ericApp().getObject("Project").getMenu("Checks") |
193 menu = ericApp().getObject("Project").getMenu("Checks") |
173 if menu: |
194 if menu: |
174 self.__projectAct = EricAction( |
195 self.__projectAct = EricAction( |
175 self.tr('Check Syntax'), |
196 self.tr("Check Syntax"), |
176 self.tr('&Syntax...'), 0, 0, |
197 self.tr("&Syntax..."), |
177 self, 'project_check_syntax') |
198 0, |
178 self.__projectAct.setStatusTip( |
199 0, |
179 self.tr('Check syntax.')) |
200 self, |
180 self.__projectAct.setWhatsThis(self.tr( |
201 "project_check_syntax", |
181 """<b>Check Syntax...</b>""" |
202 ) |
182 """<p>This checks Python files for syntax errors.</p>""" |
203 self.__projectAct.setStatusTip(self.tr("Check syntax.")) |
183 )) |
204 self.__projectAct.setWhatsThis( |
|
205 self.tr( |
|
206 """<b>Check Syntax...</b>""" |
|
207 """<p>This checks Python files for syntax errors.</p>""" |
|
208 ) |
|
209 ) |
184 self.__projectAct.triggered.connect(self.__projectSyntaxCheck) |
210 self.__projectAct.triggered.connect(self.__projectSyntaxCheck) |
185 ericApp().getObject("Project").addEricActions([self.__projectAct]) |
211 ericApp().getObject("Project").addEricActions([self.__projectAct]) |
186 menu.addAction(self.__projectAct) |
212 menu.addAction(self.__projectAct) |
187 |
213 |
188 self.__editorAct = EricAction( |
214 self.__editorAct = EricAction( |
189 self.tr('Check Syntax'), |
215 self.tr("Check Syntax"), self.tr("&Syntax..."), 0, 0, self, "" |
190 self.tr('&Syntax...'), 0, 0, |
216 ) |
191 self, "") |
217 self.__editorAct.setWhatsThis( |
192 self.__editorAct.setWhatsThis(self.tr( |
218 self.tr( |
193 """<b>Check Syntax...</b>""" |
219 """<b>Check Syntax...</b>""" |
194 """<p>This checks Python files for syntax errors.</p>""" |
220 """<p>This checks Python files for syntax errors.</p>""" |
195 )) |
221 ) |
|
222 ) |
196 self.__editorAct.triggered.connect(self.__editorSyntaxCheck) |
223 self.__editorAct.triggered.connect(self.__editorSyntaxCheck) |
197 |
224 |
198 ericApp().getObject("Project").showMenu.connect(self.__projectShowMenu) |
225 ericApp().getObject("Project").showMenu.connect(self.__projectShowMenu) |
199 ericApp().getObject("ProjectBrowser").getProjectBrowser( |
226 ericApp().getObject("ProjectBrowser").getProjectBrowser( |
200 "sources").showMenu.connect(self.__projectBrowserShowMenu) |
227 "sources" |
201 ericApp().getObject("ViewManager").editorOpenedEd.connect( |
228 ).showMenu.connect(self.__projectBrowserShowMenu) |
202 self.__editorOpened) |
229 ericApp().getObject("ViewManager").editorOpenedEd.connect(self.__editorOpened) |
203 ericApp().getObject("ViewManager").editorClosedEd.connect( |
230 ericApp().getObject("ViewManager").editorClosedEd.connect(self.__editorClosed) |
204 self.__editorClosed) |
231 |
205 |
|
206 for editor in ericApp().getObject("ViewManager").getOpenEditors(): |
232 for editor in ericApp().getObject("ViewManager").getOpenEditors(): |
207 self.__editorOpened(editor) |
233 self.__editorOpened(editor) |
208 |
234 |
209 return None, True |
235 return None, True |
210 |
236 |
211 def deactivate(self): |
237 def deactivate(self): |
212 """ |
238 """ |
213 Public method to deactivate this plugin. |
239 Public method to deactivate this plugin. |
214 """ |
240 """ |
215 ericApp().getObject("Project").showMenu.disconnect( |
241 ericApp().getObject("Project").showMenu.disconnect(self.__projectShowMenu) |
216 self.__projectShowMenu) |
|
217 ericApp().getObject("ProjectBrowser").getProjectBrowser( |
242 ericApp().getObject("ProjectBrowser").getProjectBrowser( |
218 "sources").showMenu.disconnect(self.__projectBrowserShowMenu) |
243 "sources" |
|
244 ).showMenu.disconnect(self.__projectBrowserShowMenu) |
219 ericApp().getObject("ViewManager").editorOpenedEd.disconnect( |
245 ericApp().getObject("ViewManager").editorOpenedEd.disconnect( |
220 self.__editorOpened) |
246 self.__editorOpened |
|
247 ) |
221 ericApp().getObject("ViewManager").editorClosedEd.disconnect( |
248 ericApp().getObject("ViewManager").editorClosedEd.disconnect( |
222 self.__editorClosed) |
249 self.__editorClosed |
223 |
250 ) |
|
251 |
224 menu = ericApp().getObject("Project").getMenu("Checks") |
252 menu = ericApp().getObject("Project").getMenu("Checks") |
225 if menu: |
253 if menu: |
226 menu.removeAction(self.__projectAct) |
254 menu.removeAction(self.__projectAct) |
227 |
255 |
228 if self.__projectBrowserMenu and self.__projectBrowserAct: |
256 if self.__projectBrowserMenu and self.__projectBrowserAct: |
229 self.__projectBrowserMenu.removeAction( |
257 self.__projectBrowserMenu.removeAction(self.__projectBrowserAct) |
230 self.__projectBrowserAct) |
258 |
231 |
|
232 for editor in self.__editors: |
259 for editor in self.__editors: |
233 editor.showMenu.disconnect(self.__editorShowMenu) |
260 editor.showMenu.disconnect(self.__editorShowMenu) |
234 menu = editor.getMenu("Checks") |
261 menu = editor.getMenu("Checks") |
235 if menu is not None: |
262 if menu is not None: |
236 menu.removeAction(self.__editorAct) |
263 menu.removeAction(self.__editorAct) |
237 |
264 |
238 self.__initialize() |
265 self.__initialize() |
239 |
266 |
240 def __projectShowMenu(self, menuName, menu): |
267 def __projectShowMenu(self, menuName, menu): |
241 """ |
268 """ |
242 Private slot called, when the the project menu or a submenu is |
269 Private slot called, when the the project menu or a submenu is |
243 about to be shown. |
270 about to be shown. |
244 |
271 |
245 @param menuName name of the menu to be shown (string) |
272 @param menuName name of the menu to be shown (string) |
246 @param menu reference to the menu (QMenu) |
273 @param menu reference to the menu (QMenu) |
247 """ |
274 """ |
248 if menuName == "Checks" and self.__projectAct is not None: |
275 if menuName == "Checks" and self.__projectAct is not None: |
249 self.__projectAct.setEnabled( |
276 self.__projectAct.setEnabled( |
250 ericApp().getObject("Project").getProjectLanguage() in |
277 ericApp().getObject("Project").getProjectLanguage() |
251 self.syntaxCheckService.getLanguages()) |
278 in self.syntaxCheckService.getLanguages() |
252 |
279 ) |
|
280 |
253 def __projectBrowserShowMenu(self, menuName, menu): |
281 def __projectBrowserShowMenu(self, menuName, menu): |
254 """ |
282 """ |
255 Private slot called, when the the project browser menu or a submenu is |
283 Private slot called, when the the project browser menu or a submenu is |
256 about to be shown. |
284 about to be shown. |
257 |
285 |
258 @param menuName name of the menu to be shown (string) |
286 @param menuName name of the menu to be shown (string) |
259 @param menu reference to the menu (QMenu) |
287 @param menu reference to the menu (QMenu) |
260 """ |
288 """ |
261 if ( |
289 if ( |
262 menuName == "Checks" and |
290 menuName == "Checks" |
263 ericApp().getObject("Project").getProjectLanguage() in |
291 and ericApp().getObject("Project").getProjectLanguage() |
264 self.syntaxCheckService.getLanguages() |
292 in self.syntaxCheckService.getLanguages() |
265 ): |
293 ): |
266 self.__projectBrowserMenu = menu |
294 self.__projectBrowserMenu = menu |
267 if self.__projectBrowserAct is None: |
295 if self.__projectBrowserAct is None: |
268 self.__projectBrowserAct = EricAction( |
296 self.__projectBrowserAct = EricAction( |
269 self.tr('Check Syntax'), |
297 self.tr("Check Syntax"), self.tr("&Syntax..."), 0, 0, self, "" |
270 self.tr('&Syntax...'), 0, 0, |
298 ) |
271 self, "") |
299 self.__projectBrowserAct.setWhatsThis( |
272 self.__projectBrowserAct.setWhatsThis(self.tr( |
300 self.tr( |
273 """<b>Check Syntax...</b>""" |
301 """<b>Check Syntax...</b>""" |
274 """<p>This checks Python files for syntax errors.</p>""" |
302 """<p>This checks Python files for syntax errors.</p>""" |
275 )) |
303 ) |
|
304 ) |
276 self.__projectBrowserAct.triggered.connect( |
305 self.__projectBrowserAct.triggered.connect( |
277 self.__projectBrowserSyntaxCheck) |
306 self.__projectBrowserSyntaxCheck |
|
307 ) |
278 if self.__projectBrowserAct not in menu.actions(): |
308 if self.__projectBrowserAct not in menu.actions(): |
279 menu.addAction(self.__projectBrowserAct) |
309 menu.addAction(self.__projectBrowserAct) |
280 |
310 |
281 def __projectSyntaxCheck(self): |
311 def __projectSyntaxCheck(self): |
282 """ |
312 """ |
283 Private slot used to check the project files for syntax errors. |
313 Private slot used to check the project files for syntax errors. |
284 """ |
314 """ |
285 project = ericApp().getObject("Project") |
315 project = ericApp().getObject("Project") |
286 project.saveAllScripts() |
316 project.saveAllScripts() |
287 ppath = project.getProjectPath() |
317 ppath = project.getProjectPath() |
288 extensions = tuple(self.syntaxCheckService.getExtensions()) |
318 extensions = tuple(self.syntaxCheckService.getExtensions()) |
289 files = [os.path.join(ppath, file) |
319 files = [ |
290 for file in project.pdata["SOURCES"] |
320 os.path.join(ppath, file) |
291 if file.endswith(extensions)] |
321 for file in project.pdata["SOURCES"] |
292 |
322 if file.endswith(extensions) |
293 from CheckerPlugins.SyntaxChecker.SyntaxCheckerDialog import ( |
323 ] |
294 SyntaxCheckerDialog |
324 |
295 ) |
325 from CheckerPlugins.SyntaxChecker.SyntaxCheckerDialog import SyntaxCheckerDialog |
|
326 |
296 self.__projectSyntaxCheckerDialog = SyntaxCheckerDialog() |
327 self.__projectSyntaxCheckerDialog = SyntaxCheckerDialog() |
297 self.__projectSyntaxCheckerDialog.show() |
328 self.__projectSyntaxCheckerDialog.show() |
298 self.__projectSyntaxCheckerDialog.prepare(files, project) |
329 self.__projectSyntaxCheckerDialog.prepare(files, project) |
299 |
330 |
300 def __projectBrowserSyntaxCheck(self): |
331 def __projectBrowserSyntaxCheck(self): |
301 """ |
332 """ |
302 Private method to handle the syntax check context menu action of the |
333 Private method to handle the syntax check context menu action of the |
303 project sources browser. |
334 project sources browser. |
304 """ |
335 """ |
305 browser = ericApp().getObject("ProjectBrowser").getProjectBrowser( |
336 browser = ericApp().getObject("ProjectBrowser").getProjectBrowser("sources") |
306 "sources") |
|
307 if browser.getSelectedItemsCount([ProjectBrowserFileItem]) > 1: |
337 if browser.getSelectedItemsCount([ProjectBrowserFileItem]) > 1: |
308 fn = [] |
338 fn = [] |
309 for itm in browser.getSelectedItems([ProjectBrowserFileItem]): |
339 for itm in browser.getSelectedItems([ProjectBrowserFileItem]): |
310 fn.append(itm.fileName()) |
340 fn.append(itm.fileName()) |
311 else: |
341 else: |
312 itm = browser.model().item(browser.currentIndex()) |
342 itm = browser.model().item(browser.currentIndex()) |
313 try: |
343 try: |
314 fn = itm.fileName() |
344 fn = itm.fileName() |
315 except AttributeError: |
345 except AttributeError: |
316 fn = itm.dirName() |
346 fn = itm.dirName() |
317 |
347 |
318 from CheckerPlugins.SyntaxChecker.SyntaxCheckerDialog import ( |
348 from CheckerPlugins.SyntaxChecker.SyntaxCheckerDialog import SyntaxCheckerDialog |
319 SyntaxCheckerDialog |
349 |
320 ) |
|
321 self.__projectBrowserSyntaxCheckerDialog = SyntaxCheckerDialog() |
350 self.__projectBrowserSyntaxCheckerDialog = SyntaxCheckerDialog() |
322 self.__projectBrowserSyntaxCheckerDialog.show() |
351 self.__projectBrowserSyntaxCheckerDialog.show() |
323 self.__projectBrowserSyntaxCheckerDialog.start(fn) |
352 self.__projectBrowserSyntaxCheckerDialog.start(fn) |
324 |
353 |
325 def __editorOpened(self, editor): |
354 def __editorOpened(self, editor): |
326 """ |
355 """ |
327 Private slot called, when a new editor was opened. |
356 Private slot called, when a new editor was opened. |
328 |
357 |
329 @param editor reference to the new editor (QScintilla.Editor) |
358 @param editor reference to the new editor (QScintilla.Editor) |
330 """ |
359 """ |
331 menu = editor.getMenu("Checks") |
360 menu = editor.getMenu("Checks") |
332 if menu is not None: |
361 if menu is not None: |
333 menu.addAction(self.__editorAct) |
362 menu.addAction(self.__editorAct) |
334 editor.showMenu.connect(self.__editorShowMenu) |
363 editor.showMenu.connect(self.__editorShowMenu) |
335 self.__editors.append(editor) |
364 self.__editors.append(editor) |
336 |
365 |
337 def __editorClosed(self, editor): |
366 def __editorClosed(self, editor): |
338 """ |
367 """ |
339 Private slot called, when an editor was closed. |
368 Private slot called, when an editor was closed. |
340 |
369 |
341 @param editor reference to the editor (QScintilla.Editor) |
370 @param editor reference to the editor (QScintilla.Editor) |
342 """ |
371 """ |
343 with contextlib.suppress(ValueError): |
372 with contextlib.suppress(ValueError): |
344 self.__editors.remove(editor) |
373 self.__editors.remove(editor) |
345 |
374 |
346 def __editorShowMenu(self, menuName, menu, editor): |
375 def __editorShowMenu(self, menuName, menu, editor): |
347 """ |
376 """ |
348 Private slot called, when the the editor context menu or a submenu is |
377 Private slot called, when the the editor context menu or a submenu is |
349 about to be shown. |
378 about to be shown. |
350 |
379 |
351 @param menuName name of the menu to be shown (string) |
380 @param menuName name of the menu to be shown (string) |
352 @param menu reference to the menu (QMenu) |
381 @param menu reference to the menu (QMenu) |
353 @param editor reference to the editor |
382 @param editor reference to the editor |
354 """ |
383 """ |
355 if menuName == "Checks": |
384 if menuName == "Checks": |
356 if self.__editorAct not in menu.actions(): |
385 if self.__editorAct not in menu.actions(): |
357 menu.addAction(self.__editorAct) |
386 menu.addAction(self.__editorAct) |
358 self.__editorAct.setEnabled( |
387 self.__editorAct.setEnabled( |
359 editor.getLanguage() in self.syntaxCheckService.getLanguages()) |
388 editor.getLanguage() in self.syntaxCheckService.getLanguages() |
360 |
389 ) |
|
390 |
361 def __editorSyntaxCheck(self): |
391 def __editorSyntaxCheck(self): |
362 """ |
392 """ |
363 Private slot to handle the syntax check context menu action of the |
393 Private slot to handle the syntax check context menu action of the |
364 editors. |
394 editors. |
365 """ |
395 """ |
366 editor = ericApp().getObject("ViewManager").activeWindow() |
396 editor = ericApp().getObject("ViewManager").activeWindow() |
367 if editor is not None: |
397 if editor is not None: |
368 from CheckerPlugins.SyntaxChecker.SyntaxCheckerDialog import ( |
398 from CheckerPlugins.SyntaxChecker.SyntaxCheckerDialog import ( |
369 SyntaxCheckerDialog |
399 SyntaxCheckerDialog, |
370 ) |
400 ) |
|
401 |
371 self.__editorSyntaxCheckerDialog = SyntaxCheckerDialog() |
402 self.__editorSyntaxCheckerDialog = SyntaxCheckerDialog() |
372 self.__editorSyntaxCheckerDialog.show() |
403 self.__editorSyntaxCheckerDialog.show() |
373 if editor.isJavascriptFile(): |
404 if editor.isJavascriptFile(): |
374 unnamed = "Unnamed.js" |
405 unnamed = "Unnamed.js" |
375 else: |
406 else: |
376 unnamed = "Unnamed.py" |
407 unnamed = "Unnamed.py" |
377 self.__editorSyntaxCheckerDialog.start( |
408 self.__editorSyntaxCheckerDialog.start( |
378 editor.getFileName() or unnamed, editor.text()) |
409 editor.getFileName() or unnamed, editor.text() |
|
410 ) |