19 |
19 |
20 class RenameDialog(RefactoringDialogBase, Ui_RenameDialog): |
20 class RenameDialog(RefactoringDialogBase, Ui_RenameDialog): |
21 """ |
21 """ |
22 Class implementing the Rename dialog. |
22 Class implementing the Rename dialog. |
23 """ |
23 """ |
24 def __init__(self, refactoring, title, filename, offset, isLocal, |
24 |
25 selectedText='', parent=None): |
25 def __init__( |
|
26 self, |
|
27 refactoring, |
|
28 title, |
|
29 filename, |
|
30 offset, |
|
31 isLocal, |
|
32 selectedText="", |
|
33 parent=None, |
|
34 ): |
26 """ |
35 """ |
27 Constructor |
36 Constructor |
28 |
37 |
29 @param refactoring reference to the main refactoring object |
38 @param refactoring reference to the main refactoring object |
30 @type RefactoringServer |
39 @type RefactoringServer |
31 @param title title of the dialog |
40 @param title title of the dialog |
32 @type str |
41 @type str |
33 @param filename file name to be worked on |
42 @param filename file name to be worked on |
42 @param parent reference to the parent widget |
51 @param parent reference to the parent widget |
43 @type QWidget |
52 @type QWidget |
44 """ |
53 """ |
45 RefactoringDialogBase.__init__(self, refactoring, title, parent) |
54 RefactoringDialogBase.__init__(self, refactoring, title, parent) |
46 self.setupUi(self) |
55 self.setupUi(self) |
47 |
56 |
48 self._changeGroupName = "Rename" |
57 self._changeGroupName = "Rename" |
49 |
58 |
50 self.__filename = filename |
59 self.__filename = filename |
51 self.__offset = offset |
60 self.__offset = offset |
52 self.__local = isLocal |
61 self.__local = isLocal |
53 |
62 |
54 self.__okButton = self.buttonBox.button( |
63 self.__okButton = self.buttonBox.button(QDialogButtonBox.StandardButton.Ok) |
55 QDialogButtonBox.StandardButton.Ok) |
|
56 self.__okButton.setEnabled(False) |
64 self.__okButton.setEnabled(False) |
57 self.__previewButton = self.buttonBox.addButton( |
65 self.__previewButton = self.buttonBox.addButton( |
58 self.tr("Preview"), QDialogButtonBox.ButtonRole.ActionRole) |
66 self.tr("Preview"), QDialogButtonBox.ButtonRole.ActionRole |
|
67 ) |
59 self.__previewButton.setDefault(True) |
68 self.__previewButton.setDefault(True) |
60 self.__previewButton.setEnabled(False) |
69 self.__previewButton.setEnabled(False) |
61 |
70 |
62 self.newNameEdit.setText(selectedText) |
71 self.newNameEdit.setText(selectedText) |
63 self.newNameEdit.selectAll() |
72 self.newNameEdit.selectAll() |
64 |
73 |
65 msh = self.minimumSizeHint() |
74 msh = self.minimumSizeHint() |
66 self.resize(max(self.width(), msh.width()), msh.height()) |
75 self.resize(max(self.width(), msh.width()), msh.height()) |
67 |
76 |
68 @pyqtSlot(str) |
77 @pyqtSlot(str) |
69 def on_newNameEdit_textChanged(self, text): |
78 def on_newNameEdit_textChanged(self, text): |
70 """ |
79 """ |
71 Private slot to react to changes of the new name. |
80 Private slot to react to changes of the new name. |
72 |
81 |
73 @param text text entered into the edit |
82 @param text text entered into the edit |
74 @type str |
83 @type str |
75 """ |
84 """ |
76 self.__okButton.setEnabled(text != "") |
85 self.__okButton.setEnabled(text != "") |
77 self.__previewButton.setEnabled(text != "") |
86 self.__previewButton.setEnabled(text != "") |
78 |
87 |
79 @pyqtSlot(QAbstractButton) |
88 @pyqtSlot(QAbstractButton) |
80 def on_buttonBox_clicked(self, button): |
89 def on_buttonBox_clicked(self, button): |
81 """ |
90 """ |
82 Private slot to act on the button pressed. |
91 Private slot to act on the button pressed. |
83 |
92 |
84 @param button reference to the button pressed |
93 @param button reference to the button pressed |
85 @type QAbstractButton |
94 @type QAbstractButton |
86 """ |
95 """ |
87 if button == self.__previewButton: |
96 if button == self.__previewButton: |
88 self.requestPreview() |
97 self.requestPreview() |
89 elif button == self.__okButton: |
98 elif button == self.__okButton: |
90 self.applyChanges() |
99 self.applyChanges() |
91 |
100 |
92 def __confirmUnsure(self, data): |
101 def __confirmUnsure(self, data): |
93 """ |
102 """ |
94 Private method to confirm unsure occurrences. |
103 Private method to confirm unsure occurrences. |
95 |
104 |
96 @param data dictionary containing the change data |
105 @param data dictionary containing the change data |
97 @type dict |
106 @type dict |
98 """ |
107 """ |
99 if self.ignoreButton.isChecked(): |
108 if self.ignoreButton.isChecked(): |
100 answer = False |
109 answer = False |
102 answer = True |
111 answer = True |
103 else: |
112 else: |
104 filename = data["FileName"] |
113 filename = data["FileName"] |
105 start = data["StartOffset"] |
114 start = data["StartOffset"] |
106 end = data["EndOffset"] |
115 end = data["EndOffset"] |
107 |
116 |
108 vm = ericApp().getObject("ViewManager") |
117 vm = ericApp().getObject("ViewManager") |
109 |
118 |
110 # display the file and select the match |
119 # display the file and select the match |
111 vm.openSourceFile(filename) |
120 vm.openSourceFile(filename) |
112 aw = vm.activeWindow() |
121 aw = vm.activeWindow() |
113 cline, cindex = aw.getCursorPosition() |
122 cline, cindex = aw.getCursorPosition() |
114 sline, sindex = aw.lineIndexFromPosition(start) |
123 sline, sindex = aw.lineIndexFromPosition(start) |
115 eline, eindex = aw.lineIndexFromPosition(end) |
124 eline, eindex = aw.lineIndexFromPosition(end) |
116 aw.ensureLineVisible(sline) |
125 aw.ensureLineVisible(sline) |
117 aw.gotoLine(sline) |
126 aw.gotoLine(sline) |
118 aw.setSelection(sline, sindex, eline, eindex) |
127 aw.setSelection(sline, sindex, eline, eindex) |
119 |
128 |
120 answer = EricMessageBox.yesNo( |
129 answer = EricMessageBox.yesNo( |
121 self._ui, |
130 self._ui, |
122 self.tr("Rename"), |
131 self.tr("Rename"), |
123 self.tr("""<p>Is the highlighted code a match?</p>"""), |
132 self.tr("""<p>Is the highlighted code a match?</p>"""), |
124 yesDefault=True) |
133 yesDefault=True, |
125 |
134 ) |
|
135 |
126 aw.setCursorPosition(cline, cindex) |
136 aw.setCursorPosition(cline, cindex) |
127 aw.ensureCursorVisible() |
137 aw.ensureCursorVisible() |
128 |
138 |
129 self._refactoring.sendJson("ConfirmUnsure", { |
139 self._refactoring.sendJson( |
130 "Answer": answer, |
140 "ConfirmUnsure", |
131 }) |
141 { |
132 |
142 "Answer": answer, |
|
143 }, |
|
144 ) |
|
145 |
133 def _calculateChanges(self): |
146 def _calculateChanges(self): |
134 """ |
147 """ |
135 Protected method to initiate the calculation of the changes. |
148 Protected method to initiate the calculation of the changes. |
136 """ |
149 """ |
137 if self.askButton.isChecked(): |
150 if self.askButton.isChecked(): |
138 self.hide() |
151 self.hide() |
139 |
152 |
140 self._refactoring.sendJson("CalculateRenameChanges", { |
153 self._refactoring.sendJson( |
141 "ChangeGroup": self._changeGroupName, |
154 "CalculateRenameChanges", |
142 "Title": self._title, |
155 { |
143 "FileName": self.__filename, |
156 "ChangeGroup": self._changeGroupName, |
144 "Offset": self.__offset, |
157 "Title": self._title, |
145 "LocalRename": self.__local, |
158 "FileName": self.__filename, |
146 "NewName": self.newNameEdit.text(), |
159 "Offset": self.__offset, |
147 "RenameHierarchy": self.allCheckBox.isChecked(), |
160 "LocalRename": self.__local, |
148 "RenameInStrings": self.stringsCheckBox.isChecked(), |
161 "NewName": self.newNameEdit.text(), |
149 }) |
162 "RenameHierarchy": self.allCheckBox.isChecked(), |
150 |
163 "RenameInStrings": self.stringsCheckBox.isChecked(), |
|
164 }, |
|
165 ) |
|
166 |
151 def processChangeData(self, data): |
167 def processChangeData(self, data): |
152 """ |
168 """ |
153 Public method to process the change data sent by the refactoring |
169 Public method to process the change data sent by the refactoring |
154 client. |
170 client. |
155 |
171 |
156 @param data dictionary containing the change data |
172 @param data dictionary containing the change data |
157 @type dict |
173 @type dict |
158 """ |
174 """ |
159 subcommand = data["Subcommand"] |
175 subcommand = data["Subcommand"] |
160 if subcommand == "ConfirmUnsure": |
176 if subcommand == "ConfirmUnsure": |