src/eric7/QScintilla/Editor.py

branch
eric7
changeset 9405
99e65bd24e7d
parent 9333
b0541ec21e51
child 9408
e993c39097d3
diff -r 717e1e87dc8f -r 99e65bd24e7d src/eric7/QScintilla/Editor.py
--- a/src/eric7/QScintilla/Editor.py	Fri Oct 14 14:46:40 2022 +0200
+++ b/src/eric7/QScintilla/Editor.py	Fri Oct 14 17:02:09 2022 +0200
@@ -398,24 +398,47 @@
         self.isResourcesFile = False
         if editor is None:
             if self.fileName:
-                if (
-                    pathlib.Path(self.fileName).stat().st_size // 1024
-                ) > Preferences.getEditor("WarnFilesize"):
+                if not Utilities.MimeTypes.isTextFile(self.fileName):
+                    EricMessageBox.warning(
+                        None,
+                        self.tr("Open File"),
+                        self.tr(
+                            "<p>The file <b>{0}</b> is not a text file. It will not be"
+                            " opened!</p>"
+                        ).format(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(
-                        self,
+                        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,
-                            pathlib.Path(self.fileName).stat().st_size // 1024,
-                        ),
+                        ).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)

eric ide

mercurial