Thu, 12 Aug 2010 19:06:24 +0200
Added code to use the new style signal API depending upon the eric5 version.
2
89cbc07f4bf0
First commit after porting to Python3.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff
changeset
|
1 | # -*- coding: utf-8 -*- |
89cbc07f4bf0
First commit after porting to Python3.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff
changeset
|
2 | |
89cbc07f4bf0
First commit after porting to Python3.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff
changeset
|
3 | # Copyright (c) 2008 - 2010 Detlev Offenbach <detlev@die-offenbachs.de> |
89cbc07f4bf0
First commit after porting to Python3.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff
changeset
|
4 | # |
89cbc07f4bf0
First commit after porting to Python3.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff
changeset
|
5 | |
89cbc07f4bf0
First commit after porting to Python3.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff
changeset
|
6 | """ |
89cbc07f4bf0
First commit after porting to Python3.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff
changeset
|
7 | Module implementing the eric assistant, an alternative autocompletion and |
89cbc07f4bf0
First commit after porting to Python3.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff
changeset
|
8 | calltips system. |
89cbc07f4bf0
First commit after porting to Python3.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff
changeset
|
9 | """ |
89cbc07f4bf0
First commit after porting to Python3.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff
changeset
|
10 | |
18
b8ece0b784e8
Fixed a few unicode related issues.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
5
diff
changeset
|
11 | import re |
b8ece0b784e8
Fixed a few unicode related issues.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
5
diff
changeset
|
12 | |
2
89cbc07f4bf0
First commit after porting to Python3.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff
changeset
|
13 | from PyQt4.QtCore import * |
89cbc07f4bf0
First commit after porting to Python3.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff
changeset
|
14 | |
89cbc07f4bf0
First commit after porting to Python3.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff
changeset
|
15 | from E5Gui.E5Application import e5App |
89cbc07f4bf0
First commit after porting to Python3.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff
changeset
|
16 | |
89cbc07f4bf0
First commit after porting to Python3.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff
changeset
|
17 | from .APIsManager import APIsManager, ApisNameProject |
89cbc07f4bf0
First commit after porting to Python3.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff
changeset
|
18 | |
89cbc07f4bf0
First commit after porting to Python3.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff
changeset
|
19 | from QScintilla.Editor import Editor |
89cbc07f4bf0
First commit after porting to Python3.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff
changeset
|
20 | |
89cbc07f4bf0
First commit after porting to Python3.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff
changeset
|
21 | import Preferences |
89cbc07f4bf0
First commit after porting to Python3.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff
changeset
|
22 | |
89cbc07f4bf0
First commit after porting to Python3.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff
changeset
|
23 | AcsAPIs = 0x0001 |
89cbc07f4bf0
First commit after porting to Python3.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff
changeset
|
24 | AcsDocument = 0x0002 |
89cbc07f4bf0
First commit after porting to Python3.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff
changeset
|
25 | AcsProject = 0x0004 |
89cbc07f4bf0
First commit after porting to Python3.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff
changeset
|
26 | AcsOther = 0x1000 |
89cbc07f4bf0
First commit after porting to Python3.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff
changeset
|
27 | |
89cbc07f4bf0
First commit after porting to Python3.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff
changeset
|
28 | class Assistant(QObject): |
89cbc07f4bf0
First commit after porting to Python3.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff
changeset
|
29 | """ |
89cbc07f4bf0
First commit after porting to Python3.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff
changeset
|
30 | Class implementing the autocompletion and calltips system. |
89cbc07f4bf0
First commit after porting to Python3.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff
changeset
|
31 | """ |
19
7eb775bb326b
Added code to use the new style signal API depending upon the eric5 version.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
18
diff
changeset
|
32 | def __init__(self, plugin, newStyle, parent = None): |
2
89cbc07f4bf0
First commit after porting to Python3.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff
changeset
|
33 | """ |
89cbc07f4bf0
First commit after porting to Python3.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff
changeset
|
34 | Constructor |
89cbc07f4bf0
First commit after porting to Python3.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff
changeset
|
35 | |
89cbc07f4bf0
First commit after porting to Python3.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff
changeset
|
36 | @param plugin reference to the plugin object |
19
7eb775bb326b
Added code to use the new style signal API depending upon the eric5 version.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
18
diff
changeset
|
37 | @param newStyle flag indicating usage of new style signals (bool) |
2
89cbc07f4bf0
First commit after porting to Python3.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff
changeset
|
38 | @param parent parent (QObject) |
89cbc07f4bf0
First commit after porting to Python3.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff
changeset
|
39 | """ |
89cbc07f4bf0
First commit after porting to Python3.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff
changeset
|
40 | QObject.__init__(self, parent) |
89cbc07f4bf0
First commit after porting to Python3.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff
changeset
|
41 | |
89cbc07f4bf0
First commit after porting to Python3.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff
changeset
|
42 | self.__plugin = plugin |
19
7eb775bb326b
Added code to use the new style signal API depending upon the eric5 version.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
18
diff
changeset
|
43 | self.__newStyle = newStyle |
2
89cbc07f4bf0
First commit after porting to Python3.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff
changeset
|
44 | self.__ui = parent |
89cbc07f4bf0
First commit after porting to Python3.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff
changeset
|
45 | self.__project = e5App().getObject("Project") |
89cbc07f4bf0
First commit after porting to Python3.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff
changeset
|
46 | self.__viewmanager = e5App().getObject("ViewManager") |
89cbc07f4bf0
First commit after porting to Python3.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff
changeset
|
47 | self.__pluginManager = e5App().getObject("PluginManager") |
89cbc07f4bf0
First commit after porting to Python3.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff
changeset
|
48 | |
19
7eb775bb326b
Added code to use the new style signal API depending upon the eric5 version.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
18
diff
changeset
|
49 | self.__apisManager = APIsManager(self.__newStyle, self) |
2
89cbc07f4bf0
First commit after porting to Python3.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff
changeset
|
50 | |
89cbc07f4bf0
First commit after porting to Python3.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff
changeset
|
51 | self.__editors = [] |
89cbc07f4bf0
First commit after porting to Python3.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff
changeset
|
52 | self.__completingContext = False |
89cbc07f4bf0
First commit after porting to Python3.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff
changeset
|
53 | self.__lastContext = None |
89cbc07f4bf0
First commit after porting to Python3.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff
changeset
|
54 | self.__lastFullContext = None |
89cbc07f4bf0
First commit after porting to Python3.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff
changeset
|
55 | |
89cbc07f4bf0
First commit after porting to Python3.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff
changeset
|
56 | self.__fromDocumentID = Editor.FromDocumentID |
89cbc07f4bf0
First commit after porting to Python3.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff
changeset
|
57 | |
89cbc07f4bf0
First commit after porting to Python3.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff
changeset
|
58 | def activate(self): |
89cbc07f4bf0
First commit after porting to Python3.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff
changeset
|
59 | """ |
89cbc07f4bf0
First commit after porting to Python3.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff
changeset
|
60 | Public method to perform actions upon activation. |
89cbc07f4bf0
First commit after porting to Python3.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff
changeset
|
61 | """ |
19
7eb775bb326b
Added code to use the new style signal API depending upon the eric5 version.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
18
diff
changeset
|
62 | if self.__newStyle: |
7eb775bb326b
Added code to use the new style signal API depending upon the eric5 version.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
18
diff
changeset
|
63 | self.__pluginManager.shutdown.connect(self.__shutdown) |
7eb775bb326b
Added code to use the new style signal API depending upon the eric5 version.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
18
diff
changeset
|
64 | |
7eb775bb326b
Added code to use the new style signal API depending upon the eric5 version.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
18
diff
changeset
|
65 | self.__ui.preferencesChanged.connect(self.__preferencesChanged) |
7eb775bb326b
Added code to use the new style signal API depending upon the eric5 version.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
18
diff
changeset
|
66 | |
7eb775bb326b
Added code to use the new style signal API depending upon the eric5 version.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
18
diff
changeset
|
67 | self.__viewmanager.editorOpenedEd.connect(self.__editorOpened) |
7eb775bb326b
Added code to use the new style signal API depending upon the eric5 version.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
18
diff
changeset
|
68 | self.__viewmanager.editorClosedEd.connect(self.__editorClosed) |
7eb775bb326b
Added code to use the new style signal API depending upon the eric5 version.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
18
diff
changeset
|
69 | else: |
7eb775bb326b
Added code to use the new style signal API depending upon the eric5 version.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
18
diff
changeset
|
70 | self.connect(self.__pluginManager, SIGNAL("shutdown()"), |
7eb775bb326b
Added code to use the new style signal API depending upon the eric5 version.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
18
diff
changeset
|
71 | self.__shutdown) |
7eb775bb326b
Added code to use the new style signal API depending upon the eric5 version.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
18
diff
changeset
|
72 | |
7eb775bb326b
Added code to use the new style signal API depending upon the eric5 version.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
18
diff
changeset
|
73 | self.connect(self.__ui, SIGNAL('preferencesChanged'), |
7eb775bb326b
Added code to use the new style signal API depending upon the eric5 version.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
18
diff
changeset
|
74 | self.__preferencesChanged) |
7eb775bb326b
Added code to use the new style signal API depending upon the eric5 version.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
18
diff
changeset
|
75 | |
7eb775bb326b
Added code to use the new style signal API depending upon the eric5 version.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
18
diff
changeset
|
76 | self.connect(self.__viewmanager, SIGNAL("editorOpenedEd"), |
7eb775bb326b
Added code to use the new style signal API depending upon the eric5 version.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
18
diff
changeset
|
77 | self.__editorOpened) |
7eb775bb326b
Added code to use the new style signal API depending upon the eric5 version.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
18
diff
changeset
|
78 | self.connect(self.__viewmanager, SIGNAL("editorClosedEd"), |
7eb775bb326b
Added code to use the new style signal API depending upon the eric5 version.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
18
diff
changeset
|
79 | self.__editorClosed) |
2
89cbc07f4bf0
First commit after porting to Python3.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff
changeset
|
80 | |
89cbc07f4bf0
First commit after porting to Python3.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff
changeset
|
81 | # preload the project APIs object |
89cbc07f4bf0
First commit after porting to Python3.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff
changeset
|
82 | self.__apisManager.getAPIs(ApisNameProject) |
89cbc07f4bf0
First commit after porting to Python3.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff
changeset
|
83 | |
89cbc07f4bf0
First commit after porting to Python3.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff
changeset
|
84 | for editor in self.__viewmanager.getOpenEditors(): |
89cbc07f4bf0
First commit after porting to Python3.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff
changeset
|
85 | self.__editorOpened(editor) |
89cbc07f4bf0
First commit after porting to Python3.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff
changeset
|
86 | |
89cbc07f4bf0
First commit after porting to Python3.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff
changeset
|
87 | def deactivate(self): |
89cbc07f4bf0
First commit after porting to Python3.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff
changeset
|
88 | """ |
89cbc07f4bf0
First commit after porting to Python3.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff
changeset
|
89 | Public method to perform actions upon deactivation. |
89cbc07f4bf0
First commit after porting to Python3.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff
changeset
|
90 | """ |
19
7eb775bb326b
Added code to use the new style signal API depending upon the eric5 version.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
18
diff
changeset
|
91 | if self.__newStyle: |
7eb775bb326b
Added code to use the new style signal API depending upon the eric5 version.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
18
diff
changeset
|
92 | self.__pluginManager.shutdown.disconnect(self.__shutdown) |
7eb775bb326b
Added code to use the new style signal API depending upon the eric5 version.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
18
diff
changeset
|
93 | |
7eb775bb326b
Added code to use the new style signal API depending upon the eric5 version.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
18
diff
changeset
|
94 | self.__ui.preferencesChanged.disconnect(self.__preferencesChanged) |
7eb775bb326b
Added code to use the new style signal API depending upon the eric5 version.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
18
diff
changeset
|
95 | |
7eb775bb326b
Added code to use the new style signal API depending upon the eric5 version.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
18
diff
changeset
|
96 | self.__viewmanager.editorOpenedEd.disconnect(self.__editorOpened) |
7eb775bb326b
Added code to use the new style signal API depending upon the eric5 version.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
18
diff
changeset
|
97 | self.__viewmanager.editorClosedEd.disconnect(self.__editorClosed) |
7eb775bb326b
Added code to use the new style signal API depending upon the eric5 version.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
18
diff
changeset
|
98 | else: |
7eb775bb326b
Added code to use the new style signal API depending upon the eric5 version.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
18
diff
changeset
|
99 | self.disconnect(self.__pluginManager, SIGNAL("shutdown()"), |
7eb775bb326b
Added code to use the new style signal API depending upon the eric5 version.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
18
diff
changeset
|
100 | self.__shutdown) |
7eb775bb326b
Added code to use the new style signal API depending upon the eric5 version.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
18
diff
changeset
|
101 | |
7eb775bb326b
Added code to use the new style signal API depending upon the eric5 version.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
18
diff
changeset
|
102 | self.disconnect(self.__ui, SIGNAL('preferencesChanged'), |
7eb775bb326b
Added code to use the new style signal API depending upon the eric5 version.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
18
diff
changeset
|
103 | self.__preferencesChanged) |
7eb775bb326b
Added code to use the new style signal API depending upon the eric5 version.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
18
diff
changeset
|
104 | |
7eb775bb326b
Added code to use the new style signal API depending upon the eric5 version.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
18
diff
changeset
|
105 | self.disconnect(self.__viewmanager, SIGNAL("editorOpenedEd"), |
7eb775bb326b
Added code to use the new style signal API depending upon the eric5 version.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
18
diff
changeset
|
106 | self.__editorOpened) |
7eb775bb326b
Added code to use the new style signal API depending upon the eric5 version.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
18
diff
changeset
|
107 | self.disconnect(self.__viewmanager, SIGNAL("editorClosedEd"), |
7eb775bb326b
Added code to use the new style signal API depending upon the eric5 version.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
18
diff
changeset
|
108 | self.__editorClosed) |
2
89cbc07f4bf0
First commit after porting to Python3.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff
changeset
|
109 | |
89cbc07f4bf0
First commit after porting to Python3.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff
changeset
|
110 | self.__shutdown() |
89cbc07f4bf0
First commit after porting to Python3.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff
changeset
|
111 | |
89cbc07f4bf0
First commit after porting to Python3.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff
changeset
|
112 | def __shutdown(self): |
89cbc07f4bf0
First commit after porting to Python3.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff
changeset
|
113 | """ |
89cbc07f4bf0
First commit after porting to Python3.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff
changeset
|
114 | Private slot to handle the shutdown signal. |
89cbc07f4bf0
First commit after porting to Python3.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff
changeset
|
115 | """ |
89cbc07f4bf0
First commit after porting to Python3.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff
changeset
|
116 | for editor in self.__editors[:]: |
89cbc07f4bf0
First commit after porting to Python3.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff
changeset
|
117 | self.__editorClosed(editor) |
89cbc07f4bf0
First commit after porting to Python3.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff
changeset
|
118 | |
89cbc07f4bf0
First commit after porting to Python3.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff
changeset
|
119 | self.__apisManager.deactivate() |
89cbc07f4bf0
First commit after porting to Python3.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff
changeset
|
120 | |
89cbc07f4bf0
First commit after porting to Python3.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff
changeset
|
121 | def setEnabled(self, key, enabled): |
89cbc07f4bf0
First commit after porting to Python3.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff
changeset
|
122 | """ |
89cbc07f4bf0
First commit after porting to Python3.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff
changeset
|
123 | Public method to enable or disable a feature. |
89cbc07f4bf0
First commit after porting to Python3.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff
changeset
|
124 | |
89cbc07f4bf0
First commit after porting to Python3.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff
changeset
|
125 | @param key feature to set (string) |
89cbc07f4bf0
First commit after porting to Python3.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff
changeset
|
126 | @param enabled flag indicating the status (boolean) |
89cbc07f4bf0
First commit after porting to Python3.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff
changeset
|
127 | """ |
89cbc07f4bf0
First commit after porting to Python3.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff
changeset
|
128 | for editor in self.__editors[:]: |
89cbc07f4bf0
First commit after porting to Python3.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff
changeset
|
129 | self.__editorClosed(editor) |
89cbc07f4bf0
First commit after porting to Python3.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff
changeset
|
130 | if enabled: |
89cbc07f4bf0
First commit after porting to Python3.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff
changeset
|
131 | for editor in self.__viewmanager.getOpenEditors(): |
89cbc07f4bf0
First commit after porting to Python3.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff
changeset
|
132 | self.__editorOpened(editor) |
89cbc07f4bf0
First commit after porting to Python3.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff
changeset
|
133 | |
89cbc07f4bf0
First commit after porting to Python3.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff
changeset
|
134 | def __editorOpened(self, editor): |
89cbc07f4bf0
First commit after porting to Python3.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff
changeset
|
135 | """ |
89cbc07f4bf0
First commit after porting to Python3.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff
changeset
|
136 | Private slot called, when a new editor was opened. |
89cbc07f4bf0
First commit after porting to Python3.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff
changeset
|
137 | |
89cbc07f4bf0
First commit after porting to Python3.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff
changeset
|
138 | @param editor reference to the new editor (QScintilla.Editor) |
89cbc07f4bf0
First commit after porting to Python3.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff
changeset
|
139 | """ |
89cbc07f4bf0
First commit after porting to Python3.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff
changeset
|
140 | if self.__plugin.getPreferences("AutoCompletionEnabled"): |
89cbc07f4bf0
First commit after porting to Python3.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff
changeset
|
141 | self.__setAutoCompletionHook(editor) |
89cbc07f4bf0
First commit after porting to Python3.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff
changeset
|
142 | if self.__plugin.getPreferences("CalltipsEnabled"): |
89cbc07f4bf0
First commit after porting to Python3.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff
changeset
|
143 | self.__setCalltipsHook(editor) |
19
7eb775bb326b
Added code to use the new style signal API depending upon the eric5 version.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
18
diff
changeset
|
144 | if self.__newStyle: |
7eb775bb326b
Added code to use the new style signal API depending upon the eric5 version.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
18
diff
changeset
|
145 | editor.editorSaved.connect( |
7eb775bb326b
Added code to use the new style signal API depending upon the eric5 version.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
18
diff
changeset
|
146 | self.__apisManager.getAPIs(ApisNameProject).editorSaved) |
7eb775bb326b
Added code to use the new style signal API depending upon the eric5 version.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
18
diff
changeset
|
147 | else: |
7eb775bb326b
Added code to use the new style signal API depending upon the eric5 version.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
18
diff
changeset
|
148 | self.connect(editor, SIGNAL("editorSaved"), |
7eb775bb326b
Added code to use the new style signal API depending upon the eric5 version.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
18
diff
changeset
|
149 | self.__apisManager.getAPIs(ApisNameProject).editorSaved) |
2
89cbc07f4bf0
First commit after porting to Python3.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff
changeset
|
150 | self.__editors.append(editor) |
89cbc07f4bf0
First commit after porting to Python3.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff
changeset
|
151 | |
89cbc07f4bf0
First commit after porting to Python3.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff
changeset
|
152 | # preload the api to give the manager a chance to prepare the database |
89cbc07f4bf0
First commit after porting to Python3.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff
changeset
|
153 | language = editor.getLanguage() |
89cbc07f4bf0
First commit after porting to Python3.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff
changeset
|
154 | if language == "": |
89cbc07f4bf0
First commit after porting to Python3.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff
changeset
|
155 | return |
89cbc07f4bf0
First commit after porting to Python3.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff
changeset
|
156 | self.__apisManager.getAPIs(language) |
89cbc07f4bf0
First commit after porting to Python3.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff
changeset
|
157 | |
89cbc07f4bf0
First commit after porting to Python3.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff
changeset
|
158 | def __editorClosed(self, editor): |
89cbc07f4bf0
First commit after porting to Python3.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff
changeset
|
159 | """ |
89cbc07f4bf0
First commit after porting to Python3.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff
changeset
|
160 | Private slot called, when an editor was closed. |
89cbc07f4bf0
First commit after porting to Python3.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff
changeset
|
161 | |
89cbc07f4bf0
First commit after porting to Python3.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff
changeset
|
162 | @param editor reference to the editor (QScintilla.Editor) |
89cbc07f4bf0
First commit after porting to Python3.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff
changeset
|
163 | """ |
89cbc07f4bf0
First commit after porting to Python3.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff
changeset
|
164 | if editor in self.__editors: |
19
7eb775bb326b
Added code to use the new style signal API depending upon the eric5 version.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
18
diff
changeset
|
165 | if self.__newStyle: |
7eb775bb326b
Added code to use the new style signal API depending upon the eric5 version.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
18
diff
changeset
|
166 | editor.editorSaved.disconnect( |
7eb775bb326b
Added code to use the new style signal API depending upon the eric5 version.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
18
diff
changeset
|
167 | self.__apisManager.getAPIs(ApisNameProject).editorSaved) |
7eb775bb326b
Added code to use the new style signal API depending upon the eric5 version.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
18
diff
changeset
|
168 | else: |
7eb775bb326b
Added code to use the new style signal API depending upon the eric5 version.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
18
diff
changeset
|
169 | self.disconnect(editor, SIGNAL("editorSaved"), |
7eb775bb326b
Added code to use the new style signal API depending upon the eric5 version.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
18
diff
changeset
|
170 | self.__apisManager.getAPIs(ApisNameProject).editorSaved) |
2
89cbc07f4bf0
First commit after porting to Python3.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff
changeset
|
171 | self.__editors.remove(editor) |
89cbc07f4bf0
First commit after porting to Python3.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff
changeset
|
172 | if editor.autoCompletionHook() == self.autocomplete: |
89cbc07f4bf0
First commit after porting to Python3.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff
changeset
|
173 | self.__unsetAutoCompletionHook(editor) |
89cbc07f4bf0
First commit after porting to Python3.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff
changeset
|
174 | if editor.callTipHook() == self.calltips: |
89cbc07f4bf0
First commit after porting to Python3.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff
changeset
|
175 | self.__unsetCalltipsHook(editor) |
89cbc07f4bf0
First commit after porting to Python3.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff
changeset
|
176 | |
89cbc07f4bf0
First commit after porting to Python3.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff
changeset
|
177 | def __preferencesChanged(self): |
89cbc07f4bf0
First commit after porting to Python3.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff
changeset
|
178 | """ |
89cbc07f4bf0
First commit after porting to Python3.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff
changeset
|
179 | Private method to handle a change of the global configuration. |
89cbc07f4bf0
First commit after porting to Python3.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff
changeset
|
180 | """ |
89cbc07f4bf0
First commit after porting to Python3.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff
changeset
|
181 | self.__apisManager.reloadAPIs() |
89cbc07f4bf0
First commit after porting to Python3.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff
changeset
|
182 | |
89cbc07f4bf0
First commit after porting to Python3.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff
changeset
|
183 | def __getCharacter(self, pos, editor): |
89cbc07f4bf0
First commit after porting to Python3.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff
changeset
|
184 | """ |
89cbc07f4bf0
First commit after porting to Python3.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff
changeset
|
185 | Private method to get the character to the left of the current position |
89cbc07f4bf0
First commit after porting to Python3.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff
changeset
|
186 | in the current line. |
89cbc07f4bf0
First commit after porting to Python3.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff
changeset
|
187 | |
89cbc07f4bf0
First commit after porting to Python3.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff
changeset
|
188 | @param pos position to get character at (integer) |
89cbc07f4bf0
First commit after porting to Python3.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff
changeset
|
189 | @param editor reference to the editor object to work with (QScintilla.Editor) |
89cbc07f4bf0
First commit after porting to Python3.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff
changeset
|
190 | @return requested character or "", if there are no more (string) and |
89cbc07f4bf0
First commit after porting to Python3.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff
changeset
|
191 | the next position (i.e. pos - 1) |
89cbc07f4bf0
First commit after porting to Python3.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff
changeset
|
192 | """ |
89cbc07f4bf0
First commit after porting to Python3.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff
changeset
|
193 | if pos <= 0: |
89cbc07f4bf0
First commit after porting to Python3.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff
changeset
|
194 | return "", pos |
89cbc07f4bf0
First commit after porting to Python3.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff
changeset
|
195 | |
89cbc07f4bf0
First commit after porting to Python3.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff
changeset
|
196 | pos -= 1 |
89cbc07f4bf0
First commit after porting to Python3.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff
changeset
|
197 | ch = editor.charAt(pos) |
89cbc07f4bf0
First commit after porting to Python3.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff
changeset
|
198 | |
89cbc07f4bf0
First commit after porting to Python3.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff
changeset
|
199 | # Don't go past the end of the previous line |
89cbc07f4bf0
First commit after porting to Python3.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff
changeset
|
200 | if ch == '\n' or ch == '\r': |
89cbc07f4bf0
First commit after porting to Python3.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff
changeset
|
201 | return "", pos |
89cbc07f4bf0
First commit after porting to Python3.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff
changeset
|
202 | |
89cbc07f4bf0
First commit after porting to Python3.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff
changeset
|
203 | return ch, pos |
89cbc07f4bf0
First commit after porting to Python3.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff
changeset
|
204 | |
89cbc07f4bf0
First commit after porting to Python3.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff
changeset
|
205 | ################################# |
89cbc07f4bf0
First commit after porting to Python3.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff
changeset
|
206 | ## autocompletion methods below |
89cbc07f4bf0
First commit after porting to Python3.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff
changeset
|
207 | ################################# |
89cbc07f4bf0
First commit after porting to Python3.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff
changeset
|
208 | |
89cbc07f4bf0
First commit after porting to Python3.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff
changeset
|
209 | def __completionListSelected(self, id, txt): |
89cbc07f4bf0
First commit after porting to Python3.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff
changeset
|
210 | """ |
89cbc07f4bf0
First commit after porting to Python3.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff
changeset
|
211 | Private slot to handle the selection from the completion list. |
89cbc07f4bf0
First commit after porting to Python3.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff
changeset
|
212 | |
89cbc07f4bf0
First commit after porting to Python3.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff
changeset
|
213 | @param id the ID of the user list (should be 1) (integer) |
89cbc07f4bf0
First commit after porting to Python3.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff
changeset
|
214 | @param txt the selected text (string) |
89cbc07f4bf0
First commit after porting to Python3.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff
changeset
|
215 | """ |
89cbc07f4bf0
First commit after porting to Python3.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff
changeset
|
216 | from QScintilla.Editor import EditorAutoCompletionListID |
89cbc07f4bf0
First commit after porting to Python3.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff
changeset
|
217 | |
89cbc07f4bf0
First commit after porting to Python3.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff
changeset
|
218 | editor = self.sender() |
89cbc07f4bf0
First commit after porting to Python3.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff
changeset
|
219 | if id == EditorAutoCompletionListID: |
89cbc07f4bf0
First commit after porting to Python3.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff
changeset
|
220 | lst = txt.split() |
89cbc07f4bf0
First commit after porting to Python3.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff
changeset
|
221 | if len(lst) > 1: |
89cbc07f4bf0
First commit after porting to Python3.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff
changeset
|
222 | txt = lst[0] |
89cbc07f4bf0
First commit after porting to Python3.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff
changeset
|
223 | self.__lastFullContext = lst[1][1:].split(")")[0] |
89cbc07f4bf0
First commit after porting to Python3.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff
changeset
|
224 | else: |
89cbc07f4bf0
First commit after porting to Python3.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff
changeset
|
225 | self.__lastFullContext = None |
89cbc07f4bf0
First commit after porting to Python3.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff
changeset
|
226 | |
89cbc07f4bf0
First commit after porting to Python3.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff
changeset
|
227 | if Preferences.getEditor("AutoCompletionReplaceWord"): |
89cbc07f4bf0
First commit after porting to Python3.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff
changeset
|
228 | editor.selectCurrentWord() |
89cbc07f4bf0
First commit after porting to Python3.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff
changeset
|
229 | editor.removeSelectedText() |
89cbc07f4bf0
First commit after porting to Python3.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff
changeset
|
230 | line, col = editor.getCursorPosition() |
89cbc07f4bf0
First commit after porting to Python3.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff
changeset
|
231 | else: |
89cbc07f4bf0
First commit after porting to Python3.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff
changeset
|
232 | line, col = editor.getCursorPosition() |
89cbc07f4bf0
First commit after porting to Python3.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff
changeset
|
233 | wLeft = editor.getWordLeft(line, col) |
89cbc07f4bf0
First commit after porting to Python3.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff
changeset
|
234 | if not txt.startswith(wLeft): |
89cbc07f4bf0
First commit after porting to Python3.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff
changeset
|
235 | editor.selectCurrentWord() |
89cbc07f4bf0
First commit after porting to Python3.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff
changeset
|
236 | editor.removeSelectedText() |
89cbc07f4bf0
First commit after porting to Python3.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff
changeset
|
237 | line, col = editor.getCursorPosition() |
89cbc07f4bf0
First commit after porting to Python3.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff
changeset
|
238 | elif wLeft: |
89cbc07f4bf0
First commit after porting to Python3.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff
changeset
|
239 | txt = txt[len(wLeft):] |
89cbc07f4bf0
First commit after porting to Python3.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff
changeset
|
240 | editor.insert(txt) |
89cbc07f4bf0
First commit after porting to Python3.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff
changeset
|
241 | editor.setCursorPosition(line, col + len(txt)) |
89cbc07f4bf0
First commit after porting to Python3.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff
changeset
|
242 | |
89cbc07f4bf0
First commit after porting to Python3.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff
changeset
|
243 | def __setAutoCompletionHook(self, editor): |
89cbc07f4bf0
First commit after porting to Python3.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff
changeset
|
244 | """ |
89cbc07f4bf0
First commit after porting to Python3.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff
changeset
|
245 | Private method to set the autocompletion hook. |
89cbc07f4bf0
First commit after porting to Python3.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff
changeset
|
246 | |
89cbc07f4bf0
First commit after porting to Python3.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff
changeset
|
247 | @param editor reference to the editor (QScintilla.Editor) |
89cbc07f4bf0
First commit after porting to Python3.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff
changeset
|
248 | """ |
19
7eb775bb326b
Added code to use the new style signal API depending upon the eric5 version.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
18
diff
changeset
|
249 | if self.__newStyle: |
7eb775bb326b
Added code to use the new style signal API depending upon the eric5 version.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
18
diff
changeset
|
250 | editor.userListActivated.connect(self.__completionListSelected) |
7eb775bb326b
Added code to use the new style signal API depending upon the eric5 version.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
18
diff
changeset
|
251 | else: |
7eb775bb326b
Added code to use the new style signal API depending upon the eric5 version.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
18
diff
changeset
|
252 | self.connect(editor, SIGNAL('userListActivated(int, const QString)'), |
7eb775bb326b
Added code to use the new style signal API depending upon the eric5 version.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
18
diff
changeset
|
253 | self.__completionListSelected) |
2
89cbc07f4bf0
First commit after porting to Python3.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff
changeset
|
254 | editor.setAutoCompletionHook(self.autocomplete) |
89cbc07f4bf0
First commit after porting to Python3.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff
changeset
|
255 | |
89cbc07f4bf0
First commit after porting to Python3.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff
changeset
|
256 | def __unsetAutoCompletionHook(self, editor): |
89cbc07f4bf0
First commit after porting to Python3.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff
changeset
|
257 | """ |
89cbc07f4bf0
First commit after porting to Python3.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff
changeset
|
258 | Private method to unset the autocompletion hook. |
89cbc07f4bf0
First commit after porting to Python3.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff
changeset
|
259 | |
89cbc07f4bf0
First commit after porting to Python3.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff
changeset
|
260 | @param editor reference to the editor (QScintilla.Editor) |
89cbc07f4bf0
First commit after porting to Python3.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff
changeset
|
261 | """ |
89cbc07f4bf0
First commit after porting to Python3.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff
changeset
|
262 | editor.unsetAutoCompletionHook() |
19
7eb775bb326b
Added code to use the new style signal API depending upon the eric5 version.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
18
diff
changeset
|
263 | if self.__newStyle: |
7eb775bb326b
Added code to use the new style signal API depending upon the eric5 version.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
18
diff
changeset
|
264 | editor.userListActivated.disconnect(self.__completionListSelected) |
7eb775bb326b
Added code to use the new style signal API depending upon the eric5 version.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
18
diff
changeset
|
265 | else: |
7eb775bb326b
Added code to use the new style signal API depending upon the eric5 version.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
18
diff
changeset
|
266 | self.disconnect(editor, SIGNAL('userListActivated(int, const QString)'), |
7eb775bb326b
Added code to use the new style signal API depending upon the eric5 version.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
18
diff
changeset
|
267 | self.__completionListSelected) |
2
89cbc07f4bf0
First commit after porting to Python3.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff
changeset
|
268 | |
89cbc07f4bf0
First commit after porting to Python3.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff
changeset
|
269 | def autocomplete(self, editor, context): |
89cbc07f4bf0
First commit after porting to Python3.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff
changeset
|
270 | """ |
89cbc07f4bf0
First commit after porting to Python3.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff
changeset
|
271 | Public method to determine the autocompletion proposals. |
89cbc07f4bf0
First commit after porting to Python3.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff
changeset
|
272 | |
89cbc07f4bf0
First commit after porting to Python3.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff
changeset
|
273 | @param editor reference to the editor object, that called this method |
89cbc07f4bf0
First commit after porting to Python3.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff
changeset
|
274 | (QScintilla.Editor) |
89cbc07f4bf0
First commit after porting to Python3.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff
changeset
|
275 | @param context flag indicating to autocomplete a context (boolean) |
89cbc07f4bf0
First commit after porting to Python3.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff
changeset
|
276 | """ |
89cbc07f4bf0
First commit after porting to Python3.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff
changeset
|
277 | from QScintilla.Editor import EditorAutoCompletionListID |
89cbc07f4bf0
First commit after porting to Python3.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff
changeset
|
278 | |
89cbc07f4bf0
First commit after porting to Python3.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff
changeset
|
279 | if editor.isListActive(): |
89cbc07f4bf0
First commit after porting to Python3.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff
changeset
|
280 | editor.cancelList() |
89cbc07f4bf0
First commit after porting to Python3.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff
changeset
|
281 | |
89cbc07f4bf0
First commit after porting to Python3.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff
changeset
|
282 | language = editor.getLanguage() |
89cbc07f4bf0
First commit after porting to Python3.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff
changeset
|
283 | if language == "": |
89cbc07f4bf0
First commit after porting to Python3.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff
changeset
|
284 | return |
89cbc07f4bf0
First commit after porting to Python3.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff
changeset
|
285 | |
89cbc07f4bf0
First commit after porting to Python3.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff
changeset
|
286 | line, col = editor.getCursorPosition() |
89cbc07f4bf0
First commit after porting to Python3.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff
changeset
|
287 | self.__completingContext = context |
89cbc07f4bf0
First commit after porting to Python3.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff
changeset
|
288 | apiCompletionsList = [] |
89cbc07f4bf0
First commit after porting to Python3.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff
changeset
|
289 | docCompletionsList = [] |
89cbc07f4bf0
First commit after porting to Python3.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff
changeset
|
290 | projectCompletionList = [] |
89cbc07f4bf0
First commit after porting to Python3.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff
changeset
|
291 | sep = "" |
89cbc07f4bf0
First commit after porting to Python3.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff
changeset
|
292 | if context: |
18
b8ece0b784e8
Fixed a few unicode related issues.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
5
diff
changeset
|
293 | wc = re.sub("\w", "", editor.wordCharacters()) |
2
89cbc07f4bf0
First commit after porting to Python3.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff
changeset
|
294 | text = editor.text(line) |
89cbc07f4bf0
First commit after porting to Python3.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff
changeset
|
295 | |
89cbc07f4bf0
First commit after porting to Python3.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff
changeset
|
296 | beg = text[:col] |
89cbc07f4bf0
First commit after porting to Python3.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff
changeset
|
297 | for wsep in editor.getLexer().autoCompletionWordSeparators(): |
89cbc07f4bf0
First commit after porting to Python3.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff
changeset
|
298 | if beg.endswith(wsep): |
89cbc07f4bf0
First commit after porting to Python3.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff
changeset
|
299 | sep = wsep |
89cbc07f4bf0
First commit after porting to Python3.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff
changeset
|
300 | break |
89cbc07f4bf0
First commit after porting to Python3.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff
changeset
|
301 | |
89cbc07f4bf0
First commit after porting to Python3.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff
changeset
|
302 | depth = 0 |
18
b8ece0b784e8
Fixed a few unicode related issues.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
5
diff
changeset
|
303 | while col > 0 and \ |
b8ece0b784e8
Fixed a few unicode related issues.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
5
diff
changeset
|
304 | (not text[col - 1].isalnum() or \ |
b8ece0b784e8
Fixed a few unicode related issues.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
5
diff
changeset
|
305 | (wc and text[col - 1] not in wc)): |
2
89cbc07f4bf0
First commit after porting to Python3.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff
changeset
|
306 | ch = text[col - 1] |
89cbc07f4bf0
First commit after porting to Python3.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff
changeset
|
307 | if ch == ')': |
89cbc07f4bf0
First commit after porting to Python3.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff
changeset
|
308 | depth = 1 |
89cbc07f4bf0
First commit after porting to Python3.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff
changeset
|
309 | |
89cbc07f4bf0
First commit after porting to Python3.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff
changeset
|
310 | # ignore everything back to the start of the |
89cbc07f4bf0
First commit after porting to Python3.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff
changeset
|
311 | # corresponding parenthesis |
89cbc07f4bf0
First commit after porting to Python3.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff
changeset
|
312 | col -= 1 |
89cbc07f4bf0
First commit after porting to Python3.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff
changeset
|
313 | while col > 0: |
89cbc07f4bf0
First commit after porting to Python3.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff
changeset
|
314 | ch = text[col - 1] |
89cbc07f4bf0
First commit after porting to Python3.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff
changeset
|
315 | if ch == ')': |
89cbc07f4bf0
First commit after porting to Python3.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff
changeset
|
316 | depth += 1 |
89cbc07f4bf0
First commit after porting to Python3.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff
changeset
|
317 | elif ch == '(': |
89cbc07f4bf0
First commit after porting to Python3.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff
changeset
|
318 | depth -= 1 |
89cbc07f4bf0
First commit after porting to Python3.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff
changeset
|
319 | if depth == 0: |
89cbc07f4bf0
First commit after porting to Python3.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff
changeset
|
320 | break |
89cbc07f4bf0
First commit after porting to Python3.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff
changeset
|
321 | col -= 1 |
89cbc07f4bf0
First commit after porting to Python3.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff
changeset
|
322 | elif ch == '(': |
89cbc07f4bf0
First commit after porting to Python3.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff
changeset
|
323 | break |
89cbc07f4bf0
First commit after porting to Python3.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff
changeset
|
324 | col -= 1 |
89cbc07f4bf0
First commit after porting to Python3.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff
changeset
|
325 | |
89cbc07f4bf0
First commit after porting to Python3.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff
changeset
|
326 | word = editor.getWordLeft(line, col) |
89cbc07f4bf0
First commit after porting to Python3.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff
changeset
|
327 | if context: |
89cbc07f4bf0
First commit after porting to Python3.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff
changeset
|
328 | self.__lastContext = word |
89cbc07f4bf0
First commit after porting to Python3.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff
changeset
|
329 | else: |
89cbc07f4bf0
First commit after porting to Python3.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff
changeset
|
330 | self.__lastContext = None |
89cbc07f4bf0
First commit after porting to Python3.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff
changeset
|
331 | |
89cbc07f4bf0
First commit after porting to Python3.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff
changeset
|
332 | if word: |
89cbc07f4bf0
First commit after porting to Python3.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff
changeset
|
333 | if self.__plugin.getPreferences("AutoCompletionSource") & AcsAPIs: |
89cbc07f4bf0
First commit after porting to Python3.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff
changeset
|
334 | api = self.__apisManager.getAPIs(language) |
89cbc07f4bf0
First commit after porting to Python3.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff
changeset
|
335 | apiCompletionsList = self.__getApiCompletions(api, word, context) |
89cbc07f4bf0
First commit after porting to Python3.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff
changeset
|
336 | |
89cbc07f4bf0
First commit after porting to Python3.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff
changeset
|
337 | if self.__plugin.getPreferences("AutoCompletionSource") & AcsProject: |
89cbc07f4bf0
First commit after porting to Python3.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff
changeset
|
338 | api = self.__apisManager.getAPIs(ApisNameProject) |
89cbc07f4bf0
First commit after porting to Python3.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff
changeset
|
339 | projectCompletionList = self.__getApiCompletions(api, word, context) |
89cbc07f4bf0
First commit after porting to Python3.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff
changeset
|
340 | |
89cbc07f4bf0
First commit after porting to Python3.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff
changeset
|
341 | if self.__plugin.getPreferences("AutoCompletionSource") & AcsDocument: |
89cbc07f4bf0
First commit after porting to Python3.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff
changeset
|
342 | docCompletionsList = \ |
89cbc07f4bf0
First commit after porting to Python3.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff
changeset
|
343 | self.getCompletionsFromDocument(editor, word, context, sep) |
89cbc07f4bf0
First commit after porting to Python3.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff
changeset
|
344 | |
89cbc07f4bf0
First commit after porting to Python3.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff
changeset
|
345 | completionsList = list( |
89cbc07f4bf0
First commit after porting to Python3.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff
changeset
|
346 | set(apiCompletionsList) |
89cbc07f4bf0
First commit after porting to Python3.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff
changeset
|
347 | .union(set(docCompletionsList)) |
89cbc07f4bf0
First commit after porting to Python3.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff
changeset
|
348 | .union(set(projectCompletionList)) |
89cbc07f4bf0
First commit after porting to Python3.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff
changeset
|
349 | ) |
89cbc07f4bf0
First commit after porting to Python3.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff
changeset
|
350 | |
89cbc07f4bf0
First commit after porting to Python3.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff
changeset
|
351 | if len(completionsList) > 0: |
89cbc07f4bf0
First commit after porting to Python3.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff
changeset
|
352 | completionsList.sort() |
89cbc07f4bf0
First commit after porting to Python3.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff
changeset
|
353 | editor.showUserList(EditorAutoCompletionListID, completionsList) |
89cbc07f4bf0
First commit after porting to Python3.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff
changeset
|
354 | |
89cbc07f4bf0
First commit after porting to Python3.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff
changeset
|
355 | def __getApiCompletions(self, api, word, context): |
89cbc07f4bf0
First commit after porting to Python3.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff
changeset
|
356 | """ |
89cbc07f4bf0
First commit after porting to Python3.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff
changeset
|
357 | Private method to determine a list of completions from an API object. |
89cbc07f4bf0
First commit after porting to Python3.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff
changeset
|
358 | |
89cbc07f4bf0
First commit after porting to Python3.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff
changeset
|
359 | @param api reference to the API object to be used (APIsManager.DbAPIs) |
89cbc07f4bf0
First commit after porting to Python3.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff
changeset
|
360 | @param word word (or wordpart) to complete (string) |
89cbc07f4bf0
First commit after porting to Python3.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff
changeset
|
361 | @param context flag indicating to autocomplete a context (boolean) |
89cbc07f4bf0
First commit after porting to Python3.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff
changeset
|
362 | @return list of possible completions (list of strings) |
89cbc07f4bf0
First commit after porting to Python3.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff
changeset
|
363 | """ |
89cbc07f4bf0
First commit after porting to Python3.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff
changeset
|
364 | completionsList = [] |
89cbc07f4bf0
First commit after porting to Python3.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff
changeset
|
365 | if api is not None: |
89cbc07f4bf0
First commit after porting to Python3.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff
changeset
|
366 | if context: |
89cbc07f4bf0
First commit after porting to Python3.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff
changeset
|
367 | completions = api.getCompletions(context = word) |
89cbc07f4bf0
First commit after porting to Python3.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff
changeset
|
368 | for completion in completions: |
89cbc07f4bf0
First commit after porting to Python3.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff
changeset
|
369 | entry = completion["completion"] |
89cbc07f4bf0
First commit after porting to Python3.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff
changeset
|
370 | if completion["pictureId"]: |
89cbc07f4bf0
First commit after porting to Python3.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff
changeset
|
371 | entry += "?{0}".format(completion["pictureId"]) |
89cbc07f4bf0
First commit after porting to Python3.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff
changeset
|
372 | if entry not in completionsList: |
89cbc07f4bf0
First commit after porting to Python3.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff
changeset
|
373 | completionsList.append(entry) |
89cbc07f4bf0
First commit after porting to Python3.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff
changeset
|
374 | else: |
89cbc07f4bf0
First commit after porting to Python3.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff
changeset
|
375 | completions = api.getCompletions(start = word) |
89cbc07f4bf0
First commit after porting to Python3.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff
changeset
|
376 | for completion in completions: |
89cbc07f4bf0
First commit after porting to Python3.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff
changeset
|
377 | if not completion["context"]: |
89cbc07f4bf0
First commit after porting to Python3.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff
changeset
|
378 | entry = completion["completion"] |
89cbc07f4bf0
First commit after porting to Python3.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff
changeset
|
379 | else: |
89cbc07f4bf0
First commit after porting to Python3.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff
changeset
|
380 | entry = "{0} ({1})".format( |
89cbc07f4bf0
First commit after porting to Python3.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff
changeset
|
381 | completion["completion"], |
89cbc07f4bf0
First commit after porting to Python3.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff
changeset
|
382 | completion["context"] |
89cbc07f4bf0
First commit after porting to Python3.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff
changeset
|
383 | ) |
89cbc07f4bf0
First commit after porting to Python3.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff
changeset
|
384 | if entry in completionsList: |
89cbc07f4bf0
First commit after porting to Python3.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff
changeset
|
385 | completionsList.remove(entry) |
89cbc07f4bf0
First commit after porting to Python3.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff
changeset
|
386 | if completion["pictureId"]: |
89cbc07f4bf0
First commit after porting to Python3.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff
changeset
|
387 | entry += "?{0}".format(completion["pictureId"]) |
89cbc07f4bf0
First commit after porting to Python3.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff
changeset
|
388 | else: |
89cbc07f4bf0
First commit after porting to Python3.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff
changeset
|
389 | cont = False |
89cbc07f4bf0
First commit after porting to Python3.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff
changeset
|
390 | re = QRegExp(QRegExp.escape(entry) + "\?\d{,2}") |
89cbc07f4bf0
First commit after porting to Python3.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff
changeset
|
391 | for comp in completionsList: |
89cbc07f4bf0
First commit after porting to Python3.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff
changeset
|
392 | if re.exactMatch(comp): |
89cbc07f4bf0
First commit after porting to Python3.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff
changeset
|
393 | cont = True |
89cbc07f4bf0
First commit after porting to Python3.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff
changeset
|
394 | break |
89cbc07f4bf0
First commit after porting to Python3.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff
changeset
|
395 | if cont: |
89cbc07f4bf0
First commit after porting to Python3.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff
changeset
|
396 | continue |
89cbc07f4bf0
First commit after porting to Python3.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff
changeset
|
397 | if entry not in completionsList: |
89cbc07f4bf0
First commit after porting to Python3.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff
changeset
|
398 | completionsList.append(entry) |
89cbc07f4bf0
First commit after porting to Python3.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff
changeset
|
399 | return completionsList |
89cbc07f4bf0
First commit after porting to Python3.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff
changeset
|
400 | |
89cbc07f4bf0
First commit after porting to Python3.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff
changeset
|
401 | def getCompletionsFromDocument(self, editor, word, context, sep): |
89cbc07f4bf0
First commit after porting to Python3.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff
changeset
|
402 | """ |
89cbc07f4bf0
First commit after porting to Python3.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff
changeset
|
403 | Public method to determine autocompletion proposals from the document. |
89cbc07f4bf0
First commit after porting to Python3.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff
changeset
|
404 | |
89cbc07f4bf0
First commit after porting to Python3.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff
changeset
|
405 | @param editor reference to the editor object (QScintilla.Editor) |
89cbc07f4bf0
First commit after porting to Python3.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff
changeset
|
406 | @param word string to be completed (string) |
89cbc07f4bf0
First commit after porting to Python3.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff
changeset
|
407 | @param context flag indicating to autocomplete a context (boolean) |
89cbc07f4bf0
First commit after porting to Python3.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff
changeset
|
408 | @param sep separator string (string) |
89cbc07f4bf0
First commit after porting to Python3.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff
changeset
|
409 | @return list of possible completions (list of strings) |
89cbc07f4bf0
First commit after porting to Python3.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff
changeset
|
410 | """ |
89cbc07f4bf0
First commit after porting to Python3.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff
changeset
|
411 | currentPos = editor.currentPosition() |
89cbc07f4bf0
First commit after porting to Python3.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff
changeset
|
412 | completionsList = [] |
89cbc07f4bf0
First commit after porting to Python3.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff
changeset
|
413 | if context: |
89cbc07f4bf0
First commit after porting to Python3.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff
changeset
|
414 | word += sep |
89cbc07f4bf0
First commit after porting to Python3.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff
changeset
|
415 | |
18
b8ece0b784e8
Fixed a few unicode related issues.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
5
diff
changeset
|
416 | if editor.isUtf8(): |
b8ece0b784e8
Fixed a few unicode related issues.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
5
diff
changeset
|
417 | sword = word.encode("utf-8") |
b8ece0b784e8
Fixed a few unicode related issues.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
5
diff
changeset
|
418 | else: |
b8ece0b784e8
Fixed a few unicode related issues.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
5
diff
changeset
|
419 | sword = word |
b8ece0b784e8
Fixed a few unicode related issues.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
5
diff
changeset
|
420 | res = editor.findFirstTarget(sword, False, |
b8ece0b784e8
Fixed a few unicode related issues.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
5
diff
changeset
|
421 | editor.autoCompletionCaseSensitivity(), |
2
89cbc07f4bf0
First commit after porting to Python3.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff
changeset
|
422 | False, begline = 0, begindex = 0, ws_ = True) |
89cbc07f4bf0
First commit after porting to Python3.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff
changeset
|
423 | while res: |
89cbc07f4bf0
First commit after porting to Python3.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff
changeset
|
424 | start, length = editor.getFoundTarget() |
89cbc07f4bf0
First commit after porting to Python3.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff
changeset
|
425 | pos = start + length |
89cbc07f4bf0
First commit after porting to Python3.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff
changeset
|
426 | if pos != currentPos: |
89cbc07f4bf0
First commit after porting to Python3.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff
changeset
|
427 | if context: |
89cbc07f4bf0
First commit after porting to Python3.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff
changeset
|
428 | completion = "" |
89cbc07f4bf0
First commit after porting to Python3.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff
changeset
|
429 | else: |
89cbc07f4bf0
First commit after porting to Python3.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff
changeset
|
430 | completion = word |
18
b8ece0b784e8
Fixed a few unicode related issues.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
5
diff
changeset
|
431 | line, index = editor.lineIndexFromPosition(pos) |
b8ece0b784e8
Fixed a few unicode related issues.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
5
diff
changeset
|
432 | curWord = editor.getWord(line, index, useWordChars = False) |
b8ece0b784e8
Fixed a few unicode related issues.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
5
diff
changeset
|
433 | completion += curWord[len(completion):] |
2
89cbc07f4bf0
First commit after porting to Python3.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff
changeset
|
434 | if completion and completion not in completionsList: |
89cbc07f4bf0
First commit after porting to Python3.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff
changeset
|
435 | completionsList.append( |
89cbc07f4bf0
First commit after porting to Python3.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff
changeset
|
436 | "{0}?{1}".format(completion, self.__fromDocumentID)) |
89cbc07f4bf0
First commit after porting to Python3.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff
changeset
|
437 | |
89cbc07f4bf0
First commit after porting to Python3.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff
changeset
|
438 | res = editor.findNextTarget() |
89cbc07f4bf0
First commit after porting to Python3.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff
changeset
|
439 | |
89cbc07f4bf0
First commit after porting to Python3.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff
changeset
|
440 | completionsList.sort() |
89cbc07f4bf0
First commit after porting to Python3.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff
changeset
|
441 | return completionsList |
89cbc07f4bf0
First commit after porting to Python3.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff
changeset
|
442 | |
89cbc07f4bf0
First commit after porting to Python3.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff
changeset
|
443 | ########################### |
89cbc07f4bf0
First commit after porting to Python3.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff
changeset
|
444 | ## calltips methods below |
89cbc07f4bf0
First commit after porting to Python3.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff
changeset
|
445 | ########################### |
89cbc07f4bf0
First commit after porting to Python3.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff
changeset
|
446 | |
89cbc07f4bf0
First commit after porting to Python3.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff
changeset
|
447 | def __setCalltipsHook(self, editor): |
89cbc07f4bf0
First commit after porting to Python3.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff
changeset
|
448 | """ |
89cbc07f4bf0
First commit after porting to Python3.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff
changeset
|
449 | Private method to set the calltip hook. |
89cbc07f4bf0
First commit after porting to Python3.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff
changeset
|
450 | |
89cbc07f4bf0
First commit after porting to Python3.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff
changeset
|
451 | @param editor reference to the editor (QScintilla.Editor) |
89cbc07f4bf0
First commit after porting to Python3.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff
changeset
|
452 | """ |
89cbc07f4bf0
First commit after porting to Python3.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff
changeset
|
453 | editor.setCallTipHook(self.calltips) |
89cbc07f4bf0
First commit after porting to Python3.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff
changeset
|
454 | |
89cbc07f4bf0
First commit after porting to Python3.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff
changeset
|
455 | def __unsetCalltipsHook(self, editor): |
89cbc07f4bf0
First commit after porting to Python3.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff
changeset
|
456 | """ |
89cbc07f4bf0
First commit after porting to Python3.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff
changeset
|
457 | Private method to unset the calltip hook. |
89cbc07f4bf0
First commit after porting to Python3.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff
changeset
|
458 | |
89cbc07f4bf0
First commit after porting to Python3.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff
changeset
|
459 | @param editor reference to the editor (QScintilla.Editor) |
89cbc07f4bf0
First commit after porting to Python3.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff
changeset
|
460 | """ |
89cbc07f4bf0
First commit after porting to Python3.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff
changeset
|
461 | editor.unsetCallTipHook() |
89cbc07f4bf0
First commit after porting to Python3.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff
changeset
|
462 | |
89cbc07f4bf0
First commit after porting to Python3.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff
changeset
|
463 | def calltips(self, editor, pos, commas): |
89cbc07f4bf0
First commit after porting to Python3.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff
changeset
|
464 | """ |
89cbc07f4bf0
First commit after porting to Python3.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff
changeset
|
465 | Public method to return a list of calltips. |
89cbc07f4bf0
First commit after porting to Python3.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff
changeset
|
466 | |
89cbc07f4bf0
First commit after porting to Python3.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff
changeset
|
467 | @param editor reference to the editor (QScintilla.Editor) |
89cbc07f4bf0
First commit after porting to Python3.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff
changeset
|
468 | @param pos position in the text for the calltip (integer) |
89cbc07f4bf0
First commit after porting to Python3.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff
changeset
|
469 | @param commas minimum number of commas contained in the calltip (integer) |
89cbc07f4bf0
First commit after porting to Python3.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff
changeset
|
470 | @return list of possible calltips (list of strings) |
89cbc07f4bf0
First commit after porting to Python3.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff
changeset
|
471 | """ |
89cbc07f4bf0
First commit after porting to Python3.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff
changeset
|
472 | language = editor.getLanguage() |
89cbc07f4bf0
First commit after porting to Python3.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff
changeset
|
473 | if language == "": |
89cbc07f4bf0
First commit after porting to Python3.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff
changeset
|
474 | return |
89cbc07f4bf0
First commit after porting to Python3.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff
changeset
|
475 | |
89cbc07f4bf0
First commit after porting to Python3.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff
changeset
|
476 | line, col = editor.lineIndexFromPosition(pos) |
18
b8ece0b784e8
Fixed a few unicode related issues.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
5
diff
changeset
|
477 | wc = re.sub("\w", "", editor.wordCharacters()) |
2
89cbc07f4bf0
First commit after porting to Python3.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff
changeset
|
478 | text = editor.text(line) |
18
b8ece0b784e8
Fixed a few unicode related issues.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
5
diff
changeset
|
479 | while col > 0 and \ |
b8ece0b784e8
Fixed a few unicode related issues.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
5
diff
changeset
|
480 | (not text[col - 1].isalnum() or \ |
b8ece0b784e8
Fixed a few unicode related issues.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
5
diff
changeset
|
481 | (wc and text[col - 1] not in wc)): |
2
89cbc07f4bf0
First commit after porting to Python3.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff
changeset
|
482 | col -= 1 |
89cbc07f4bf0
First commit after porting to Python3.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff
changeset
|
483 | word = editor.getWordLeft(line, col) |
89cbc07f4bf0
First commit after porting to Python3.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff
changeset
|
484 | |
89cbc07f4bf0
First commit after porting to Python3.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff
changeset
|
485 | apiCalltips = [] |
89cbc07f4bf0
First commit after porting to Python3.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff
changeset
|
486 | projectCalltips = [] |
89cbc07f4bf0
First commit after porting to Python3.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff
changeset
|
487 | |
89cbc07f4bf0
First commit after porting to Python3.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff
changeset
|
488 | if self.__plugin.getPreferences("AutoCompletionSource") & AcsAPIs: |
89cbc07f4bf0
First commit after porting to Python3.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff
changeset
|
489 | api = self.__apisManager.getAPIs(language) |
89cbc07f4bf0
First commit after porting to Python3.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff
changeset
|
490 | if api is not None: |
89cbc07f4bf0
First commit after porting to Python3.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff
changeset
|
491 | apiCalltips = api.getCalltips(word, commas, self.__lastContext, |
89cbc07f4bf0
First commit after porting to Python3.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff
changeset
|
492 | self.__lastFullContext, |
89cbc07f4bf0
First commit after porting to Python3.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff
changeset
|
493 | self.__plugin.getPreferences("CallTipsContextShown")) |
89cbc07f4bf0
First commit after porting to Python3.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff
changeset
|
494 | |
89cbc07f4bf0
First commit after porting to Python3.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff
changeset
|
495 | if self.__plugin.getPreferences("AutoCompletionSource") & AcsProject: |
89cbc07f4bf0
First commit after porting to Python3.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff
changeset
|
496 | api = self.__apisManager.getAPIs(ApisNameProject) |
89cbc07f4bf0
First commit after porting to Python3.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff
changeset
|
497 | projectCalltips = api.getCalltips(word, commas, self.__lastContext, |
89cbc07f4bf0
First commit after porting to Python3.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff
changeset
|
498 | self.__lastFullContext, |
89cbc07f4bf0
First commit after porting to Python3.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff
changeset
|
499 | self.__plugin.getPreferences("CallTipsContextShown")) |
89cbc07f4bf0
First commit after porting to Python3.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff
changeset
|
500 | |
89cbc07f4bf0
First commit after porting to Python3.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff
changeset
|
501 | return sorted(set(apiCalltips).union(set(projectCalltips))) |