Adapted to the extended Editor API as of eric 6.1.0. release-3.1.0

Sun, 31 May 2015 18:03:01 +0200

author
Detlev Offenbach <detlev@die-offenbachs.de>
date
Sun, 31 May 2015 18:03:01 +0200
changeset 119
263a95431e41
parent 118
67d952a9036e
child 120
8ddfaad361c7

Adapted to the extended Editor API as of eric 6.1.0.

AssistantEric/Assistant.py file | annotate | diff | comparison | revisions
AssistantEric/Documentation/source/Plugin_Assistant_Eric.AssistantEric.Assistant.html file | annotate | diff | comparison | revisions
ChangeLog file | annotate | diff | comparison | revisions
PluginAssistantEric.py file | annotate | diff | comparison | revisions
PluginAssistantEric.zip file | annotate | diff | comparison | revisions
--- a/AssistantEric/Assistant.py	Sun Mar 22 17:37:55 2015 +0100
+++ b/AssistantEric/Assistant.py	Sun May 31 18:03:01 2015 +0200
@@ -124,9 +124,8 @@
         
         # preload the api to give the manager a chance to prepare the database
         language = editor.getLanguage()
-        if language == "":
-            return
-        self.__apisManager.getAPIs(language)
+        if language:
+            self.__apisManager.getAPIs(language)
     
     def __editorClosed(self, editor):
         """
@@ -138,10 +137,20 @@
             editor.editorSaved.disconnect(
                 self.__apisManager.getAPIs(ApisNameProject).editorSaved)
             self.__editors.remove(editor)
-            if editor.autoCompletionHook() == self.autocomplete:
-                self.__unsetAutoCompletionHook(editor)
-            if editor.callTipHook() == self.calltips:
-                self.__unsetCalltipsHook(editor)
+            try:
+                if editor.getCompletionListHook("Assistant"):
+                    self.__unsetAutoCompletionHook(editor)
+            except AttributeError:
+                # old interface (before 6.1.0)
+                if editor.autoCompletionHook() == self.autocomplete:
+                    self.__unsetAutoCompletionHook(editor)
+            try:
+                if editor.getCallTipHook("Assistant"):
+                    self.__unsetCalltipsHook(editor)
+            except AttributeError:
+                # old interface (before 6.1.0)
+                if editor.callTipHook() == self.calltips:
+                    self.__unsetCalltipsHook(editor)
     
     def __preferencesChanged(self):
         """
@@ -149,31 +158,8 @@
         """
         self.__apisManager.reloadAPIs()
     
-    def __getCharacter(self, pos, editor):
-        """
-        Private method to get the character to the left of the current position
-        in the current line.
-        
-        @param pos position to get character at (integer)
-        @param editor reference to the editor object to work with
-            (QScintilla.Editor)
-        @return requested character or "", if there are no more (string) and
-            the next position (i.e. pos - 1)
-        """
-        if pos <= 0:
-            return "", pos
-        
-        pos -= 1
-        ch = editor.charAt(pos)
-        
-        # Don't go past the end of the previous line
-        if ch == '\n' or ch == '\r':
-            return "", pos
-        
-        return ch, pos
-    
     #################################
-    ## autocompletion methods below
+    ## auto-completion methods below
     #################################
     
     def __completionListSelected(self, id, txt):
@@ -210,14 +196,36 @@
             editor.insert(txt)
             editor.setCursorPosition(line, col + len(txt))
     
+    def __recordSelectedContext(self, id, txt):
+        """
+        Private slot to handle the selection from the completion list to
+        record the selected completion context.
+        
+        @param id the ID of the user list (should be 1) (integer)
+        @param txt the selected text (string)
+        """
+        from QScintilla.Editor import EditorAutoCompletionListID
+        
+        if id == EditorAutoCompletionListID:
+            lst = txt.split()
+            if len(lst) > 1:
+                self.__lastFullContext = lst[1][1:].split(")")[0]
+            else:
+                self.__lastFullContext = None
+    
     def __setAutoCompletionHook(self, editor):
         """
         Private method to set the autocompletion hook.
         
         @param editor reference to the editor (QScintilla.Editor)
         """
-        editor.userListActivated.connect(self.__completionListSelected)
-        editor.setAutoCompletionHook(self.autocomplete)
+        try:
+            editor.userListActivated.connect(self.__recordSelectedContext)
+            editor.addCompletionListHook("Assistant", self.getCompletionsList)
+        except AttributeError:
+            # old interface (before 6.1.0)
+            editor.userListActivated.connect(self.__completionListSelected)
+            editor.setAutoCompletionHook(self.autocomplete)
     
     def __unsetAutoCompletionHook(self, editor):
         """
@@ -225,8 +233,13 @@
         
         @param editor reference to the editor (QScintilla.Editor)
         """
-        editor.unsetAutoCompletionHook()
-        editor.userListActivated.disconnect(self.__completionListSelected)
+        try:
+            editor.userListActivated.disconnect(self.__recordSelectedContext)
+            editor.removeCompletionListHook("Assistant")
+        except AttributeError:
+            # old interface (before 6.1.0)
+            editor.unsetAutoCompletionHook()
+            editor.userListActivated.disconnect(self.__completionListSelected)
     
     def autocomplete(self, editor, context):
         """
@@ -697,7 +710,11 @@
         
         @param editor reference to the editor (QScintilla.Editor)
         """
-        editor.setCallTipHook(self.calltips)
+        try:
+            editor.addCallTipHook("Assistant", self.calltips)
+        except AttributeError:
+            # old interface (before 6.1.0)
+            editor.setCallTipHook(self.calltips)
     
     def __unsetCalltipsHook(self, editor):
         """
@@ -705,7 +722,11 @@
         
         @param editor reference to the editor (QScintilla.Editor)
         """
-        editor.unsetCallTipHook()
+        try:
+            editor.removeCallTipHook("Assistant")
+        except AttributeError:
+            # old interface (before 6.1.0)
+            editor.unsetCallTipHook()
     
     def calltips(self, editor, pos, commas):
         """
--- a/AssistantEric/Documentation/source/Plugin_Assistant_Eric.AssistantEric.Assistant.html	Sun Mar 22 17:37:55 2015 +0100
+++ b/AssistantEric/Documentation/source/Plugin_Assistant_Eric.AssistantEric.Assistant.html	Sun May 31 18:03:01 2015 +0200
@@ -76,9 +76,6 @@
 <td><a href="#Assistant.__getApiCompletions">__getApiCompletions</a></td>
 <td>Private method to determine a list of completions from an API object.</td>
 </tr><tr>
-<td><a href="#Assistant.__getCharacter">__getCharacter</a></td>
-<td>Private method to get the character to the left of the current position in the current line.</td>
-</tr><tr>
 <td><a href="#Assistant.__getCompletions">__getCompletions</a></td>
 <td>Private method to get the list of possible completions.</td>
 </tr><tr>
@@ -91,6 +88,9 @@
 <td><a href="#Assistant.__preferencesChanged">__preferencesChanged</a></td>
 <td>Private method to handle a change of the global configuration.</td>
 </tr><tr>
+<td><a href="#Assistant.__recordSelectedContext">__recordSelectedContext</a></td>
+<td>Private slot to handle the selection from the completion list to record the selected completion context.</td>
+</tr><tr>
 <td><a href="#Assistant.__setAutoCompletionHook">__setAutoCompletionHook</a></td>
 <td>Private method to set the autocompletion hook.</td>
 </tr><tr>
@@ -236,27 +236,6 @@
 <dd>
 list of possible completions (list of strings)
 </dd>
-</dl><a NAME="Assistant.__getCharacter" ID="Assistant.__getCharacter"></a>
-<h4>Assistant.__getCharacter</h4>
-<b>__getCharacter</b>(<i>pos, editor</i>)
-<p>
-        Private method to get the character to the left of the current position
-        in the current line.
-</p><dl>
-<dt><i>pos</i></dt>
-<dd>
-position to get character at (integer)
-</dd><dt><i>editor</i></dt>
-<dd>
-reference to the editor object to work with
-            (QScintilla.Editor)
-</dd>
-</dl><dl>
-<dt>Returns:</dt>
-<dd>
-requested character or "", if there are no more (string) and
-            the next position (i.e. pos - 1)
-</dd>
 </dl><a NAME="Assistant.__getCompletions" ID="Assistant.__getCompletions"></a>
 <h4>Assistant.__getCompletions</h4>
 <b>__getCompletions</b>(<i>word, context, prefix, language, module, editor, importCompletion, sep</i>)
@@ -358,7 +337,21 @@
 <b>__preferencesChanged</b>(<i></i>)
 <p>
         Private method to handle a change of the global configuration.
-</p><a NAME="Assistant.__setAutoCompletionHook" ID="Assistant.__setAutoCompletionHook"></a>
+</p><a NAME="Assistant.__recordSelectedContext" ID="Assistant.__recordSelectedContext"></a>
+<h4>Assistant.__recordSelectedContext</h4>
+<b>__recordSelectedContext</b>(<i>id, txt</i>)
+<p>
+        Private slot to handle the selection from the completion list to
+        record the selected completion context.
+</p><dl>
+<dt><i>id</i></dt>
+<dd>
+the ID of the user list (should be 1) (integer)
+</dd><dt><i>txt</i></dt>
+<dd>
+the selected text (string)
+</dd>
+</dl><a NAME="Assistant.__setAutoCompletionHook" ID="Assistant.__setAutoCompletionHook"></a>
 <h4>Assistant.__setAutoCompletionHook</h4>
 <b>__setAutoCompletionHook</b>(<i>editor</i>)
 <p>
--- a/ChangeLog	Sun Mar 22 17:37:55 2015 +0100
+++ b/ChangeLog	Sun May 31 18:03:01 2015 +0200
@@ -1,5 +1,9 @@
 ChangeLog
 ---------
+Version 3.1.0:
+- adapted to the extended Editor API as of eric 6.1.0
+- bug fixes
+
 Version 3.0.4:
 - made the method to get a list of completions publicly available
 - bug fixes
--- a/PluginAssistantEric.py	Sun Mar 22 17:37:55 2015 +0100
+++ b/PluginAssistantEric.py	Sun May 31 18:03:01 2015 +0200
@@ -24,7 +24,7 @@
 author = "Detlev Offenbach <detlev@die-offenbachs.de>"
 autoactivate = True
 deactivateable = True
-version = "3.0.4"
+version = "3.1.0"
 className = "AssistantEricPlugin"
 packageName = "AssistantEric"
 shortDescription = "Alternative autocompletion and calltips provider."
Binary file PluginAssistantEric.zip has changed

eric ide

mercurial