diff -r 49a4abfc1f89 -r 07dabc6bb157 RefactoringRope/Refactoring.py --- a/RefactoringRope/Refactoring.py Sat Jan 29 19:40:01 2011 +0100 +++ b/RefactoringRope/Refactoring.py Sat Jan 29 19:57:25 2011 +0100 @@ -19,7 +19,7 @@ import rope.refactor.rename import rope.refactor.extract ##import rope.refactor.usefunction -##import rope.refactor.inline +import rope.refactor.inline ##import rope.refactor.move ##import rope.refactor.change_signature ##import rope.refactor.introduce_factory @@ -51,6 +51,7 @@ from ChangeOccurrencesDialog import ChangeOccurrencesDialog from HistoryDialog import HistoryDialog from ExtractDialog import ExtractDialog +from InlineDialog import InlineDialog import Utilities @@ -212,6 +213,29 @@ self.actions.append(self.refactoringExtractLocalVariableAct) ##################################################### + ## Inline refactoring actions + ##################################################### + + self.refactoringInlineAct = E5Action( + self.trUtf8('Inline'), + self.trUtf8('&Inline'), + 0, 0, + self,'refactoring_inline') + self.refactoringInlineAct.setStatusTip(self.trUtf8( + 'Inlines the selected local variable or method')) + self.refactoringInlineAct.setWhatsThis(self.trUtf8( + """<b>Inline</b>""" + """<p>Inlines the selected local variable or method.</p>""" + )) + if self.__newStyle: + self.refactoringInlineAct.triggered[()].connect( + self.__inline) + else: + self.connect(self.refactoringInlineAct, + SIGNAL('triggered()'), self.__inline) + self.actions.append(self.refactoringInlineAct) + + ##################################################### ## Undo/Redo actions ##################################################### @@ -487,8 +511,8 @@ smenu.addAction(self.refactoringExtractMethodAct) ## smenu.addAction(self.refactoringMoveMethodAct) smenu.addSeparator() -## smenu.addAction(self.refactoringInlineAct) -## smenu.addSeparator() + smenu.addAction(self.refactoringInlineAct) + smenu.addSeparator() smenu.addAction(self.refactoringExtractLocalVariableAct) smenu.addSeparator() smenu.addAction(self.refactoringRenameModuleAct) @@ -833,6 +857,46 @@ self.dlg.show() ##################################################### + ## Inline refactorings + ##################################################### + + def __inline(self): + """ + Private slot to handle the Inline Local Variable action. + """ + aw = e5App().getObject("ViewManager").activeWindow() + + if aw is None: + return + + title = self.trUtf8("Inline") + if not aw.hasSelectedText(): + # no selection available + E5MessageBox.warning(self.__ui, title, + self.trUtf8("Highlight the local variable, method or parameter" + " you want to inline and try again.")) + return + + if not self.confirmAllBuffersSaved(): + return + + filename = aw.getFileName() + line, index, line1, index1 = aw.getSelection() + offset = aw.positionFromLineIndex(line, index) + + resource = rope.base.libutils.path_to_resource( + self.__project, filename) + try: + inliner = rope.refactor.inline.create_inline( + self.__project, resource, offset) + except Exception as err: + self.handleRopeError(err, title) + return + + self.dlg = InlineDialog(self, title, inliner, parent = self.__ui) + self.dlg.show() + + ##################################################### ## Undo/Redo refactorings #####################################################