--- a/RefactoringRope/Refactoring.py Sun Jun 14 13:55:57 2015 +0200 +++ b/RefactoringRope/Refactoring.py Sat Jun 27 11:15:48 2015 +0200 @@ -1880,7 +1880,7 @@ self.__project.history.clear() ##################################################### - ## Find actions + ## Find actions including mouse click handler ##################################################### def __queryReferences(self): @@ -1893,19 +1893,12 @@ return title = self.tr("Find Occurrences") - if not aw.hasSelectedText(): - # no selection available - E5MessageBox.warning( - self.__ui, title, - self.tr("Highlight the class, method, function or variable" - " to search for and try again.")) - return if not self.confirmAllBuffersSaved(): return filename = aw.getFileName() - line, index, line1, index1 = aw.getSelection() + line, index = aw.getCursorPosition() offset = self.__getOffset(aw, line, index) import rope.contrib.findit @@ -1946,20 +1939,12 @@ return title = self.tr("Find &Definition") - if not aw.hasSelectedText(): - # no selection available - E5MessageBox.warning( - self.__ui, title, - self.tr("Highlight the class, method, function or" - " variable reference to search definition for and" - " try again.")) - return if not self.confirmAllBuffersSaved(): return filename = aw.getFileName() - line, index, line1, index1 = aw.getSelection() + line, index = aw.getCursorPosition() offset = self.__getOffset(aw, line, index) import rope.contrib.findit @@ -1982,6 +1967,36 @@ self.__ui, title, self.tr("No matching definition found.")) + def gotoDefinition(self): + """ + Public slot to find the definition for the word at the cursor position + and go to it. + + Note: This is executed upon a mouse click sequence. + """ + aw = e5App().getObject("ViewManager").activeWindow() + + if aw is None: + return + + filename = aw.getFileName() + line, index = aw.getCursorPosition() + offset = self.__getOffset(aw, line, index) + + import rope.contrib.findit + resource = rope.base.libutils.path_to_resource( + self.__project, filename) + try: + location = rope.contrib.findit.find_definition( + self.__project, aw.text(), offset, resource) + except Exception: + # simply ignore them + return + + if location is not None: + e5App().getObject("ViewManager").openSourceFile( + location.resource.real_path, location.lineno, next=True) + def __queryImplementations(self): """ Private slot to handle the Find Implementations action. @@ -1992,19 +2007,12 @@ return title = self.tr("Find Implementations") - if not aw.hasSelectedText(): - # no selection available - E5MessageBox.warning( - self.__ui, title, - self.tr("Highlight the method to search for" - " and try again.")) - return if not self.confirmAllBuffersSaved(): return filename = aw.getFileName() - line, index, line1, index1 = aw.getSelection() + line, index = aw.getCursorPosition() offset = self.__getOffset(aw, line, index) import rope.contrib.findit