--- a/RefactoringRope/InlineDialog.py Wed Sep 20 19:49:26 2017 +0200 +++ b/RefactoringRope/InlineDialog.py Thu Sep 21 19:18:51 2017 +0200 @@ -12,8 +12,6 @@ from PyQt5.QtCore import pyqtSlot from PyQt5.QtWidgets import QDialogButtonBox, QAbstractButton -import rope.refactor.inline - from Ui_InlineDialog import Ui_InlineDialog from RefactoringDialogBase import RefactoringDialogBase @@ -22,26 +20,54 @@ """ Class implementing the Inline dialog. """ - def __init__(self, refactoring, title, inliner, 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 inliner reference to the inliner object - (rope.refactor.inline.InlineMethod, - rope.refactor.inline.InlineVariable - or rope.refactor.inline.InlineParameter) - @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.__inliner = inliner + self._changeGroupName = "Inline" + + 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.__inlinerKind = "" - # polish up the dialog - if isinstance(self.__inliner, rope.refactor.inline.InlineParameter): + self._refactoring.sendJson("RequestInlineType", { + "ChangeGroup": self._changeGroupName, + "Title": self._title, + "FileName": self.__filename, + "Offset": self.__offset, + }) + + def __processInlineType(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 change data + @type dict + """ + self.__inlinerKind = data["Kind"] + + if data["Kind"] == "parameter": self.removeCheckBox.setVisible(False) self.currentCheckBox.setVisible(False) self.hierarchyCheckBox.setVisible(True) @@ -52,13 +78,8 @@ self.resize(500, 20) self.description.setText( - self.tr("Inlining occurrences of <b>{0}</b> (type {1}).") - .format(self.__inliner.name, self.__inliner.get_kind())) - - self.__okButton = self.buttonBox.button(QDialogButtonBox.Ok) - self.__previewButton = self.buttonBox.addButton( - self.tr("Preview"), QDialogButtonBox.ActionRole) - self.__previewButton.setDefault(True) + self.tr("Inlining occurrences of <b>{0}</b> (type '<i>{1}</i>').") + .format(data["Name"], data["Kind"])) msh = self.minimumSizeHint() self.resize(max(self.width(), msh.width()), msh.height()) @@ -68,34 +89,40 @@ """ 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: - if isinstance(self.__inliner, - rope.refactor.inline.InlineParameter): - opts = { - "in_hierarchy": self.hierarchyCheckBox.isChecked(), - } - else: - opts = { - "remove": self.removeCheckBox.isChecked(), - "only_current": self.currentCheckBox.isChecked(), - } - changes = self.__inliner.get_changes(task_handle=handle, **opts) - return changes - except Exception as err: - self._refactoring.handleRopeError(err, self._title, handle) - return None + self._refactoring.sendJson("CalculateInlineChanges", { + "ChangeGroup": self._changeGroupName, + "Title": self._title, + "FileName": self.__filename, + "Offset": self.__offset, + "Kind": self.__inlinerKind, + "Hierarchy": self.hierarchyCheckBox.isChecked(), + "Remove": self.removeCheckBox.isChecked(), + "OnlyCurrent": self.currentCheckBox.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 == "InlineType": + self.__processInlineType(data) + else: + # pass on to base class + RefactoringDialogBase.processChangeData(self, data)