18 |
18 |
19 class ExtractDialog(RefactoringDialogBase, Ui_ExtractDialog): |
19 class ExtractDialog(RefactoringDialogBase, Ui_ExtractDialog): |
20 """ |
20 """ |
21 Class implementing the Extract dialog. |
21 Class implementing the Extract dialog. |
22 """ |
22 """ |
23 def __init__(self, refactoring, title, extractor, parent=None): |
23 def __init__(self, refactoring, title, filename, startOffset, endOffset, |
|
24 extractionType, parent=None): |
24 """ |
25 """ |
25 Constructor |
26 Constructor |
26 |
27 |
27 @param refactoring reference to the main refactoring object |
28 @param refactoring reference to the main refactoring object |
28 (Refactoring) |
29 @type Refactoring |
29 @param title title of the dialog (string) |
30 @param title title of the dialog |
30 @param extractor reference to the extractor object |
31 @str str |
31 (rope.refactor.extract.ExtractMethod or |
32 @param filename file name to be worked on |
32 rope.refactor.extract.ExtractVariable) |
33 @type str |
33 @param parent reference to the parent widget (QWidget) |
34 @param startOffset offset within file to start extraction |
|
35 @type int |
|
36 @param endOffset offset within file to end extraction |
|
37 @type int |
|
38 @param parent reference to the parent widget |
|
39 @type QWidget |
34 """ |
40 """ |
35 RefactoringDialogBase.__init__(self, refactoring, title, parent) |
41 RefactoringDialogBase.__init__(self, refactoring, title, parent) |
36 self.setupUi(self) |
42 self.setupUi(self) |
37 |
43 |
38 self.__extractor = extractor |
44 self._changeGroupName = "Extract" |
|
45 |
|
46 self.__filename = filename |
|
47 self.__startOffset = startOffset |
|
48 self.__endOffset = endOffset |
|
49 self.__extractionType = extractionType |
39 |
50 |
40 self.__okButton = self.buttonBox.button(QDialogButtonBox.Ok) |
51 self.__okButton = self.buttonBox.button(QDialogButtonBox.Ok) |
41 self.__okButton.setEnabled(False) |
52 self.__okButton.setEnabled(False) |
42 self.__previewButton = self.buttonBox.addButton( |
53 self.__previewButton = self.buttonBox.addButton( |
43 self.tr("Preview"), QDialogButtonBox.ActionRole) |
54 self.tr("Preview"), QDialogButtonBox.ActionRole) |
49 @pyqtSlot(str) |
60 @pyqtSlot(str) |
50 def on_newNameEdit_textChanged(self, text): |
61 def on_newNameEdit_textChanged(self, text): |
51 """ |
62 """ |
52 Private slot to react to changes of the new name. |
63 Private slot to react to changes of the new name. |
53 |
64 |
54 @param text text entered into the edit (string) |
65 @param text text entered into the edit |
|
66 @type str |
55 """ |
67 """ |
56 self.__okButton.setEnabled(text != "") |
68 self.__okButton.setEnabled(text != "") |
57 |
69 |
58 @pyqtSlot(QAbstractButton) |
70 @pyqtSlot(QAbstractButton) |
59 def on_buttonBox_clicked(self, button): |
71 def on_buttonBox_clicked(self, button): |
60 """ |
72 """ |
61 Private slot to act on the button pressed. |
73 Private slot to act on the button pressed. |
62 |
74 |
63 @param button reference to the button pressed (QAbstractButton) |
75 @param button reference to the button pressed |
|
76 @type QAbstractButton |
64 """ |
77 """ |
65 if button == self.__previewButton: |
78 if button == self.__previewButton: |
66 self.previewChanges() |
79 self.requestPreview() |
67 elif button == self.__okButton: |
80 elif button == self.__okButton: |
68 self.applyChanges() |
81 self.applyChanges() |
69 |
82 |
70 def _calculateChanges(self, handle): |
83 def _calculateChanges(self): |
71 """ |
84 """ |
72 Protected method to calculate the changes. |
85 Protected method to calculate the changes. |
73 |
|
74 @param handle reference to the task handle |
|
75 (rope.base.taskhandle.TaskHandle) |
|
76 @return reference to the Changes object (rope.base.change.ChangeSet) |
|
77 """ |
86 """ |
78 try: |
87 self._refactoring.sendJson("CalculateExtractChanges", { |
79 changes = self.__extractor.get_changes( |
88 "ChangeGroup": self._changeGroupName, |
80 self.newNameEdit.text(), |
89 "Title": self._title, |
81 similar=self.similarCheckBox.isChecked(), |
90 "FileName": self.__filename, |
82 global_=self.globalCheckBox.isChecked()) |
91 "StartOffset": self.__startOffset, |
83 return changes |
92 "EndOffset": self.__endOffset, |
84 except Exception as err: |
93 "Kind": self.__extractionType, |
85 self._refactoring.handleRopeError(err, self._title, handle) |
94 "NewName": self.newNameEdit.text(), |
86 return None |
95 "Similar": self.similarCheckBox.isChecked(), |
|
96 "Global": self.globalCheckBox.isChecked(), |
|
97 }) |