RefactoringRope/IntroduceFactoryDialog.py

branch
server_client_variant
changeset 180
a33ef7ab8c54
parent 147
3f8a995f6e49
child 181
3e3d6de2f0ca
--- a/RefactoringRope/IntroduceFactoryDialog.py	Sat Sep 23 12:01:48 2017 +0200
+++ b/RefactoringRope/IntroduceFactoryDialog.py	Sat Sep 23 12:16:59 2017 +0200
@@ -20,27 +20,35 @@
     """
     Class implementing the Introduce Factory dialog.
     """
-    def __init__(self, refactoring, title, introducer, 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 introducer reference to the factory introducer object
-            (rope.refactor.introduce_factory.IntroduceFactoryRefactoring)
-        @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.__introducer = introducer
+        self._changeGroupName = "IntroduceFactory"
+        
+        self.__filename = filename
+        self.__offset = offset
         
         self.__okButton = self.buttonBox.button(QDialogButtonBox.Ok)
         self.__okButton.setEnabled(False)
         self.__previewButton = self.buttonBox.addButton(
             self.tr("Preview"), QDialogButtonBox.ActionRole)
         self.__previewButton.setDefault(True)
+        self.__previewButton.setEnabled(False)
         
         self.nameEdit.setText("create")
         self.nameEdit.selectAll()
@@ -55,34 +63,32 @@
         
         @param text text entered into the edit (string)
         """
-        self.__okButton.setEnabled(text != "")
+        enable = bool(text)
+        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()
     
-    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.
         """
-        try:
-            changes = self.__introducer.get_changes(
-                self.nameEdit.text(),
-                global_factory=self.globalButton.isChecked(),
-                task_handle=handle)
-            return changes
-        except Exception as err:
-            self._refactoring.handleRopeError(err, self._title, handle)
-            return None
+        self._refactoring.sendJson("CalculateIntroduceFactoryChanges", {
+            "ChangeGroup": self._changeGroupName,
+            "Title": self._title,
+            "FileName": self.__filename,
+            "Offset": self.__offset,
+            "Name": self.nameEdit.text(),
+            "GlobalFactory": self.globalButton.isChecked(),
+        })

eric ide

mercurial