--- a/src/eric7/QScintilla/Editor.py Mon Feb 13 17:51:03 2023 +0100 +++ b/src/eric7/QScintilla/Editor.py Mon Feb 13 17:52:26 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,15 @@ 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 __registerImages(self): """ Private method to register images for autocompletion lists. @@ -3111,6 +3122,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 +3238,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 +3510,9 @@ @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 + return False newName = None if saveas or self.fileName == "": @@ -3524,7 +3542,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) @@ -3580,7 +3598,7 @@ """ self.__clearBreakpoints(fn) - self.__setFileName(fn) + self.setFileName(fn) self.setWindowTitle(self.fileName) self.__loadEditorConfig() @@ -7251,7 +7269,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 +7412,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 +7426,18 @@ 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 +8815,7 @@ """ editorConfig = {} - if fileName: + if fileName and self.isLocalFile(): try: editorConfig = editorconfig.get_properties(fileName) except editorconfig.EditorConfigError: