402 if editor is None: |
402 if editor is None: |
403 if self.fileName: |
403 if self.fileName: |
404 if not Utilities.MimeTypes.isTextFile(self.fileName): |
404 if not Utilities.MimeTypes.isTextFile(self.fileName): |
405 raise OSError() |
405 raise OSError() |
406 |
406 |
407 fileSizeKB = pathlib.Path(self.fileName).stat().st_size // 1024 |
407 if self.isLocalFile(): |
408 if fileSizeKB > Preferences.getEditor("RejectFilesize"): |
408 fileSizeKB = pathlib.Path(self.fileName).stat().st_size // 1024 |
409 EricMessageBox.warning( |
409 if fileSizeKB > Preferences.getEditor("RejectFilesize"): |
410 None, |
410 EricMessageBox.warning( |
411 self.tr("Open File"), |
411 None, |
412 self.tr( |
412 self.tr("Open File"), |
413 "<p>The size of the file <b>{0}</b> is <b>{1} KB</b> and" |
413 self.tr( |
414 " exceeds the configured limit of <b>{2} KB</b>. It will" |
414 "<p>The size of the file <b>{0}</b> is <b>{1} KB</b> and" |
415 " not be opened!</p>" |
415 " exceeds the configured limit of <b>{2} KB</b>. It will" |
416 ).format( |
416 " not be opened!</p>" |
417 self.fileName, |
417 ).format( |
418 fileSizeKB, |
418 self.fileName, |
419 Preferences.getEditor("RejectFilesize"), |
419 fileSizeKB, |
420 ), |
420 Preferences.getEditor("RejectFilesize"), |
421 ) |
421 ), |
422 raise OSError() |
422 ) |
423 elif fileSizeKB > Preferences.getEditor("WarnFilesize"): |
|
424 res = EricMessageBox.yesNo( |
|
425 None, |
|
426 self.tr("Open File"), |
|
427 self.tr( |
|
428 """<p>The size of the file <b>{0}</b>""" |
|
429 """ is <b>{1} KB</b>.""" |
|
430 """ Do you really want to load it?</p>""" |
|
431 ).format(self.fileName, fileSizeKB), |
|
432 icon=EricMessageBox.Warning, |
|
433 ) |
|
434 if not res: |
|
435 raise OSError() |
423 raise OSError() |
436 |
424 elif fileSizeKB > Preferences.getEditor("WarnFilesize"): |
437 self.readFile(self.fileName, True) |
425 res = EricMessageBox.yesNo( |
|
426 None, |
|
427 self.tr("Open File"), |
|
428 self.tr( |
|
429 """<p>The size of the file <b>{0}</b>""" |
|
430 """ is <b>{1} KB</b>.""" |
|
431 """ Do you really want to load it?</p>""" |
|
432 ).format(self.fileName, fileSizeKB), |
|
433 icon=EricMessageBox.Warning, |
|
434 ) |
|
435 if not res: |
|
436 raise OSError() |
|
437 |
|
438 self.readFile(self.fileName, True) |
|
439 |
438 self.__bindLexer(self.fileName) |
440 self.__bindLexer(self.fileName) |
439 self.__bindCompleter(self.fileName) |
441 self.__bindCompleter(self.fileName) |
440 self.checkSyntax() |
442 self.checkSyntax() |
441 self.isResourcesFile = self.fileName.endswith(".qrc") |
443 self.isResourcesFile = self.fileName.endswith(".qrc") |
442 |
444 |
609 self.grabGesture(Qt.GestureType.PinchGesture) |
611 self.grabGesture(Qt.GestureType.PinchGesture) |
610 |
612 |
611 self.SCN_ZOOM.connect(self.__markerMap.update) |
613 self.SCN_ZOOM.connect(self.__markerMap.update) |
612 self.__markerMap.update() |
614 self.__markerMap.update() |
613 |
615 |
614 def __setFileName(self, name): |
616 def setFileName(self, name): |
615 """ |
617 """ |
616 Private method to set the file name of the current file. |
618 Public method to set the file name of the current file. |
617 |
619 |
618 @param name name of the current file |
620 @param name name of the current file |
619 @type str |
621 @type str |
620 """ |
622 """ |
621 self.fileName = name |
623 self.fileName = name |
622 |
624 |
623 if self.fileName: |
625 if self.fileName: |
624 self.__fileNameExtension = os.path.splitext(self.fileName)[1][1:].lower() |
626 self.__fileNameExtension = os.path.splitext(self.fileName)[1][1:].lower() |
625 else: |
627 else: |
626 self.__fileNameExtension = "" |
628 self.__fileNameExtension = "" |
|
629 |
|
630 def isLocalFile(self): |
|
631 """ |
|
632 Public method to check, if the editor contains a local file. |
|
633 |
|
634 @return flag indicating a local file |
|
635 @rtype bool |
|
636 """ |
|
637 return not self.fileName.startswith(("device:", "remote:")) |
627 |
638 |
628 def __registerImages(self): |
639 def __registerImages(self): |
629 """ |
640 """ |
630 Private method to register images for autocompletion lists. |
641 Private method to register images for autocompletion lists. |
631 """ |
642 """ |
3109 self.markerDeleteAll(self.__changeMarkerSaved) |
3120 self.markerDeleteAll(self.__changeMarkerSaved) |
3110 self.__hasChangeMarkers = False |
3121 self.__hasChangeMarkers = False |
3111 self.changeMarkersUpdated.emit(self) |
3122 self.changeMarkersUpdated.emit(self) |
3112 self.__markerMap.update() |
3123 self.__markerMap.update() |
3113 |
3124 |
|
3125 def clearChangeMarkers(self): |
|
3126 """ |
|
3127 Public method to clear all change markers. |
|
3128 """ |
|
3129 self.__reinitOnlineChangeTrace() |
|
3130 |
3114 def getChangeLines(self): |
3131 def getChangeLines(self): |
3115 """ |
3132 """ |
3116 Public method to get the lines containing a change. |
3133 Public method to get the lines containing a change. |
3117 |
3134 |
3118 @return list of lines containing a change (list of integer) |
3135 @return list of lines containing a change (list of integer) |
3219 fn = self.noName |
3236 fn = self.noName |
3220 res = EricMessageBox.okToClearData( |
3237 res = EricMessageBox.okToClearData( |
3221 self, |
3238 self, |
3222 self.tr("File Modified"), |
3239 self.tr("File Modified"), |
3223 self.tr("<p>The file <b>{0}</b> has unsaved changes.</p>").format(fn), |
3240 self.tr("<p>The file <b>{0}</b> has unsaved changes.</p>").format(fn), |
3224 self.saveFile, |
3241 self.saveFile if self.isLocalFile() else None, |
3225 ) |
3242 ) |
3226 if res: |
3243 if res: |
3227 self.vm.setEditorName(self, self.fileName) |
3244 self.vm.setEditorName(self, self.fileName) |
3228 return res |
3245 return res |
3229 |
3246 |
3491 |
3508 |
3492 @param saveas flag indicating a 'save as' action (boolean) |
3509 @param saveas flag indicating a 'save as' action (boolean) |
3493 @param path directory to save the file in (string) |
3510 @param path directory to save the file in (string) |
3494 @return flag indicating success (boolean) |
3511 @return flag indicating success (boolean) |
3495 """ |
3512 """ |
3496 if not saveas and not self.isModified(): |
3513 if not saveas and (not self.isModified() or not self.isLocalFile()): |
3497 return False # do nothing if text wasn't changed |
3514 # do nothing if text wasn't changed or is not a local file |
|
3515 return False |
3498 |
3516 |
3499 newName = None |
3517 newName = None |
3500 if saveas or self.fileName == "": |
3518 if saveas or self.fileName == "": |
3501 saveas = True |
3519 saveas = True |
3502 |
3520 |
3522 self.__loadEditorConfig(fn) |
3540 self.__loadEditorConfig(fn) |
3523 self.editorAboutToBeSaved.emit(self.fileName) |
3541 self.editorAboutToBeSaved.emit(self.fileName) |
3524 if self.writeFile(fn): |
3542 if self.writeFile(fn): |
3525 if saveas: |
3543 if saveas: |
3526 self.__clearBreakpoints(self.fileName) |
3544 self.__clearBreakpoints(self.fileName) |
3527 self.__setFileName(fn) |
3545 self.setFileName(fn) |
3528 self.setModified(False) |
3546 self.setModified(False) |
3529 self.setReadOnly(False) |
3547 self.setReadOnly(False) |
3530 self.setWindowTitle(self.fileName) |
3548 self.setWindowTitle(self.fileName) |
3531 # get eric specific flags |
3549 # get eric specific flags |
3532 changedFlags = self.__processFlags() |
3550 changedFlags = self.__processFlags() |
3578 |
3596 |
3579 @param fn filename to be set for the editor (string). |
3597 @param fn filename to be set for the editor (string). |
3580 """ |
3598 """ |
3581 self.__clearBreakpoints(fn) |
3599 self.__clearBreakpoints(fn) |
3582 |
3600 |
3583 self.__setFileName(fn) |
3601 self.setFileName(fn) |
3584 self.setWindowTitle(self.fileName) |
3602 self.setWindowTitle(self.fileName) |
3585 |
3603 |
3586 self.__loadEditorConfig() |
3604 self.__loadEditorConfig() |
3587 |
3605 |
3588 if self.lexer_ is None: |
3606 if self.lexer_ is None: |
7249 cap = ( |
7267 cap = ( |
7250 os.path.basename(self.fileName) |
7268 os.path.basename(self.fileName) |
7251 if self.windowState() == Qt.WindowState.WindowMinimized |
7269 if self.windowState() == Qt.WindowState.WindowMinimized |
7252 else self.fileName |
7270 else self.fileName |
7253 ) |
7271 ) |
7254 if self.isReadOnly(): |
7272 if self.checkReadOnly(): |
7255 cap = self.tr("{0} (ro)").format(cap) |
7273 cap = self.tr("{0} (ro)").format(cap) |
7256 self.setWindowTitle(cap) |
7274 self.setWindowTitle(cap) |
7257 |
7275 |
7258 super().changeEvent(evt) |
7276 super().changeEvent(evt) |
7259 |
7277 |
7392 caption change. |
7410 caption change. |
7393 |
7411 |
7394 @param bForce True to force change, False to only update and emit |
7412 @param bForce True to force change, False to only update and emit |
7395 signal if there was an attribute change. |
7413 signal if there was an attribute change. |
7396 """ |
7414 """ |
7397 if self.fileName == "": |
7415 if self.fileName == "" or not self.isLocalFile(): |
7398 return |
7416 return |
7399 |
7417 |
7400 readOnly = not os.access(self.fileName, os.W_OK) or self.isReadOnly() |
7418 readOnly = self.checkReadOnly() |
7401 if not bForce and (readOnly == self.isReadOnly()): |
7419 if not bForce and (readOnly == self.isReadOnly()): |
7402 return |
7420 return |
7403 |
7421 |
7404 cap = self.fileName |
7422 cap = self.fileName |
7405 if readOnly: |
7423 if readOnly: |
7406 cap = self.tr("{0} (ro)".format(cap)) |
7424 cap = self.tr("{0} (ro)".format(cap)) |
7407 self.setReadOnly(readOnly) |
7425 self.setReadOnly(readOnly) |
7408 self.setWindowTitle(cap) |
7426 self.setWindowTitle(cap) |
7409 self.captionChanged.emit(cap, self) |
7427 self.captionChanged.emit(cap, self) |
|
7428 |
|
7429 def checkReadOnly(self): |
|
7430 """ |
|
7431 Public method to check the 'read only' state. |
|
7432 |
|
7433 @return flag indicate a 'read only' state |
|
7434 @rtype bool |
|
7435 """ |
|
7436 return ( |
|
7437 (self.isLocalFile() and not os.access(self.fileName, os.W_OK)) |
|
7438 or self.isReadOnly() |
|
7439 ) |
7410 |
7440 |
7411 def refresh(self): |
7441 def refresh(self): |
7412 """ |
7442 """ |
7413 Public slot to refresh the editor contents. |
7443 Public slot to refresh the editor contents. |
7414 """ |
7444 """ |