QScintilla/APIsManager.py

branch
APIs
changeset 5349
bccda3b5920a
parent 4631
5c1a96925da4
child 5358
2584d0a08bf4
diff -r 96197e13fdf3 -r bccda3b5920a QScintilla/APIsManager.py
--- a/QScintilla/APIsManager.py	Wed Nov 30 18:54:04 2016 +0100
+++ b/QScintilla/APIsManager.py	Wed Nov 30 19:59:57 2016 +0100
@@ -34,23 +34,34 @@
     apiPreparationCancelled = pyqtSignal()
     apiPreparationStarted = pyqtSignal()
     
-    def __init__(self, language, forPreparation=False, parent=None):
+    def __init__(self, language, projectType="", forPreparation=False,
+                 parent=None):
         """
         Constructor
         
-        @param language language of the APIs object (string)
+        @param language language of the APIs object
+        @type str
+        @param projectType type of the project
+        @type str
         @param forPreparation flag indicating this object is just needed
-            for a preparation process (boolean)
-        @param parent reference to the parent object (QObject)
+            for a preparation process
+        @type bool
+        @param parent reference to the parent object
+        @type QObject
         """
         super(APIs, self).__init__(parent)
-        self.setObjectName("APIs_{0}".format(language))
+        if projectType:
+            self.setObjectName("APIs_{0}_{1}".format(language, projectType))
+        else:
+            self.setObjectName("APIs_{0}".format(language))
         
         self.__inPreparation = False
         self.__language = language
+        self.__projectType = projectType
         self.__forPreparation = forPreparation
         self.__lexer = Lexers.getLexer(self.__language)
-        self.__apifiles = Preferences.getEditorAPI(self.__language)
+        self.__apifiles = Preferences.getEditorAPI(self.__language,
+                                                   self.__projectType)
         self.__apifiles.sort()
         if self.__lexer is None:
             self.__apis = None
@@ -73,7 +84,7 @@
             if not self.__forPreparation and \
                     Preferences.getEditor("AutoPrepareAPIs"):
                 self.prepareAPIs()
-            self.__apis.loadPrepared()
+            self.__apis.loadPrepared(self.__preparedName())
         else:
             # load the raw files and prepare the API file
             if not self.__forPreparation and \
@@ -112,7 +123,7 @@
         """
         Private method called to save an API, after it has been prepared.
         """
-        self.__apis.savePrepared()
+        self.__apis.savePrepared(self.__preparedName())
         self.__inPreparation = False
         self.apiPreparationFinished.emit()
     
@@ -146,15 +157,15 @@
             needsPreparation = True
         else:
             # check, if a new preparation is necessary
-            preparedAPIs = self.__defaultPreparedName()
+            preparedAPIs = self.__preparedName()
             if preparedAPIs:
                 preparedAPIsInfo = QFileInfo(preparedAPIs)
                 if not preparedAPIsInfo.exists():
                     needsPreparation = True
                 else:
                     preparedAPIsTime = preparedAPIsInfo.lastModified()
-                    apifiles = sorted(
-                        Preferences.getEditorAPI(self.__language))
+                    apifiles = sorted(Preferences.getEditorAPI(
+                        self.__language, self.__projectType))
                     if self.__apifiles != apifiles:
                         needsPreparation = True
                     for apifile in apifiles:
@@ -169,7 +180,8 @@
             if rawList:
                 apifiles = rawList
             else:
-                apifiles = Preferences.getEditorAPI(self.__language)
+                apifiles = Preferences.getEditorAPI(
+                    self.__language, self.__projectType)
             for apifile in apifiles:
                 self.__apis.load(apifile)
             self.__apis.prepare()
@@ -209,14 +221,20 @@
         else:
             return []
     
-    def __defaultPreparedName(self):
+    def __preparedName(self):
         """
         Private method returning the default name of a prepared API file.
         
         @return complete filename for the Prepared APIs file (string)
         """
+        apisDir = os.path.join(Globals.getConfigDir(), "APIs")
         if self.__apis is not None:
-            return self.__apis.defaultPreparedName()
+            if self.__projectType:
+                filename = "{0}_{1}.pap".format(self.__language,
+                                                self.__projectType)
+            else:
+                filename = "{0}.pap".format(self.__language)
+            return os.path.join(apisDir, filename)
         else:
             return ""
     
@@ -244,28 +262,35 @@
         for api in list(self.__apis.values()):
             api and api.reloadAPIs()
     
-    def getAPIs(self, language, forPreparation=False):
+    def getAPIs(self, language, projectType="", forPreparation=False):
         """
-        Public method to get an apis object for autocompletion/calltips.
+        Public method to get an APIs object for autocompletion/calltips.
         
         This method creates and loads an APIs object dynamically upon request.
         This saves memory for languages, that might not be needed at the
         moment.
         
-        @param language the language of the requested api object (string)
-        @param forPreparation flag indicating the requested api object is just
-            needed for a preparation process (boolean)
-        @return the apis object (APIs)
+        @param language language of the requested APIs object
+        @type str
+        @param projectType type of the project
+        @type str
+        @param forPreparation flag indicating the requested APIs object is just
+            needed for a preparation process
+        @type bool
+        @return reference to the APIs object
+        @rtype APIs
         """
         if forPreparation:
-            return APIs(language, forPreparation=forPreparation)
+            return APIs(language, projectType=projectType,
+                        forPreparation=forPreparation)
         else:
             try:
-                return self.__apis[language]
+                return self.__apis[(language, projectType)]
             except KeyError:
                 if language in Lexers.getSupportedLanguages():
                     # create the api object
-                    self.__apis[language] = APIs(language)
-                    return self.__apis[language]
+                    self.__apis[(language, projectType)] = \
+                        APIs(language, projectType=projectType)
+                    return self.__apis[(language, projectType)]
                 else:
                     return None

eric ide

mercurial