RefactoringRope/RenameDialog.py

branch
server_client_variant
changeset 172
c8890f852917
parent 147
3f8a995f6e49
child 173
2cdb7c48b719
--- a/RefactoringRope/RenameDialog.py	Sun Sep 17 20:03:39 2017 +0200
+++ b/RefactoringRope/RenameDialog.py	Mon Sep 18 20:05:28 2017 +0200
@@ -23,35 +23,47 @@
     """
     Class implementing the Rename dialog.
     """
-    def __init__(self, refactoring, title, renamer, resource=None,
+    def __init__(self, refactoring, title, filename, offset, isLocal,
                  selectedText='', parent=None):
         """
         Constructor
         
         @param refactoring reference to the main refactoring object
-            (Refactoring)
-        @param title title of the dialog (string)
-        @param renamer reference to the renamer object
-            (rope.refactor.rename.Rename)
-        @param resource reference to a resource object, if the action is to
-            be applied to the local file only (rope.base.resources.File)
-        @param selectedText selected text to rename (str)
-        @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 isLocal flag indicating to restrict refactoring to
+            the local file
+        @type bool
+        @param selectedText selected text to rename
+        @type str
+        @param parent reference to the parent widget
+        @type QWidget
         """
         RefactoringDialogBase.__init__(self, refactoring, title, parent)
         self.setupUi(self)
         
-        self.__renamer = renamer
-        if resource is not None:
-            self.__resources = [resource]
-        else:
-            self.__resources = None
+        self._changeGroupName = "Rename"
         
+        self.__filename = filename
+        self.__offset = offset
+        self.__local = isLocal
+##        self.__renamer = renamer
+##        if resource is not None:
+##            self.__resources = [resource]
+##        else:
+##            self.__resources = None
+##        
         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.newNameEdit.setText(selectedText)
         self.newNameEdit.selectAll()
         
@@ -75,64 +87,84 @@
         @param button reference to the button pressed (QAbstractButton)
         """
         if button == self.__previewButton:
-            self.previewChanges()
+            self.requestPreview()
         elif button == self.__okButton:
             self.applyChanges()
     
-    def __confirmUnsure(self, occurrence):
+    def __confirmUnsure(self, data):
         """
         Private method to confirm unsure occurrences.
         
-        @parameter occurrence reference to the occurrence object
-            (rope.refactor.occurrences.Occurrence)
-        @return flag indicating an occurrence (boolean)
+        @param data dictionary containing the change data
+        @type dict
         """
+        # TODO: change this to the distributed version
         if self.ignoreButton.isChecked():
-            return False
-        if self.matchButton.isChecked():
-            return True
-        
-        filename = occurrence.resource.real_path
-        start, end = occurrence.get_primary_range()
-        
-        vm = e5App().getObject("ViewManager")
+            answer = False
+        elif self.matchButton.isChecked():
+            answer = True
+        else:
+            filename = occurrence.resource.real_path
+            start, end = occurrence.get_primary_range()
+            
+            vm = e5App().getObject("ViewManager")
+            
+            # display the file and select the match
+            vm.openSourceFile(filename)
+            aw = vm.activeWindow()
+            cline, cindex = aw.getCursorPosition()
+            sline, sindex = aw.lineIndexFromPosition(start)
+            eline, eindex = aw.lineIndexFromPosition(end)
+            aw.ensureLineVisible(sline)
+            aw.gotoLine(sline)
+            aw.setSelection(sline, sindex, eline, eindex)
+            answer = E5MessageBox.yesNo(
+                self,
+                self.tr("Rename"),
+                self.tr("""<p>Is the highlighted code a match?</p>"""),
+                yesDefault=True)
+            aw.setCursorPosition(cline, cindex)
+            aw.ensureCursorVisible()
         
-        # display the file and select the match
-        vm.openSourceFile(filename)
-        aw = vm.activeWindow()
-        cline, cindex = aw.getCursorPosition()
-        sline, sindex = aw.lineIndexFromPosition(start)
-        eline, eindex = aw.lineIndexFromPosition(end)
-        aw.ensureLineVisible(sline)
-        aw.gotoLine(sline)
-        aw.setSelection(sline, sindex, eline, eindex)
-        ans = E5MessageBox.yesNo(
-            self,
-            self.tr("Rename"),
-            self.tr("""<p>Is the highlighted code a match?</p>"""),
-            yesDefault=True)
-        aw.setCursorPosition(cline, cindex)
-        aw.ensureCursorVisible()
-        
-        return ans
+        return answer
     
-    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.__renamer.get_changes(
-                self.newNameEdit.text(),
-                resources=self.__resources,
-                in_hierarchy=self.allCheckBox.isChecked(),
-                unsure=self.__confirmUnsure,
-                docs=self.stringsCheckBox.isChecked(),
-                task_handle=handle)
-            return changes
-        except Exception as err:
-            self._refactoring.handleRopeError(err, self._title, handle)
-            return None
+        self._refactoring.sendJson("CalculateRenameChanges", {
+            "Title": self._title,
+            "FileName": self.__filename,
+            "Offset": self.__offset,
+            "LocalRename": self.__local,
+            "NewName": self.newNameEdit.text(),
+            "RenameHierarchy": self.allCheckBox.isChecked(),
+            "RenameInStrings": self.stringsCheckBox.isChecked(),
+        })
+##        try:
+##            changes = self.__renamer.get_changes(
+##                self.newNameEdit.text(),
+##                resources=self.__resources,
+##                in_hierarchy=self.allCheckBox.isChecked(),
+##                unsure=self.__confirmUnsure,
+##                docs=self.stringsCheckBox.isChecked(),
+##                task_handle=handle)
+##            return changes
+##        except Exception as err:
+##            self._refactoring.handleRopeError(err, self._title, handle)
+##            return None
+    
+    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 == "ConfirmUnsure":
+            self.__confirmUnsure(data)
+        else:
+            # pass on to base class
+            RefactoringDialogBase.processChangeData(self, data)

eric ide

mercurial