src/eric7/Utilities/MimeTypes.py

branch
eric7
changeset 9563
8ee667840224
parent 9559
34fc53e6159d
child 9564
f413aee05c4d
diff -r 94f349d5cd1e -r 8ee667840224 src/eric7/Utilities/MimeTypes.py
--- a/src/eric7/Utilities/MimeTypes.py	Mon Dec 05 11:42:45 2022 +0100
+++ b/src/eric7/Utilities/MimeTypes.py	Mon Dec 05 11:44:08 2022 +0100
@@ -7,9 +7,13 @@
 Module implementing mimetype dependent functions.
 """
 
+import fnmatch
 import mimetypes
 
+from PyQt6.QtCore import QCoreApplication
+
 from eric7 import Preferences
+from eric7.EricWidgets import EricMessageBox
 
 
 def isTextFile(filename):
@@ -22,16 +26,31 @@
     @rtype bool
     """
     mimetype = mimetypes.guess_type(filename)[0]
-    # TODO: add a dialog to ask if the file is a text file in case mimetype is None
-    #       and option is not set
     # TODO: add capability to define additional text file patterns for fnmatch test
-    return (mimetype is None and Preferences.getUI("LoadUnknownMimeTypeFiles")) or (
-        mimetype is not None
-        and (
+    if mimetype is None:
+        return (
+            Preferences.getUI("LoadUnknownMimeTypeFiles")
+            or any(
+                fnmatch.fnmatch(filename, pat)
+                for pat in Preferences.getUI("TextFilePatterns")
+            )
+            or EricMessageBox.yesNo(
+                None,
+                QCoreApplication.translate("MimeTypes", "Open File"),
+                QCoreApplication.translate(
+                    "MimeTypes",
+                    "<p>Is the file <b>{0}</b> a text file to be opened in eric?</p>"
+                    "<p><b>Note:</b> You may suppress this question by adding a pattern"
+                    " to the list of known text files on the <b>MimeTypes</b>"
+                    " configuration page."
+                ).format(filename),
+            )
+        )
+    else:
+        return (
             mimetype.split("/")[0] == "text"
             or mimetype in Preferences.getUI("TextMimeTypes")
         )
-    )
 
 
 def mimeType(filename):

eric ide

mercurial