16 |
16 |
17 class RestructureDialog(RefactoringDialogBase, Ui_RestructureDialog): |
17 class RestructureDialog(RefactoringDialogBase, Ui_RestructureDialog): |
18 """ |
18 """ |
19 Class implementing the Restructure dialog. |
19 Class implementing the Restructure dialog. |
20 """ |
20 """ |
|
21 |
21 history = None |
22 history = None |
22 |
23 |
23 def __init__(self, refactoring, title, parent=None): |
24 def __init__(self, refactoring, title, 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 @type RefactoringServer |
29 @type RefactoringServer |
29 @param title title of the dialog |
30 @param title title of the dialog |
30 @type str |
31 @type str |
31 @param parent reference to the parent widget |
32 @param parent reference to the parent widget |
32 @type QWidget |
33 @type QWidget |
33 """ |
34 """ |
34 RefactoringDialogBase.__init__(self, refactoring, title, parent) |
35 RefactoringDialogBase.__init__(self, refactoring, title, parent) |
35 self.setupUi(self) |
36 self.setupUi(self) |
36 |
37 |
37 self._changeGroupName = "Restructure" |
38 self._changeGroupName = "Restructure" |
38 |
39 |
39 self.__okButton = self.buttonBox.button( |
40 self.__okButton = self.buttonBox.button(QDialogButtonBox.StandardButton.Ok) |
40 QDialogButtonBox.StandardButton.Ok) |
|
41 self.__okButton.setEnabled(False) |
41 self.__okButton.setEnabled(False) |
42 self.__previewButton = self.buttonBox.addButton( |
42 self.__previewButton = self.buttonBox.addButton( |
43 self.tr("Preview"), QDialogButtonBox.ButtonRole.ActionRole) |
43 self.tr("Preview"), QDialogButtonBox.ButtonRole.ActionRole |
|
44 ) |
44 self.__previewButton.setDefault(True) |
45 self.__previewButton.setDefault(True) |
45 self.__previewButton.setEnabled(False) |
46 self.__previewButton.setEnabled(False) |
46 |
47 |
47 self.__loadData() |
48 self.__loadData() |
48 |
49 |
49 def __updateUI(self): |
50 def __updateUI(self): |
50 """ |
51 """ |
51 Private slot to update the UI. |
52 Private slot to update the UI. |
52 """ |
53 """ |
53 enable = ( |
54 enable = bool(self.patternEdit.toPlainText()) and bool( |
54 bool(self.patternEdit.toPlainText()) and |
55 self.goalEdit.toPlainText() |
55 bool(self.goalEdit.toPlainText()) |
|
56 ) |
56 ) |
57 |
57 |
58 self.__okButton.setEnabled(enable) |
58 self.__okButton.setEnabled(enable) |
59 self.__previewButton.setEnabled(enable) |
59 self.__previewButton.setEnabled(enable) |
60 |
60 |
61 @pyqtSlot() |
61 @pyqtSlot() |
62 def on_patternEdit_textChanged(self): |
62 def on_patternEdit_textChanged(self): |
63 """ |
63 """ |
64 Private slot to react to changes of the pattern. |
64 Private slot to react to changes of the pattern. |
65 """ |
65 """ |
66 self.__updateUI() |
66 self.__updateUI() |
67 |
67 |
68 @pyqtSlot() |
68 @pyqtSlot() |
69 def on_goalEdit_textChanged(self): |
69 def on_goalEdit_textChanged(self): |
70 """ |
70 """ |
71 Private slot to react to changes of the goal. |
71 Private slot to react to changes of the goal. |
72 """ |
72 """ |
73 self.__updateUI() |
73 self.__updateUI() |
74 |
74 |
75 @pyqtSlot(QAbstractButton) |
75 @pyqtSlot(QAbstractButton) |
76 def on_buttonBox_clicked(self, button): |
76 def on_buttonBox_clicked(self, button): |
77 """ |
77 """ |
78 Private slot to act on the button pressed. |
78 Private slot to act on the button pressed. |
79 |
79 |
80 @param button reference to the button pressed |
80 @param button reference to the button pressed |
81 @type QAbstractButton |
81 @type QAbstractButton |
82 """ |
82 """ |
83 if button == self.__previewButton: |
83 if button == self.__previewButton: |
84 self.requestPreview() |
84 self.requestPreview() |
85 elif button == self.__okButton: |
85 elif button == self.__okButton: |
86 self.applyChanges() |
86 self.applyChanges() |
87 |
87 |
88 def _calculateChanges(self): |
88 def _calculateChanges(self): |
89 """ |
89 """ |
90 Protected method to initiate the calculation of the changes. |
90 Protected method to initiate the calculation of the changes. |
91 """ |
91 """ |
92 self.__saveData() |
92 self.__saveData() |
93 |
93 |
94 pattern = self.patternEdit.toPlainText() |
94 pattern = self.patternEdit.toPlainText() |
95 goal = self.goalEdit.toPlainText() |
95 goal = self.goalEdit.toPlainText() |
96 imports = [line for line in self.importsEdit.toPlainText().splitlines() |
96 imports = [ |
97 if line.strip()] |
97 line for line in self.importsEdit.toPlainText().splitlines() if line.strip() |
98 |
98 ] |
|
99 |
99 args = {} |
100 args = {} |
100 checks = self.argsEdit.toPlainText().splitlines() |
101 checks = self.argsEdit.toPlainText().splitlines() |
101 for check in checks: |
102 for check in checks: |
102 if ':' in check: |
103 if ":" in check: |
103 splitted = check.split(':', 1) |
104 splitted = check.split(":", 1) |
104 name = splitted[0].strip() |
105 name = splitted[0].strip() |
105 value = splitted[1].strip() |
106 value = splitted[1].strip() |
106 args[name] = value |
107 args[name] = value |
107 |
108 |
108 self._refactoring.sendJson("CalculateRestructureChanges", { |
109 self._refactoring.sendJson( |
109 "ChangeGroup": self._changeGroupName, |
110 "CalculateRestructureChanges", |
110 "Title": self._title, |
111 { |
111 "Pattern": pattern, |
112 "ChangeGroup": self._changeGroupName, |
112 "Goal": goal, |
113 "Title": self._title, |
113 "Args": args, |
114 "Pattern": pattern, |
114 "Imports": imports, |
115 "Goal": goal, |
115 }) |
116 "Args": args, |
116 |
117 "Imports": imports, |
|
118 }, |
|
119 ) |
|
120 |
117 def __saveData(self): |
121 def __saveData(self): |
118 """ |
122 """ |
119 Private slot to save the data for later reuse. |
123 Private slot to save the data for later reuse. |
120 """ |
124 """ |
121 data = {'pattern': self.patternEdit.toPlainText(), |
125 data = { |
122 'goal': self.goalEdit.toPlainText(), |
126 "pattern": self.patternEdit.toPlainText(), |
123 'checks': self.argsEdit.toPlainText(), |
127 "goal": self.goalEdit.toPlainText(), |
124 'imports': self.importsEdit.toPlainText() |
128 "checks": self.argsEdit.toPlainText(), |
125 } |
129 "imports": self.importsEdit.toPlainText(), |
|
130 } |
126 RestructureDialog.history = data |
131 RestructureDialog.history = data |
127 |
132 |
128 def __loadData(self): |
133 def __loadData(self): |
129 """ |
134 """ |
130 Private slot to load the history data into the dialog. |
135 Private slot to load the history data into the dialog. |
131 """ |
136 """ |
132 if RestructureDialog.history is not None: |
137 if RestructureDialog.history is not None: |
133 data = RestructureDialog.history |
138 data = RestructureDialog.history |
134 self.patternEdit.setPlainText(data['pattern']) |
139 self.patternEdit.setPlainText(data["pattern"]) |
135 self.goalEdit.setPlainText(data['goal']) |
140 self.goalEdit.setPlainText(data["goal"]) |
136 self.argsEdit.setPlainText(data['checks']) |
141 self.argsEdit.setPlainText(data["checks"]) |
137 self.importsEdit.setPlainText(data['imports']) |
142 self.importsEdit.setPlainText(data["imports"]) |