Changed the find location widget to find files without extension as well. eric7

Tue, 21 Dec 2021 12:14:24 +0100

author
Detlev Offenbach <detlev@die-offenbachs.de>
date
Tue, 21 Dec 2021 12:14:24 +0100
branch
eric7
changeset 8845
3d3c1b812fe4
parent 8844
cae9a0840828
child 8846
4196ec4c37a5

Changed the find location widget to find files without extension as well.

eric7/UI/FindLocationWidget.py file | annotate | diff | comparison | revisions
eric7/Utilities/__init__.py file | annotate | diff | comparison | revisions
--- a/eric7/UI/FindLocationWidget.py	Mon Dec 20 22:06:09 2021 +0100
+++ b/eric7/UI/FindLocationWidget.py	Tue Dec 21 12:14:24 2021 +0100
@@ -152,8 +152,17 @@
         else:
             patternFormat = "{0}*{1}{2}"
         
-        fileNamePattern = patternFormat.format(
-            fileName or '*', os.extsep, fileExt or '*')
+        fileNamePatterns = [patternFormat.format(
+            fileName or "*", os.extsep, fileExt or "*")]
+        
+        if not fileExt:
+            # search for files without extension as well
+            if "*" in fileName or "?" in fileName:
+                patternFormat = "{0}"
+            else:
+                patternFormat = "{0}*"
+            
+            fileNamePatterns.append(patternFormat.format(fileName or "*"))
         
         searchPaths = []
         if (
@@ -175,7 +184,7 @@
         
         for path in searchPaths:
             if os.path.isdir(path):
-                files = direntries(path, True, fileNamePattern,
+                files = direntries(path, True, fileNamePatterns,
                                    False, self.checkStop)
                 if files:
                     for file in files:
--- a/eric7/Utilities/__init__.py	Mon Dec 20 22:06:09 2021 +0100
+++ b/eric7/Utilities/__init__.py	Tue Dec 21 12:14:24 2021 +0100
@@ -1129,14 +1129,22 @@
     Function returning a list of all files and directories.
     
     @param path root of the tree to check
+    @type str
     @param filesonly flag indicating that only files are wanted
-    @param pattern a filename pattern to check against
+    @type bool
+    @param pattern a filename pattern or list of filename patterns to check
+        against
+    @type str or list of str
     @param followsymlinks flag indicating whether symbolic links
-            should be followed
+        should be followed
+    @type bool
     @param checkStop function to be called to check for a stop
+    @type function
     @return list of all files and directories in the tree rooted
         at path. The names are expanded to start with path.
+    @rtype list of strs
     """
+    patterns = pattern if isinstance(pattern, list) else [pattern]
     files = [] if filesonly else [path]
     try:
         entries = os.listdir(path)
@@ -1148,14 +1156,15 @@
                          '.hg',
                          '.git',
                          '.ropeproject',
-                         '.eric7project']:
+                         '.eric7project',
+                         '.jedi']:
                 continue
             
             fentry = os.path.join(path, entry)
             if (
                 pattern and
                 not os.path.isdir(fentry) and
-                not fnmatch.fnmatch(entry, pattern)
+                not any(fnmatch.fnmatch(entry, p) for p in patterns)
             ):
                 # entry doesn't fit the given pattern
                 continue

eric ide

mercurial