--- a/AssistantEric/Assistant.py Sun Apr 23 17:27:36 2017 +0200 +++ b/AssistantEric/Assistant.py Mon Oct 09 19:23:14 2017 +0200 @@ -19,12 +19,9 @@ from .APIsManager import APIsManager, ApisNameProject -import Preferences - AcsAPIs = 0x0001 AcsDocument = 0x0002 AcsProject = 0x0004 -AcsOther = 0x1000 class Assistant(QObject): @@ -49,7 +46,6 @@ self.__apisManager = APIsManager(self.__ui, self) self.__editors = [] - self.__completingContext = False self.__lastContext = None self.__lastFullContext = None @@ -126,7 +122,7 @@ try: language = editor.getApiLanguage() except AttributeError: - # backward compatibility + # backward compatibility < 16.12 language = editor.apiLanguage if language: projectType = self.__getProjectType(editor) @@ -142,20 +138,10 @@ editor.editorSaved.disconnect( self.__apisManager.getAPIs(ApisNameProject).editorSaved) self.__editors.remove(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) + if editor.getCompletionListHook("Assistant"): + self.__unsetAutoCompletionHook(editor) + if editor.getCallTipHook("Assistant"): + self.__unsetCalltipsHook(editor) def __preferencesChanged(self): """ @@ -185,40 +171,6 @@ ## auto-completion methods below ################################# - def __completionListSelected(self, userListId, txt): - """ - Private slot to handle the selection from the completion list. - - @param userListId the ID of the user list (should be 1) (integer) - @param txt the selected text (string) - """ - from QScintilla.Editor import EditorAutoCompletionListID - - editor = self.sender() - if userListId == EditorAutoCompletionListID: - lst = txt.split() - if len(lst) > 1: - txt = lst[0] - self.__lastFullContext = lst[1][1:].split(")")[0] - else: - self.__lastFullContext = None - - if Preferences.getEditor("AutoCompletionReplaceWord"): - editor.selectCurrentWord() - editor.removeSelectedText() - line, col = editor.getCursorPosition() - else: - line, col = editor.getCursorPosition() - wLeft = editor.getWordLeft(line, col) - if not txt.startswith(wLeft): - editor.selectCurrentWord() - editor.removeSelectedText() - line, col = editor.getCursorPosition() - elif wLeft: - txt = txt[len(wLeft):] - editor.insert(txt) - editor.setCursorPosition(line, col + len(txt)) - def __recordSelectedContext(self, userListId, txt): """ Private slot to handle the selection from the completion list to @@ -242,13 +194,8 @@ @param editor reference to the editor (QScintilla.Editor) """ - 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) + editor.userListActivated.connect(self.__recordSelectedContext) + editor.addCompletionListHook("Assistant", self.getCompletionsList) def __unsetAutoCompletionHook(self, editor): """ @@ -256,32 +203,8 @@ @param editor reference to the editor (QScintilla.Editor) """ - 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): - """ - Public method to determine the autocompletion proposals. - - @param editor reference to the editor object, that called this method - (QScintilla.Editor) - @param context flag indicating to autocomplete a context (boolean) - """ - from QScintilla.Editor import EditorAutoCompletionListID - - if editor.isListActive(): - editor.cancelList() - - completionsList = self.getCompletionsList(editor, context) - if len(completionsList) > 0: - completionsList.sort() - editor.showUserList(EditorAutoCompletionListID, - completionsList) + editor.userListActivated.disconnect(self.__recordSelectedContext) + editor.removeCompletionListHook("Assistant") def getCompletionsList(self, editor, context): """ @@ -295,7 +218,7 @@ try: language = editor.getApiLanguage() except AttributeError: - # backward compatibility + # backward compatibility < 16.12 language = editor.apiLanguage completeFromDocumentOnly = False @@ -309,7 +232,6 @@ projectType = self.__getProjectType(editor) line, col = editor.getCursorPosition() - self.__completingContext = context sep = "" if language and context: wc = re.sub("\w", "", editor.wordCharacters()) @@ -754,11 +676,7 @@ @param editor reference to the editor (QScintilla.Editor) """ - try: - editor.addCallTipHook("Assistant", self.calltips) - except AttributeError: - # old interface (before 6.1.0) - editor.setCallTipHook(self.calltips) + editor.addCallTipHook("Assistant", self.calltips) def __unsetCalltipsHook(self, editor): """ @@ -766,11 +684,7 @@ @param editor reference to the editor (QScintilla.Editor) """ - try: - editor.removeCallTipHook("Assistant") - except AttributeError: - # old interface (before 6.1.0) - editor.unsetCallTipHook() + editor.removeCallTipHook("Assistant") def calltips(self, editor, pos, commas): """ @@ -785,7 +699,7 @@ try: language = editor.getApiLanguage() except AttributeError: - # backward compatibility + # backward compatibility < 16.12 language = editor.apiLanguage completeFromDocumentOnly = False