src/eric7/Project/Project.py

branch
eric7-maintenance
changeset 10272
7ae72d1df070
parent 10174
6aac1022f330
parent 10263
f4bb67586615
child 10349
df7edc29cbfb
diff -r 3a99ac054b39 -r 7ae72d1df070 src/eric7/Project/Project.py
--- a/src/eric7/Project/Project.py	Thu Oct 05 10:06:49 2023 +0200
+++ b/src/eric7/Project/Project.py	Tue Oct 31 09:22:17 2023 +0100
@@ -712,11 +712,11 @@
         """
         return list(self.__fileCategoriesRepository.keys())
 
-    def getFileCategoryFilterString(
+    def getFileCategoryFilters(
         self, categories=None, withOthers=False, withAll=True
     ):
         """
-        Public method to get a file selection string for the given categories.
+        Public method to get a list of file selection filters for the given categories.
 
         @param categories list of file type categories (defaults to None).
             A value of None means all categories except 'OTHERS'.
@@ -727,8 +727,8 @@
         @param withAll flag indicating to include a filter for 'All Files'
             (defaults to True)
         @type bool (optional)
-        @return file selection filter string
-        @rtype str
+        @return list of file selection filter strings
+        @rtype list of str
         """
         if categories is None:
             categories = [c for c in self.__fileCategoriesRepository if c != "OTHERS"]
@@ -749,11 +749,35 @@
                     " ".join(sorted(patterns[filetype]))
                 )
             )
-        filterString = ";;".join(sorted(filters))
+        filters = sorted(filters)
         if withAll:
-            filterString += ";;" + self.tr("All Files (*)")
-
-        return filterString
+            filters.append(self.tr("All Files (*)"))
+
+        return filters
+
+    def getFileCategoryFilterString(
+        self, categories=None, withOthers=False, withAll=True
+    ):
+        """
+        Public method to get a file selection string for the given categories.
+
+        @param categories list of file type categories (defaults to None).
+            A value of None means all categories except 'OTHERS'.
+        @type list of str (optional)
+        @param withOthers flag indicating to include the 'OTHERS' category
+            (defaults to False)
+        @type bool (optional)
+        @param withAll flag indicating to include a filter for 'All Files'
+            (defaults to True)
+        @type bool (optional)
+        @return file selection filter string
+        @rtype str
+        """
+        return ";;".join(
+            self.getFileCategoryFilters(
+                categ=categories, withOthers=withOthers, withAll=withAll
+            )
+        )
 
     def getFileCategoryString(self, category):
         """
@@ -1756,8 +1780,9 @@
         """
         langFile = self.getRelativePath(langFile)
         qmFile = self.__binaryTranslationFile(langFile)
-        self.__pdata["TRANSLATIONS"].remove(langFile)
-        self.__model.removeItem(langFile)
+        with contextlib.suppress(ValueError):
+            self.__model.removeItem(langFile)
+            self.__pdata["TRANSLATIONS"].remove(langFile)
         if qmFile:
             with contextlib.suppress(ValueError):
                 if self.__pdata["TRANSLATIONSBINPATH"]:
@@ -1767,8 +1792,8 @@
                             os.path.basename(qmFile),
                         )
                     )
+                self.__model.removeItem(qmFile)
                 self.__pdata["TRANSLATIONS"].remove(qmFile)
-                self.__model.removeItem(qmFile)
         self.setDirty(True)
 
     def deleteLanguageFile(self, langFile):
@@ -1901,7 +1926,7 @@
         """
         from .AddFileDialog import AddFileDialog
 
-        if startdir is None:
+        if not startdir:
             startdir = self.ppath
 
         dlg = AddFileDialog(self, self.parent(), fileTypeFilter, startdir=startdir)
@@ -2079,7 +2104,7 @@
         """
         from .AddDirectoryDialog import AddDirectoryDialog
 
-        if startdir is None:
+        if not startdir:
             startdir = self.ppath
 
         dlg = AddDirectoryDialog(self, fileTypeFilter, self.parent(), startdir=startdir)

eric ide

mercurial