RefactoringRope/ChangeSignatureDialog.py

branch
server_client_variant
changeset 184
4a806271f0b9
parent 151
5260100b6700
child 189
2711fdd91925
diff -r bac69c80d5f4 -r 4a806271f0b9 RefactoringRope/ChangeSignatureDialog.py
--- a/RefactoringRope/ChangeSignatureDialog.py	Sat Sep 23 15:20:09 2017 +0200
+++ b/RefactoringRope/ChangeSignatureDialog.py	Sat Sep 23 16:52:29 2017 +0200
@@ -15,8 +15,6 @@
 from PyQt5.QtWidgets import QDialog, QDialogButtonBox, QListWidgetItem, \
     QAbstractButton
 
-import rope.refactor.change_signature
-
 from Ui_ChangeSignatureDialog import Ui_ChangeSignatureDialog
 from RefactoringDialogBase import RefactoringDialogBase
 
@@ -30,22 +28,30 @@
     DefaultRole = Qt.UserRole + 2
     ValueRole = Qt.UserRole + 3
     
-    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.__to_be_removed = []
         
         self.__okButton = self.buttonBox.button(QDialogButtonBox.Ok)
@@ -53,12 +59,29 @@
             self.tr("Preview"), QDialogButtonBox.ActionRole)
         self.__previewButton.setDefault(True)
         
+        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 None:
                 itm = QListWidgetItem(arg, self.parameterList)
             else:
-                itm = QListWidgetItem("{0} = {1}".format(arg, default),
+                itm = QListWidgetItem("{0}={1}".format(arg, default),
                                       self.parameterList)
             itm.setData(ChangeSignatureDialog.NameRole, arg)
             itm.setData(ChangeSignatureDialog.IsAddedRole, False)
@@ -75,7 +98,8 @@
         """
         Private slot called, when the current row is changed.
         
-        @param currentRow index of the current row (integer)
+        @param currentRow index of the current row
+        @type int
         """
         if currentRow == -1:
             self.upButton.setEnabled(False)
@@ -143,7 +167,7 @@
         if dlg.exec_() == QDialog.Accepted:
             name, default, value = dlg.getData()
             if default:
-                s = "{0} = {1}".format(name, default)
+                s = "{0}={1}".format(name, default)
             else:
                 s = name
             itm = QListWidgetItem(s)
@@ -169,10 +193,11 @@
         """
         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()
     
@@ -180,23 +205,23 @@
         """
         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.
         """
-        changers = []
+        removals = []
         definition_info = copy.deepcopy(self.__definition_info)
         for itm in self.__to_be_removed:
             if itm.data(ChangeSignatureDialog.IsAddedRole):
@@ -204,41 +229,55 @@
             index = self.__getParameterIndex(
                 definition_info,
                 itm.data(ChangeSignatureDialog.NameRole))
-            remover = rope.refactor.change_signature.ArgumentRemover(index)
-            changers.append(remover)
+            removals.append(index)
             del definition_info[index]
         
+        additions = []
         for index in range(self.parameterList.count()):
             itm = self.parameterList.item(index)
             if itm.data(ChangeSignatureDialog.IsAddedRole):
                 name = itm.data(ChangeSignatureDialog.NameRole)
                 default = itm.data(ChangeSignatureDialog.DefaultRole)
                 value = itm.data(ChangeSignatureDialog.ValueRole)
-                adder = rope.refactor.change_signature.ArgumentAdder(
-                    index, name, default, value)
-                changers.append(adder)
+                additions.append([index, name, default, value])
                 try:
-                    definition_info.insert(index, (name, default))
+                    definition_info.insert(index, [name, default])
                 except Exception as err:
                     self._refactoring.handleRopeError(err, self._title)
         
-        new_ordering = []
+        newOrdering = []
         for row in range(self.parameterList.count()):
             itm = self.parameterList.item(row)
             name = itm.data(ChangeSignatureDialog.NameRole)
-            new_ordering.append(
+            newOrdering.append(
                 self.__getParameterIndex(definition_info, name))
         autodef = self.autodefEdit.text()
         if not autodef:
             autodef = None
-        changers.append(rope.refactor.change_signature.ArgumentReorderer(
-            new_ordering, autodef=autodef))
         
-        try:
-            changes = self.__signature.get_changes(
-                changers, in_hierarchy=self.hierarchyCheckBox.isChecked(),
-                task_handle=handle)
-            return changes
-        except Exception as err:
-            self._refactoring.handleRopeError(err, self._title, handle)
-            return None
+        self._refactoring.sendJson("CalculateSignatureChanges", {
+            "ChangeGroup": self._changeGroupName,
+            "Title": self._title,
+            "FileName": self.__filename,
+            "Offset": self.__offset,
+            "Removals": removals,
+            "Additions": additions,
+            "Ordering": newOrdering,
+            "AutoDef": autodef,
+            "Hierarchy": self.hierarchyCheckBox.isChecked(),
+        })
+    
+    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