49 from eric7.EricGui.EricOverrideCursor import EricOverrideCursor |
49 from eric7.EricGui.EricOverrideCursor import EricOverrideCursor |
50 from eric7.EricUtilities.EricCache import EricCache |
50 from eric7.EricUtilities.EricCache import EricCache |
51 from eric7.EricWidgets import EricFileDialog, EricMessageBox |
51 from eric7.EricWidgets import EricFileDialog, EricMessageBox |
52 from eric7.EricWidgets.EricApplication import ericApp |
52 from eric7.EricWidgets.EricApplication import ericApp |
53 from eric7.Globals import recentNameBreakpointConditions |
53 from eric7.Globals import recentNameBreakpointConditions |
54 from eric7.SystemUtilities import OSUtilities, PythonUtilities |
54 from eric7.SystemUtilities import FileSystemUtilities, OSUtilities, PythonUtilities |
55 from eric7.UI import PythonDisViewer |
55 from eric7.UI import PythonDisViewer |
56 from eric7.Utilities import MouseUtilities |
56 from eric7.Utilities import MouseUtilities |
57 |
57 |
58 from . import Exporters, Lexers, TypingCompleters |
58 from . import Exporters, Lexers, TypingCompleters |
59 from .EditorMarkerMap import EditorMarkerMap |
59 from .EditorMarkerMap import EditorMarkerMap |
416 if editor is None: |
416 if editor is None: |
417 if self.fileName: |
417 if self.fileName: |
418 if not Utilities.MimeTypes.isTextFile(self.fileName): |
418 if not Utilities.MimeTypes.isTextFile(self.fileName): |
419 raise OSError() |
419 raise OSError() |
420 |
420 |
421 if self.isLocalFile() and pathlib.Path(self.fileName).exists(): |
421 if ( |
|
422 FileSystemUtilities.isPlainFileName(self.fileName) |
|
423 and pathlib.Path(self.fileName).exists() |
|
424 ): |
422 fileSizeKB = pathlib.Path(self.fileName).stat().st_size // 1024 |
425 fileSizeKB = pathlib.Path(self.fileName).stat().st_size // 1024 |
423 if fileSizeKB > Preferences.getEditor("RejectFilesize"): |
426 if fileSizeKB > Preferences.getEditor("RejectFilesize"): |
424 EricMessageBox.warning( |
427 EricMessageBox.warning( |
425 None, |
428 None, |
426 self.tr("Open File"), |
429 self.tr("Open File"), |
643 if self.fileName: |
646 if self.fileName: |
644 self.__fileNameExtension = os.path.splitext(self.fileName)[1][1:].lower() |
647 self.__fileNameExtension = os.path.splitext(self.fileName)[1][1:].lower() |
645 else: |
648 else: |
646 self.__fileNameExtension = "" |
649 self.__fileNameExtension = "" |
647 |
650 |
648 def isLocalFile(self): |
|
649 """ |
|
650 Public method to check, if the editor contains a local file. |
|
651 |
|
652 @return flag indicating a local file |
|
653 @rtype bool |
|
654 """ |
|
655 return not self.fileName.startswith(("device:", "remote:")) |
|
656 |
|
657 def isDeviceFile(self): |
|
658 """ |
|
659 Public method to check, if the editor contains a MCU device file. |
|
660 |
|
661 @return flag indicating a MCU device file |
|
662 @rtype bool |
|
663 """ |
|
664 return self.fileName.startswith("device:") |
|
665 |
|
666 def isRemoteFile(self): |
|
667 """ |
|
668 Public method to check, if the editor contains a remote file. |
|
669 |
|
670 @return flag indicating a remote file |
|
671 @rtype bool |
|
672 """ |
|
673 return self.fileName.startswith("remote:") |
|
674 |
|
675 def __registerImages(self): |
651 def __registerImages(self): |
676 """ |
652 """ |
677 Private method to register images for autocompletion lists. |
653 Private method to register images for autocompletion lists. |
678 """ |
654 """ |
679 # finale size of the completion images |
655 # finale size of the completion images |
3348 fn = self.noName |
3324 fn = self.noName |
3349 res = EricMessageBox.okToClearData( |
3325 res = EricMessageBox.okToClearData( |
3350 self, |
3326 self, |
3351 self.tr("File Modified"), |
3327 self.tr("File Modified"), |
3352 self.tr("<p>The file <b>{0}</b> has unsaved changes.</p>").format(fn), |
3328 self.tr("<p>The file <b>{0}</b> has unsaved changes.</p>").format(fn), |
3353 self.saveFile if not self.isRemoteFile() else None, |
3329 self.saveFile |
|
3330 if not FileSystemUtilities.isRemoteFileName(self.fileName) |
|
3331 else None, |
3354 ) |
3332 ) |
3355 if res: |
3333 if res: |
3356 self.vm.setEditorName(self, self.fileName) |
3334 self.vm.setEditorName(self, self.fileName) |
3357 return res |
3335 return res |
3358 |
3336 |
3632 |
3610 |
3633 @param saveas flag indicating a 'save as' action (boolean) |
3611 @param saveas flag indicating a 'save as' action (boolean) |
3634 @param path directory to save the file in (string) |
3612 @param path directory to save the file in (string) |
3635 @return flag indicating success (boolean) |
3613 @return flag indicating success (boolean) |
3636 """ |
3614 """ |
3637 if not saveas and (not self.isModified() or self.isRemoteFile()): |
3615 if not saveas and ( |
|
3616 not self.isModified() or FileSystemUtilities.isRemoteFileName(self.fileName) |
|
3617 ): |
3638 # do nothing if text wasn't changed or is a remote file |
3618 # do nothing if text wasn't changed or is a remote file |
3639 return False |
3619 return False |
3640 |
3620 |
3641 if self.isDeviceFile(): |
3621 if FileSystemUtilities.isDeviceFileName(self.fileName): |
3642 return self.__saveDeviceFile(saveas=saveas) |
3622 return self.__saveDeviceFile(saveas=saveas) |
3643 |
3623 |
3644 newName = None |
3624 newName = None |
3645 if saveas or self.fileName == "": |
3625 if saveas or self.fileName == "": |
3646 saveas = True |
3626 saveas = True |
3746 # Convert the file name to device path separators ('/') and ensure, |
3726 # Convert the file name to device path separators ('/') and ensure, |
3747 # intermediate directories exist (creating them if necessary) |
3727 # intermediate directories exist (creating them if necessary) |
3748 fn = fn.replace("\\", "/") |
3728 fn = fn.replace("\\", "/") |
3749 if "/" in fn: |
3729 if "/" in fn: |
3750 dn = fn.rsplit("/", 1)[0] |
3730 dn = fn.rsplit("/", 1)[0] |
3751 filemanager.makedirs(dn.replace("device:", "")) |
3731 filemanager.makedirs(FileSystemUtilities.plainFileName(dn)) |
3752 success = filemanager.writeFile(fn.replace("device:", ""), self.text()) |
3732 success = filemanager.writeFile( |
|
3733 FileSystemUtilities.plainFileName(fn), self.text() |
|
3734 ) |
3753 if success: |
3735 if success: |
3754 self.setFileName(fn) |
3736 self.setFileName(fn) |
3755 self.setModified(False) |
3737 self.setModified(False) |
3756 self.resetOnlineChangeTraceInfo() |
3738 self.resetOnlineChangeTraceInfo() |
3757 return success |
3739 return success |
7976 caption change. |
7958 caption change. |
7977 |
7959 |
7978 @param bForce True to force change, False to only update and emit |
7960 @param bForce True to force change, False to only update and emit |
7979 signal if there was an attribute change. |
7961 signal if there was an attribute change. |
7980 """ |
7962 """ |
7981 if self.fileName == "" or not self.isLocalFile(): |
7963 if self.fileName == "" or not FileSystemUtilities.isPlainFileName( |
|
7964 self.fileName |
|
7965 ): |
7982 return |
7966 return |
7983 |
7967 |
7984 readOnly = self.checkReadOnly() |
7968 readOnly = self.checkReadOnly() |
7985 if not bForce and (readOnly == self.isReadOnly()): |
7969 if not bForce and (readOnly == self.isReadOnly()): |
7986 return |
7970 return |
9453 @return EditorConfig dictionary |
9438 @return EditorConfig dictionary |
9454 @rtype dict |
9439 @rtype dict |
9455 """ |
9440 """ |
9456 editorConfig = {} |
9441 editorConfig = {} |
9457 |
9442 |
9458 if fileName and self.isLocalFile(): |
9443 if fileName and FileSystemUtilities.isPlainFileName(self.fileName): |
9459 try: |
9444 try: |
9460 editorConfig = editorconfig.get_properties(fileName) |
9445 editorConfig = editorconfig.get_properties(fileName) |
9461 except editorconfig.EditorConfigError: |
9446 except editorconfig.EditorConfigError: |
9462 EricMessageBox.warning( |
9447 EricMessageBox.warning( |
9463 self, |
9448 self, |