RefactoringRope/RefactoringServer.py

branch
eric7
changeset 365
f740b50380df
parent 360
2b35968f3d02
child 374
958f34e97952
equal deleted inserted replaced
364:a92b3272f4c1 365:f740b50380df
8 """ 8 """
9 9
10 import os 10 import os
11 import contextlib 11 import contextlib
12 12
13 from PyQt5.QtCore import pyqtSlot 13 from PyQt6.QtCore import pyqtSlot
14 from PyQt5.QtWidgets import QMenu, QApplication, QAction 14 from PyQt6.QtGui import QAction
15 from PyQt5.Qsci import QsciScintilla 15 from PyQt6.QtWidgets import QMenu, QApplication
16 from PyQt6.Qsci import QsciScintilla
16 17
17 from E5Gui.E5Application import e5App 18 from EricWidgets.EricApplication import ericApp
18 from E5Gui import E5MessageBox 19 from EricWidgets import EricMessageBox
19 from E5Gui.E5Action import E5Action 20 from EricGui.EricAction import EricAction
20 21
21 try: 22 from EricNetwork.EricJsonServer import EricJsonServer
22 from E5Network.E5JsonServer import E5JsonServer 23
23 except ImportError:
24 # TODO: delete JsonServer once ported to eric7
25 from .JsonServer import JsonServer as E5JsonServer
26 from .RopeProgressDialog import RopeProgressDialog 24 from .RopeProgressDialog import RopeProgressDialog
27 25
28 import Utilities 26 import Utilities
29 import Preferences 27 import Preferences
30 import Globals 28 import Globals
31 29
32 from Preferences.Shortcuts import readShortcuts 30 from Preferences.Shortcuts import readShortcuts
33 31
34 32
35 class RefactoringServer(E5JsonServer): 33 class RefactoringServer(EricJsonServer):
36 """ 34 """
37 Class implementing the refactoring interface to rope. 35 Class implementing the refactoring interface to rope.
38 """ 36 """
39 def __init__(self, plugin, parent=None): 37 def __init__(self, plugin, parent=None):
40 """ 38 """
48 super().__init__( 46 super().__init__(
49 "RefactoringServer", parent=parent) 47 "RefactoringServer", parent=parent)
50 48
51 self.__plugin = plugin 49 self.__plugin = plugin
52 self.__ui = parent 50 self.__ui = parent
53 self.__vm = e5App().getObject("ViewManager") 51 self.__vm = ericApp().getObject("ViewManager")
54 self.__e5project = e5App().getObject("Project") 52 self.__ericProject = ericApp().getObject("Project")
55 self.__projectpath = '' 53 self.__projectpath = ''
56 self.__projectLanguage = "" 54 self.__projectLanguage = ""
57 self.__projectopen = False 55 self.__projectopen = False
58 self.__ropeConfig = {} 56 self.__ropeConfig = {}
59 57
64 self.__progressDialog = None 62 self.__progressDialog = None
65 self.__helpDialog = None 63 self.__helpDialog = None
66 self.__historyDialog = None 64 self.__historyDialog = None
67 self.__refactoringDialogs = {} 65 self.__refactoringDialogs = {}
68 66
69 from .FileSystemCommands import E5FileSystemCommands 67 from .FileSystemCommands import EricFileSystemCommands
70 self.__fsCommands = E5FileSystemCommands(self.__e5project) 68 self.__fsCommands = EricFileSystemCommands(self.__ericProject)
71 69
72 self.__methodMapping = { 70 self.__methodMapping = {
73 "Config": self.__setConfig, 71 "Config": self.__setConfig,
74 "Progress": self.__processProgress, 72 "Progress": self.__processProgress,
75 "QueryReferencesResult": self.__queryReferencesResult, 73 "QueryReferencesResult": self.__queryReferencesResult,
100 Public method to activate the refactoring server. 98 Public method to activate the refactoring server.
101 99
102 This is performed when the rope plug-in is activated. 100 This is performed when the rope plug-in is activated.
103 """ 101 """
104 self.__initActions() 102 self.__initActions()
105 e5App().registerPluginObject("RefactoringRope", self) 103 ericApp().registerPluginObject("RefactoringRope", self)
106 readShortcuts(pluginName="RefactoringRope") 104 readShortcuts(pluginName="RefactoringRope")
107 105
108 self.__mainMenu = self.__initMenu() 106 self.__mainMenu = self.__initMenu()
109 projectToolsMenu = self.__ui.getMenu("project_tools") 107 projectToolsMenu = self.__ui.getMenu("project_tools")
110 if projectToolsMenu is not None: 108 if projectToolsMenu is not None:
119 insertBeforeAct = actions[actions.index(projectAct) + 1] 117 insertBeforeAct = actions[actions.index(projectAct) + 1]
120 self.__mainAct = self.__ui.menuBar().insertMenu( 118 self.__mainAct = self.__ui.menuBar().insertMenu(
121 insertBeforeAct, self.__mainMenu) 119 insertBeforeAct, self.__mainMenu)
122 self.__mainAct.setEnabled(False) 120 self.__mainAct.setEnabled(False)
123 121
124 if e5App().getObject("Project").isOpen(): 122 if ericApp().getObject("Project").isOpen():
125 self.projectOpened() 123 self.projectOpened()
126 124
127 e5App().getObject("Project").projectOpened.connect( 125 ericApp().getObject("Project").projectOpened.connect(
128 self.projectOpened) 126 self.projectOpened)
129 e5App().getObject("Project").projectPropertiesChanged.connect( 127 ericApp().getObject("Project").projectPropertiesChanged.connect(
130 self.projectOpened) 128 self.projectOpened)
131 e5App().getObject("Project").projectClosed.connect( 129 ericApp().getObject("Project").projectClosed.connect(
132 self.projectClosed) 130 self.projectClosed)
133 e5App().getObject("Project").newProject.connect( 131 ericApp().getObject("Project").newProject.connect(
134 self.projectOpened) 132 self.projectOpened)
135 133
136 def deactivate(self): 134 def deactivate(self):
137 """ 135 """
138 Public method to deactivate the refactoring server. 136 Public method to deactivate the refactoring server.
139 """ 137 """
140 e5App().unregisterPluginObject("RefactoringRope") 138 ericApp().unregisterPluginObject("RefactoringRope")
141 139
142 e5App().getObject("Project").projectOpened.disconnect( 140 ericApp().getObject("Project").projectOpened.disconnect(
143 self.projectOpened) 141 self.projectOpened)
144 e5App().getObject("Project").projectPropertiesChanged.disconnect( 142 ericApp().getObject("Project").projectPropertiesChanged.disconnect(
145 self.projectOpened) 143 self.projectOpened)
146 e5App().getObject("Project").projectClosed.disconnect( 144 ericApp().getObject("Project").projectClosed.disconnect(
147 self.projectClosed) 145 self.projectClosed)
148 e5App().getObject("Project").newProject.disconnect( 146 ericApp().getObject("Project").newProject.disconnect(
149 self.projectOpened) 147 self.projectOpened)
150 148
151 projectToolsMenu = self.__ui.getMenu("project_tools") 149 projectToolsMenu = self.__ui.getMenu("project_tools")
152 if projectToolsMenu is not None: 150 if projectToolsMenu is not None:
153 projectToolsMenu.removeAction(self.__separatorAct) 151 projectToolsMenu.removeAction(self.__separatorAct)
174 172
175 ##################################################### 173 #####################################################
176 ## Rename refactoring actions 174 ## Rename refactoring actions
177 ##################################################### 175 #####################################################
178 176
179 self.refactoringRenameAct = E5Action( 177 self.refactoringRenameAct = EricAction(
180 self.tr('Rename'), 178 self.tr('Rename'),
181 self.tr('&Rename'), 179 self.tr('&Rename'),
182 0, 0, 180 0, 0,
183 self, 'refactoring_rename') 181 self, 'refactoring_rename')
184 self.refactoringRenameAct.setStatusTip(self.tr( 182 self.refactoringRenameAct.setStatusTip(self.tr(
189 )) 187 ))
190 self.refactoringRenameAct.triggered.connect( 188 self.refactoringRenameAct.triggered.connect(
191 self.__rename) 189 self.__rename)
192 self.actions.append(self.refactoringRenameAct) 190 self.actions.append(self.refactoringRenameAct)
193 191
194 self.refactoringRenameLocalAct = E5Action( 192 self.refactoringRenameLocalAct = EricAction(
195 self.tr('Local Rename'), 193 self.tr('Local Rename'),
196 self.tr('&Local Rename'), 194 self.tr('&Local Rename'),
197 0, 0, 195 0, 0,
198 self, 'refactoring_rename_local') 196 self, 'refactoring_rename_local')
199 self.refactoringRenameLocalAct.setStatusTip(self.tr( 197 self.refactoringRenameLocalAct.setStatusTip(self.tr(
205 )) 203 ))
206 self.refactoringRenameLocalAct.triggered.connect( 204 self.refactoringRenameLocalAct.triggered.connect(
207 self.__renameLocal) 205 self.__renameLocal)
208 self.actions.append(self.refactoringRenameLocalAct) 206 self.actions.append(self.refactoringRenameLocalAct)
209 207
210 self.refactoringRenameModuleAct = E5Action( 208 self.refactoringRenameModuleAct = EricAction(
211 self.tr('Rename Current Module'), 209 self.tr('Rename Current Module'),
212 self.tr('Rename Current Module'), 210 self.tr('Rename Current Module'),
213 0, 0, 211 0, 0,
214 self, 'refactoring_rename_module') 212 self, 'refactoring_rename_module')
215 self.refactoringRenameModuleAct.setStatusTip(self.tr( 213 self.refactoringRenameModuleAct.setStatusTip(self.tr(
220 )) 218 ))
221 self.refactoringRenameModuleAct.triggered.connect( 219 self.refactoringRenameModuleAct.triggered.connect(
222 self.__renameModule) 220 self.__renameModule)
223 self.actions.append(self.refactoringRenameModuleAct) 221 self.actions.append(self.refactoringRenameModuleAct)
224 222
225 self.refactoringChangeOccurrencesAct = E5Action( 223 self.refactoringChangeOccurrencesAct = EricAction(
226 self.tr('Change Occurrences'), 224 self.tr('Change Occurrences'),
227 self.tr('Change &Occurrences'), 225 self.tr('Change &Occurrences'),
228 0, 0, 226 0, 0,
229 self, 'refactoring_change_occurrences') 227 self, 'refactoring_change_occurrences')
230 self.refactoringChangeOccurrencesAct.setStatusTip(self.tr( 228 self.refactoringChangeOccurrencesAct.setStatusTip(self.tr(
239 237
240 ##################################################### 238 #####################################################
241 ## Extract refactoring actions 239 ## Extract refactoring actions
242 ##################################################### 240 #####################################################
243 241
244 self.refactoringExtractMethodAct = E5Action( 242 self.refactoringExtractMethodAct = EricAction(
245 self.tr('Extract method'), 243 self.tr('Extract method'),
246 self.tr('Extract &Method'), 244 self.tr('Extract &Method'),
247 0, 0, 245 0, 0,
248 self, 'refactoring_extract_method') 246 self, 'refactoring_extract_method')
249 self.refactoringExtractMethodAct.setStatusTip(self.tr( 247 self.refactoringExtractMethodAct.setStatusTip(self.tr(
254 )) 252 ))
255 self.refactoringExtractMethodAct.triggered.connect( 253 self.refactoringExtractMethodAct.triggered.connect(
256 self.__extractMethod) 254 self.__extractMethod)
257 self.actions.append(self.refactoringExtractMethodAct) 255 self.actions.append(self.refactoringExtractMethodAct)
258 256
259 self.refactoringExtractLocalVariableAct = E5Action( 257 self.refactoringExtractLocalVariableAct = EricAction(
260 self.tr('Extract local variable'), 258 self.tr('Extract local variable'),
261 self.tr('&Extract Local Variable'), 259 self.tr('&Extract Local Variable'),
262 0, 0, 260 0, 0,
263 self, 'refactoring_extract_variable') 261 self, 'refactoring_extract_variable')
264 self.refactoringExtractLocalVariableAct.setStatusTip(self.tr( 262 self.refactoringExtractLocalVariableAct.setStatusTip(self.tr(
273 271
274 ##################################################### 272 #####################################################
275 ## Inline refactoring actions 273 ## Inline refactoring actions
276 ##################################################### 274 #####################################################
277 275
278 self.refactoringInlineAct = E5Action( 276 self.refactoringInlineAct = EricAction(
279 self.tr('Inline'), 277 self.tr('Inline'),
280 self.tr('&Inline'), 278 self.tr('&Inline'),
281 0, 0, 279 0, 0,
282 self, 'refactoring_inline') 280 self, 'refactoring_inline')
283 self.refactoringInlineAct.setStatusTip(self.tr( 281 self.refactoringInlineAct.setStatusTip(self.tr(
292 290
293 ##################################################### 291 #####################################################
294 ## Move refactoring actions 292 ## Move refactoring actions
295 ##################################################### 293 #####################################################
296 294
297 self.refactoringMoveMethodAct = E5Action( 295 self.refactoringMoveMethodAct = EricAction(
298 self.tr('Move method'), 296 self.tr('Move method'),
299 self.tr('Mo&ve Method'), 297 self.tr('Mo&ve Method'),
300 0, 0, 298 0, 0,
301 self, 'refactoring_move_method') 299 self, 'refactoring_move_method')
302 self.refactoringMoveMethodAct.setStatusTip(self.tr( 300 self.refactoringMoveMethodAct.setStatusTip(self.tr(
307 )) 305 ))
308 self.refactoringMoveMethodAct.triggered.connect( 306 self.refactoringMoveMethodAct.triggered.connect(
309 lambda: self.__move("move_method")) 307 lambda: self.__move("move_method"))
310 self.actions.append(self.refactoringMoveMethodAct) 308 self.actions.append(self.refactoringMoveMethodAct)
311 309
312 self.refactoringMoveModuleAct = E5Action( 310 self.refactoringMoveModuleAct = EricAction(
313 self.tr('Move current module'), 311 self.tr('Move current module'),
314 self.tr('Move Current Module'), 312 self.tr('Move Current Module'),
315 0, 0, 313 0, 0,
316 self, 'refactoring_move_module') 314 self, 'refactoring_move_module')
317 self.refactoringMoveModuleAct.setStatusTip(self.tr( 315 self.refactoringMoveModuleAct.setStatusTip(self.tr(
326 324
327 ##################################################### 325 #####################################################
328 ## Use function refactoring action 326 ## Use function refactoring action
329 ##################################################### 327 #####################################################
330 328
331 self.refactoringUseFunctionAct = E5Action( 329 self.refactoringUseFunctionAct = EricAction(
332 self.tr('Use Function'), 330 self.tr('Use Function'),
333 self.tr('Use Function'), 331 self.tr('Use Function'),
334 0, 0, 332 0, 0,
335 self, 'refactoring_use_function') 333 self, 'refactoring_use_function')
336 self.refactoringUseFunctionAct.setStatusTip(self.tr( 334 self.refactoringUseFunctionAct.setStatusTip(self.tr(
345 343
346 ##################################################### 344 #####################################################
347 ## Introduce refactorings actions 345 ## Introduce refactorings actions
348 ##################################################### 346 #####################################################
349 347
350 self.refactoringIntroduceFactoryAct = E5Action( 348 self.refactoringIntroduceFactoryAct = EricAction(
351 self.tr('Introduce Factory Method'), 349 self.tr('Introduce Factory Method'),
352 self.tr('Introduce &Factory Method'), 350 self.tr('Introduce &Factory Method'),
353 0, 0, 351 0, 0,
354 self, 'refactoring_introduce_factory_method') 352 self, 'refactoring_introduce_factory_method')
355 self.refactoringIntroduceFactoryAct.setStatusTip(self.tr( 353 self.refactoringIntroduceFactoryAct.setStatusTip(self.tr(
360 )) 358 ))
361 self.refactoringIntroduceFactoryAct.triggered.connect( 359 self.refactoringIntroduceFactoryAct.triggered.connect(
362 self.__introduceFactoryMethod) 360 self.__introduceFactoryMethod)
363 self.actions.append(self.refactoringIntroduceFactoryAct) 361 self.actions.append(self.refactoringIntroduceFactoryAct)
364 362
365 self.refactoringIntroduceParameterAct = E5Action( 363 self.refactoringIntroduceParameterAct = EricAction(
366 self.tr('Introduce Parameter'), 364 self.tr('Introduce Parameter'),
367 self.tr('Introduce &Parameter'), 365 self.tr('Introduce &Parameter'),
368 0, 0, 366 0, 0,
369 self, 'refactoring_introduce_parameter_method') 367 self, 'refactoring_introduce_parameter_method')
370 self.refactoringIntroduceParameterAct.setStatusTip(self.tr( 368 self.refactoringIntroduceParameterAct.setStatusTip(self.tr(
379 377
380 ##################################################### 378 #####################################################
381 ## Import refactorings actions 379 ## Import refactorings actions
382 ##################################################### 380 #####################################################
383 381
384 self.refactoringImportsOrganizeAct = E5Action( 382 self.refactoringImportsOrganizeAct = EricAction(
385 self.tr('Organize Imports'), 383 self.tr('Organize Imports'),
386 self.tr('&Organize Imports'), 384 self.tr('&Organize Imports'),
387 0, 0, 385 0, 0,
388 self, 'refactoring_organize_imports') 386 self, 'refactoring_organize_imports')
389 self.refactoringImportsOrganizeAct.setStatusTip(self.tr( 387 self.refactoringImportsOrganizeAct.setStatusTip(self.tr(
394 )) 392 ))
395 self.refactoringImportsOrganizeAct.triggered.connect( 393 self.refactoringImportsOrganizeAct.triggered.connect(
396 self.__importsOrganize) 394 self.__importsOrganize)
397 self.actions.append(self.refactoringImportsOrganizeAct) 395 self.actions.append(self.refactoringImportsOrganizeAct)
398 396
399 self.refactoringImportsStarExpandAct = E5Action( 397 self.refactoringImportsStarExpandAct = EricAction(
400 self.tr('Expand Star Imports'), 398 self.tr('Expand Star Imports'),
401 self.tr('E&xpand Star Imports'), 399 self.tr('E&xpand Star Imports'),
402 0, 0, 400 0, 0,
403 self, 'refactoring_expand_star_imports') 401 self, 'refactoring_expand_star_imports')
404 self.refactoringImportsStarExpandAct.setStatusTip(self.tr( 402 self.refactoringImportsStarExpandAct.setStatusTip(self.tr(
411 )) 409 ))
412 self.refactoringImportsStarExpandAct.triggered.connect( 410 self.refactoringImportsStarExpandAct.triggered.connect(
413 self.__importsExpandStar) 411 self.__importsExpandStar)
414 self.actions.append(self.refactoringImportsStarExpandAct) 412 self.actions.append(self.refactoringImportsStarExpandAct)
415 413
416 self.refactoringImportsRelativeToAbsoluteAct = E5Action( 414 self.refactoringImportsRelativeToAbsoluteAct = EricAction(
417 self.tr('Relative to Absolute'), 415 self.tr('Relative to Absolute'),
418 self.tr('Relative to &Absolute'), 416 self.tr('Relative to &Absolute'),
419 0, 0, 417 0, 0,
420 self, 'refactoring_relative_to_absolute_imports') 418 self, 'refactoring_relative_to_absolute_imports')
421 self.refactoringImportsRelativeToAbsoluteAct.setStatusTip(self.tr( 419 self.refactoringImportsRelativeToAbsoluteAct.setStatusTip(self.tr(
428 )) 426 ))
429 self.refactoringImportsRelativeToAbsoluteAct.triggered.connect( 427 self.refactoringImportsRelativeToAbsoluteAct.triggered.connect(
430 self.__importsRelativeToAbsolute) 428 self.__importsRelativeToAbsolute)
431 self.actions.append(self.refactoringImportsRelativeToAbsoluteAct) 429 self.actions.append(self.refactoringImportsRelativeToAbsoluteAct)
432 430
433 self.refactoringImportsFromsToImportsAct = E5Action( 431 self.refactoringImportsFromsToImportsAct = EricAction(
434 self.tr('Froms to Imports'), 432 self.tr('Froms to Imports'),
435 self.tr('Froms to &Imports'), 433 self.tr('Froms to &Imports'),
436 0, 0, 434 0, 0,
437 self, 'refactoring_froms_to_imports') 435 self, 'refactoring_froms_to_imports')
438 self.refactoringImportsFromsToImportsAct.setStatusTip(self.tr( 436 self.refactoringImportsFromsToImportsAct.setStatusTip(self.tr(
445 )) 443 ))
446 self.refactoringImportsFromsToImportsAct.triggered.connect( 444 self.refactoringImportsFromsToImportsAct.triggered.connect(
447 self.__importsFromToImport) 445 self.__importsFromToImport)
448 self.actions.append(self.refactoringImportsFromsToImportsAct) 446 self.actions.append(self.refactoringImportsFromsToImportsAct)
449 447
450 self.refactoringImportsHandleLongAct = E5Action( 448 self.refactoringImportsHandleLongAct = EricAction(
451 self.tr('Handle Long Imports'), 449 self.tr('Handle Long Imports'),
452 self.tr('Handle &Long Imports'), 450 self.tr('Handle &Long Imports'),
453 0, 0, 451 0, 0,
454 self, 'refactoring_organize_imports') 452 self, 'refactoring_organize_imports')
455 self.refactoringImportsHandleLongAct.setStatusTip(self.tr( 453 self.refactoringImportsHandleLongAct.setStatusTip(self.tr(
466 464
467 ##################################################### 465 #####################################################
468 ## Various refactorings actions 466 ## Various refactorings actions
469 ##################################################### 467 #####################################################
470 468
471 self.refactoringRestructureAct = E5Action( 469 self.refactoringRestructureAct = EricAction(
472 self.tr('Restructure'), 470 self.tr('Restructure'),
473 self.tr('Res&tructure'), 471 self.tr('Res&tructure'),
474 0, 0, 472 0, 0,
475 self, 'refactoring_restructure') 473 self, 'refactoring_restructure')
476 self.refactoringRestructureAct.setStatusTip(self.tr( 474 self.refactoringRestructureAct.setStatusTip(self.tr(
481 )) 479 ))
482 self.refactoringRestructureAct.triggered.connect( 480 self.refactoringRestructureAct.triggered.connect(
483 self.__restructure) 481 self.__restructure)
484 self.actions.append(self.refactoringRestructureAct) 482 self.actions.append(self.refactoringRestructureAct)
485 483
486 self.refactoringChangeSignatureAct = E5Action( 484 self.refactoringChangeSignatureAct = EricAction(
487 self.tr('Change Method Signature'), 485 self.tr('Change Method Signature'),
488 self.tr('&Change Method Signature'), 486 self.tr('&Change Method Signature'),
489 0, 0, 487 0, 0,
490 self, 'refactoring_change_method_signature') 488 self, 'refactoring_change_method_signature')
491 self.refactoringChangeSignatureAct.setStatusTip(self.tr( 489 self.refactoringChangeSignatureAct.setStatusTip(self.tr(
497 )) 495 ))
498 self.refactoringChangeSignatureAct.triggered.connect( 496 self.refactoringChangeSignatureAct.triggered.connect(
499 self.__changeSignature) 497 self.__changeSignature)
500 self.actions.append(self.refactoringChangeSignatureAct) 498 self.actions.append(self.refactoringChangeSignatureAct)
501 499
502 self.refactoringInlineArgumentDefaultAct = E5Action( 500 self.refactoringInlineArgumentDefaultAct = EricAction(
503 self.tr('Inline Argument Default'), 501 self.tr('Inline Argument Default'),
504 self.tr('Inline &Argument Default'), 502 self.tr('Inline &Argument Default'),
505 0, 0, 503 0, 0,
506 self, 'refactoring_inline_argument_default') 504 self, 'refactoring_inline_argument_default')
507 self.refactoringInlineArgumentDefaultAct.setStatusTip(self.tr( 505 self.refactoringInlineArgumentDefaultAct.setStatusTip(self.tr(
512 )) 510 ))
513 self.refactoringInlineArgumentDefaultAct.triggered.connect( 511 self.refactoringInlineArgumentDefaultAct.triggered.connect(
514 self.__inlineArgumentDefault) 512 self.__inlineArgumentDefault)
515 self.actions.append(self.refactoringInlineArgumentDefaultAct) 513 self.actions.append(self.refactoringInlineArgumentDefaultAct)
516 514
517 self.refactoringTransformModuleAct = E5Action( 515 self.refactoringTransformModuleAct = EricAction(
518 self.tr('Transform Module to Package'), 516 self.tr('Transform Module to Package'),
519 self.tr('Transform Module to Package'), 517 self.tr('Transform Module to Package'),
520 0, 0, 518 0, 0,
521 self, 'refactoring_transform_module_to_package') 519 self, 'refactoring_transform_module_to_package')
522 self.refactoringTransformModuleAct.setStatusTip(self.tr( 520 self.refactoringTransformModuleAct.setStatusTip(self.tr(
527 )) 525 ))
528 self.refactoringTransformModuleAct.triggered.connect( 526 self.refactoringTransformModuleAct.triggered.connect(
529 self.__transformModuleToPackage) 527 self.__transformModuleToPackage)
530 self.actions.append(self.refactoringTransformModuleAct) 528 self.actions.append(self.refactoringTransformModuleAct)
531 529
532 self.refactoringEncapsulateAttributeAct = E5Action( 530 self.refactoringEncapsulateAttributeAct = EricAction(
533 self.tr('Encapsulate Attribute'), 531 self.tr('Encapsulate Attribute'),
534 self.tr('Encap&sulate Attribute'), 532 self.tr('Encap&sulate Attribute'),
535 0, 0, 533 0, 0,
536 self, 'refactoring_encapsulate_attribute') 534 self, 'refactoring_encapsulate_attribute')
537 self.refactoringEncapsulateAttributeAct.setStatusTip(self.tr( 535 self.refactoringEncapsulateAttributeAct.setStatusTip(self.tr(
543 )) 541 ))
544 self.refactoringEncapsulateAttributeAct.triggered.connect( 542 self.refactoringEncapsulateAttributeAct.triggered.connect(
545 self.__encapsulateAttribute) 543 self.__encapsulateAttribute)
546 self.actions.append(self.refactoringEncapsulateAttributeAct) 544 self.actions.append(self.refactoringEncapsulateAttributeAct)
547 545
548 self.refactoringLocalVariableToAttributeAct = E5Action( 546 self.refactoringLocalVariableToAttributeAct = EricAction(
549 self.tr('Local Variable to Attribute'), 547 self.tr('Local Variable to Attribute'),
550 self.tr('Local Varia&ble to Attribute'), 548 self.tr('Local Varia&ble to Attribute'),
551 0, 0, 549 0, 0,
552 self, 'refactoring_local_variable_to_attribute') 550 self, 'refactoring_local_variable_to_attribute')
553 self.refactoringLocalVariableToAttributeAct.setStatusTip(self.tr( 551 self.refactoringLocalVariableToAttributeAct.setStatusTip(self.tr(
558 )) 556 ))
559 self.refactoringLocalVariableToAttributeAct.triggered.connect( 557 self.refactoringLocalVariableToAttributeAct.triggered.connect(
560 self.__convertLocalToAttribute) 558 self.__convertLocalToAttribute)
561 self.actions.append(self.refactoringLocalVariableToAttributeAct) 559 self.actions.append(self.refactoringLocalVariableToAttributeAct)
562 560
563 self.refactoringMethodToMethodObjectAct = E5Action( 561 self.refactoringMethodToMethodObjectAct = EricAction(
564 self.tr('Method To Method Object'), 562 self.tr('Method To Method Object'),
565 self.tr('Method To Method Ob&ject'), 563 self.tr('Method To Method Ob&ject'),
566 0, 0, 564 0, 0,
567 self, 'refactoring_method_to_methodobject') 565 self, 'refactoring_method_to_methodobject')
568 self.refactoringMethodToMethodObjectAct.setStatusTip(self.tr( 566 self.refactoringMethodToMethodObjectAct.setStatusTip(self.tr(
577 575
578 ##################################################### 576 #####################################################
579 ## History actions 577 ## History actions
580 ##################################################### 578 #####################################################
581 579
582 self.refactoringProjectHistoryAct = E5Action( 580 self.refactoringProjectHistoryAct = EricAction(
583 self.tr('Show Project History'), 581 self.tr('Show Project History'),
584 self.tr('Show Project History...'), 582 self.tr('Show Project History...'),
585 0, 0, 583 0, 0,
586 self, 'refactoring_show_project_history') 584 self, 'refactoring_show_project_history')
587 self.refactoringProjectHistoryAct.setStatusTip(self.tr( 585 self.refactoringProjectHistoryAct.setStatusTip(self.tr(
593 )) 591 ))
594 self.refactoringProjectHistoryAct.triggered.connect( 592 self.refactoringProjectHistoryAct.triggered.connect(
595 self.__showProjectHistory) 593 self.__showProjectHistory)
596 self.actions.append(self.refactoringProjectHistoryAct) 594 self.actions.append(self.refactoringProjectHistoryAct)
597 595
598 self.refactoringFileHistoryAct = E5Action( 596 self.refactoringFileHistoryAct = EricAction(
599 self.tr('Show Current File History'), 597 self.tr('Show Current File History'),
600 self.tr('Show Current File History...'), 598 self.tr('Show Current File History...'),
601 0, 0, 599 0, 0,
602 self, 'refactoring_show_file_history') 600 self, 'refactoring_show_file_history')
603 self.refactoringFileHistoryAct.setStatusTip(self.tr( 601 self.refactoringFileHistoryAct.setStatusTip(self.tr(
609 )) 607 ))
610 self.refactoringFileHistoryAct.triggered.connect( 608 self.refactoringFileHistoryAct.triggered.connect(
611 self.__showFileHistory) 609 self.__showFileHistory)
612 self.actions.append(self.refactoringFileHistoryAct) 610 self.actions.append(self.refactoringFileHistoryAct)
613 611
614 self.refactoringClearHistoryAct = E5Action( 612 self.refactoringClearHistoryAct = EricAction(
615 self.tr('Clear History'), 613 self.tr('Clear History'),
616 self.tr('Clear History'), 614 self.tr('Clear History'),
617 0, 0, 615 0, 0,
618 self, 'refactoring_clear_history') 616 self, 'refactoring_clear_history')
619 self.refactoringClearHistoryAct.setStatusTip(self.tr( 617 self.refactoringClearHistoryAct.setStatusTip(self.tr(
628 626
629 ##################################################### 627 #####################################################
630 ## Query actions 628 ## Query actions
631 ##################################################### 629 #####################################################
632 630
633 self.queryReferencesAct = E5Action( 631 self.queryReferencesAct = EricAction(
634 self.tr('Find occurrences'), 632 self.tr('Find occurrences'),
635 self.tr('Find &Occurrences'), 633 self.tr('Find &Occurrences'),
636 0, 0, 634 0, 0,
637 self, 'refactoring_find_occurrences') 635 self, 'refactoring_find_occurrences')
638 self.queryReferencesAct.setStatusTip(self.tr( 636 self.queryReferencesAct.setStatusTip(self.tr(
644 )) 642 ))
645 self.queryReferencesAct.triggered.connect( 643 self.queryReferencesAct.triggered.connect(
646 self.__queryReferences) 644 self.__queryReferences)
647 self.actions.append(self.queryReferencesAct) 645 self.actions.append(self.queryReferencesAct)
648 646
649 self.queryDefinitionAct = E5Action( 647 self.queryDefinitionAct = EricAction(
650 self.tr('Find definition'), 648 self.tr('Find definition'),
651 self.tr('Find &Definition'), 649 self.tr('Find &Definition'),
652 0, 0, 650 0, 0,
653 self, 'refactoring_find_definition') 651 self, 'refactoring_find_definition')
654 self.queryDefinitionAct.setStatusTip(self.tr( 652 self.queryDefinitionAct.setStatusTip(self.tr(
660 )) 658 ))
661 self.queryDefinitionAct.triggered.connect( 659 self.queryDefinitionAct.triggered.connect(
662 self.__queryDefinition) 660 self.__queryDefinition)
663 self.actions.append(self.queryDefinitionAct) 661 self.actions.append(self.queryDefinitionAct)
664 662
665 self.queryImplementationsAct = E5Action( 663 self.queryImplementationsAct = EricAction(
666 self.tr('Find implementations'), 664 self.tr('Find implementations'),
667 self.tr('Find &Implementations'), 665 self.tr('Find &Implementations'),
668 0, 0, 666 0, 0,
669 self, 'refactoring_find_implementations') 667 self, 'refactoring_find_implementations')
670 self.queryImplementationsAct.setStatusTip(self.tr( 668 self.queryImplementationsAct.setStatusTip(self.tr(
679 677
680 ##################################################### 678 #####################################################
681 ## Various actions 679 ## Various actions
682 ##################################################### 680 #####################################################
683 681
684 self.refactoringEditConfigAct = E5Action( 682 self.refactoringEditConfigAct = EricAction(
685 self.tr('Configure Rope'), 683 self.tr('Configure Rope'),
686 self.tr('&Configure Rope'), 684 self.tr('&Configure Rope'),
687 0, 0, 685 0, 0,
688 self, 'refactoring_edit_config') 686 self, 'refactoring_edit_config')
689 self.refactoringEditConfigAct.setStatusTip(self.tr( 687 self.refactoringEditConfigAct.setStatusTip(self.tr(
692 """<b>Configure Rope</b>""" 690 """<b>Configure Rope</b>"""
693 """<p>Opens the rope configuration file in an editor.</p>""" 691 """<p>Opens the rope configuration file in an editor.</p>"""
694 )) 692 ))
695 self.refactoringEditConfigAct.triggered.connect( 693 self.refactoringEditConfigAct.triggered.connect(
696 self.__editConfig) 694 self.__editConfig)
697 self.refactoringEditConfigAct.setMenuRole(QAction.NoRole) 695 self.refactoringEditConfigAct.setMenuRole(QAction.MenuRole.NoRole)
698 self.actions.append(self.refactoringEditConfigAct) 696 self.actions.append(self.refactoringEditConfigAct)
699 697
700 self.refactoringHelpAct = E5Action( 698 self.refactoringHelpAct = EricAction(
701 self.tr('Rope Help'), 699 self.tr('Rope Help'),
702 self.tr('Rope &Help'), 700 self.tr('Rope &Help'),
703 0, 0, 701 0, 0,
704 self, 'refactoring_help') 702 self, 'refactoring_help')
705 self.refactoringHelpAct.setStatusTip(self.tr( 703 self.refactoringHelpAct.setStatusTip(self.tr(
710 )) 708 ))
711 self.refactoringHelpAct.triggered.connect( 709 self.refactoringHelpAct.triggered.connect(
712 self.__showRopeHelp) 710 self.__showRopeHelp)
713 self.actions.append(self.refactoringHelpAct) 711 self.actions.append(self.refactoringHelpAct)
714 712
715 self.refactoringAllSoaAct = E5Action( 713 self.refactoringAllSoaAct = EricAction(
716 self.tr('Analyse all modules'), 714 self.tr('Analyse all modules'),
717 self.tr('&Analyse all modules'), 715 self.tr('&Analyse all modules'),
718 0, 0, 716 0, 0,
719 self, 'refactoring_analyze_all') 717 self, 'refactoring_analyze_all')
720 self.refactoringAllSoaAct.setStatusTip(self.tr( 718 self.refactoringAllSoaAct.setStatusTip(self.tr(
728 )) 726 ))
729 self.refactoringAllSoaAct.triggered.connect( 727 self.refactoringAllSoaAct.triggered.connect(
730 self.__performSOA) 728 self.__performSOA)
731 self.actions.append(self.refactoringAllSoaAct) 729 self.actions.append(self.refactoringAllSoaAct)
732 730
733 self.updateConfigAct = E5Action( 731 self.updateConfigAct = EricAction(
734 self.tr('Update Configuration'), 732 self.tr('Update Configuration'),
735 self.tr('&Update Configuration'), 733 self.tr('&Update Configuration'),
736 0, 0, 734 0, 0,
737 self, 'refactoring_update_configuration') 735 self, 'refactoring_update_configuration')
738 self.updateConfigAct.setStatusTip(self.tr( 736 self.updateConfigAct.setStatusTip(self.tr(
835 def __ropeInfo(self): 833 def __ropeInfo(self):
836 """ 834 """
837 Private slot to show some info about rope. 835 Private slot to show some info about rope.
838 """ 836 """
839 if self.__ropeConfig: 837 if self.__ropeConfig:
840 E5MessageBox.about( 838 EricMessageBox.about(
841 self.__ui, 839 self.__ui,
842 self.tr("About rope"), 840 self.tr("About rope"),
843 self.tr("{0}\nVersion {1}\n\n{2}".format( 841 self.tr("{0}\nVersion {1}\n\n{2}".format(
844 self.__ropeConfig["RopeInfo"], 842 self.__ropeConfig["RopeInfo"],
845 self.__ropeConfig["RopeVersion"], 843 self.__ropeConfig["RopeVersion"],
867 return True 865 return True
868 866
869 title = result.get("Title", self.tr("Rope Error")) 867 title = result.get("Title", self.tr("Rope Error"))
870 868
871 if result["Error"] == 'ModuleSyntaxError': 869 if result["Error"] == 'ModuleSyntaxError':
872 res = E5MessageBox.warning( 870 res = EricMessageBox.warning(
873 self.__ui, title, 871 self.__ui, title,
874 self.tr("Rope error: {0}").format( 872 self.tr("Rope error: {0}").format(
875 result["ErrorString"]), 873 result["ErrorString"]),
876 E5MessageBox.Ok | E5MessageBox.Open) 874 EricMessageBox.Ok | EricMessageBox.Open)
877 if res == E5MessageBox.Open: 875 if res == EricMessageBox.Open:
878 self.__vm.openSourceFile( 876 self.__vm.openSourceFile(
879 os.path.join(self.__e5project.getProjectPath(), 877 os.path.join(self.__ericProject.getProjectPath(),
880 result["ErrorFile"]), 878 result["ErrorFile"]),
881 result["ErrorLine"]) 879 result["ErrorLine"])
882 elif result["Error"] == "InterruptedTaskError": 880 elif result["Error"] == "InterruptedTaskError":
883 return True 881 return True
884 else: 882 else:
898 character. 896 character.
899 897
900 Note: rope seems to convert all EOL styles to just \n. 898 Note: rope seems to convert all EOL styles to just \n.
901 899
902 @param editor reference to the editor 900 @param editor reference to the editor
903 @type QScintilla.Editor.Editor 901 @type Editor
904 @param line line for the offset 902 @param line line for the offset
905 @type int 903 @type int
906 @param index index into line for the offset 904 @param index index into line for the offset
907 @type int 905 @type int
908 @return rope compliant offset into the file 906 @return rope compliant offset into the file
909 @rtype int 907 @rtype int
910 """ 908 """
911 source = editor.text() 909 source = editor.text()
912 offset = len("".join(source.splitlines(True)[:line])) + index 910 offset = len("".join(source.splitlines(True)[:line])) + index
913 if editor.eolMode() == QsciScintilla.EolWindows: 911 if editor.eolMode() == QsciScintilla.EolMode.EolWindows:
914 offset -= line 912 offset -= line
915 return offset 913 return offset
916 914
917 ################################################################## 915 ##################################################################
918 ## slots below implement the various refactorings 916 ## slots below implement the various refactorings
983 if aw is None: 981 if aw is None:
984 return 982 return
985 983
986 if not renameModule and not aw.hasSelectedText(): 984 if not renameModule and not aw.hasSelectedText():
987 # no selection available 985 # no selection available
988 E5MessageBox.warning( 986 EricMessageBox.warning(
989 self.__ui, title, 987 self.__ui, title,
990 self.tr("Highlight the declaration you want to rename" 988 self.tr("Highlight the declaration you want to rename"
991 " and try again.")) 989 " and try again."))
992 return 990 return
993 991
1006 selectedText, _ = os.path.splitext(os.path.basename(filename)) 1004 selectedText, _ = os.path.splitext(os.path.basename(filename))
1007 else: 1005 else:
1008 line, index, line1, index1 = aw.getSelection() 1006 line, index, line1, index1 = aw.getSelection()
1009 if line != line1: 1007 if line != line1:
1010 # selection span more than one line 1008 # selection span more than one line
1011 E5MessageBox.warning( 1009 EricMessageBox.warning(
1012 self.__ui, title, 1010 self.__ui, title,
1013 self.tr("The selection must not extend beyond" 1011 self.tr("The selection must not extend beyond"
1014 " one line.")) 1012 " one line."))
1015 return 1013 return
1016 index = int(index + (index1 - index) / 2) 1014 index = int(index + (index1 - index) / 2)
1037 return 1035 return
1038 1036
1039 title = self.tr("Change Occurrences") 1037 title = self.tr("Change Occurrences")
1040 if not aw.hasSelectedText(): 1038 if not aw.hasSelectedText():
1041 # no selection available 1039 # no selection available
1042 E5MessageBox.warning( 1040 EricMessageBox.warning(
1043 self.__ui, title, 1041 self.__ui, title,
1044 self.tr("Highlight an occurrence to be changed" 1042 self.tr("Highlight an occurrence to be changed"
1045 " and try again.")) 1043 " and try again."))
1046 return 1044 return
1047 1045
1091 if aw is None: 1089 if aw is None:
1092 return 1090 return
1093 1091
1094 if not aw.hasSelectedText(): 1092 if not aw.hasSelectedText():
1095 # no selection available 1093 # no selection available
1096 E5MessageBox.warning( 1094 EricMessageBox.warning(
1097 self.__ui, title, 1095 self.__ui, title,
1098 self.tr("Highlight the region of code you want to extract" 1096 self.tr("Highlight the region of code you want to extract"
1099 " and try again.")) 1097 " and try again."))
1100 return 1098 return
1101 1099
1130 return 1128 return
1131 1129
1132 title = self.tr("Inline") 1130 title = self.tr("Inline")
1133 if not aw.hasSelectedText(): 1131 if not aw.hasSelectedText():
1134 # no selection available 1132 # no selection available
1135 E5MessageBox.warning( 1133 EricMessageBox.warning(
1136 self.__ui, title, 1134 self.__ui, title,
1137 self.tr("Highlight the local variable, method or parameter" 1135 self.tr("Highlight the local variable, method or parameter"
1138 " you want to inline and try again.")) 1136 " you want to inline and try again."))
1139 return 1137 return
1140 1138
1171 1169
1172 if moveKind == "move_method": 1170 if moveKind == "move_method":
1173 title = self.tr("Move Method") 1171 title = self.tr("Move Method")
1174 if not aw.hasSelectedText(): 1172 if not aw.hasSelectedText():
1175 # no selection available 1173 # no selection available
1176 E5MessageBox.warning( 1174 EricMessageBox.warning(
1177 self.__ui, title, 1175 self.__ui, title,
1178 self.tr("Highlight the method to move" 1176 self.tr("Highlight the method to move"
1179 " and try again.")) 1177 " and try again."))
1180 return 1178 return
1181 else: 1179 else:
1213 return 1211 return
1214 1212
1215 title = self.tr("Use Function") 1213 title = self.tr("Use Function")
1216 if not aw.hasSelectedText(): 1214 if not aw.hasSelectedText():
1217 # no selection available 1215 # no selection available
1218 E5MessageBox.warning( 1216 EricMessageBox.warning(
1219 self.__ui, title, 1217 self.__ui, title,
1220 self.tr("Highlight a global function and try again.")) 1218 self.tr("Highlight a global function and try again."))
1221 return 1219 return
1222 1220
1223 if not self.confirmAllBuffersSaved(): 1221 if not self.confirmAllBuffersSaved():
1250 return 1248 return
1251 1249
1252 title = self.tr("Introduce Factory Method") 1250 title = self.tr("Introduce Factory Method")
1253 if not aw.hasSelectedText(): 1251 if not aw.hasSelectedText():
1254 # no selection available 1252 # no selection available
1255 E5MessageBox.warning( 1253 EricMessageBox.warning(
1256 self.__ui, title, 1254 self.__ui, title,
1257 self.tr("Highlight the class to introduce a factory" 1255 self.tr("Highlight the class to introduce a factory"
1258 " method for and try again.")) 1256 " method for and try again."))
1259 return 1257 return
1260 1258
1284 return 1282 return
1285 1283
1286 title = self.tr("Introduce Parameter") 1284 title = self.tr("Introduce Parameter")
1287 if not aw.hasSelectedText(): 1285 if not aw.hasSelectedText():
1288 # no selection available 1286 # no selection available
1289 E5MessageBox.warning( 1287 EricMessageBox.warning(
1290 self.__ui, title, 1288 self.__ui, title,
1291 self.tr("Highlight the code for the new parameter" 1289 self.tr("Highlight the code for the new parameter"
1292 " and try again.")) 1290 " and try again."))
1293 return 1291 return
1294 1292
1417 return 1415 return
1418 1416
1419 title = self.tr("Change Method Signature") 1417 title = self.tr("Change Method Signature")
1420 if not aw.hasSelectedText(): 1418 if not aw.hasSelectedText():
1421 # no selection available 1419 # no selection available
1422 E5MessageBox.warning( 1420 EricMessageBox.warning(
1423 self.__ui, title, 1421 self.__ui, title,
1424 self.tr("Highlight the method or function to change" 1422 self.tr("Highlight the method or function to change"
1425 " and try again.")) 1423 " and try again."))
1426 return 1424 return
1427 1425
1452 return 1450 return
1453 1451
1454 title = self.tr("Inline Argument Default") 1452 title = self.tr("Inline Argument Default")
1455 if not aw.hasSelectedText(): 1453 if not aw.hasSelectedText():
1456 # no selection available 1454 # no selection available
1457 E5MessageBox.warning( 1455 EricMessageBox.warning(
1458 self.__ui, title, 1456 self.__ui, title,
1459 self.tr("Highlight the method or function to inline" 1457 self.tr("Highlight the method or function to inline"
1460 " a parameter's default and try again.")) 1458 " a parameter's default and try again."))
1461 return 1459 return
1462 1460
1515 return 1513 return
1516 1514
1517 title = self.tr("Encapsulate Attribute") 1515 title = self.tr("Encapsulate Attribute")
1518 if not aw.hasSelectedText(): 1516 if not aw.hasSelectedText():
1519 # no selection available 1517 # no selection available
1520 E5MessageBox.warning( 1518 EricMessageBox.warning(
1521 self.__ui, title, 1519 self.__ui, title,
1522 self.tr("Highlight the attribute to encapsulate" 1520 self.tr("Highlight the attribute to encapsulate"
1523 " and try again.")) 1521 " and try again."))
1524 return 1522 return
1525 1523
1549 return 1547 return
1550 1548
1551 title = self.tr("Local Variable to Attribute") 1549 title = self.tr("Local Variable to Attribute")
1552 if not aw.hasSelectedText(): 1550 if not aw.hasSelectedText():
1553 # no selection available 1551 # no selection available
1554 E5MessageBox.warning( 1552 EricMessageBox.warning(
1555 self.__ui, title, 1553 self.__ui, title,
1556 self.tr("Highlight the local variable to make an attribute" 1554 self.tr("Highlight the local variable to make an attribute"
1557 " and try again.")) 1555 " and try again."))
1558 return 1556 return
1559 1557
1588 return 1586 return
1589 1587
1590 title = self.tr("Replace Method With Method Object") 1588 title = self.tr("Replace Method With Method Object")
1591 if not aw.hasSelectedText(): 1589 if not aw.hasSelectedText():
1592 # no selection available 1590 # no selection available
1593 E5MessageBox.warning( 1591 EricMessageBox.warning(
1594 self.__ui, title, 1592 self.__ui, title,
1595 self.tr("Highlight the method or function to convert" 1593 self.tr("Highlight the method or function to convert"
1596 " and try again.")) 1594 " and try again."))
1597 return 1595 return
1598 1596
1649 1647
1650 def __clearHistory(self): 1648 def __clearHistory(self):
1651 """ 1649 """
1652 Private slot to clear the redo and undo lists. 1650 Private slot to clear the redo and undo lists.
1653 """ 1651 """
1654 res = E5MessageBox.yesNo( 1652 res = EricMessageBox.yesNo(
1655 None, 1653 None,
1656 self.tr("Clear History"), 1654 self.tr("Clear History"),
1657 self.tr("Do you really want to clear the refactoring history?")) 1655 self.tr("Do you really want to clear the refactoring history?"))
1658 if res: 1656 if res:
1659 self.sendJson("History", { 1657 self.sendJson("History", {
1725 for occurrence in result["Entries"]: 1723 for occurrence in result["Entries"]:
1726 self.dlg.addEntry( 1724 self.dlg.addEntry(
1727 # file name, lineno, unsure 1725 # file name, lineno, unsure
1728 occurrence[0], occurrence[1], occurrence[2]) 1726 occurrence[0], occurrence[1], occurrence[2])
1729 else: 1727 else:
1730 E5MessageBox.warning( 1728 EricMessageBox.warning(
1731 self.__ui, title, 1729 self.__ui, title,
1732 self.tr("No occurrences found.")) 1730 self.tr("No occurrences found."))
1733 1731
1734 def __queryDefinition(self): 1732 def __queryDefinition(self):
1735 """ 1733 """
1773 self.dlg = MatchesDialog(self.__ui, False) 1771 self.dlg = MatchesDialog(self.__ui, False)
1774 self.dlg.show() 1772 self.dlg.show()
1775 self.dlg.addEntry(location[0], location[1]) 1773 self.dlg.addEntry(location[0], location[1])
1776 # file name, lineno 1774 # file name, lineno
1777 else: 1775 else:
1778 E5MessageBox.warning( 1776 EricMessageBox.warning(
1779 self.__ui, title, 1777 self.__ui, title,
1780 self.tr("No matching definition found.")) 1778 self.tr("No matching definition found."))
1781 1779
1782 def __queryImplementations(self): 1780 def __queryImplementations(self):
1783 """ 1781 """
1820 for occurrence in result["Entries"]: 1818 for occurrence in result["Entries"]:
1821 self.dlg.addEntry( 1819 self.dlg.addEntry(
1822 # file name, lineno, unsure 1820 # file name, lineno, unsure
1823 occurrence[0], occurrence[1], occurrence[2]) 1821 occurrence[0], occurrence[1], occurrence[2])
1824 else: 1822 else:
1825 E5MessageBox.warning( 1823 EricMessageBox.warning(
1826 self.__ui, title, self.tr("No implementations found.")) 1824 self.__ui, title, self.tr("No implementations found."))
1827 1825
1828 ##################################################### 1826 #####################################################
1829 ## Various actions 1827 ## Various actions
1830 ##################################################### 1828 #####################################################
1841 from QScintilla.MiniEditor import MiniEditor 1839 from QScintilla.MiniEditor import MiniEditor
1842 self.__editor = MiniEditor(configfile) 1840 self.__editor = MiniEditor(configfile)
1843 self.__editor.show() 1841 self.__editor.show()
1844 self.__editor.editorSaved.connect(self.__configChanged) 1842 self.__editor.editorSaved.connect(self.__configChanged)
1845 else: 1843 else:
1846 E5MessageBox.critical( 1844 EricMessageBox.critical(
1847 self.__ui, 1845 self.__ui,
1848 self.tr("Configure Rope"), 1846 self.tr("Configure Rope"),
1849 self.tr("""The Rope configuration file '{0}' does""" 1847 self.tr("""The Rope configuration file '{0}' does"""
1850 """ not exist.""").format(configfile)) 1848 """ not exist.""").format(configfile))
1851 else: 1849 else:
1852 E5MessageBox.critical( 1850 EricMessageBox.critical(
1853 self.__ui, 1851 self.__ui,
1854 self.tr("Configure Rope"), 1852 self.tr("Configure Rope"),
1855 self.tr("""The Rope admin directory does not exist.""")) 1853 self.tr("""The Rope admin directory does not exist."""))
1856 1854
1857 def __updateConfig(self): 1855 def __updateConfig(self):
1858 """ 1856 """
1859 Private slot to update the configuration file. 1857 Private slot to update the configuration file.
1860 """ 1858 """
1861 res = E5MessageBox.yesNo( 1859 res = EricMessageBox.yesNo(
1862 self.__ui, 1860 self.__ui,
1863 self.tr("Update Configuration"), 1861 self.tr("Update Configuration"),
1864 self.tr("""Shall rope's current configuration be replaced """ 1862 self.tr("""Shall rope's current configuration be replaced """
1865 """by a new default configuration?""")) 1863 """by a new default configuration?"""))
1866 if res: 1864 if res:
1871 with open(cname, "w") as f: 1869 with open(cname, "w") as f:
1872 f.write(src) 1870 f.write(src)
1873 self.__configChanged() 1871 self.__configChanged()
1874 self.__editConfig() 1872 self.__editConfig()
1875 except OSError as err: 1873 except OSError as err:
1876 E5MessageBox.critical( 1874 EricMessageBox.critical(
1877 None, 1875 None,
1878 self.tr("Update Configuration"), 1876 self.tr("Update Configuration"),
1879 self.tr("""<p>The configuration could not be""" 1877 self.tr("""<p>The configuration could not be"""
1880 """ updated.</p><p>Reason: {0}</p>""") 1878 """ updated.</p><p>Reason: {0}</p>""")
1881 .format(str(err))) 1879 .format(str(err)))
1895 def __performSOA(self): 1893 def __performSOA(self):
1896 """ 1894 """
1897 Private slot to perform SOA on all modules. 1895 Private slot to perform SOA on all modules.
1898 """ 1896 """
1899 title = self.tr("Analyse all modules") 1897 title = self.tr("Analyse all modules")
1900 res = E5MessageBox.yesNo( 1898 res = EricMessageBox.yesNo(
1901 self.__ui, 1899 self.__ui,
1902 title, 1900 title,
1903 self.tr("""This action might take some time. """ 1901 self.tr("""This action might take some time. """
1904 """Do you really want to perform SOA?""")) 1902 """Do you really want to perform SOA?"""))
1905 if res: 1903 if res:
1917 @type dict 1915 @type dict
1918 """ 1916 """
1919 if self.handleRopeError(result): 1917 if self.handleRopeError(result):
1920 title = result["Title"] 1918 title = result["Title"]
1921 1919
1922 E5MessageBox.information( 1920 EricMessageBox.information(
1923 self.__ui, 1921 self.__ui,
1924 title, 1922 title,
1925 self.tr("""Static object analysis (SOA) done. """ 1923 self.tr("""Static object analysis (SOA) done. """
1926 """SOA database updated.""")) 1924 """SOA database updated."""))
1927 1925
2008 def getActions(self): 2006 def getActions(self):
2009 """ 2007 """
2010 Public method to get a list of all actions. 2008 Public method to get a list of all actions.
2011 2009
2012 @return list of all actions 2010 @return list of all actions
2013 @rtype list of E5Action 2011 @rtype list of EricAction
2014 """ 2012 """
2015 return self.actions[:] 2013 return self.actions[:]
2016 2014
2017 def projectOpened(self): 2015 def projectOpened(self):
2018 """ 2016 """
2020 """ 2018 """
2021 if self.__projectopen: 2019 if self.__projectopen:
2022 self.projectClosed() 2020 self.projectClosed()
2023 2021
2024 self.__projectopen = True 2022 self.__projectopen = True
2025 self.__projectpath = self.__e5project.getProjectPath() 2023 self.__projectpath = self.__ericProject.getProjectPath()
2026 self.__projectLanguage = self.__e5project.getProjectLanguage() 2024 self.__projectLanguage = self.__ericProject.getProjectLanguage()
2027 2025
2028 ok = False 2026 ok = False
2029 2027
2030 if (self.__projectLanguage.startswith("Python") or 2028 if self.__projectLanguage in ("Python3", "MicroPython", "Cython"):
2031 self.__projectLanguage == "MicroPython"):
2032 clientEnv = os.environ.copy() 2029 clientEnv = os.environ.copy()
2033 if "PATH" in clientEnv: 2030 if "PATH" in clientEnv:
2034 clientEnv["PATH"] = self.__ui.getOriginalPathString() 2031 clientEnv["PATH"] = self.__ui.getOriginalPathString()
2035 2032
2036 venvManager = e5App().getObject("VirtualEnvManager") 2033 venvManager = ericApp().getObject("VirtualEnvManager")
2037 2034
2038 # get virtual environment from project first 2035 # get virtual environment from project first
2039 venvName = self.__e5project.getDebugProperty("VIRTUALENV") 2036 venvName = self.__ericProject.getDebugProperty("VIRTUALENV")
2040 if venvName: 2037 if venvName:
2041 try: 2038 try:
2042 isRemote = venvManager.isRemoteEnvironment(venvName) 2039 isRemote = venvManager.isRemoteEnvironment(venvName)
2043 except AttributeError: 2040 except AttributeError:
2044 isRemote = False 2041 isRemote = False
2045 else: 2042 else:
2046 isRemote = False 2043 isRemote = False
2047 if (not venvName) or isRemote: 2044 if (not venvName) or isRemote:
2048 # get it from debugger settings next 2045 # get it from debugger settings next
2049 if self.__projectLanguage in ("Python3", "MicroPython"): 2046 if self.__projectLanguage in (
2047 "Python3", "MicroPython", "Cython"
2048 ):
2050 venvName = Preferences.getDebugger("Python3VirtualEnv") 2049 venvName = Preferences.getDebugger("Python3VirtualEnv")
2051 if not venvName: 2050 if not venvName:
2052 venvName, _ = venvManager.getDefaultEnvironment() 2051 venvName, _ = venvManager.getDefaultEnvironment()
2053 else: 2052 else:
2054 venvName = "" 2053 venvName = ""
2125 def confirmBufferIsSaved(self, editor): 2124 def confirmBufferIsSaved(self, editor):
2126 """ 2125 """
2127 Public method to check, if an editor has unsaved changes. 2126 Public method to check, if an editor has unsaved changes.
2128 2127
2129 @param editor reference to the editor to be checked 2128 @param editor reference to the editor to be checked
2130 @type QScintilla.Editor.Editor 2129 @type Editor
2131 @return flag indicating, that the editor doesn't contain 2130 @return flag indicating, that the editor doesn't contain
2132 unsaved edits 2131 unsaved edits
2133 @rtype bool 2132 @rtype bool
2134 """ 2133 """
2135 res = editor.checkDirty() 2134 res = editor.checkDirty()
2178 @type str 2177 @type str
2179 @param oldSource source code before the change 2178 @param oldSource source code before the change
2180 @type str 2179 @type str
2181 """ 2180 """
2182 if ( 2181 if (
2183 self.__e5project.isOpen() and 2182 self.__ericProject.isOpen() and
2184 self.__e5project.isProjectFile(filename) 2183 self.__ericProject.isProjectFile(filename)
2185 ): 2184 ):
2186 editor = self.__vm.getOpenEditor(filename) 2185 editor = self.__vm.getOpenEditor(filename)
2187 if ( 2186 if (
2188 self.__ropeConfig and 2187 self.__ropeConfig and
2189 editor is not None and 2188 editor is not None and
2215 2214
2216 @param params dictionary containing the exception data 2215 @param params dictionary containing the exception data
2217 @type dict 2216 @type dict
2218 """ 2217 """
2219 if params["ExceptionType"] == "ProtocolError": 2218 if params["ExceptionType"] == "ProtocolError":
2220 E5MessageBox.critical( 2219 EricMessageBox.critical(
2221 None, 2220 None,
2222 self.tr("Refactoring Protocol Error"), 2221 self.tr("Refactoring Protocol Error"),
2223 self.tr("""<p>The data received from the refactoring""" 2222 self.tr("""<p>The data received from the refactoring"""
2224 """ server could not be decoded. Please report""" 2223 """ server could not be decoded. Please report"""
2225 """ this issue with the received data to the""" 2224 """ this issue with the received data to the"""
2226 """ eric bugs email address.</p>""" 2225 """ eric bugs email address.</p>"""
2227 """<p>Error: {0}</p>""" 2226 """<p>Error: {0}</p>"""
2228 """<p>Data:<br/>{1}</p>""").format( 2227 """<p>Data:<br/>{1}</p>""").format(
2229 params["ExceptionValue"], 2228 params["ExceptionValue"],
2230 Utilities.html_encode(params["ProtocolData"])), 2229 Utilities.html_encode(params["ProtocolData"])),
2231 E5MessageBox.StandardButtons( 2230 EricMessageBox.StandardButtons(
2232 E5MessageBox.Ok)) 2231 EricMessageBox.Ok))
2233 else: 2232 else:
2234 E5MessageBox.critical( 2233 EricMessageBox.critical(
2235 None, 2234 None,
2236 self.tr("Refactoring Client Error"), 2235 self.tr("Refactoring Client Error"),
2237 self.tr("<p>An exception happened in the refactoring" 2236 self.tr("<p>An exception happened in the refactoring"
2238 " client. Please report it to the eric bugs" 2237 " client. Please report it to the eric bugs"
2239 " email address.</p>" 2238 " email address.</p>"
2243 Utilities.html_encode(params["ExceptionType"]), 2242 Utilities.html_encode(params["ExceptionType"]),
2244 params["ExceptionValue"], 2243 params["ExceptionValue"],
2245 params["Traceback"].replace("\r\n", "<br/>") 2244 params["Traceback"].replace("\r\n", "<br/>")
2246 .replace("\n", "<br/>").replace("\r", "<br/>"), 2245 .replace("\n", "<br/>").replace("\r", "<br/>"),
2247 ), 2246 ),
2248 E5MessageBox.StandardButtons( 2247 EricMessageBox.StandardButtons(
2249 E5MessageBox.Ok)) 2248 EricMessageBox.Ok))
2250 2249
2251 def __startRefactoringClient(self, interpreter, clientEnv): 2250 def __startRefactoringClient(self, interpreter, clientEnv):
2252 """ 2251 """
2253 Private method to start the refactoring client. 2252 Private method to start the refactoring client.
2254 2253
2263 if interpreter: 2262 if interpreter:
2264 client = os.path.join(os.path.dirname(__file__), 2263 client = os.path.join(os.path.dirname(__file__),
2265 "RefactoringClient.py") 2264 "RefactoringClient.py")
2266 ok, exitCode = self.startClient( 2265 ok, exitCode = self.startClient(
2267 interpreter, client, 2266 interpreter, client,
2268 [self.__projectpath, Globals.getPythonModulesDirectory()], 2267 [self.__projectpath, Globals.getPythonLibraryDirectory()],
2269 environment=clientEnv) 2268 environment=clientEnv)
2270 if not ok and exitCode == 42: 2269 if not ok and exitCode == 42:
2271 self.__ui.appendToStderr("RefactoringServer: " + self.tr( 2270 self.__ui.appendToStderr("RefactoringServer: " + self.tr(
2272 "The rope refactoring library is not installed.\n" 2271 "The rope refactoring library is not installed.\n"
2273 )) 2272 ))

eric ide

mercurial