RefactoringRope/Refactoring.py

changeset 8
fc14525f0501
parent 7
5ecf9ef23d39
child 10
0fdfae822ca7
equal deleted inserted replaced
7:5ecf9ef23d39 8:fc14525f0501
16 import rope.base.project 16 import rope.base.project
17 import rope.base.exceptions 17 import rope.base.exceptions
18 18
19 import rope.refactor.rename 19 import rope.refactor.rename
20 import rope.refactor.extract 20 import rope.refactor.extract
21 ##import rope.refactor.usefunction 21 import rope.refactor.usefunction
22 import rope.refactor.inline 22 import rope.refactor.inline
23 import rope.refactor.move 23 import rope.refactor.move
24 ##import rope.refactor.change_signature 24 ##import rope.refactor.change_signature
25 ##import rope.refactor.introduce_factory 25 ##import rope.refactor.introduce_factory
26 ##import rope.refactor.introduce_parameter 26 ##import rope.refactor.introduce_parameter
52 from HistoryDialog import HistoryDialog 52 from HistoryDialog import HistoryDialog
53 from ExtractDialog import ExtractDialog 53 from ExtractDialog import ExtractDialog
54 from InlineDialog import InlineDialog 54 from InlineDialog import InlineDialog
55 from MoveMethodDialog import MoveMethodDialog 55 from MoveMethodDialog import MoveMethodDialog
56 from MoveModuleDialog import MoveModuleDialog 56 from MoveModuleDialog import MoveModuleDialog
57 from UseFunctionDialog import UseFunctionDialog
57 58
58 import Utilities 59 import Utilities
59 60
60 61
61 class Refactoring(QObject): 62 class Refactoring(QObject):
105 'Rename the highlighted object')) 106 'Rename the highlighted object'))
106 self.refactoringRenameAct.setWhatsThis(self.trUtf8( 107 self.refactoringRenameAct.setWhatsThis(self.trUtf8(
107 """<b>Rename</b>""" 108 """<b>Rename</b>"""
108 """<p>Rename the highlighted Python object.</p>""" 109 """<p>Rename the highlighted Python object.</p>"""
109 )) 110 ))
110 if self.__newStyle: 111 self.refactoringRenameAct.triggered[()].connect(
111 self.refactoringRenameAct.triggered[()].connect( 112 self.__rename)
112 self.__rename)
113 else:
114 self.connect(self.refactoringRenameAct, SIGNAL('triggered()'),
115 self.__rename)
116 self.actions.append(self.refactoringRenameAct) 113 self.actions.append(self.refactoringRenameAct)
117 114
118 self.refactoringRenameLocalAct = E5Action(self.trUtf8('Local Rename'), 115 self.refactoringRenameLocalAct = E5Action(self.trUtf8('Local Rename'),
119 self.trUtf8('&Local Rename'), 116 self.trUtf8('&Local Rename'),
120 0, 0, 117 0, 0,
124 self.refactoringRenameLocalAct.setWhatsThis(self.trUtf8( 121 self.refactoringRenameLocalAct.setWhatsThis(self.trUtf8(
125 """<b>Local Rename</b>""" 122 """<b>Local Rename</b>"""
126 """<p>Rename the highlighted Python object in the current""" 123 """<p>Rename the highlighted Python object in the current"""
127 """ module only.</p>""" 124 """ module only.</p>"""
128 )) 125 ))
129 if self.__newStyle: 126 self.refactoringRenameLocalAct.triggered[()].connect(
130 self.refactoringRenameLocalAct.triggered[()].connect( 127 self.__renameLocal)
131 self.__renameLocal)
132 else:
133 self.connect(self.refactoringRenameLocalAct,
134 SIGNAL('triggered()'), self.__renameLocal)
135 self.actions.append(self.refactoringRenameLocalAct) 128 self.actions.append(self.refactoringRenameLocalAct)
136 129
137 self.refactoringRenameModuleAct = E5Action( 130 self.refactoringRenameModuleAct = E5Action(
138 self.trUtf8('Rename Current Module'), 131 self.trUtf8('Rename Current Module'),
139 self.trUtf8('Rename Current Module'), 132 self.trUtf8('Rename Current Module'),
143 'Rename the current module')) 136 'Rename the current module'))
144 self.refactoringRenameModuleAct.setWhatsThis(self.trUtf8( 137 self.refactoringRenameModuleAct.setWhatsThis(self.trUtf8(
145 """<b>Rename Current Module</b>""" 138 """<b>Rename Current Module</b>"""
146 """<p>Rename the current module.</p>""" 139 """<p>Rename the current module.</p>"""
147 )) 140 ))
148 if self.__newStyle: 141 self.refactoringRenameModuleAct.triggered[()].connect(
149 self.refactoringRenameModuleAct.triggered[()].connect( 142 self.__renameModule)
150 self.__renameModule)
151 else:
152 self.connect(self.refactoringRenameModuleAct,
153 SIGNAL('triggered()'), self.__renameModule)
154 self.actions.append(self.refactoringRenameModuleAct) 143 self.actions.append(self.refactoringRenameModuleAct)
155 144
156 self.refactoringChangeOccurrencesAct = E5Action( 145 self.refactoringChangeOccurrencesAct = E5Action(
157 self.trUtf8('Change Occurrences'), 146 self.trUtf8('Change Occurrences'),
158 self.trUtf8('Change &Occurrences'), 147 self.trUtf8('Change &Occurrences'),
162 'Change all occurrences in the local scope')) 151 'Change all occurrences in the local scope'))
163 self.refactoringChangeOccurrencesAct.setWhatsThis(self.trUtf8( 152 self.refactoringChangeOccurrencesAct.setWhatsThis(self.trUtf8(
164 """<b>Change Occurrences</b>""" 153 """<b>Change Occurrences</b>"""
165 """<p>Change all occurrences in the local scope.</p>""" 154 """<p>Change all occurrences in the local scope.</p>"""
166 )) 155 ))
167 if self.__newStyle: 156 self.refactoringChangeOccurrencesAct.triggered[()].connect(
168 self.refactoringChangeOccurrencesAct.triggered[()].connect( 157 self.__changeOccurrences)
169 self.__changeOccurrences)
170 else:
171 self.connect(self.refactoringChangeOccurrencesAct,
172 SIGNAL('triggered()'), self.__changeOccurrences)
173 self.actions.append(self.refactoringChangeOccurrencesAct) 158 self.actions.append(self.refactoringChangeOccurrencesAct)
174 159
175 ##################################################### 160 #####################################################
176 ## Extract refactoring actions 161 ## Extract refactoring actions
177 ##################################################### 162 #####################################################
185 'Extract the highlighted area as a method')) 170 'Extract the highlighted area as a method'))
186 self.refactoringExtractMethodAct.setWhatsThis(self.trUtf8( 171 self.refactoringExtractMethodAct.setWhatsThis(self.trUtf8(
187 """<b>Extract method</b>""" 172 """<b>Extract method</b>"""
188 """<p>Extract the highlighted area as a method or function.</p>""" 173 """<p>Extract the highlighted area as a method or function.</p>"""
189 )) 174 ))
190 if self.__newStyle: 175 self.refactoringExtractMethodAct.triggered[()].connect(
191 self.refactoringExtractMethodAct.triggered[()].connect( 176 self.__extractMethod)
192 self.__extractMethod)
193 else:
194 self.connect(self.refactoringExtractMethodAct,
195 SIGNAL('triggered()'), self.__extractMethod)
196 self.actions.append(self.refactoringExtractMethodAct) 177 self.actions.append(self.refactoringExtractMethodAct)
197 178
198 self.refactoringExtractLocalVariableAct = E5Action( 179 self.refactoringExtractLocalVariableAct = E5Action(
199 self.trUtf8('Extract local variable'), 180 self.trUtf8('Extract local variable'),
200 self.trUtf8('&Extract Local Variable'), 181 self.trUtf8('&Extract Local Variable'),
204 'Extract the highlighted area as a local variable')) 185 'Extract the highlighted area as a local variable'))
205 self.refactoringExtractLocalVariableAct.setWhatsThis(self.trUtf8( 186 self.refactoringExtractLocalVariableAct.setWhatsThis(self.trUtf8(
206 """<b>Extract local variable</b>""" 187 """<b>Extract local variable</b>"""
207 """<p>Extract the highlighted area as a local variable.</p>""" 188 """<p>Extract the highlighted area as a local variable.</p>"""
208 )) 189 ))
209 if self.__newStyle: 190 self.refactoringExtractLocalVariableAct.triggered[()].connect(
210 self.refactoringExtractLocalVariableAct.triggered[()].connect( 191 self.__extractLocalVariable)
211 self.__extractLocalVariable)
212 else:
213 self.connect(self.refactoringExtractLocalVariableAct,
214 SIGNAL('triggered()'), self.__extractLocalVariable)
215 self.actions.append(self.refactoringExtractLocalVariableAct) 192 self.actions.append(self.refactoringExtractLocalVariableAct)
216 193
217 ##################################################### 194 #####################################################
218 ## Inline refactoring actions 195 ## Inline refactoring actions
219 ##################################################### 196 #####################################################
227 'Inlines the selected local variable or method')) 204 'Inlines the selected local variable or method'))
228 self.refactoringInlineAct.setWhatsThis(self.trUtf8( 205 self.refactoringInlineAct.setWhatsThis(self.trUtf8(
229 """<b>Inline</b>""" 206 """<b>Inline</b>"""
230 """<p>Inlines the selected local variable or method.</p>""" 207 """<p>Inlines the selected local variable or method.</p>"""
231 )) 208 ))
232 if self.__newStyle: 209 self.refactoringInlineAct.triggered[()].connect(
233 self.refactoringInlineAct.triggered[()].connect( 210 self.__inline)
234 self.__inline)
235 else:
236 self.connect(self.refactoringInlineAct,
237 SIGNAL('triggered()'), self.__inline)
238 self.actions.append(self.refactoringInlineAct) 211 self.actions.append(self.refactoringInlineAct)
239 212
240 ##################################################### 213 #####################################################
241 ## Move refactoring actions 214 ## Move refactoring actions
242 ##################################################### 215 #####################################################
250 'Move the highlighted method to another class')) 223 'Move the highlighted method to another class'))
251 self.refactoringMoveMethodAct.setWhatsThis(self.trUtf8( 224 self.refactoringMoveMethodAct.setWhatsThis(self.trUtf8(
252 """<b>Move method</b>""" 225 """<b>Move method</b>"""
253 """<p>Move the highlighted method to another class.</p>""" 226 """<p>Move the highlighted method to another class.</p>"""
254 )) 227 ))
255 if self.__newStyle: 228 self.refactoringMoveMethodAct.triggered[()].connect(
256 self.refactoringMoveMethodAct.triggered[()].connect( 229 self.__moveMethod)
257 self.__moveMethod)
258 else:
259 self.connect(self.refactoringMoveMethodAct,
260 SIGNAL('triggered()'), self.__moveMethod)
261 self.actions.append(self.refactoringMoveMethodAct) 230 self.actions.append(self.refactoringMoveMethodAct)
262 231
263 self.refactoringMoveModuleAct = E5Action( 232 self.refactoringMoveModuleAct = E5Action(
264 self.trUtf8('Move current module'), 233 self.trUtf8('Move current module'),
265 self.trUtf8('Move Current Module'), 234 self.trUtf8('Move Current Module'),
269 'Move the current module to another package')) 238 'Move the current module to another package'))
270 self.refactoringMoveModuleAct.setWhatsThis(self.trUtf8( 239 self.refactoringMoveModuleAct.setWhatsThis(self.trUtf8(
271 """<b>Move current module</b>""" 240 """<b>Move current module</b>"""
272 """<p>Move the current module to another package.</p>""" 241 """<p>Move the current module to another package.</p>"""
273 )) 242 ))
274 if self.__newStyle: 243 self.refactoringMoveModuleAct.triggered[()].connect(
275 self.refactoringMoveModuleAct.triggered[()].connect( 244 self.__moveModule)
276 self.__moveModule)
277 else:
278 self.connect(self.refactoringMoveModuleAct,
279 SIGNAL('triggered()'), self.__moveModule)
280 self.actions.append(self.refactoringMoveModuleAct) 245 self.actions.append(self.refactoringMoveModuleAct)
246
247 #####################################################
248 ## Use function refactoring action
249 #####################################################
250
251 self.refactoringUseFunctionAct = E5Action(
252 self.trUtf8('Use Function'),
253 self.trUtf8('Use Function'),
254 0, 0,
255 self,'refactoring_use_function')
256 self.refactoringUseFunctionAct.setStatusTip(self.trUtf8(
257 'Use a function wherever possible.'))
258 self.refactoringUseFunctionAct.setWhatsThis(self.trUtf8(
259 """<b>Use function</b>"""
260 """<p>Tries to use a function wherever possible.</p>"""
261 ))
262 self.refactoringUseFunctionAct.triggered[()].connect(
263 self.__useFunction)
264 self.actions.append(self.refactoringUseFunctionAct)
281 265
282 ##################################################### 266 #####################################################
283 ## Undo/Redo actions 267 ## Undo/Redo actions
284 ##################################################### 268 #####################################################
285 269
291 'Undo the last refactoring')) 275 'Undo the last refactoring'))
292 self.refactoringUndoAct.setWhatsThis(self.trUtf8( 276 self.refactoringUndoAct.setWhatsThis(self.trUtf8(
293 """<b>Undo</b>""" 277 """<b>Undo</b>"""
294 """<p>Undo the last refactoring.</p>""" 278 """<p>Undo the last refactoring.</p>"""
295 )) 279 ))
296 if self.__newStyle: 280 self.refactoringUndoAct.triggered[()].connect(
297 self.refactoringUndoAct.triggered[()].connect( 281 self.__undo)
298 self.__undo)
299 else:
300 self.connect(self.refactoringUndoAct,
301 SIGNAL('triggered()'), self.__undo)
302 self.actions.append(self.refactoringUndoAct) 282 self.actions.append(self.refactoringUndoAct)
303 283
304 self.refactoringRedoAct = E5Action(self.trUtf8('Redo'), 284 self.refactoringRedoAct = E5Action(self.trUtf8('Redo'),
305 self.trUtf8('Re&do'), 285 self.trUtf8('Re&do'),
306 0, 0, 286 0, 0,
309 'Redo the last refactoring')) 289 'Redo the last refactoring'))
310 self.refactoringRedoAct.setWhatsThis(self.trUtf8( 290 self.refactoringRedoAct.setWhatsThis(self.trUtf8(
311 """<b>Redo</b>""" 291 """<b>Redo</b>"""
312 """<p>Redo the last refactoring.</p>""" 292 """<p>Redo the last refactoring.</p>"""
313 )) 293 ))
314 if self.__newStyle: 294 self.refactoringRedoAct.triggered[()].connect(
315 self.refactoringRedoAct.triggered[()].connect( 295 self.__redo)
316 self.__redo)
317 else:
318 self.connect(self.refactoringRedoAct,
319 SIGNAL('triggered()'), self.__redo)
320 self.actions.append(self.refactoringRedoAct) 296 self.actions.append(self.refactoringRedoAct)
321 297
322 self.refactoringUndoHistoryAct = \ 298 self.refactoringUndoHistoryAct = \
323 E5Action(self.trUtf8('Show Project Undo History'), 299 E5Action(self.trUtf8('Show Project Undo History'),
324 self.trUtf8('Show Project Undo History'), 300 self.trUtf8('Show Project Undo History'),
329 self.refactoringUndoHistoryAct.setWhatsThis(self.trUtf8( 305 self.refactoringUndoHistoryAct.setWhatsThis(self.trUtf8(
330 """<b>Show Project Undo History</b>""" 306 """<b>Show Project Undo History</b>"""
331 """<p>Opens a dialog to show the undo history list of""" 307 """<p>Opens a dialog to show the undo history list of"""
332 """ the project.</p>""" 308 """ the project.</p>"""
333 )) 309 ))
334 if self.__newStyle: 310 self.refactoringUndoHistoryAct.triggered[()].connect(
335 self.refactoringUndoHistoryAct.triggered[()].connect( 311 self.__showProjectUndoHistory)
336 self.__showProjectUndoHistory)
337 else:
338 self.connect(self.refactoringUndoHistoryAct,
339 SIGNAL('triggered()'), self.__showProjectUndoHistory)
340 self.actions.append(self.refactoringUndoHistoryAct) 312 self.actions.append(self.refactoringUndoHistoryAct)
341 313
342 self.refactoringRedoHistoryAct = \ 314 self.refactoringRedoHistoryAct = \
343 E5Action(self.trUtf8('Show Project Redo History'), 315 E5Action(self.trUtf8('Show Project Redo History'),
344 self.trUtf8('Show Project Redo History'), 316 self.trUtf8('Show Project Redo History'),
349 self.refactoringRedoHistoryAct.setWhatsThis(self.trUtf8( 321 self.refactoringRedoHistoryAct.setWhatsThis(self.trUtf8(
350 """<b>Show Project Redo History</b>""" 322 """<b>Show Project Redo History</b>"""
351 """<p>Opens a dialog to show the redo history list of""" 323 """<p>Opens a dialog to show the redo history list of"""
352 """ the project.</p>""" 324 """ the project.</p>"""
353 )) 325 ))
354 if self.__newStyle: 326 self.refactoringRedoHistoryAct.triggered[()].connect(
355 self.refactoringRedoHistoryAct.triggered[()].connect( 327 self.__showProjectRedoHistory)
356 self.__showProjectRedoHistory)
357 else:
358 self.connect(self.refactoringRedoHistoryAct,
359 SIGNAL('triggered()'), self.__showProjectRedoHistory)
360 self.actions.append(self.refactoringRedoHistoryAct) 328 self.actions.append(self.refactoringRedoHistoryAct)
361 329
362 self.refactoringUndoFileHistoryAct = \ 330 self.refactoringUndoFileHistoryAct = \
363 E5Action(self.trUtf8('Show Current File Undo History'), 331 E5Action(self.trUtf8('Show Current File Undo History'),
364 self.trUtf8('Show Current File Undo History'), 332 self.trUtf8('Show Current File Undo History'),
369 self.refactoringUndoFileHistoryAct.setWhatsThis(self.trUtf8( 337 self.refactoringUndoFileHistoryAct.setWhatsThis(self.trUtf8(
370 """<b>Show Current File Undo History</b>""" 338 """<b>Show Current File Undo History</b>"""
371 """<p>Opens a dialog to show the undo history list of""" 339 """<p>Opens a dialog to show the undo history list of"""
372 """ the current file.</p>""" 340 """ the current file.</p>"""
373 )) 341 ))
374 if self.__newStyle: 342 self.refactoringUndoFileHistoryAct.triggered[()].connect(
375 self.refactoringUndoFileHistoryAct.triggered[()].connect( 343 self.__showFileUndoHistory)
376 self.__showFileUndoHistory)
377 else:
378 self.connect(self.refactoringUndoFileHistoryAct,
379 SIGNAL('triggered()'), self.__showFileUndoHistory)
380 self.actions.append(self.refactoringUndoFileHistoryAct) 344 self.actions.append(self.refactoringUndoFileHistoryAct)
381 345
382 self.refactoringRedoFileHistoryAct = \ 346 self.refactoringRedoFileHistoryAct = \
383 E5Action(self.trUtf8('Show Current File Redo History'), 347 E5Action(self.trUtf8('Show Current File Redo History'),
384 self.trUtf8('Show Current File Redo History'), 348 self.trUtf8('Show Current File Redo History'),
389 self.refactoringRedoFileHistoryAct.setWhatsThis(self.trUtf8( 353 self.refactoringRedoFileHistoryAct.setWhatsThis(self.trUtf8(
390 """<b>Show Current File Redo History</b>""" 354 """<b>Show Current File Redo History</b>"""
391 """<p>Opens a dialog to show the redo history list of""" 355 """<p>Opens a dialog to show the redo history list of"""
392 """ the current file.</p>""" 356 """ the current file.</p>"""
393 )) 357 ))
394 if self.__newStyle: 358 self.refactoringRedoFileHistoryAct.triggered[()].connect(
395 self.refactoringRedoFileHistoryAct.triggered[()].connect( 359 self.__showFileRedoHistory)
396 self.__showFileRedoHistory)
397 else:
398 self.connect(self.refactoringRedoFileHistoryAct,
399 SIGNAL('triggered()'), self.__showFileRedoHistory)
400 self.actions.append(self.refactoringRedoFileHistoryAct) 360 self.actions.append(self.refactoringRedoFileHistoryAct)
401 361
402 self.refactoringClearHistoryAct = \ 362 self.refactoringClearHistoryAct = \
403 E5Action(self.trUtf8('Clear History'), 363 E5Action(self.trUtf8('Clear History'),
404 self.trUtf8('Clear History'), 364 self.trUtf8('Clear History'),
408 'Clear the refactoring history')) 368 'Clear the refactoring history'))
409 self.refactoringClearHistoryAct.setWhatsThis(self.trUtf8( 369 self.refactoringClearHistoryAct.setWhatsThis(self.trUtf8(
410 """<b>Clear History</b>""" 370 """<b>Clear History</b>"""
411 """<p>Clears the refactoring history.</p>""" 371 """<p>Clears the refactoring history.</p>"""
412 )) 372 ))
413 if self.__newStyle: 373 self.refactoringClearHistoryAct.triggered[()].connect(
414 self.refactoringClearHistoryAct.triggered[()].connect( 374 self.__clearHistory)
415 self.__clearHistory)
416 else:
417 self.connect(self.refactoringClearHistoryAct,
418 SIGNAL('triggered()'), self.__clearHistory)
419 self.actions.append(self.refactoringClearHistoryAct) 375 self.actions.append(self.refactoringClearHistoryAct)
420 376
421 ##################################################### 377 #####################################################
422 ## Query actions 378 ## Query actions
423 ##################################################### 379 #####################################################
431 self.queryReferencesAct.setWhatsThis(self.trUtf8( 387 self.queryReferencesAct.setWhatsThis(self.trUtf8(
432 """<b>Find occurrences</b>""" 388 """<b>Find occurrences</b>"""
433 """<p>Find occurrences of the highlighted class, method,""" 389 """<p>Find occurrences of the highlighted class, method,"""
434 """ function or variable.</p>""" 390 """ function or variable.</p>"""
435 )) 391 ))
436 if self.__newStyle: 392 self.queryReferencesAct.triggered[()].connect(
437 self.queryReferencesAct.triggered[()].connect( 393 self.__queryReferences)
438 self.__queryReferences)
439 else:
440 self.connect(self.queryReferencesAct, SIGNAL('triggered()'),
441 self.__queryReferences)
442 self.actions.append(self.queryReferencesAct) 394 self.actions.append(self.queryReferencesAct)
443 395
444 self.queryDefinitionAct = E5Action(self.trUtf8('Find definition'), 396 self.queryDefinitionAct = E5Action(self.trUtf8('Find definition'),
445 self.trUtf8('Find &Definition'), 397 self.trUtf8('Find &Definition'),
446 0, 0, 398 0, 0,
450 self.queryDefinitionAct.setWhatsThis(self.trUtf8( 402 self.queryDefinitionAct.setWhatsThis(self.trUtf8(
451 """<b>Find definition</b>""" 403 """<b>Find definition</b>"""
452 """<p>Find the definition of the highlighted class, method,""" 404 """<p>Find the definition of the highlighted class, method,"""
453 """ function or variable.</p>""" 405 """ function or variable.</p>"""
454 )) 406 ))
455 if self.__newStyle: 407 self.queryDefinitionAct.triggered[()].connect(
456 self.queryDefinitionAct.triggered[()].connect( 408 self.__queryDefinition)
457 self.__queryDefinition)
458 else:
459 self.connect(self.queryDefinitionAct, SIGNAL('triggered()'),
460 self.__queryDefinition)
461 self.actions.append(self.queryDefinitionAct) 409 self.actions.append(self.queryDefinitionAct)
462 410
463 self.queryImplementationsAct = E5Action( 411 self.queryImplementationsAct = E5Action(
464 self.trUtf8('Find implementations'), 412 self.trUtf8('Find implementations'),
465 self.trUtf8('Find &Implementations'), 413 self.trUtf8('Find &Implementations'),
469 'Find places where the selected method is overridden')) 417 'Find places where the selected method is overridden'))
470 self.queryImplementationsAct.setWhatsThis(self.trUtf8( 418 self.queryImplementationsAct.setWhatsThis(self.trUtf8(
471 """<b>Find implementations</b>""" 419 """<b>Find implementations</b>"""
472 """<p>Find places where the selected method is overridden.</p>""" 420 """<p>Find places where the selected method is overridden.</p>"""
473 )) 421 ))
474 if self.__newStyle: 422 self.queryImplementationsAct.triggered[()].connect(
475 self.queryImplementationsAct.triggered[()].connect( 423 self.__queryImplementations)
476 self.__queryImplementations)
477 else:
478 self.connect(self.queryImplementationsAct, SIGNAL('triggered()'),
479 self.__queryImplementations)
480 self.actions.append(self.queryImplementationsAct) 424 self.actions.append(self.queryImplementationsAct)
481 425
482 ##################################################### 426 #####################################################
483 ## Various actions 427 ## Various actions
484 ##################################################### 428 #####################################################
491 'Open the rope configuration file')) 435 'Open the rope configuration file'))
492 self.refactoringEditConfigAct.setWhatsThis(self.trUtf8( 436 self.refactoringEditConfigAct.setWhatsThis(self.trUtf8(
493 """<b>Configure Rope</b>""" 437 """<b>Configure Rope</b>"""
494 """<p>Opens the rope configuration file in an editor.</p>""" 438 """<p>Opens the rope configuration file in an editor.</p>"""
495 )) 439 ))
496 if self.__newStyle: 440 self.refactoringEditConfigAct.triggered[()].connect(
497 self.refactoringEditConfigAct.triggered[()].connect( 441 self.__editConfig)
498 self.__editConfig)
499 else:
500 self.connect(self.refactoringEditConfigAct, SIGNAL('triggered()'),
501 self.__editConfig)
502 self.actions.append(self.refactoringEditConfigAct) 442 self.actions.append(self.refactoringEditConfigAct)
503 443
504 self.refactoringHelpAct = E5Action(self.trUtf8('Rope help'), 444 self.refactoringHelpAct = E5Action(self.trUtf8('Rope help'),
505 self.trUtf8('Rope &Help'), 445 self.trUtf8('Rope &Help'),
506 0, 0, 446 0, 0,
509 'Show help about the rope refactorings')) 449 'Show help about the rope refactorings'))
510 self.refactoringHelpAct.setWhatsThis(self.trUtf8( 450 self.refactoringHelpAct.setWhatsThis(self.trUtf8(
511 """<b>Rope help</b>""" 451 """<b>Rope help</b>"""
512 """<p>Show some help text about the rope refactorings.</p>""" 452 """<p>Show some help text about the rope refactorings.</p>"""
513 )) 453 ))
514 if self.__newStyle: 454 self.refactoringHelpAct.triggered[()].connect(
515 self.refactoringHelpAct.triggered[()].connect( 455 self.__showRopeHelp)
516 self.__showRopeHelp)
517 else:
518 self.connect(self.refactoringHelpAct, SIGNAL('triggered()'),
519 self.__showRopeHelp)
520 self.actions.append(self.refactoringHelpAct) 456 self.actions.append(self.refactoringHelpAct)
521 457
522 for act in self.actions: 458 for act in self.actions:
523 act.setEnabled(False) 459 act.setEnabled(False)
524 460
541 smenu.addAction(self.queryReferencesAct) 477 smenu.addAction(self.queryReferencesAct)
542 smenu.addAction(self.queryDefinitionAct) 478 smenu.addAction(self.queryDefinitionAct)
543 smenu.addAction(self.queryImplementationsAct) 479 smenu.addAction(self.queryImplementationsAct)
544 480
545 smenu = menu.addMenu(self.trUtf8("&Refactoring")) 481 smenu = menu.addMenu(self.trUtf8("&Refactoring"))
546 if self.__newStyle: 482 smenu.aboutToShow.connect(self.__showRefactoringMenu)
547 smenu.aboutToShow.connect(self.__showRefactoringMenu)
548 else:
549 self.connect(smenu, SIGNAL("aboutToShow()"),
550 self.__showRefactoringMenu)
551 smenu.addAction(self.refactoringRenameAct) 483 smenu.addAction(self.refactoringRenameAct)
552 smenu.addAction(self.refactoringRenameLocalAct) 484 smenu.addAction(self.refactoringRenameLocalAct)
553 smenu.addAction(self.refactoringChangeOccurrencesAct) 485 smenu.addAction(self.refactoringChangeOccurrencesAct)
554 smenu.addSeparator() 486 smenu.addSeparator()
555 smenu.addAction(self.refactoringExtractMethodAct) 487 smenu.addAction(self.refactoringExtractMethodAct)
556 smenu.addAction(self.refactoringMoveMethodAct) 488 smenu.addAction(self.refactoringMoveMethodAct)
557 smenu.addSeparator() 489 smenu.addSeparator()
558 smenu.addAction(self.refactoringInlineAct) 490 smenu.addAction(self.refactoringInlineAct)
559 smenu.addSeparator() 491 smenu.addSeparator()
560 smenu.addAction(self.refactoringExtractLocalVariableAct) 492 smenu.addAction(self.refactoringExtractLocalVariableAct)
493 smenu.addSeparator()
494 smenu.addAction(self.refactoringUseFunctionAct)
561 smenu.addSeparator() 495 smenu.addSeparator()
562 smenu.addAction(self.refactoringRenameModuleAct) 496 smenu.addAction(self.refactoringRenameModuleAct)
563 smenu.addAction(self.refactoringMoveModuleAct) 497 smenu.addAction(self.refactoringMoveModuleAct)
564 smenu.addSeparator() 498 smenu.addSeparator()
565 499
1006 except Exception as err: 940 except Exception as err:
1007 self.handleRopeError(err, title) 941 self.handleRopeError(err, title)
1008 return 942 return
1009 943
1010 self.dlg = MoveModuleDialog(self, title, mover, parent=self.__ui) 944 self.dlg = MoveModuleDialog(self, title, mover, parent=self.__ui)
945 self.dlg.show()
946
947 #####################################################
948 ## Use function refactoring
949 #####################################################
950
951 def __useFunction(self):
952 """
953 Private slot to use a function wherever possible.
954 """
955 aw = e5App().getObject("ViewManager").activeWindow()
956
957 if aw is None:
958 return
959
960 title = self.trUtf8("Use Function")
961 if not aw.hasSelectedText():
962 # no selection available
963 E5MessageBox.warning(self.__ui, title,
964 self.trUtf8("Highlight a global function and try again."))
965 return
966
967 if not self.confirmAllBuffersSaved():
968 return
969
970 filename = aw.getFileName()
971 line, index, line1, index1 = aw.getSelection()
972 offset = aw.positionFromLineIndex(line, index)
973
974 resource = rope.base.libutils.path_to_resource(
975 self.__project, filename)
976 try:
977 user = rope.refactor.usefunction.UseFunction(
978 self.__project, resource, offset)
979 except Exception as err:
980 self.handleRopeError(err, title)
981 return
982
983 self.dlg = UseFunctionDialog(self, title, user, parent = self.__ui)
1011 self.dlg.show() 984 self.dlg.show()
1012 985
1013 ##################################################### 986 #####################################################
1014 ## Undo/Redo refactorings 987 ## Undo/Redo refactorings
1015 ##################################################### 988 #####################################################

eric ide

mercurial