225 |
225 |
226 self.enableMultiCursorSupport() |
226 self.enableMultiCursorSupport() |
227 |
227 |
228 self.dbs = dbs |
228 self.dbs = dbs |
229 self.taskViewer = tv |
229 self.taskViewer = tv |
230 self.setFileName(fn) |
230 self.fileName = "" |
231 self.vm = vm |
231 self.vm = vm |
232 self.filetype = filetype |
232 self.filetype = filetype |
233 self.filetypeByFlag = False |
233 self.filetypeByFlag = False |
234 self.noName = "" |
234 self.noName = "" |
235 self.project = ericApp().getObject("Project") |
235 self.project = ericApp().getObject("Project") |
|
236 self.setFileName(fn) |
236 |
237 |
237 # clear some variables |
238 # clear some variables |
238 self.lastHighlight = None # remember the last highlighted line |
239 self.lastHighlight = None # remember the last highlighted line |
239 self.lastErrorMarker = None # remember the last error line |
240 self.lastErrorMarker = None # remember the last error line |
240 self.lastCurrMarker = None # remember the last current line |
241 self.lastCurrMarker = None # remember the last current line |
618 Public method to set the file name of the current file. |
619 Public method to set the file name of the current file. |
619 |
620 |
620 @param name name of the current file |
621 @param name name of the current file |
621 @type str |
622 @type str |
622 """ |
623 """ |
|
624 renamed = self.fileName != name |
|
625 |
623 self.fileName = name |
626 self.fileName = name |
|
627 |
|
628 if renamed: |
|
629 self.vm.setEditorName(self, self.fileName) |
624 |
630 |
625 if self.fileName: |
631 if self.fileName: |
626 self.__fileNameExtension = os.path.splitext(self.fileName)[1][1:].lower() |
632 self.__fileNameExtension = os.path.splitext(self.fileName)[1][1:].lower() |
627 else: |
633 else: |
628 self.__fileNameExtension = "" |
634 self.__fileNameExtension = "" |
2280 self.filetype = "JavaScript" |
2286 self.filetype = "JavaScript" |
2281 return True |
2287 return True |
2282 |
2288 |
2283 return False |
2289 return False |
2284 |
2290 |
|
2291 def isProjectFile(self): |
|
2292 """ |
|
2293 Public method to check, if the file of the editor belongs to the current |
|
2294 project. |
|
2295 |
|
2296 @return flag indicating a project file |
|
2297 @rtype bool |
|
2298 """ |
|
2299 return ( |
|
2300 bool(self.fileName) |
|
2301 and self.project.isOpen() |
|
2302 and self.project.isProjectFile(self.fileName) |
|
2303 ) |
|
2304 |
2285 def highlightVisible(self): |
2305 def highlightVisible(self): |
2286 """ |
2306 """ |
2287 Public method to make sure that the highlight is visible. |
2307 Public method to make sure that the highlight is visible. |
2288 """ |
2308 """ |
2289 if self.lastHighlight is not None: |
2309 if self.lastHighlight is not None: |
3254 fn = self.noName |
3274 fn = self.noName |
3255 res = EricMessageBox.okToClearData( |
3275 res = EricMessageBox.okToClearData( |
3256 self, |
3276 self, |
3257 self.tr("File Modified"), |
3277 self.tr("File Modified"), |
3258 self.tr("<p>The file <b>{0}</b> has unsaved changes.</p>").format(fn), |
3278 self.tr("<p>The file <b>{0}</b> has unsaved changes.</p>").format(fn), |
3259 self.saveFile if self.isLocalFile() else None, |
3279 self.saveFile if not self.isRemoteFile() else None, |
3260 ) |
3280 ) |
3261 if res: |
3281 if res: |
3262 self.vm.setEditorName(self, self.fileName) |
3282 self.vm.setEditorName(self, self.fileName) |
3263 return res |
3283 return res |
3264 |
3284 |
3526 |
3546 |
3527 @param saveas flag indicating a 'save as' action (boolean) |
3547 @param saveas flag indicating a 'save as' action (boolean) |
3528 @param path directory to save the file in (string) |
3548 @param path directory to save the file in (string) |
3529 @return flag indicating success (boolean) |
3549 @return flag indicating success (boolean) |
3530 """ |
3550 """ |
3531 if not saveas and (not self.isModified() or not self.isLocalFile()): |
3551 if not saveas and (not self.isModified() or self.isRemoteFile()): |
3532 # do nothing if text wasn't changed or is not a local file |
3552 # do nothing if text wasn't changed or is a remote file |
3533 # TODO: write the file back to the MCU if isDeviceFile() |
|
3534 return False |
3553 return False |
|
3554 |
|
3555 if self.isDeviceFile(): |
|
3556 return self.__saveDeviceFile(saveas=saveas) |
3535 |
3557 |
3536 newName = None |
3558 newName = None |
3537 if saveas or self.fileName == "": |
3559 if saveas or self.fileName == "": |
3538 saveas = True |
3560 saveas = True |
3539 |
3561 |
3607 @return tuple of two values (boolean, string) giving a success |
3629 @return tuple of two values (boolean, string) giving a success |
3608 indicator and the name of the saved file |
3630 indicator and the name of the saved file |
3609 """ |
3631 """ |
3610 return self.saveFile(True, path) |
3632 return self.saveFile(True, path) |
3611 |
3633 |
|
3634 def __saveDeviceFile(self, saveas=False): |
|
3635 """ |
|
3636 Private method to save the text to a file on the connected device. |
|
3637 |
|
3638 @param saveas flag indicating a 'save as' action (defaults to False) |
|
3639 @type bool (optional) |
|
3640 @return flag indicating success |
|
3641 @rtype bool |
|
3642 """ |
|
3643 with contextlib.suppress(KeyError): |
|
3644 mpy = ericApp().getObject("MicroPython") |
|
3645 filemanager = mpy.getFileManager() |
|
3646 if saveas: |
|
3647 fn, ok = QInputDialog.getText( |
|
3648 self, |
|
3649 self.tr("Save File to Device"), |
|
3650 self.tr("Enter the complete device file path:"), |
|
3651 QLineEdit.EchoMode.Normal, |
|
3652 self.fileName, |
|
3653 ) |
|
3654 if not ok or not fn: |
|
3655 # aborted |
|
3656 return False |
|
3657 else: |
|
3658 fn = self.fileName |
|
3659 # Convert the file name to device path separators ('/') and ensure, |
|
3660 # intermediate directories exist (creating them if necessary) |
|
3661 fn = fn.replace("\\", "/") |
|
3662 if "/" in fn: |
|
3663 dn = fn.rsplit("/", 1)[0] |
|
3664 filemanager.makedirs(dn.replace("device:", "")) |
|
3665 success = filemanager.writeFile(fn.replace("device:", ""), self.text()) |
|
3666 if success: |
|
3667 self.setFileName(fn) |
|
3668 self.setModified(False) |
|
3669 self.resetOnlineChangeTraceInfo() |
|
3670 return success |
|
3671 |
|
3672 return False |
|
3673 |
3612 def handleRenamed(self, fn): |
3674 def handleRenamed(self, fn): |
3613 """ |
3675 """ |
3614 Public slot to handle the editorRenamed signal. |
3676 Public slot to handle the editorRenamed signal. |
3615 |
3677 |
3616 @param fn filename to be set for the editor (string). |
3678 @param fn filename to be set for the editor (string). |
3890 """ |
3952 """ |
3891 self.clearAllIndicators(self.searchIndicator) |
3953 self.clearAllIndicators(self.searchIndicator) |
3892 self.__markedText = "" |
3954 self.__markedText = "" |
3893 self.__searchIndicatorLines = [] |
3955 self.__searchIndicatorLines = [] |
3894 self.__markerMap.update() |
3956 self.__markerMap.update() |
|
3957 |
|
3958 def highlightSearchSelection(self, startLine, startIndex, endLine, endIndex): |
|
3959 """ |
|
3960 Public method to set a highlight for the selection at the start of a search. |
|
3961 |
|
3962 @param startLine line of the selection start |
|
3963 @type int |
|
3964 @param startIndex index of the selection start |
|
3965 @type int |
|
3966 @param endLine line of the selection end |
|
3967 @type int |
|
3968 @param endIndex index of the selection end |
|
3969 @type int |
|
3970 """ |
|
3971 self.setIndicator( |
|
3972 self.searchSelectionIndicator, startLine, startIndex, endLine, endIndex |
|
3973 ) |
|
3974 |
|
3975 def clearSearchSelectionHighlight(self): |
|
3976 """ |
|
3977 Public method to clear all highlights. |
|
3978 """ |
|
3979 self.clearAllIndicators(self.searchSelectionIndicator) |
3895 |
3980 |
3896 def __markOccurrences(self): |
3981 def __markOccurrences(self): |
3897 """ |
3982 """ |
3898 Private method to mark all occurrences of the current word. |
3983 Private method to mark all occurrences of the current word. |
3899 """ |
3984 """ |
4846 self.highlightIndicator = QsciScintilla.INDIC_CONTAINER + 2 |
4931 self.highlightIndicator = QsciScintilla.INDIC_CONTAINER + 2 |
4847 self.indicatorDefine( |
4932 self.indicatorDefine( |
4848 self.highlightIndicator, |
4933 self.highlightIndicator, |
4849 QsciScintilla.INDIC_FULLBOX, |
4934 QsciScintilla.INDIC_FULLBOX, |
4850 Preferences.getEditorColour("HighlightMarker"), |
4935 Preferences.getEditorColour("HighlightMarker"), |
|
4936 ) |
|
4937 |
|
4938 self.searchSelectionIndicator = QsciScintilla.INDIC_CONTAINER + 3 |
|
4939 self.indicatorDefine( |
|
4940 self.searchSelectionIndicator, |
|
4941 QsciScintilla.INDIC_FULLBOX, |
|
4942 Preferences.getEditorColour("SearchSelectionMarker"), |
4851 ) |
4943 ) |
4852 |
4944 |
4853 self.setCursorFlashTime(QApplication.cursorFlashTime()) |
4945 self.setCursorFlashTime(QApplication.cursorFlashTime()) |
4854 |
4946 |
4855 with contextlib.suppress(AttributeError): |
4947 with contextlib.suppress(AttributeError): |
6066 self.syntaxCheckService is None |
6158 self.syntaxCheckService is None |
6067 or fileType not in self.syntaxCheckService.getLanguages() |
6159 or fileType not in self.syntaxCheckService.getLanguages() |
6068 ): |
6160 ): |
6069 return |
6161 return |
6070 |
6162 |
6071 if Preferences.getEditor("AutoCheckSyntax"): |
6163 if ( |
6072 if Preferences.getEditor("OnlineSyntaxCheck"): |
6164 Preferences.getEditor("AutoCheckSyntax") |
6073 self.__onlineSyntaxCheckTimer.stop() |
6165 and Preferences.getEditor("OnlineSyntaxCheck") |
6074 |
6166 ): |
|
6167 self.__onlineSyntaxCheckTimer.stop() |
|
6168 |
|
6169 if self.isPy3File(): |
|
6170 additionalBuiltins = ( |
|
6171 self.project.getData("CHECKERSPARMS", "SyntaxChecker", {}).get( |
|
6172 "AdditionalBuiltins", [] |
|
6173 ) |
|
6174 if self.isProjectFile() |
|
6175 else Preferences.getFlakes("AdditionalBuiltins") |
|
6176 ) |
6075 self.syntaxCheckService.syntaxCheck( |
6177 self.syntaxCheckService.syntaxCheck( |
6076 fileType, self.fileName or "(Unnamed)", self.text() |
6178 fileType, |
|
6179 self.fileName or "(Unnamed)", |
|
6180 self.text(), |
|
6181 additionalBuiltins, |
|
6182 ) |
|
6183 else: |
|
6184 self.syntaxCheckService.syntaxCheck( |
|
6185 fileType, |
|
6186 self.fileName or "(Unnamed)", |
|
6187 self.text(), |
6077 ) |
6188 ) |
6078 |
6189 |
6079 def __processSyntaxCheckError(self, fn, msg): |
6190 def __processSyntaxCheckError(self, fn, msg): |
6080 """ |
6191 """ |
6081 Private slot to report an error message of a syntax check. |
6192 Private slot to report an error message of a syntax check. |