RefactoringRope/InlineArgumentDefaultDialog.py

branch
server_client_variant
changeset 185
3336637a673b
parent 147
3f8a995f6e49
child 189
2711fdd91925
diff -r 4a806271f0b9 -r 3336637a673b RefactoringRope/InlineArgumentDefaultDialog.py
--- a/RefactoringRope/InlineArgumentDefaultDialog.py	Sat Sep 23 16:52:29 2017 +0200
+++ b/RefactoringRope/InlineArgumentDefaultDialog.py	Sat Sep 23 17:21:24 2017 +0200
@@ -23,22 +23,30 @@
     """
     NameRole = Qt.UserRole
     
-    def __init__(self, refactoring, title, changer, parent=None):
+    def __init__(self, refactoring, title, filename, offset, parent=None):
         """
         Constructor
         
         @param refactoring reference to the main refactoring object
-            (Refactoring)
-        @param title title of the dialog (string)
-        @param changer reference to the signature changer object
-            (rope.refactor.change_signature.ChangeSignature)
-        @param parent reference to the parent widget (QWidget)
+        @type Refactoring
+        @param title title of the dialog
+        @type str
+        @param filename file name to be worked on
+        @type str
+        @param offset offset within file
+        @type int or None
+        @param parent reference to the parent widget
+        @type QWidget
         """
         RefactoringDialogBase.__init__(self, refactoring, title, parent)
         self.setupUi(self)
         
-        self.__signature = changer
-        self.__definition_info = self.__signature.get_args()
+        self._changeGroupName = "ChangeSignature"
+        
+        self.__filename = filename
+        self.__offset = offset
+        
+        self.__definition_info = []
         
         self.__okButton = self.buttonBox.button(QDialogButtonBox.Ok)
         self.__okButton.setEnabled(False)
@@ -47,10 +55,27 @@
         self.__previewButton.setDefault(True)
         self.__previewButton.setEnabled(False)
         
+        self._refactoring.sendJson("RequestSignature", {
+            "ChangeGroup": self._changeGroupName,
+            "Title": self._title,
+            "FileName": self.__filename,
+            "Offset": self.__offset,
+        })
+    
+    def __processSignature(self, data):
+        """
+        Private method to process the inline type data sent by the refactoring
+        client in order to polish the dialog.
+        
+        @param data dictionary containing the inline type data
+        @type dict
+        """
+        self.__definition_info = data["DefinitionInfo"]
+        
         # populate the parameters list
         for arg, default in self.__definition_info:
             if default is not None:
-                itm = QListWidgetItem("{0} = {1}".format(arg, default),
+                itm = QListWidgetItem("{0}={1}".format(arg, default),
                                       self.parameterList)
                 itm.setData(InlineArgumentDefaultDialog.NameRole, arg)
     
@@ -59,20 +84,21 @@
         """
         Private slot called, when the selection changes.
         """
-        self.__okButton.setEnabled(
-            len(self.parameterList.selectedItems()) > 0)
-        self.__previewButton.setEnabled(
-            len(self.parameterList.selectedItems()) > 0)
+        enable = len(self.parameterList.selectedItems()) > 0
+        
+        self.__okButton.setEnabled(enable)
+        self.__previewButton.setEnabled(enable)
     
     @pyqtSlot(QAbstractButton)
     def on_buttonBox_clicked(self, button):
         """
         Private slot to act on the button pressed.
         
-        @param button reference to the button pressed (QAbstractButton)
+        @param button reference to the button pressed
+        @type QAbstractButton
         """
         if button == self.__previewButton:
-            self.previewChanges()
+            self.requestPreview()
         elif button == self.__okButton:
             self.applyChanges()
     
@@ -80,36 +106,48 @@
         """
         Private method to calculate the index of the given paramter.
         
-        @param definition_info object containing the method definition
-        @param name parameter name (string)
-        @return index of the parameter (integer)
+        @param definition_info list of lists containing the method signature
+            definition
+        @type list of lists of two str
+        @param name parameter name
+        @type str
+        @return index of the parameter
+        @rtype int
         """
         for index, pair in enumerate(definition_info):
             if pair[0] == name:
                 return index
 
-    def _calculateChanges(self, handle):
+    def _calculateChanges(self):
         """
-        Protected method to calculate the changes.
-        
-        @param handle reference to the task handle
-            (rope.base.taskhandle.TaskHandle)
-        @return reference to the Changes object (rope.base.change.ChangeSet)
+        Protected method to initiate the calculation of the changes.
         """
         items = self.parameterList.selectedItems()
         if len(items) > 0:
-            import rope.refactor.change_signature
-            
             itm = items[0]
             name = itm.data(InlineArgumentDefaultDialog.NameRole)
             index = self.__getParameterIndex(self.__definition_info, name)
-            try:
-                inliner = \
-                    rope.refactor.change_signature.ArgumentDefaultInliner(
-                        index)
-                changes = self.__signature.get_changes(
-                    [inliner], task_handle=handle)
-                return changes
-            except Exception as err:
-                self._refactoring.handleRopeError(err, self._title, handle)
-                return None
+            
+            self._refactoring.sendJson(
+                "CalculateInlineArgumentDefaultChanges", {
+                    "ChangeGroup": self._changeGroupName,
+                    "Title": self._title,
+                    "FileName": self.__filename,
+                    "Offset": self.__offset,
+                    "Index": index,
+                })
+    
+    def processChangeData(self, data):
+        """
+        Public method to process the change data sent by the refactoring
+        client.
+        
+        @param data dictionary containing the change data
+        @type dict
+        """
+        subcommand = data["Subcommand"]
+        if subcommand == "Signature":
+            self.__processSignature(data)
+        else:
+            # pass on to base class
+            RefactoringDialogBase.processChangeData(self, data)

eric ide

mercurial