8 """ |
8 """ |
9 |
9 |
10 from __future__ import unicode_literals |
10 from __future__ import unicode_literals |
11 |
11 |
12 from PyQt5.QtCore import pyqtSlot |
12 from PyQt5.QtCore import pyqtSlot |
13 from PyQt5.QtWidgets import QDialog, QDialogButtonBox, QAbstractButton |
13 from PyQt5.QtWidgets import QDialogButtonBox, QAbstractButton |
14 |
14 |
15 from Ui_ConfirmationDialog import Ui_ConfirmationDialog |
15 from Ui_ConfirmationDialog import Ui_ConfirmationDialog |
|
16 from RefactoringDialogBase import RefactoringDialogBase |
16 |
17 |
17 import Utilities |
18 import Utilities |
18 |
19 |
19 |
20 |
20 class ConfirmationDialog(QDialog, Ui_ConfirmationDialog): |
21 class ConfirmationDialog(RefactoringDialogBase, Ui_ConfirmationDialog): |
21 """ |
22 """ |
22 Class implementing the Confirmation dialog. |
23 Class implementing the Confirmation dialog. |
23 """ |
24 """ |
24 def __init__(self, changes, parent=None): |
25 def __init__(self, refactoring, title, changeGroupName, method, parameters, |
|
26 parent=None): |
25 """ |
27 """ |
26 Constructor |
28 Constructor |
27 |
29 |
28 @param changes reference to the Changes object |
30 @param refactoring reference to the main refactoring object |
29 (rope.base.change.ChangeSet) |
31 @type Refactoring |
30 @param parent reference to the parent widget (QWidget) |
32 @param title title of the dialog |
|
33 @type str |
|
34 @param changeGroupName name of the change group |
|
35 @type str |
|
36 @param method method to produce the refactoring changes |
|
37 @type str |
|
38 @param parameters dictionary containing the method parameters |
|
39 @type dict |
|
40 @param parent reference to the parent widget |
|
41 @type QWidget |
31 """ |
42 """ |
32 QDialog.__init__(self, parent) |
43 RefactoringDialogBase.__init__(self, refactoring, title, parent) |
33 self.setupUi(self) |
44 self.setupUi(self) |
34 |
45 |
35 self.__changes = changes |
46 self._changeGroupName = changeGroupName |
36 |
|
37 self.description.setText( |
|
38 self.tr("Shall the refactoring <b>{0}</b> be done?") |
|
39 .format(Utilities.html_encode(self.__changes.description))) |
|
40 |
47 |
41 self.__okButton = self.buttonBox.button(QDialogButtonBox.Ok) |
48 self.__okButton = self.buttonBox.button(QDialogButtonBox.Ok) |
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 |
|
53 self.__method = method |
|
54 self.__parameters = parameters |
|
55 |
|
56 self._calculateChanges() |
|
57 |
|
58 def __processChangeDescription(self, data): |
|
59 """ |
|
60 Private method to process the change description data sent by the |
|
61 refactoring client in order to polish the dialog. |
|
62 |
|
63 @param data dictionary containing the data |
|
64 @type dict |
|
65 """ |
|
66 changeDescription = data["Description"] |
|
67 if changeDescription: |
|
68 self.description.setText( |
|
69 self.tr("Shall the refactoring <b>{0}</b> be done?") |
|
70 .format(Utilities.html_encode(changeDescription))) |
|
71 else: |
|
72 self.description.setText( |
|
73 self.tr("The selected refactoring did not produce any" |
|
74 " changes.")) |
|
75 self.__okButton.setEnabled(False) |
|
76 self.__previewButton.setEnabled(False) |
45 |
77 |
46 msh = self.minimumSizeHint() |
78 msh = self.minimumSizeHint() |
47 self.resize(max(self.width(), msh.width()), msh.height()) |
79 self.resize(max(self.width(), msh.width()), msh.height()) |
48 |
80 |
49 @pyqtSlot(QAbstractButton) |
81 @pyqtSlot(QAbstractButton) |
50 def on_buttonBox_clicked(self, button): |
82 def on_buttonBox_clicked(self, button): |
51 """ |
83 """ |
52 Private slot to act on the button pressed. |
84 Private slot to act on the button pressed. |
53 |
85 |
54 @param button reference to the button pressed (QAbstractButton) |
86 @param button reference to the button pressed |
|
87 @type QAbstractButton |
55 """ |
88 """ |
56 if button == self.__previewButton: |
89 if button == self.__previewButton: |
57 self.__previewChanges() |
90 self.requestPreview() |
|
91 elif button == self.__okButton: |
|
92 self.applyChanges() |
58 |
93 |
59 def __previewChanges(self): |
94 def _calculateChanges(self): |
60 """ |
95 """ |
61 Private method to preview the changes. |
96 Protected method to initiate the calculation of the changes. |
62 """ |
97 """ |
63 from ChangesPreviewDialog import ChangesPreviewDialog |
98 if "ChangeGroup" not in self.__parameters: |
64 dlg = ChangesPreviewDialog(self.__changes, self) |
99 self.__parameters["ChangeGroup"] = self._changeGroupName |
65 if dlg.exec_() == QDialog.Accepted: |
100 if "Title" not in self.__parameters: |
66 self.accept() |
101 self.__parameters["Title"] = self._title |
|
102 |
|
103 self._refactoring.sendJson(self.__method, self.__parameters) |
|
104 |
|
105 def processChangeData(self, data): |
|
106 """ |
|
107 Public method to process the change data sent by the refactoring |
|
108 client. |
|
109 |
|
110 @param data dictionary containing the change data |
|
111 @type dict |
|
112 """ |
|
113 subcommand = data["Subcommand"] |
|
114 if subcommand == "ChangeDescription": |
|
115 self.__processChangeDescription(data) |
|
116 else: |
|
117 # pass on to base class |
|
118 RefactoringDialogBase.processChangeData(self, data) |