19 class MethodToMethodObjectDialog(RefactoringDialogBase, |
19 class MethodToMethodObjectDialog(RefactoringDialogBase, |
20 Ui_MethodToMethodObjectDialog): |
20 Ui_MethodToMethodObjectDialog): |
21 """ |
21 """ |
22 Class implementing the Method To Method object dialog. |
22 Class implementing the Method To Method object dialog. |
23 """ |
23 """ |
24 def __init__(self, refactoring, title, converter, 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 converter reference to the converter object |
31 @type str |
32 (rope.refactor.method_object.MethodObject) |
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.__converter = converter |
42 self._changeGroupName = "MethodToMethodObject" |
|
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("_MethodObject") |
54 self.nameEdit.setText("_MethodObject") |
47 self.nameEdit.selectAll() |
55 self.nameEdit.selectAll() |
48 |
56 |
49 msh = self.minimumSizeHint() |
57 msh = self.minimumSizeHint() |
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 (string) |
58 """ |
66 """ |
59 self.__okButton.setEnabled(text != "") |
67 self.__okButton.setEnabled(bool(text)) |
|
68 self.__previewButton.setEnabled(bool(text)) |
60 |
69 |
61 @pyqtSlot(QAbstractButton) |
70 @pyqtSlot(QAbstractButton) |
62 def on_buttonBox_clicked(self, button): |
71 def on_buttonBox_clicked(self, button): |
63 """ |
72 """ |
64 Private slot to act on the button pressed. |
73 Private slot to act on the button pressed. |
65 |
74 |
66 @param button reference to the button pressed (QAbstractButton) |
75 @param button reference to the button pressed (QAbstractButton) |
67 """ |
76 """ |
68 if button == self.__previewButton: |
77 if button == self.__previewButton: |
69 self.previewChanges() |
78 self.requestPreview() |
70 elif button == self.__okButton: |
79 elif button == self.__okButton: |
71 self.applyChanges() |
80 self.applyChanges() |
72 |
81 |
73 def _calculateChanges(self, handle): |
82 def _calculateChanges(self): |
74 """ |
83 """ |
75 Protected method to calculate the changes. |
84 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 """ |
85 """ |
81 try: |
86 self._refactoring.sendJson("CalculateMethodObjectChanges", { |
82 changes = self.__converter.get_changes(self.nameEdit.text()) |
87 "ChangeGroup": self._changeGroupName, |
83 return changes |
88 "Title": self._title, |
84 except Exception as err: |
89 "FileName": self.__filename, |
85 self._refactoring.handleRopeError(err, self._title, handle) |
90 "Offset": self.__offset, |
86 return None |
91 "Name": self.nameEdit.text(), |
|
92 }) |