RefactoringRope/Refactoring.py

changeset 13
dad628301abc
parent 12
75fff1da56b6
child 14
cc9f4507be3d
diff -r 75fff1da56b6 -r dad628301abc RefactoringRope/Refactoring.py
--- a/RefactoringRope/Refactoring.py	Sun Jan 30 17:24:58 2011 +0100
+++ b/RefactoringRope/Refactoring.py	Sun Jan 30 17:35:48 2011 +0100
@@ -24,7 +24,7 @@
 import rope.refactor.change_signature
 import rope.refactor.introduce_factory
 import rope.refactor.introduce_parameter
-##import rope.refactor.method_object
+import rope.refactor.method_object
 import rope.refactor.encapsulate_field
 import rope.refactor.localtofield
 import rope.refactor.topackage
@@ -62,6 +62,7 @@
 from ChangeSignatureDialog import ChangeSignatureDialog
 from InlineArgumentDefaultDialog import InlineArgumentDefaultDialog
 from GetterSetterDialog import GetterSetterDialog
+from MethodToMethodObjectDialog import MethodToMethodObjectDialog
 
 import Utilities
 
@@ -487,6 +488,21 @@
             self.__convertLocalToAttribute)
         self.actions.append(self.refactoringLocalVariableToAttributeAct)
         
+        self.refactoringMethodToMethodObjectAct = E5Action(
+                self.trUtf8('Method To Method Object'),
+                self.trUtf8('Method To Method Ob&ject'),
+                0, 0,
+                self,'refactoring_method_to_methodobject')
+        self.refactoringMethodToMethodObjectAct.setStatusTip(self.trUtf8(
+            'Transform a function or a method to a method object'))
+        self.refactoringMethodToMethodObjectAct.setWhatsThis(self.trUtf8(
+            """<b>Method To Method Object</b>"""
+            """<p>Transform a function or a method to a method object.</p>"""
+        ))
+        self.refactoringMethodToMethodObjectAct.triggered[()].connect(
+            self.__methodToMethodObject)
+        self.actions.append(self.refactoringMethodToMethodObjectAct)
+        
         #####################################################
         ## Undo/Redo actions
         #####################################################
@@ -724,7 +740,7 @@
         smenu.addSeparator()
         smenu.addAction(self.refactoringIntroduceFactoryAct)
         smenu.addAction(self.refactoringIntroduceParameterAct)
-##        smenu.addAction(self.refactoringMethodToMethodObjectAct)
+        smenu.addAction(self.refactoringMethodToMethodObjectAct)
         smenu.addSeparator()
         smenu.addAction(self.refactoringEncapsulateAttributeAct)
         smenu.addAction(self.refactoringLocalVariableToAttributeAct)
@@ -1590,6 +1606,43 @@
         except Exception as err:
             self.handleRopeError(err, title)
     
+    def __methodToMethodObject(self):
+        """
+        Private slot to change the signature of a method or function.
+        """
+        aw = e5App().getObject("ViewManager").activeWindow()
+        
+        if aw is None:
+            return
+        
+        title = self.trUtf8("Replace Method With Method Object")
+        if not aw.hasSelectedText():
+            # no selection available
+            E5MessageBox.warning(self.__ui, title,
+                self.trUtf8("Highlight the method or function to convert"
+                    " 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:
+            converter = rope.refactor.method_object.MethodObject(
+                self.__project, resource, offset)
+        except Exception as err:
+            self.handleRopeError(err, title)
+            return 
+        
+        self.dlg = MethodToMethodObjectDialog(self, title, converter,
+                                              parent=self.__ui)
+        self.dlg.show()
+    
     #####################################################
     ## Undo/Redo refactorings
     #####################################################

eric ide

mercurial