src/eric7/UI/BrowserModel.py

branch
eric7
changeset 10470
cd7bfd539ac9
parent 10468
fcae57045733
child 10517
aecd5a8c958c
--- a/src/eric7/UI/BrowserModel.py	Wed Jan 03 11:25:17 2024 +0100
+++ b/src/eric7/UI/BrowserModel.py	Wed Jan 03 12:05:03 2024 +0100
@@ -8,6 +8,7 @@
 """
 
 import contextlib
+import enum
 import fnmatch
 import json
 import os
@@ -30,19 +31,30 @@
 from eric7.Utilities import ClassBrowsers
 from eric7.Utilities.ClassBrowsers import ClbrBaseClasses
 
-# TODO: change this to enum.Enum
-BrowserItemRoot = 0
-BrowserItemSimpleDirectory = 1
-BrowserItemDirectory = 2
-BrowserItemSysPath = 3
-BrowserItemFile = 4
-BrowserItemClass = 5
-BrowserItemMethod = 6
-BrowserItemAttributes = 7
-BrowserItemAttribute = 8
-BrowserItemCoding = 9
-BrowserItemImports = 10
-BrowserItemImport = 11
+
+class BrowserItemType(enum.Enum):
+    """
+    Class defining the various browser item types.
+    """
+
+    # Base types used everywhere
+    Root = 0
+    SimpleDirectory = 1
+    Directory = 2
+    SysPath = 3
+    File = 4
+    Class = 5
+    Method = 6
+    Attributes = 7
+    Attribute = 8
+    Coding = 9
+    Imports = 10
+    Import = 11
+
+    # Types used by the project browser model
+    PbSimpleDirectory = 100
+    PbDirectory = 101
+    PbFile = 102
 
 
 class BrowserModel(QAbstractItemModel):
@@ -571,17 +583,17 @@
         @param repopulate flag indicating a repopulation
         @type bool
         """
-        if parentItem.type() == BrowserItemDirectory:
+        if parentItem.type() == BrowserItemType.Directory:
             self.populateDirectoryItem(parentItem, repopulate)
-        elif parentItem.type() == BrowserItemSysPath:
+        elif parentItem.type() == BrowserItemType.SysPath:
             self.populateSysPathItem(parentItem, repopulate)
-        elif parentItem.type() == BrowserItemFile:
+        elif parentItem.type() == BrowserItemType.File:
             self.populateFileItem(parentItem, repopulate)
-        elif parentItem.type() == BrowserItemClass:
+        elif parentItem.type() == BrowserItemType.Class:
             self.populateClassItem(parentItem, repopulate)
-        elif parentItem.type() == BrowserItemMethod:
+        elif parentItem.type() == BrowserItemType.Method:
             self.populateMethodItem(parentItem, repopulate)
-        elif parentItem.type() == BrowserItemAttributes:
+        elif parentItem.type() == BrowserItemType.Attributes:
             self.populateClassAttributesItem(parentItem, repopulate)
 
     def populateDirectoryItem(self, parentItem, repopulate=False):
@@ -764,7 +776,7 @@
 
         parentItem._populated = True
         if (
-            parentItem.type_ == BrowserItemFile
+            parentItem.type_ == BrowserItemType.File
             and fileName not in self.watchedFileItems
         ):
             # watch the file only in the file browser not the project viewer
@@ -953,7 +965,7 @@
 
         self.parentItem = parent
         self.itemData = [data]
-        self.type_ = BrowserItemRoot
+        self.type_ = BrowserItemType.Root
         self.icon = EricPixmapCache.getIcon("empty")
         self._populated = True
         self._lazyPopulation = False
@@ -1062,9 +1074,8 @@
         Public method to get the item type.
 
         @return type of the item
-        @rtype int
+        @rtype BrowserItemType
         """
-        # TODO: change this to reference the new Enum
         return self.type_
 
     def isPublic(self):
@@ -1149,7 +1160,7 @@
         """
         BrowserItem.__init__(self, parent, text)
 
-        self.type_ = BrowserItemSimpleDirectory
+        self.type_ = BrowserItemType.SimpleDirectory
 
         self._dirName = path
         if not os.path.isdir(self._dirName):
@@ -1232,7 +1243,7 @@
         dn = self._dirName if full else os.path.basename(self._dirName)
         BrowserItem.__init__(self, parent, dn)
 
-        self.type_ = BrowserItemDirectory
+        self.type_ = BrowserItemType.Directory
         if (
             not FileSystemUtilities.isDrive(self._dirName)
             and os.path.lexists(self._dirName)
@@ -1311,7 +1322,7 @@
         """
         BrowserItem.__init__(self, parent, "sys.path")
 
-        self.type_ = BrowserItemSysPath
+        self.type_ = BrowserItemType.SysPath
         self.icon = EricPixmapCache.getIcon("filePython")
         self._populated = False
         self._lazyPopulation = True
@@ -1346,7 +1357,7 @@
         """
         BrowserItem.__init__(self, parent, os.path.basename(finfo))
 
-        self.type_ = BrowserItemFile
+        self.type_ = BrowserItemType.File
         self.fileext = os.path.splitext(finfo)[1].lower()
         self._filename = os.path.abspath(finfo)
         self._dirName = os.path.dirname(finfo)
@@ -1679,7 +1690,7 @@
 
         BrowserItem.__init__(self, parent, name)
 
-        self.type_ = BrowserItemClass
+        self.type_ = BrowserItemType.Class
         self._name = name
         self._classObject = cl
         self._filename = filename
@@ -1823,7 +1834,7 @@
         name = fn.name
         BrowserItem.__init__(self, parent, name)
 
-        self.type_ = BrowserItemMethod
+        self.type_ = BrowserItemType.Method
         self._name = name
         self._functionObject = fn
         self._filename = filename
@@ -1960,7 +1971,7 @@
         """
         BrowserItem.__init__(self, parent, text)
 
-        self.type_ = BrowserItemAttributes
+        self.type_ = BrowserItemType.Attributes
         self._attributes = attributes.copy()
         self._populated = False
         self._lazyPopulation = True
@@ -2036,7 +2047,7 @@
         """
         BrowserItem.__init__(self, parent, attribute.name)
 
-        self.type_ = BrowserItemAttribute
+        self.type_ = BrowserItemType.Attribute
         self._attributeObject = attribute
         self.__public = attribute.isPublic()
         if isClass:
@@ -2152,7 +2163,7 @@
         """
         BrowserItem.__init__(self, parent, text)
 
-        self.type_ = BrowserItemCoding
+        self.type_ = BrowserItemType.Coding
         self.icon = EricPixmapCache.getIcon("textencoding")
 
         self.__lineno = linenumber
@@ -2204,7 +2215,7 @@
         """
         BrowserItem.__init__(self, parent, text)
 
-        self.type_ = BrowserItemImports
+        self.type_ = BrowserItemType.Imports
         self.icon = EricPixmapCache.getIcon("imports")
 
     def lessThan(self, other, column, order):
@@ -2252,7 +2263,7 @@
         self.__filename = filename
         self.__linenos = lineNumbers[:]
 
-        self.type_ = BrowserItemImport
+        self.type_ = BrowserItemType.Import
         if isModule:
             self.icon = EricPixmapCache.getIcon("importedModule")
         else:

eric ide

mercurial