RefactoringRope/IntroduceParameterDialog.py

branch
server_client_variant
changeset 181
3e3d6de2f0ca
parent 147
3f8a995f6e49
child 189
2711fdd91925
equal deleted inserted replaced
180:a33ef7ab8c54 181:3e3d6de2f0ca
19 class IntroduceParameterDialog(RefactoringDialogBase, 19 class IntroduceParameterDialog(RefactoringDialogBase,
20 Ui_IntroduceParameterDialog): 20 Ui_IntroduceParameterDialog):
21 """ 21 """
22 Class implementing the Introduce Parameter dialog. 22 Class implementing the Introduce Parameter dialog.
23 """ 23 """
24 def __init__(self, refactoring, title, introducer, parent=None): 24 def __init__(self, refactoring, title, filename, offset, parent=None):
25 """ 25 """
26 Constructor 26 Constructor
27 27
28 @param refactoring reference to the main refactoring object 28 @param refactoring reference to the main refactoring object
29 (Refactoring) 29 @type Refactoring
30 @param title title of the dialog (string) 30 @param title title of the dialog
31 @param introducer reference to the factory introducer object 31 @type str
32 (rope.refactor.introduce_parameter.IntroduceParameter) 32 @param filename file name to be worked on
33 @param parent reference to the parent widget (QWidget) 33 @type str
34 @param offset offset within file
35 @type int or None
36 @param parent reference to the parent widget
37 @type QWidget
34 """ 38 """
35 RefactoringDialogBase.__init__(self, refactoring, title, parent) 39 RefactoringDialogBase.__init__(self, refactoring, title, parent)
36 self.setupUi(self) 40 self.setupUi(self)
37 41
38 self.__introducer = introducer 42 self._changeGroupName = "IntroduceParameter"
43
44 self.__filename = filename
45 self.__offset = offset
39 46
40 self.__okButton = self.buttonBox.button(QDialogButtonBox.Ok) 47 self.__okButton = self.buttonBox.button(QDialogButtonBox.Ok)
41 self.__okButton.setEnabled(False) 48 self.__okButton.setEnabled(False)
42 self.__previewButton = self.buttonBox.addButton( 49 self.__previewButton = self.buttonBox.addButton(
43 self.tr("Preview"), QDialogButtonBox.ActionRole) 50 self.tr("Preview"), QDialogButtonBox.ActionRole)
44 self.__previewButton.setDefault(True) 51 self.__previewButton.setDefault(True)
52 self.__previewButton.setEnabled(False)
45 53
46 self.nameEdit.setText("new_parameter") 54 self.nameEdit.setText("new_parameter")
47 self.nameEdit.selectAll() 55 self.nameEdit.selectAll()
48 56
49 msh = self.minimumSizeHint() 57 msh = self.minimumSizeHint()
52 @pyqtSlot(str) 60 @pyqtSlot(str)
53 def on_nameEdit_textChanged(self, text): 61 def on_nameEdit_textChanged(self, text):
54 """ 62 """
55 Private slot to react to changes of the name. 63 Private slot to react to changes of the name.
56 64
57 @param text text entered into the edit (string) 65 @param text text entered into the edit
66 @type str
58 """ 67 """
59 self.__okButton.setEnabled(text != "") 68 enable = bool(text)
69 self.__okButton.setEnabled(enable)
70 self.__previewButton.setEnabled(enable)
60 71
61 @pyqtSlot(QAbstractButton) 72 @pyqtSlot(QAbstractButton)
62 def on_buttonBox_clicked(self, button): 73 def on_buttonBox_clicked(self, button):
63 """ 74 """
64 Private slot to act on the button pressed. 75 Private slot to act on the button pressed.
65 76
66 @param button reference to the button pressed (QAbstractButton) 77 @param button reference to the button pressed
78 @type QAbstractButton
67 """ 79 """
68 if button == self.__previewButton: 80 if button == self.__previewButton:
69 self.previewChanges() 81 self.requestPreview()
70 elif button == self.__okButton: 82 elif button == self.__okButton:
71 self.applyChanges() 83 self.applyChanges()
72 84
73 def _calculateChanges(self, handle): 85 def _calculateChanges(self):
74 """ 86 """
75 Protected method to calculate the changes. 87 Protected method to initiate the calculation of the changes.
76
77 @param handle reference to the task handle
78 (rope.base.taskhandle.TaskHandle)
79 @return reference to the Changes object (rope.base.change.ChangeSet)
80 """ 88 """
81 try: 89 self._refactoring.sendJson("CalculateIntroduceParameterChanges", {
82 changes = self.__introducer.get_changes(self.nameEdit.text()) 90 "ChangeGroup": self._changeGroupName,
83 return changes 91 "Title": self._title,
84 except Exception as err: 92 "FileName": self.__filename,
85 self._refactoring.handleRopeError(err, self._title, handle) 93 "Offset": self.__offset,
86 return None 94 "Name": self.nameEdit.text(),
95 })

eric ide

mercurial