21 |
21 |
22 class RenameDialog(RefactoringDialogBase, Ui_RenameDialog): |
22 class RenameDialog(RefactoringDialogBase, Ui_RenameDialog): |
23 """ |
23 """ |
24 Class implementing the Rename dialog. |
24 Class implementing the Rename dialog. |
25 """ |
25 """ |
26 def __init__(self, refactoring, title, renamer, resource=None, |
26 def __init__(self, refactoring, title, filename, offset, isLocal, |
27 selectedText='', parent=None): |
27 selectedText='', parent=None): |
28 """ |
28 """ |
29 Constructor |
29 Constructor |
30 |
30 |
31 @param refactoring reference to the main refactoring object |
31 @param refactoring reference to the main refactoring object |
32 (Refactoring) |
32 @type Refactoring |
33 @param title title of the dialog (string) |
33 @param title title of the dialog |
34 @param renamer reference to the renamer object |
34 @type str |
35 (rope.refactor.rename.Rename) |
35 @param filename file name to be worked on |
36 @param resource reference to a resource object, if the action is to |
36 @type str |
37 be applied to the local file only (rope.base.resources.File) |
37 @param offset offset within file |
38 @param selectedText selected text to rename (str) |
38 @type int or None |
39 @param parent reference to the parent widget (QWidget) |
39 @param isLocal flag indicating to restrict refactoring to |
|
40 the local file |
|
41 @type bool |
|
42 @param selectedText selected text to rename |
|
43 @type str |
|
44 @param parent reference to the parent widget |
|
45 @type QWidget |
40 """ |
46 """ |
41 RefactoringDialogBase.__init__(self, refactoring, title, parent) |
47 RefactoringDialogBase.__init__(self, refactoring, title, parent) |
42 self.setupUi(self) |
48 self.setupUi(self) |
43 |
49 |
44 self.__renamer = renamer |
50 self._changeGroupName = "Rename" |
45 if resource is not None: |
|
46 self.__resources = [resource] |
|
47 else: |
|
48 self.__resources = None |
|
49 |
51 |
|
52 self.__filename = filename |
|
53 self.__offset = offset |
|
54 self.__local = isLocal |
|
55 ## self.__renamer = renamer |
|
56 ## if resource is not None: |
|
57 ## self.__resources = [resource] |
|
58 ## else: |
|
59 ## self.__resources = None |
|
60 ## |
50 self.__okButton = self.buttonBox.button(QDialogButtonBox.Ok) |
61 self.__okButton = self.buttonBox.button(QDialogButtonBox.Ok) |
51 self.__okButton.setEnabled(False) |
62 self.__okButton.setEnabled(False) |
52 self.__previewButton = self.buttonBox.addButton( |
63 self.__previewButton = self.buttonBox.addButton( |
53 self.tr("Preview"), QDialogButtonBox.ActionRole) |
64 self.tr("Preview"), QDialogButtonBox.ActionRole) |
54 self.__previewButton.setDefault(True) |
65 self.__previewButton.setDefault(True) |
|
66 |
55 self.newNameEdit.setText(selectedText) |
67 self.newNameEdit.setText(selectedText) |
56 self.newNameEdit.selectAll() |
68 self.newNameEdit.selectAll() |
57 |
69 |
58 msh = self.minimumSizeHint() |
70 msh = self.minimumSizeHint() |
59 self.resize(max(self.width(), msh.width()), msh.height()) |
71 self.resize(max(self.width(), msh.width()), msh.height()) |
73 Private slot to act on the button pressed. |
85 Private slot to act on the button pressed. |
74 |
86 |
75 @param button reference to the button pressed (QAbstractButton) |
87 @param button reference to the button pressed (QAbstractButton) |
76 """ |
88 """ |
77 if button == self.__previewButton: |
89 if button == self.__previewButton: |
78 self.previewChanges() |
90 self.requestPreview() |
79 elif button == self.__okButton: |
91 elif button == self.__okButton: |
80 self.applyChanges() |
92 self.applyChanges() |
81 |
93 |
82 def __confirmUnsure(self, occurrence): |
94 def __confirmUnsure(self, data): |
83 """ |
95 """ |
84 Private method to confirm unsure occurrences. |
96 Private method to confirm unsure occurrences. |
85 |
97 |
86 @parameter occurrence reference to the occurrence object |
98 @param data dictionary containing the change data |
87 (rope.refactor.occurrences.Occurrence) |
99 @type dict |
88 @return flag indicating an occurrence (boolean) |
|
89 """ |
100 """ |
|
101 # TODO: change this to the distributed version |
90 if self.ignoreButton.isChecked(): |
102 if self.ignoreButton.isChecked(): |
91 return False |
103 answer = False |
92 if self.matchButton.isChecked(): |
104 elif self.matchButton.isChecked(): |
93 return True |
105 answer = True |
|
106 else: |
|
107 filename = occurrence.resource.real_path |
|
108 start, end = occurrence.get_primary_range() |
|
109 |
|
110 vm = e5App().getObject("ViewManager") |
|
111 |
|
112 # display the file and select the match |
|
113 vm.openSourceFile(filename) |
|
114 aw = vm.activeWindow() |
|
115 cline, cindex = aw.getCursorPosition() |
|
116 sline, sindex = aw.lineIndexFromPosition(start) |
|
117 eline, eindex = aw.lineIndexFromPosition(end) |
|
118 aw.ensureLineVisible(sline) |
|
119 aw.gotoLine(sline) |
|
120 aw.setSelection(sline, sindex, eline, eindex) |
|
121 answer = E5MessageBox.yesNo( |
|
122 self, |
|
123 self.tr("Rename"), |
|
124 self.tr("""<p>Is the highlighted code a match?</p>"""), |
|
125 yesDefault=True) |
|
126 aw.setCursorPosition(cline, cindex) |
|
127 aw.ensureCursorVisible() |
94 |
128 |
95 filename = occurrence.resource.real_path |
129 return answer |
96 start, end = occurrence.get_primary_range() |
130 |
|
131 def _calculateChanges(self): |
|
132 """ |
|
133 Protected method to initiate the calculation of the changes. |
|
134 """ |
|
135 self._refactoring.sendJson("CalculateRenameChanges", { |
|
136 "Title": self._title, |
|
137 "FileName": self.__filename, |
|
138 "Offset": self.__offset, |
|
139 "LocalRename": self.__local, |
|
140 "NewName": self.newNameEdit.text(), |
|
141 "RenameHierarchy": self.allCheckBox.isChecked(), |
|
142 "RenameInStrings": self.stringsCheckBox.isChecked(), |
|
143 }) |
|
144 ## try: |
|
145 ## changes = self.__renamer.get_changes( |
|
146 ## self.newNameEdit.text(), |
|
147 ## resources=self.__resources, |
|
148 ## in_hierarchy=self.allCheckBox.isChecked(), |
|
149 ## unsure=self.__confirmUnsure, |
|
150 ## docs=self.stringsCheckBox.isChecked(), |
|
151 ## task_handle=handle) |
|
152 ## return changes |
|
153 ## except Exception as err: |
|
154 ## self._refactoring.handleRopeError(err, self._title, handle) |
|
155 ## return None |
|
156 |
|
157 def processChangeData(self, data): |
|
158 """ |
|
159 Public method to process the change data sent by the refactoring |
|
160 client. |
97 |
161 |
98 vm = e5App().getObject("ViewManager") |
162 @param data dictionary containing the change data |
99 |
163 @type dict |
100 # display the file and select the match |
|
101 vm.openSourceFile(filename) |
|
102 aw = vm.activeWindow() |
|
103 cline, cindex = aw.getCursorPosition() |
|
104 sline, sindex = aw.lineIndexFromPosition(start) |
|
105 eline, eindex = aw.lineIndexFromPosition(end) |
|
106 aw.ensureLineVisible(sline) |
|
107 aw.gotoLine(sline) |
|
108 aw.setSelection(sline, sindex, eline, eindex) |
|
109 ans = E5MessageBox.yesNo( |
|
110 self, |
|
111 self.tr("Rename"), |
|
112 self.tr("""<p>Is the highlighted code a match?</p>"""), |
|
113 yesDefault=True) |
|
114 aw.setCursorPosition(cline, cindex) |
|
115 aw.ensureCursorVisible() |
|
116 |
|
117 return ans |
|
118 |
|
119 def _calculateChanges(self, handle): |
|
120 """ |
164 """ |
121 Protected method to calculate the changes. |
165 subcommand = data["Subcommand"] |
122 |
166 if subcommand == "ConfirmUnsure": |
123 @param handle reference to the task handle |
167 self.__confirmUnsure(data) |
124 (rope.base.taskhandle.TaskHandle) |
168 else: |
125 @return reference to the Changes object (rope.base.change.ChangeSet) |
169 # pass on to base class |
126 """ |
170 RefactoringDialogBase.processChangeData(self, data) |
127 try: |
|
128 changes = self.__renamer.get_changes( |
|
129 self.newNameEdit.text(), |
|
130 resources=self.__resources, |
|
131 in_hierarchy=self.allCheckBox.isChecked(), |
|
132 unsure=self.__confirmUnsure, |
|
133 docs=self.stringsCheckBox.isChecked(), |
|
134 task_handle=handle) |
|
135 return changes |
|
136 except Exception as err: |
|
137 self._refactoring.handleRopeError(err, self._title, handle) |
|
138 return None |
|