17 import rope.base.exceptions |
17 import rope.base.exceptions |
18 |
18 |
19 import rope.refactor.rename |
19 import rope.refactor.rename |
20 import rope.refactor.extract |
20 import rope.refactor.extract |
21 ##import rope.refactor.usefunction |
21 ##import rope.refactor.usefunction |
22 ##import rope.refactor.inline |
22 import rope.refactor.inline |
23 ##import rope.refactor.move |
23 ##import rope.refactor.move |
24 ##import rope.refactor.change_signature |
24 ##import rope.refactor.change_signature |
25 ##import rope.refactor.introduce_factory |
25 ##import rope.refactor.introduce_factory |
26 ##import rope.refactor.introduce_parameter |
26 ##import rope.refactor.introduce_parameter |
27 ##import rope.refactor.method_object |
27 ##import rope.refactor.method_object |
49 from MatchesDialog import MatchesDialog |
49 from MatchesDialog import MatchesDialog |
50 from RenameDialog import RenameDialog |
50 from RenameDialog import RenameDialog |
51 from ChangeOccurrencesDialog import ChangeOccurrencesDialog |
51 from ChangeOccurrencesDialog import ChangeOccurrencesDialog |
52 from HistoryDialog import HistoryDialog |
52 from HistoryDialog import HistoryDialog |
53 from ExtractDialog import ExtractDialog |
53 from ExtractDialog import ExtractDialog |
|
54 from InlineDialog import InlineDialog |
54 |
55 |
55 import Utilities |
56 import Utilities |
56 |
57 |
57 |
58 |
58 class Refactoring(QObject): |
59 class Refactoring(QObject): |
208 self.__extractLocalVariable) |
209 self.__extractLocalVariable) |
209 else: |
210 else: |
210 self.connect(self.refactoringExtractLocalVariableAct, |
211 self.connect(self.refactoringExtractLocalVariableAct, |
211 SIGNAL('triggered()'), self.__extractLocalVariable) |
212 SIGNAL('triggered()'), self.__extractLocalVariable) |
212 self.actions.append(self.refactoringExtractLocalVariableAct) |
213 self.actions.append(self.refactoringExtractLocalVariableAct) |
|
214 |
|
215 ##################################################### |
|
216 ## Inline refactoring actions |
|
217 ##################################################### |
|
218 |
|
219 self.refactoringInlineAct = E5Action( |
|
220 self.trUtf8('Inline'), |
|
221 self.trUtf8('&Inline'), |
|
222 0, 0, |
|
223 self,'refactoring_inline') |
|
224 self.refactoringInlineAct.setStatusTip(self.trUtf8( |
|
225 'Inlines the selected local variable or method')) |
|
226 self.refactoringInlineAct.setWhatsThis(self.trUtf8( |
|
227 """<b>Inline</b>""" |
|
228 """<p>Inlines the selected local variable or method.</p>""" |
|
229 )) |
|
230 if self.__newStyle: |
|
231 self.refactoringInlineAct.triggered[()].connect( |
|
232 self.__inline) |
|
233 else: |
|
234 self.connect(self.refactoringInlineAct, |
|
235 SIGNAL('triggered()'), self.__inline) |
|
236 self.actions.append(self.refactoringInlineAct) |
213 |
237 |
214 ##################################################### |
238 ##################################################### |
215 ## Undo/Redo actions |
239 ## Undo/Redo actions |
216 ##################################################### |
240 ##################################################### |
217 |
241 |
485 smenu.addAction(self.refactoringChangeOccurrencesAct) |
509 smenu.addAction(self.refactoringChangeOccurrencesAct) |
486 smenu.addSeparator() |
510 smenu.addSeparator() |
487 smenu.addAction(self.refactoringExtractMethodAct) |
511 smenu.addAction(self.refactoringExtractMethodAct) |
488 ## smenu.addAction(self.refactoringMoveMethodAct) |
512 ## smenu.addAction(self.refactoringMoveMethodAct) |
489 smenu.addSeparator() |
513 smenu.addSeparator() |
490 ## smenu.addAction(self.refactoringInlineAct) |
514 smenu.addAction(self.refactoringInlineAct) |
491 ## smenu.addSeparator() |
515 smenu.addSeparator() |
492 smenu.addAction(self.refactoringExtractLocalVariableAct) |
516 smenu.addAction(self.refactoringExtractLocalVariableAct) |
493 smenu.addSeparator() |
517 smenu.addSeparator() |
494 smenu.addAction(self.refactoringRenameModuleAct) |
518 smenu.addAction(self.refactoringRenameModuleAct) |
495 smenu.addSeparator() |
519 smenu.addSeparator() |
496 |
520 |
828 except Exception as err: |
852 except Exception as err: |
829 self.handleRopeError(err, title) |
853 self.handleRopeError(err, title) |
830 return |
854 return |
831 |
855 |
832 self.dlg = ExtractDialog(self, title, extractor, parent = self.__ui) |
856 self.dlg = ExtractDialog(self, title, extractor, parent = self.__ui) |
|
857 self.dlg.show() |
|
858 |
|
859 ##################################################### |
|
860 ## Inline refactorings |
|
861 ##################################################### |
|
862 |
|
863 def __inline(self): |
|
864 """ |
|
865 Private slot to handle the Inline Local Variable action. |
|
866 """ |
|
867 aw = e5App().getObject("ViewManager").activeWindow() |
|
868 |
|
869 if aw is None: |
|
870 return |
|
871 |
|
872 title = self.trUtf8("Inline") |
|
873 if not aw.hasSelectedText(): |
|
874 # no selection available |
|
875 E5MessageBox.warning(self.__ui, title, |
|
876 self.trUtf8("Highlight the local variable, method or parameter" |
|
877 " you want to inline and try again.")) |
|
878 return |
|
879 |
|
880 if not self.confirmAllBuffersSaved(): |
|
881 return |
|
882 |
|
883 filename = aw.getFileName() |
|
884 line, index, line1, index1 = aw.getSelection() |
|
885 offset = aw.positionFromLineIndex(line, index) |
|
886 |
|
887 resource = rope.base.libutils.path_to_resource( |
|
888 self.__project, filename) |
|
889 try: |
|
890 inliner = rope.refactor.inline.create_inline( |
|
891 self.__project, resource, offset) |
|
892 except Exception as err: |
|
893 self.handleRopeError(err, title) |
|
894 return |
|
895 |
|
896 self.dlg = InlineDialog(self, title, inliner, parent = self.__ui) |
833 self.dlg.show() |
897 self.dlg.show() |
834 |
898 |
835 ##################################################### |
899 ##################################################### |
836 ## Undo/Redo refactorings |
900 ## Undo/Redo refactorings |
837 ##################################################### |
901 ##################################################### |