--- a/src/eric7/QScintilla/Editor.py Wed Mar 01 09:06:13 2023 +0100 +++ b/src/eric7/QScintilla/Editor.py Wed Mar 29 10:03:06 2023 +0200 @@ -227,12 +227,13 @@ self.dbs = dbs self.taskViewer = tv - self.setFileName(fn) + self.fileName = "" self.vm = vm self.filetype = filetype self.filetypeByFlag = False self.noName = "" self.project = ericApp().getObject("Project") + self.setFileName(fn) # clear some variables self.lastHighlight = None # remember the last highlighted line @@ -620,8 +621,13 @@ @param name name of the current file @type str """ + renamed = self.fileName != name + self.fileName = name + if renamed: + self.vm.setEditorName(self, self.fileName) + if self.fileName: self.__fileNameExtension = os.path.splitext(self.fileName)[1][1:].lower() else: @@ -2282,6 +2288,20 @@ return False + def isProjectFile(self): + """ + Public method to check, if the file of the editor belongs to the current + project. + + @return flag indicating a project file + @rtype bool + """ + return ( + bool(self.fileName) + and self.project.isOpen() + and self.project.isProjectFile(self.fileName) + ) + def highlightVisible(self): """ Public method to make sure that the highlight is visible. @@ -3256,7 +3276,7 @@ self, self.tr("File Modified"), self.tr("<p>The file <b>{0}</b> has unsaved changes.</p>").format(fn), - self.saveFile if self.isLocalFile() else None, + self.saveFile if not self.isRemoteFile() else None, ) if res: self.vm.setEditorName(self, self.fileName) @@ -3528,11 +3548,13 @@ @param path directory to save the file in (string) @return flag indicating success (boolean) """ - if not saveas and (not self.isModified() or not self.isLocalFile()): - # do nothing if text wasn't changed or is not a local file - # TODO: write the file back to the MCU if isDeviceFile() + if not saveas and (not self.isModified() or self.isRemoteFile()): + # do nothing if text wasn't changed or is a remote file return False + if self.isDeviceFile(): + return self.__saveDeviceFile(saveas=saveas) + newName = None if saveas or self.fileName == "": saveas = True @@ -3609,6 +3631,46 @@ """ return self.saveFile(True, path) + def __saveDeviceFile(self, saveas=False): + """ + Private method to save the text to a file on the connected device. + + @param saveas flag indicating a 'save as' action (defaults to False) + @type bool (optional) + @return flag indicating success + @rtype bool + """ + with contextlib.suppress(KeyError): + mpy = ericApp().getObject("MicroPython") + filemanager = mpy.getFileManager() + if saveas: + fn, ok = QInputDialog.getText( + self, + self.tr("Save File to Device"), + self.tr("Enter the complete device file path:"), + QLineEdit.EchoMode.Normal, + self.fileName, + ) + if not ok or not fn: + # aborted + return False + else: + fn = self.fileName + # Convert the file name to device path separators ('/') and ensure, + # intermediate directories exist (creating them if necessary) + fn = fn.replace("\\", "/") + if "/" in fn: + dn = fn.rsplit("/", 1)[0] + filemanager.makedirs(dn.replace("device:", "")) + success = filemanager.writeFile(fn.replace("device:", ""), self.text()) + if success: + self.setFileName(fn) + self.setModified(False) + self.resetOnlineChangeTraceInfo() + return success + + return False + def handleRenamed(self, fn): """ Public slot to handle the editorRenamed signal. @@ -3893,6 +3955,29 @@ self.__searchIndicatorLines = [] self.__markerMap.update() + def highlightSearchSelection(self, startLine, startIndex, endLine, endIndex): + """ + Public method to set a highlight for the selection at the start of a search. + + @param startLine line of the selection start + @type int + @param startIndex index of the selection start + @type int + @param endLine line of the selection end + @type int + @param endIndex index of the selection end + @type int + """ + self.setIndicator( + self.searchSelectionIndicator, startLine, startIndex, endLine, endIndex + ) + + def clearSearchSelectionHighlight(self): + """ + Public method to clear all highlights. + """ + self.clearAllIndicators(self.searchSelectionIndicator) + def __markOccurrences(self): """ Private method to mark all occurrences of the current word. @@ -4850,6 +4935,13 @@ Preferences.getEditorColour("HighlightMarker"), ) + self.searchSelectionIndicator = QsciScintilla.INDIC_CONTAINER + 3 + self.indicatorDefine( + self.searchSelectionIndicator, + QsciScintilla.INDIC_FULLBOX, + Preferences.getEditorColour("SearchSelectionMarker"), + ) + self.setCursorFlashTime(QApplication.cursorFlashTime()) with contextlib.suppress(AttributeError): @@ -6068,12 +6160,31 @@ ): return - if Preferences.getEditor("AutoCheckSyntax"): - if Preferences.getEditor("OnlineSyntaxCheck"): - self.__onlineSyntaxCheckTimer.stop() - + if ( + Preferences.getEditor("AutoCheckSyntax") + and Preferences.getEditor("OnlineSyntaxCheck") + ): + self.__onlineSyntaxCheckTimer.stop() + + if self.isPy3File(): + additionalBuiltins = ( + self.project.getData("CHECKERSPARMS", "SyntaxChecker", {}).get( + "AdditionalBuiltins", [] + ) + if self.isProjectFile() + else Preferences.getFlakes("AdditionalBuiltins") + ) self.syntaxCheckService.syntaxCheck( - fileType, self.fileName or "(Unnamed)", self.text() + fileType, + self.fileName or "(Unnamed)", + self.text(), + additionalBuiltins, + ) + else: + self.syntaxCheckService.syntaxCheck( + fileType, + self.fileName or "(Unnamed)", + self.text(), ) def __processSyntaxCheckError(self, fn, msg):