|
1 # -*- coding: utf-8 -*- |
|
2 |
|
3 # Copyright (c) 2011 Detlev Offenbach <detlev@die-offenbachs.de> |
|
4 # |
|
5 |
|
6 """ |
|
7 Module implementing the Extract dialog. |
|
8 """ |
|
9 |
|
10 from PyQt4.QtCore import pyqtSlot |
|
11 from PyQt4.QtGui import QDialogButtonBox, QAbstractButton |
|
12 |
|
13 from Ui_ExtractDialog import Ui_ExtractDialog |
|
14 from RefactoringDialogBase import RefactoringDialogBase |
|
15 |
|
16 class ExtractDialog(RefactoringDialogBase, Ui_ExtractDialog): |
|
17 """ |
|
18 Class implementing the Extract dialog. |
|
19 """ |
|
20 def __init__(self, refactoring, title, extractor, parent=None): |
|
21 """ |
|
22 Constructor |
|
23 |
|
24 @param refactoring reference to the main refactoring object |
|
25 (Refactoring) |
|
26 @param title title of the dialog (string or QString) |
|
27 @param extractor reference to the extractor object |
|
28 (rope.refactor.extract.ExtractMethod or |
|
29 rope.refactor.extract.ExtractVariable) |
|
30 @param parent reference to the parent widget (QWidget) |
|
31 """ |
|
32 RefactoringDialogBase.__init__(self, refactoring, title, parent) |
|
33 self.setupUi(self) |
|
34 |
|
35 self.__extractor = extractor |
|
36 |
|
37 self.__okButton = self.buttonBox.button(QDialogButtonBox.Ok) |
|
38 self.__okButton.setEnabled(False) |
|
39 self.__previewButton = self.buttonBox.addButton( |
|
40 self.trUtf8("Preview"), QDialogButtonBox.ActionRole) |
|
41 self.__previewButton.setDefault(True) |
|
42 |
|
43 @pyqtSlot(str) |
|
44 def on_newNameEdit_textChanged(self, text): |
|
45 """ |
|
46 Private slot to react to changes of the new name. |
|
47 |
|
48 @param text text entered into the edit (string) |
|
49 """ |
|
50 self.__okButton.setEnabled(text != "") |
|
51 |
|
52 @pyqtSlot(QAbstractButton) |
|
53 def on_buttonBox_clicked(self, button): |
|
54 """ |
|
55 Private slot to act on the button pressed. |
|
56 |
|
57 @param button reference to the button pressed (QAbstractButton) |
|
58 """ |
|
59 if button == self.__previewButton: |
|
60 self.previewChanges() |
|
61 elif button == self.__okButton: |
|
62 self.applyChanges() |
|
63 |
|
64 def _calculateChanges(self, handle): |
|
65 """ |
|
66 Protected method to calculate the changes. |
|
67 |
|
68 @param handle reference to the task handle |
|
69 (rope.base.taskhandle.TaskHandle) |
|
70 @return reference to the Changes object (rope.base.change.ChangeSet) |
|
71 """ |
|
72 try: |
|
73 changes = self.__extractor.get_changes(self.newNameEdit.text(), |
|
74 similar=self.similarCheckBox.isChecked(), |
|
75 global_=self.globalCheckBox.isChecked()) |
|
76 return changes |
|
77 except Exception as err: |
|
78 self._refactoring.handleRopeError(err, self._title, handle) |
|
79 return None |