--- a/RefactoringRope/RefactoringServer.py Fri Oct 06 18:49:50 2017 +0200 +++ b/RefactoringRope/RefactoringServer.py Sun Oct 08 17:54:29 2017 +0200 @@ -50,6 +50,7 @@ self.__plugin = plugin self.__ui = parent + self.__vm = e5App().getObject("ViewManager") self.__e5project = e5App().getObject("Project") self.__projectpath = '' self.__projectLanguage = "" @@ -830,7 +831,7 @@ """ Private slot called before the refactoring history menu is shown. """ - aw = e5App().getObject("ViewManager").activeWindow() + aw = self.__vm.activeWindow() enable = aw is not None and bool(aw.getFileName()) self.refactoringFileHistoryAct.setEnabled(enable) @@ -859,7 +860,7 @@ result["ErrorString"]), E5MessageBox.Ok | E5MessageBox.Open) if res == E5MessageBox.Open: - e5App().getObject("ViewManager").openSourceFile( + self.__vm.openSourceFile( os.path.join(self.__e5project.getProjectPath(), result["ErrorFile"]), result["ErrorLine"]) @@ -966,7 +967,7 @@ @param renameModule flag indicating a module rename refactoring @type bool """ - aw = e5App().getObject("ViewManager").activeWindow() + aw = self.__vm.activeWindow() if aw is None: return @@ -1017,7 +1018,7 @@ """ Private slot to perform the Change Occurrences refactoring. """ - aw = e5App().getObject("ViewManager").activeWindow() + aw = self.__vm.activeWindow() if aw is None: return @@ -1074,7 +1075,7 @@ """ assert kind in ["variable", "method"] - aw = e5App().getObject("ViewManager").activeWindow() + aw = self.__vm.activeWindow() if aw is None: return @@ -1112,7 +1113,7 @@ """ Private slot to handle the Inline Local Variable action. """ - aw = e5App().getObject("ViewManager").activeWindow() + aw = self.__vm.activeWindow() if aw is None: return @@ -1152,7 +1153,7 @@ @param moveKind kind of move to be performed @type str (one of 'move_method' or 'move_module') """ - aw = e5App().getObject("ViewManager").activeWindow() + aw = self.__vm.activeWindow() if aw is None: return @@ -1195,7 +1196,7 @@ """ Private slot to use a function wherever possible. """ - aw = e5App().getObject("ViewManager").activeWindow() + aw = self.__vm.activeWindow() if aw is None: return @@ -1232,7 +1233,7 @@ """ Private slot to introduce a factory method or global function. """ - aw = e5App().getObject("ViewManager").activeWindow() + aw = self.__vm.activeWindow() if aw is None: return @@ -1266,7 +1267,7 @@ """ Private slot to introduce a parameter in a function. """ - aw = e5App().getObject("ViewManager").activeWindow() + aw = self.__vm.activeWindow() if aw is None: return @@ -1349,7 +1350,7 @@ @param methodName name of the method performing the import refactoring @type str """ - aw = e5App().getObject("ViewManager").activeWindow() + aw = self.__vm.activeWindow() if aw is None: return @@ -1399,7 +1400,7 @@ """ Private slot to change the signature of a method or function. """ - aw = e5App().getObject("ViewManager").activeWindow() + aw = self.__vm.activeWindow() if aw is None: return @@ -1434,7 +1435,7 @@ Private slot to inline the default value of a parameter of a method or function. """ - aw = e5App().getObject("ViewManager").activeWindow() + aw = self.__vm.activeWindow() if aw is None: return @@ -1468,7 +1469,7 @@ """ Private slot to transform a module to a package. """ - aw = e5App().getObject("ViewManager").activeWindow() + aw = self.__vm.activeWindow() if aw is None: return @@ -1497,7 +1498,7 @@ """ Private slot to encapsulate an attribute. """ - aw = e5App().getObject("ViewManager").activeWindow() + aw = self.__vm.activeWindow() if aw is None: return @@ -1531,7 +1532,7 @@ """ Private slot to convert a local variable to an attribute. """ - aw = e5App().getObject("ViewManager").activeWindow() + aw = self.__vm.activeWindow() if aw is None: return @@ -1570,7 +1571,7 @@ """ Private slot to change the signature of a method or function. """ - aw = e5App().getObject("ViewManager").activeWindow() + aw = self.__vm.activeWindow() if aw is None: return @@ -1620,7 +1621,7 @@ """ Private method to show the refactoring history of the current file. """ - aw = e5App().getObject("ViewManager").activeWindow() + aw = self.__vm.activeWindow() if aw is None: return @@ -1676,7 +1677,7 @@ """ Private slot to handle the Find References action. """ - aw = e5App().getObject("ViewManager").activeWindow() + aw = self.__vm.activeWindow() if aw is None: return @@ -1723,7 +1724,7 @@ """ Private slot to handle the Find Definition action. """ - aw = e5App().getObject("ViewManager").activeWindow() + aw = self.__vm.activeWindow() if aw is None: return @@ -1755,17 +1756,18 @@ @param editor reference to the calling editor @type QScintilla.Editor """ - filename = editor.getFileName() - line, index = editor.getCursorPosition() - offset = self.__getOffset(editor, line, index) - - self.sendJson("QueryDefinition", { - "Title": "", - "FileName": filename, - "Offset": offset, - "Source": editor.text(), - "Subcommand": "Goto", - }) + if self.__projectopen: + filename = editor.getFileName() + line, index = editor.getCursorPosition() + offset = self.__getOffset(editor, line, index) + + self.sendJson("QueryDefinition", { + "Title": "", + "FileName": filename, + "Offset": offset, + "Source": editor.text(), + "Subcommand": "Goto", + }) def __queryDefinitionResult(self, result): """ @@ -1796,11 +1798,11 @@ if "Location" in result: location = result["Location"] try: - e5App().getObject("ViewManager").openSourceFile( + self.__vm.openSourceFile( location[0], location[1], addNext=True) except TypeError: # backward compatibility; <= 17.03 - e5App().getObject("ViewManager").openSourceFile( + self.__vm.openSourceFile( location[0], location[1], next=True) else: e5App().getObject("UserInterface").statusBar().showMessage( @@ -1810,7 +1812,7 @@ """ Private slot to handle the Find Implementations action. """ - aw = e5App().getObject("ViewManager").activeWindow() + aw = self.__vm.activeWindow() if aw is None: return @@ -2139,7 +2141,7 @@ @return flag indicating, that no editor contains unsaved edits @rtype bool """ - res = e5App().getObject("ViewManager").checkAllDirty() + res = self.__vm.checkAllDirty() self.sendJson("Validate", {}) return res @@ -2150,20 +2152,21 @@ @param changedFiles list of changed files @type list of str """ - vm = e5App().getObject("ViewManager") - openFiles = [Utilities.normcasepath(f) for f in vm.getOpenFilenames()] + openFiles = [Utilities.normcasepath(f) + for f in self.__vm.getOpenFilenames()] for fileName in changedFiles: normfile = Utilities.normcasepath(fileName) if normfile in openFiles: - editor = vm.getEditor(normfile)[1] + editor = self.__vm.getEditor(normfile)[1] editor.refresh() - aw = vm.activeWindow() + aw = self.__vm.activeWindow() if aw is not None: filename = aw.getFileName() if filename is not None: - vm.openSourceFile(filename, aw.getCursorPosition()[0] + 1) + self.__vm.openSourceFile(filename, + aw.getCursorPosition()[0] + 1) def reportChanged(self, filename, oldSource): """ @@ -2176,10 +2179,13 @@ """ if self.__e5project.isOpen() and \ self.__e5project.isProjectFile(filename): - self.sendJson("ReportChanged", { - "FileName": filename, - "OldSource": oldSource, - }) + editor = self.__vm.getOpenEditor(filename) + if editor is not None and \ + editor.getLanguage() == self.__ropeConfig["PythonVersion"]: + self.sendJson("ReportChanged", { + "FileName": filename, + "OldSource": oldSource, + }) ####################################################################### ## Methods below handle the network connection @@ -2248,3 +2254,52 @@ "RefactoringClient.py") ok = self.startClient(interpreter, client, [self.__projectpath]) return ok + + ######################################################################### + ## Methods below handle setting/unsetting the mouse click handler methods + ######################################################################### + + def connectEditor(self, editor): + """ + Public method to connect an editor. + + @param editor reference to the editor + @type QScintilla.Editor + """ + + if self.__plugin.getPreferences("MouseClickEnabled"): + self.__disconnectMouseClickHandler(editor) + self.__connectMouseClickHandler(editor) + + def disconnectEditor(self, editor): + """ + Public method to disconnect an editor. + + @param editor reference to the editor + @type QScintilla.Editor + """ + self.__disconnectMouseClickHandler(editor) + + def __connectMouseClickHandler(self, editor): + """ + Private method to connect the mouse click handler to an editor. + + @param editor reference to the editor + @type QScintilla.Editor + """ + if self.__plugin.getPreferences("MouseClickGotoButton"): + editor.setMouseClickHandler( + "rope", + self.__plugin.getPreferences("MouseClickGotoModifiers"), + self.__plugin.getPreferences("MouseClickGotoButton"), + self.gotoDefinition + ) + + def __disconnectMouseClickHandler(self, editor): + """ + Private method to disconnect the mouse click handler from an editor. + + @param editor reference to the editor + @type QScintilla.Editor + """ + editor.removeMouseClickHandlers("rope")