--- a/src/eric7/QScintilla/Editor.py Tue Jan 24 10:16:03 2023 +0100 +++ b/src/eric7/QScintilla/Editor.py Wed Mar 01 09:05:47 2023 +0100 @@ -227,7 +227,7 @@ self.dbs = dbs self.taskViewer = tv - self.__setFileName(fn) + self.setFileName(fn) self.vm = vm self.filetype = filetype self.filetypeByFlag = False @@ -404,37 +404,39 @@ if not Utilities.MimeTypes.isTextFile(self.fileName): raise OSError() - fileSizeKB = pathlib.Path(self.fileName).stat().st_size // 1024 - if fileSizeKB > Preferences.getEditor("RejectFilesize"): - EricMessageBox.warning( - None, - self.tr("Open File"), - self.tr( - "<p>The size of the file <b>{0}</b> is <b>{1} KB</b> and" - " exceeds the configured limit of <b>{2} KB</b>. It will" - " not be opened!</p>" - ).format( - self.fileName, - fileSizeKB, - Preferences.getEditor("RejectFilesize"), - ), - ) - raise OSError() - elif fileSizeKB > Preferences.getEditor("WarnFilesize"): - res = EricMessageBox.yesNo( - None, - self.tr("Open File"), - self.tr( - """<p>The size of the file <b>{0}</b>""" - """ is <b>{1} KB</b>.""" - """ Do you really want to load it?</p>""" - ).format(self.fileName, fileSizeKB), - icon=EricMessageBox.Warning, - ) - if not res: + if self.isLocalFile(): + fileSizeKB = pathlib.Path(self.fileName).stat().st_size // 1024 + if fileSizeKB > Preferences.getEditor("RejectFilesize"): + EricMessageBox.warning( + None, + self.tr("Open File"), + self.tr( + "<p>The size of the file <b>{0}</b> is <b>{1} KB</b>" + " and exceeds the configured limit of <b>{2} KB</b>." + " It will not be opened!</p>" + ).format( + self.fileName, + fileSizeKB, + Preferences.getEditor("RejectFilesize"), + ), + ) raise OSError() - - self.readFile(self.fileName, True) + elif fileSizeKB > Preferences.getEditor("WarnFilesize"): + res = EricMessageBox.yesNo( + None, + self.tr("Open File"), + self.tr( + """<p>The size of the file <b>{0}</b>""" + """ is <b>{1} KB</b>.""" + """ Do you really want to load it?</p>""" + ).format(self.fileName, fileSizeKB), + icon=EricMessageBox.Warning, + ) + if not res: + raise OSError() + + self.readFile(self.fileName, True) + self.__bindLexer(self.fileName) self.__bindCompleter(self.fileName) self.checkSyntax() @@ -611,9 +613,9 @@ self.SCN_ZOOM.connect(self.__markerMap.update) self.__markerMap.update() - def __setFileName(self, name): - """ - Private method to set the file name of the current file. + def setFileName(self, name): + """ + Public method to set the file name of the current file. @param name name of the current file @type str @@ -625,6 +627,33 @@ else: self.__fileNameExtension = "" + def isLocalFile(self): + """ + Public method to check, if the editor contains a local file. + + @return flag indicating a local file + @rtype bool + """ + return not self.fileName.startswith(("device:", "remote:")) + + def isDeviceFile(self): + """ + Public method to check, if the editor contains a MCU device file. + + @return flag indicating a MCU device file + @rtype bool + """ + return self.fileName.startswith("device:") + + def isRemoteFile(self): + """ + Public method to check, if the editor contains a remote file. + + @return flag indicating a remote file + @rtype bool + """ + return self.fileName.startswith("remote:") + def __registerImages(self): """ Private method to register images for autocompletion lists. @@ -2701,7 +2730,7 @@ @param fileName name of the file (string) """ idxList = [] - for (ln, _, _, _, _) in self.breaks.values(): + for ln, _, _, _, _ in self.breaks.values(): index = self.breakpointModel.getBreakPointIndex(fileName, ln) if index.isValid(): idxList.append(index) @@ -3079,9 +3108,9 @@ self.changeMarkersUpdated.emit(self) self.__markerMap.update() - def __resetOnlineChangeTraceInfo(self): - """ - Private slot to reset the online change trace info. + def resetOnlineChangeTraceInfo(self): + """ + Public slot to reset the online change trace info. """ self.__lastSavedText = self.text() self.__deleteAllChangeMarkers() @@ -3111,6 +3140,12 @@ self.changeMarkersUpdated.emit(self) self.__markerMap.update() + def clearChangeMarkers(self): + """ + Public method to clear all change markers. + """ + self.__reinitOnlineChangeTrace() + def getChangeLines(self): """ Public method to get the lines containing a change. @@ -3221,7 +3256,7 @@ self, self.tr("File Modified"), self.tr("<p>The file <b>{0}</b> has unsaved changes.</p>").format(fn), - self.saveFile, + self.saveFile if self.isLocalFile() else None, ) if res: self.vm.setEditorName(self, self.fileName) @@ -3493,8 +3528,10 @@ @param path directory to save the file in (string) @return flag indicating success (boolean) """ - if not saveas and not self.isModified(): - return False # do nothing if text wasn't changed + 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() + return False newName = None if saveas or self.fileName == "": @@ -3524,7 +3561,7 @@ if self.writeFile(fn): if saveas: self.__clearBreakpoints(self.fileName) - self.__setFileName(fn) + self.setFileName(fn) self.setModified(False) self.setReadOnly(False) self.setWindowTitle(self.fileName) @@ -3551,7 +3588,7 @@ self.editorSaved.emit(self.fileName) self.checkSyntax() self.extractTasks() - self.__resetOnlineChangeTraceInfo() + self.resetOnlineChangeTraceInfo() self.__checkEncoding() return True else: @@ -3580,7 +3617,7 @@ """ self.__clearBreakpoints(fn) - self.__setFileName(fn) + self.setFileName(fn) self.setWindowTitle(self.fileName) self.__loadEditorConfig() @@ -7251,7 +7288,7 @@ if self.windowState() == Qt.WindowState.WindowMinimized else self.fileName ) - if self.isReadOnly(): + if self.checkReadOnly(): cap = self.tr("{0} (ro)").format(cap) self.setWindowTitle(cap) @@ -7394,10 +7431,10 @@ @param bForce True to force change, False to only update and emit signal if there was an attribute change. """ - if self.fileName == "": + if self.fileName == "" or not self.isLocalFile(): return - readOnly = not os.access(self.fileName, os.W_OK) or self.isReadOnly() + readOnly = self.checkReadOnly() if not bForce and (readOnly == self.isReadOnly()): return @@ -7408,6 +7445,17 @@ self.setWindowTitle(cap) self.captionChanged.emit(cap, self) + def checkReadOnly(self): + """ + Public method to check the 'read only' state. + + @return flag indicate a 'read only' state + @rtype bool + """ + return ( + self.isLocalFile() and not os.access(self.fileName, os.W_OK) + ) or self.isReadOnly() + def refresh(self): """ Public slot to refresh the editor contents. @@ -8785,7 +8833,7 @@ """ editorConfig = {} - if fileName: + if fileName and self.isLocalFile(): try: editorConfig = editorconfig.get_properties(fileName) except editorconfig.EditorConfigError: