RefactoringRope/UseFunctionDialog.py

branch
server_client_variant
changeset 179
8ae4e95f5fa6
parent 147
3f8a995f6e49
child 189
2711fdd91925
diff -r 70b4fb448811 -r 8ae4e95f5fa6 RefactoringRope/UseFunctionDialog.py
--- a/RefactoringRope/UseFunctionDialog.py	Fri Sep 22 19:47:36 2017 +0200
+++ b/RefactoringRope/UseFunctionDialog.py	Sat Sep 23 12:01:48 2017 +0200
@@ -4,7 +4,7 @@
 #
 
 """
-Module implementing the Inline dialog.
+Module implementing the Use Function dialog.
 """
 
 from __future__ import unicode_literals
@@ -18,33 +18,59 @@
 
 class UseFunctionDialog(RefactoringDialogBase, Ui_UseFunctionDialog):
     """
-    Class implementing the Inline dialog.
+    Class implementing the Use Function dialog.
     """
-    def __init__(self, refactoring, title, user, 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 user reference to the usefunction object
-            (rope.refactor.usefunction.UseFunction)
-        @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.__user = user
+        self._changeGroupName = "UseFunction"
         
-        self.description.setText(
-            self.tr("Using Function <b>{0}</b>.")
-                .format(self.__user.get_function_name()))
+        self.__filename = filename
+        self.__offset = offset
         
         self.__okButton = self.buttonBox.button(QDialogButtonBox.Ok)
         self.__previewButton = self.buttonBox.addButton(
             self.tr("Preview"), QDialogButtonBox.ActionRole)
         self.__previewButton.setDefault(True)
         
+        self._refactoring.sendJson("RequestUseFunction", {
+            "ChangeGroup": self._changeGroupName,
+            "Title": self._title,
+            "FileName": self.__filename,
+            "Offset": self.__offset,
+        })
+    
+    def __processUseFunctionName(self, data):
+        """
+        Private method to process the function name data sent by the
+        refactoring client in order to polish the dialog.
+        
+        @param data dictionary containing the inline type data
+        @type dict
+        """
+        self.description.setText(
+            self.tr("Using Function <b>{0}</b>.")
+                .format(data["FunctionName"]))
+        
+        if not data["FunctionName"]:
+            self.__okButton.setEnabled(False)
+            self.__previewButton.setEnabled(False)
+        
         msh = self.minimumSizeHint()
         self.resize(max(self.width(), msh.width()), msh.height())
     
@@ -53,24 +79,36 @@
         """
         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()
     
-    def _calculateChanges(self, handle):
+    def _calculateChanges(self):
+        """
+        Protected method to initiate the calculation of the changes.
         """
-        Protected method to calculate the changes.
+        self._refactoring.sendJson("CalculateUseFunctionChanges", {
+            "ChangeGroup": self._changeGroupName,
+            "Title": self._title,
+            "FileName": self.__filename,
+            "Offset": self.__offset,
+        })
+    
+    def processChangeData(self, data):
+        """
+        Public method to process the change data sent by the refactoring
+        client.
         
-        @param handle reference to the task handle
-            (rope.base.taskhandle.TaskHandle)
-        @return reference to the Changes object (rope.base.change.ChangeSet)
+        @param data dictionary containing the change data
+        @type dict
         """
-        try:
-            changes = self.__user.get_changes(task_handle=handle)
-            return changes
-        except Exception as err:
-            self._refactoring.handleRopeError(err, self._title, handle)
-            return None
+        subcommand = data["Subcommand"]
+        if subcommand == "UseFunctionName":
+            self.__processUseFunctionName(data)
+        else:
+            # pass on to base class
+            RefactoringDialogBase.processChangeData(self, data)

eric ide

mercurial