|
1 # -*- coding: utf-8 -*- |
|
2 |
|
3 # Copyright (c) 2011 Detlev Offenbach <detlev@die-offenbachs.de> |
|
4 # |
|
5 |
|
6 """ |
|
7 Module implementing the Change Occurrences dialog. |
|
8 """ |
|
9 |
|
10 from PyQt4.QtCore import pyqtSlot |
|
11 from PyQt4.QtGui import QDialogButtonBox, QAbstractButton |
|
12 |
|
13 from Ui_ChangeOccurrencesDialog import Ui_ChangeOccurrencesDialog |
|
14 from RefactoringDialogBase import RefactoringDialogBase |
|
15 |
|
16 class ChangeOccurrencesDialog(RefactoringDialogBase, |
|
17 Ui_ChangeOccurrencesDialog): |
|
18 """ |
|
19 Class implementing the Change Occurrences dialog. |
|
20 """ |
|
21 def __init__(self, refactoring, title, renamer, parent = None): |
|
22 """ |
|
23 Constructor |
|
24 |
|
25 @param refactoring reference to the main refactoring object |
|
26 (Refactoring) |
|
27 @param title title of the dialog (string) |
|
28 @param renamer reference to the renamer object |
|
29 (rope.refactor.rename.Rename) |
|
30 @param parent reference to the parent widget (QWidget) |
|
31 """ |
|
32 RefactoringDialogBase.__init__(self, refactoring, title, parent) |
|
33 self.setupUi(self) |
|
34 |
|
35 self.__renamer = renamer |
|
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_replaceEdit_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.__renamer.get_changes(self.replaceEdit.text(), |
|
74 only_calls=self.onlyCallsCheckBox.isChecked(), |
|
75 reads=self.readsCheckBox.isChecked(), |
|
76 writes=self.writesCheckBox.isChecked()) |
|
77 return changes |
|
78 except Exception as err: |
|
79 self._refactoring.handleRopeError(err, self._title, handle) |
|
80 return None |