RefactoringRope/RefactoringServer.py

branch
eric7
changeset 389
4f53795beff0
parent 383
a89b3f379703
child 392
b9b0a462123d
equal deleted inserted replaced
388:cb044ec27c24 389:4f53795beff0
32 32
33 class RefactoringServer(EricJsonServer): 33 class RefactoringServer(EricJsonServer):
34 """ 34 """
35 Class implementing the refactoring interface to rope. 35 Class implementing the refactoring interface to rope.
36 """ 36 """
37
37 def __init__(self, plugin, parent=None): 38 def __init__(self, plugin, parent=None):
38 """ 39 """
39 Constructor 40 Constructor
40 41
41 @param plugin reference to the plugin object 42 @param plugin reference to the plugin object
42 @type RefactoringRopePlugin 43 @type RefactoringRopePlugin
43 @param parent parent 44 @param parent parent
44 @type QObject 45 @type QObject
45 """ 46 """
46 super().__init__( 47 super().__init__("RefactoringServer", parent=parent)
47 "RefactoringServer", parent=parent) 48
48
49 self.__plugin = plugin 49 self.__plugin = plugin
50 self.__ui = parent 50 self.__ui = parent
51 self.__vm = ericApp().getObject("ViewManager") 51 self.__vm = ericApp().getObject("ViewManager")
52 self.__ericProject = ericApp().getObject("Project") 52 self.__ericProject = ericApp().getObject("Project")
53 self.__projectpath = '' 53 self.__projectpath = ""
54 self.__projectLanguage = "" 54 self.__projectLanguage = ""
55 self.__projectopen = False 55 self.__projectopen = False
56 self.__ropeConfig = {} 56 self.__ropeConfig = {}
57 57
58 self.__mainMenu = None 58 self.__mainMenu = None
59 self.__mainAct = None 59 self.__mainAct = None
60 self.__separatorAct = None 60 self.__separatorAct = None
61 61
62 self.__progressDialog = None 62 self.__progressDialog = None
63 self.__helpDialog = None 63 self.__helpDialog = None
64 self.__historyDialog = None 64 self.__historyDialog = None
65 self.__refactoringDialogs = {} 65 self.__refactoringDialogs = {}
66 66
67 from .FileSystemCommands import EricFileSystemCommands 67 from .FileSystemCommands import EricFileSystemCommands
68
68 self.__fsCommands = EricFileSystemCommands(self.__ericProject) 69 self.__fsCommands = EricFileSystemCommands(self.__ericProject)
69 70
70 self.__methodMapping = { 71 self.__methodMapping = {
71 "Config": self.__setConfig, 72 "Config": self.__setConfig,
72 "Progress": self.__processProgress, 73 "Progress": self.__processProgress,
73 "QueryReferencesResult": self.__queryReferencesResult, 74 "QueryReferencesResult": self.__queryReferencesResult,
74 "QueryDefinitionResult": self.__queryDefinitionResult, 75 "QueryDefinitionResult": self.__queryDefinitionResult,
75 "QueryImplementationsResult": self.__queryImplementationsResult, 76 "QueryImplementationsResult": self.__queryImplementationsResult,
76 "SoaFinished": self.__soaFinished, 77 "SoaFinished": self.__soaFinished,
77
78 "FileSystemCommand": self.__fsCommands.processFileSystemCommand, 78 "FileSystemCommand": self.__fsCommands.processFileSystemCommand,
79
80 "ClientException": self.__processClientException, 79 "ClientException": self.__processClientException,
81
82 "HistoryResult": self.__processHistoryResult, 80 "HistoryResult": self.__processHistoryResult,
83
84 "Changes": self.__processChanges, 81 "Changes": self.__processChanges,
85 } 82 }
86 83
87 @pyqtSlot() 84 @pyqtSlot()
88 def handleNewConnection(self): 85 def handleNewConnection(self):
89 """ 86 """
90 Public slot for new incoming connections from a client. 87 Public slot for new incoming connections from a client.
91 """ 88 """
92 super().handleNewConnection() 89 super().handleNewConnection()
93 90
94 self.sendJson("GetConfig", {}) 91 self.sendJson("GetConfig", {})
95 92
96 def activate(self): 93 def activate(self):
97 """ 94 """
98 Public method to activate the refactoring server. 95 Public method to activate the refactoring server.
99 96
100 This is performed when the rope plug-in is activated. 97 This is performed when the rope plug-in is activated.
101 """ 98 """
102 self.__initActions() 99 self.__initActions()
103 ericApp().registerPluginObject("RefactoringRope", self) 100 ericApp().registerPluginObject("RefactoringRope", self)
104 readShortcuts(pluginName="RefactoringRope") 101 readShortcuts(pluginName="RefactoringRope")
105 102
106 self.__mainMenu = self.__initMenu() 103 self.__mainMenu = self.__initMenu()
107 projectToolsMenu = self.__ui.getMenu("project_tools") 104 projectToolsMenu = self.__ui.getMenu("project_tools")
108 if projectToolsMenu is not None: 105 if projectToolsMenu is not None:
109 insertBeforeAct = projectToolsMenu.actions()[0] 106 insertBeforeAct = projectToolsMenu.actions()[0]
110 self.__mainAct = projectToolsMenu.insertMenu( 107 self.__mainAct = projectToolsMenu.insertMenu(
111 insertBeforeAct, self.__mainMenu) 108 insertBeforeAct, self.__mainMenu
112 self.__separatorAct = projectToolsMenu.insertSeparator( 109 )
113 insertBeforeAct) 110 self.__separatorAct = projectToolsMenu.insertSeparator(insertBeforeAct)
114 else: 111 else:
115 projectAct = self.__ui.getMenuBarAction("project") 112 projectAct = self.__ui.getMenuBarAction("project")
116 actions = self.__ui.menuBar().actions() 113 actions = self.__ui.menuBar().actions()
117 insertBeforeAct = actions[actions.index(projectAct) + 1] 114 insertBeforeAct = actions[actions.index(projectAct) + 1]
118 self.__mainAct = self.__ui.menuBar().insertMenu( 115 self.__mainAct = self.__ui.menuBar().insertMenu(
119 insertBeforeAct, self.__mainMenu) 116 insertBeforeAct, self.__mainMenu
117 )
120 self.__mainAct.setEnabled(False) 118 self.__mainAct.setEnabled(False)
121 119
122 if ericApp().getObject("Project").isOpen(): 120 if ericApp().getObject("Project").isOpen():
123 self.projectOpened() 121 self.projectOpened()
124 122
125 ericApp().getObject("Project").projectOpened.connect( 123 ericApp().getObject("Project").projectOpened.connect(self.projectOpened)
126 self.projectOpened)
127 ericApp().getObject("Project").projectPropertiesChanged.connect( 124 ericApp().getObject("Project").projectPropertiesChanged.connect(
128 self.projectOpened) 125 self.projectOpened
129 ericApp().getObject("Project").projectClosed.connect( 126 )
130 self.projectClosed) 127 ericApp().getObject("Project").projectClosed.connect(self.projectClosed)
131 ericApp().getObject("Project").newProject.connect( 128 ericApp().getObject("Project").newProject.connect(self.projectOpened)
132 self.projectOpened) 129
133
134 def deactivate(self): 130 def deactivate(self):
135 """ 131 """
136 Public method to deactivate the refactoring server. 132 Public method to deactivate the refactoring server.
137 """ 133 """
138 ericApp().unregisterPluginObject("RefactoringRope") 134 ericApp().unregisterPluginObject("RefactoringRope")
139 135
140 ericApp().getObject("Project").projectOpened.disconnect( 136 ericApp().getObject("Project").projectOpened.disconnect(self.projectOpened)
141 self.projectOpened)
142 ericApp().getObject("Project").projectPropertiesChanged.disconnect( 137 ericApp().getObject("Project").projectPropertiesChanged.disconnect(
143 self.projectOpened) 138 self.projectOpened
144 ericApp().getObject("Project").projectClosed.disconnect( 139 )
145 self.projectClosed) 140 ericApp().getObject("Project").projectClosed.disconnect(self.projectClosed)
146 ericApp().getObject("Project").newProject.disconnect( 141 ericApp().getObject("Project").newProject.disconnect(self.projectOpened)
147 self.projectOpened) 142
148
149 projectToolsMenu = self.__ui.getMenu("project_tools") 143 projectToolsMenu = self.__ui.getMenu("project_tools")
150 if projectToolsMenu is not None: 144 if projectToolsMenu is not None:
151 projectToolsMenu.removeAction(self.__separatorAct) 145 projectToolsMenu.removeAction(self.__separatorAct)
152 projectToolsMenu.removeAction(self.__mainAct) 146 projectToolsMenu.removeAction(self.__mainAct)
153 else: 147 else:
154 self.__ui.menuBar().removeAction(self.__mainAct) 148 self.__ui.menuBar().removeAction(self.__mainAct)
155 149
156 self.projectClosed() 150 self.projectClosed()
157 151
158 def getMainWindow(self): 152 def getMainWindow(self):
159 """ 153 """
160 Public method to get a reference to the IDE main window. 154 Public method to get a reference to the IDE main window.
161 155
162 @return reference to the IDE main window 156 @return reference to the IDE main window
163 @rtype UserInterface 157 @rtype UserInterface
164 """ 158 """
165 return self.__ui 159 return self.__ui
166 160
167 def __initActions(self): 161 def __initActions(self):
168 """ 162 """
169 Private method to define the refactoring actions. 163 Private method to define the refactoring actions.
170 """ 164 """
171 self.actions = [] 165 self.actions = []
172 166
173 ##################################################### 167 #####################################################
174 ## Rename refactoring actions 168 ## Rename refactoring actions
175 ##################################################### 169 #####################################################
176 170
177 self.refactoringRenameAct = EricAction( 171 self.refactoringRenameAct = EricAction(
178 self.tr('Rename'), 172 self.tr("Rename"), self.tr("&Rename"), 0, 0, self, "refactoring_rename"
179 self.tr('&Rename'), 173 )
180 0, 0, 174 self.refactoringRenameAct.setStatusTip(self.tr("Rename the highlighted object"))
181 self, 'refactoring_rename') 175 self.refactoringRenameAct.setWhatsThis(
182 self.refactoringRenameAct.setStatusTip(self.tr( 176 self.tr(
183 'Rename the highlighted object')) 177 """<b>Rename</b>""" """<p>Rename the highlighted Python object.</p>"""
184 self.refactoringRenameAct.setWhatsThis(self.tr( 178 )
185 """<b>Rename</b>""" 179 )
186 """<p>Rename the highlighted Python object.</p>""" 180 self.refactoringRenameAct.triggered.connect(self.__rename)
187 ))
188 self.refactoringRenameAct.triggered.connect(
189 self.__rename)
190 self.actions.append(self.refactoringRenameAct) 181 self.actions.append(self.refactoringRenameAct)
191 182
192 self.refactoringRenameLocalAct = EricAction( 183 self.refactoringRenameLocalAct = EricAction(
193 self.tr('Local Rename'), 184 self.tr("Local Rename"),
194 self.tr('&Local Rename'), 185 self.tr("&Local Rename"),
195 0, 0, 186 0,
196 self, 'refactoring_rename_local') 187 0,
197 self.refactoringRenameLocalAct.setStatusTip(self.tr( 188 self,
198 'Rename the highlighted object in the current module only')) 189 "refactoring_rename_local",
199 self.refactoringRenameLocalAct.setWhatsThis(self.tr( 190 )
200 """<b>Local Rename</b>""" 191 self.refactoringRenameLocalAct.setStatusTip(
201 """<p>Rename the highlighted Python object in the current""" 192 self.tr("Rename the highlighted object in the current module only")
202 """ module only.</p>""" 193 )
203 )) 194 self.refactoringRenameLocalAct.setWhatsThis(
204 self.refactoringRenameLocalAct.triggered.connect( 195 self.tr(
205 self.__renameLocal) 196 """<b>Local Rename</b>"""
197 """<p>Rename the highlighted Python object in the current"""
198 """ module only.</p>"""
199 )
200 )
201 self.refactoringRenameLocalAct.triggered.connect(self.__renameLocal)
206 self.actions.append(self.refactoringRenameLocalAct) 202 self.actions.append(self.refactoringRenameLocalAct)
207 203
208 self.refactoringRenameModuleAct = EricAction( 204 self.refactoringRenameModuleAct = EricAction(
209 self.tr('Rename Current Module'), 205 self.tr("Rename Current Module"),
210 self.tr('Rename Current Module'), 206 self.tr("Rename Current Module"),
211 0, 0, 207 0,
212 self, 'refactoring_rename_module') 208 0,
213 self.refactoringRenameModuleAct.setStatusTip(self.tr( 209 self,
214 'Rename the current module')) 210 "refactoring_rename_module",
215 self.refactoringRenameModuleAct.setWhatsThis(self.tr( 211 )
216 """<b>Rename Current Module</b>""" 212 self.refactoringRenameModuleAct.setStatusTip(
217 """<p>Rename the current module.</p>""" 213 self.tr("Rename the current module")
218 )) 214 )
219 self.refactoringRenameModuleAct.triggered.connect( 215 self.refactoringRenameModuleAct.setWhatsThis(
220 self.__renameModule) 216 self.tr(
217 """<b>Rename Current Module</b>"""
218 """<p>Rename the current module.</p>"""
219 )
220 )
221 self.refactoringRenameModuleAct.triggered.connect(self.__renameModule)
221 self.actions.append(self.refactoringRenameModuleAct) 222 self.actions.append(self.refactoringRenameModuleAct)
222 223
223 self.refactoringChangeOccurrencesAct = EricAction( 224 self.refactoringChangeOccurrencesAct = EricAction(
224 self.tr('Change Occurrences'), 225 self.tr("Change Occurrences"),
225 self.tr('Change &Occurrences'), 226 self.tr("Change &Occurrences"),
226 0, 0, 227 0,
227 self, 'refactoring_change_occurrences') 228 0,
228 self.refactoringChangeOccurrencesAct.setStatusTip(self.tr( 229 self,
229 'Change all occurrences in the local scope')) 230 "refactoring_change_occurrences",
230 self.refactoringChangeOccurrencesAct.setWhatsThis(self.tr( 231 )
231 """<b>Change Occurrences</b>""" 232 self.refactoringChangeOccurrencesAct.setStatusTip(
232 """<p>Change all occurrences in the local scope.</p>""" 233 self.tr("Change all occurrences in the local scope")
233 )) 234 )
234 self.refactoringChangeOccurrencesAct.triggered.connect( 235 self.refactoringChangeOccurrencesAct.setWhatsThis(
235 self.__changeOccurrences) 236 self.tr(
237 """<b>Change Occurrences</b>"""
238 """<p>Change all occurrences in the local scope.</p>"""
239 )
240 )
241 self.refactoringChangeOccurrencesAct.triggered.connect(self.__changeOccurrences)
236 self.actions.append(self.refactoringChangeOccurrencesAct) 242 self.actions.append(self.refactoringChangeOccurrencesAct)
237 243
238 ##################################################### 244 #####################################################
239 ## Extract refactoring actions 245 ## Extract refactoring actions
240 ##################################################### 246 #####################################################
241 247
242 self.refactoringExtractMethodAct = EricAction( 248 self.refactoringExtractMethodAct = EricAction(
243 self.tr('Extract method'), 249 self.tr("Extract method"),
244 self.tr('Extract &Method'), 250 self.tr("Extract &Method"),
245 0, 0, 251 0,
246 self, 'refactoring_extract_method') 252 0,
247 self.refactoringExtractMethodAct.setStatusTip(self.tr( 253 self,
248 'Extract the highlighted area as a method')) 254 "refactoring_extract_method",
249 self.refactoringExtractMethodAct.setWhatsThis(self.tr( 255 )
250 """<b>Extract method</b>""" 256 self.refactoringExtractMethodAct.setStatusTip(
251 """<p>Extract the highlighted area as a method or function.</p>""" 257 self.tr("Extract the highlighted area as a method")
252 )) 258 )
253 self.refactoringExtractMethodAct.triggered.connect( 259 self.refactoringExtractMethodAct.setWhatsThis(
254 self.__extractMethod) 260 self.tr(
261 """<b>Extract method</b>"""
262 """<p>Extract the highlighted area as a method or function.</p>"""
263 )
264 )
265 self.refactoringExtractMethodAct.triggered.connect(self.__extractMethod)
255 self.actions.append(self.refactoringExtractMethodAct) 266 self.actions.append(self.refactoringExtractMethodAct)
256 267
257 self.refactoringExtractLocalVariableAct = EricAction( 268 self.refactoringExtractLocalVariableAct = EricAction(
258 self.tr('Extract local variable'), 269 self.tr("Extract local variable"),
259 self.tr('&Extract Local Variable'), 270 self.tr("&Extract Local Variable"),
260 0, 0, 271 0,
261 self, 'refactoring_extract_variable') 272 0,
262 self.refactoringExtractLocalVariableAct.setStatusTip(self.tr( 273 self,
263 'Extract the highlighted area as a local variable')) 274 "refactoring_extract_variable",
264 self.refactoringExtractLocalVariableAct.setWhatsThis(self.tr( 275 )
265 """<b>Extract local variable</b>""" 276 self.refactoringExtractLocalVariableAct.setStatusTip(
266 """<p>Extract the highlighted area as a local variable.</p>""" 277 self.tr("Extract the highlighted area as a local variable")
267 )) 278 )
279 self.refactoringExtractLocalVariableAct.setWhatsThis(
280 self.tr(
281 """<b>Extract local variable</b>"""
282 """<p>Extract the highlighted area as a local variable.</p>"""
283 )
284 )
268 self.refactoringExtractLocalVariableAct.triggered.connect( 285 self.refactoringExtractLocalVariableAct.triggered.connect(
269 self.__extractLocalVariable) 286 self.__extractLocalVariable
287 )
270 self.actions.append(self.refactoringExtractLocalVariableAct) 288 self.actions.append(self.refactoringExtractLocalVariableAct)
271 289
272 ##################################################### 290 #####################################################
273 ## Inline refactoring actions 291 ## Inline refactoring actions
274 ##################################################### 292 #####################################################
275 293
276 self.refactoringInlineAct = EricAction( 294 self.refactoringInlineAct = EricAction(
277 self.tr('Inline'), 295 self.tr("Inline"), self.tr("&Inline"), 0, 0, self, "refactoring_inline"
278 self.tr('&Inline'), 296 )
279 0, 0, 297 self.refactoringInlineAct.setStatusTip(
280 self, 'refactoring_inline') 298 self.tr("Inlines the selected local variable or method")
281 self.refactoringInlineAct.setStatusTip(self.tr( 299 )
282 'Inlines the selected local variable or method')) 300 self.refactoringInlineAct.setWhatsThis(
283 self.refactoringInlineAct.setWhatsThis(self.tr( 301 self.tr(
284 """<b>Inline</b>""" 302 """<b>Inline</b>"""
285 """<p>Inlines the selected local variable or method.</p>""" 303 """<p>Inlines the selected local variable or method.</p>"""
286 )) 304 )
287 self.refactoringInlineAct.triggered.connect( 305 )
288 self.__inline) 306 self.refactoringInlineAct.triggered.connect(self.__inline)
289 self.actions.append(self.refactoringInlineAct) 307 self.actions.append(self.refactoringInlineAct)
290 308
291 ##################################################### 309 #####################################################
292 ## Move refactoring actions 310 ## Move refactoring actions
293 ##################################################### 311 #####################################################
294 312
295 self.refactoringMoveMethodAct = EricAction( 313 self.refactoringMoveMethodAct = EricAction(
296 self.tr('Move method'), 314 self.tr("Move method"),
297 self.tr('Mo&ve Method'), 315 self.tr("Mo&ve Method"),
298 0, 0, 316 0,
299 self, 'refactoring_move_method') 317 0,
300 self.refactoringMoveMethodAct.setStatusTip(self.tr( 318 self,
301 'Move the highlighted method to another class')) 319 "refactoring_move_method",
302 self.refactoringMoveMethodAct.setWhatsThis(self.tr( 320 )
303 """<b>Move method</b>""" 321 self.refactoringMoveMethodAct.setStatusTip(
304 """<p>Move the highlighted method to another class.</p>""" 322 self.tr("Move the highlighted method to another class")
305 )) 323 )
324 self.refactoringMoveMethodAct.setWhatsThis(
325 self.tr(
326 """<b>Move method</b>"""
327 """<p>Move the highlighted method to another class.</p>"""
328 )
329 )
306 self.refactoringMoveMethodAct.triggered.connect( 330 self.refactoringMoveMethodAct.triggered.connect(
307 lambda: self.__move("move_method")) 331 lambda: self.__move("move_method")
332 )
308 self.actions.append(self.refactoringMoveMethodAct) 333 self.actions.append(self.refactoringMoveMethodAct)
309 334
310 self.refactoringMoveModuleAct = EricAction( 335 self.refactoringMoveModuleAct = EricAction(
311 self.tr('Move current module'), 336 self.tr("Move current module"),
312 self.tr('Move Current Module'), 337 self.tr("Move Current Module"),
313 0, 0, 338 0,
314 self, 'refactoring_move_module') 339 0,
315 self.refactoringMoveModuleAct.setStatusTip(self.tr( 340 self,
316 'Move the current module to another package')) 341 "refactoring_move_module",
317 self.refactoringMoveModuleAct.setWhatsThis(self.tr( 342 )
318 """<b>Move current module</b>""" 343 self.refactoringMoveModuleAct.setStatusTip(
319 """<p>Move the current module to another package.</p>""" 344 self.tr("Move the current module to another package")
320 )) 345 )
346 self.refactoringMoveModuleAct.setWhatsThis(
347 self.tr(
348 """<b>Move current module</b>"""
349 """<p>Move the current module to another package.</p>"""
350 )
351 )
321 self.refactoringMoveModuleAct.triggered.connect( 352 self.refactoringMoveModuleAct.triggered.connect(
322 lambda: self.__move("move_module")) 353 lambda: self.__move("move_module")
354 )
323 self.actions.append(self.refactoringMoveModuleAct) 355 self.actions.append(self.refactoringMoveModuleAct)
324 356
325 ##################################################### 357 #####################################################
326 ## Use function refactoring action 358 ## Use function refactoring action
327 ##################################################### 359 #####################################################
328 360
329 self.refactoringUseFunctionAct = EricAction( 361 self.refactoringUseFunctionAct = EricAction(
330 self.tr('Use Function'), 362 self.tr("Use Function"),
331 self.tr('Use Function'), 363 self.tr("Use Function"),
332 0, 0, 364 0,
333 self, 'refactoring_use_function') 365 0,
334 self.refactoringUseFunctionAct.setStatusTip(self.tr( 366 self,
335 'Use a function wherever possible.')) 367 "refactoring_use_function",
336 self.refactoringUseFunctionAct.setWhatsThis(self.tr( 368 )
337 """<b>Use function</b>""" 369 self.refactoringUseFunctionAct.setStatusTip(
338 """<p>Tries to use a function wherever possible.</p>""" 370 self.tr("Use a function wherever possible.")
339 )) 371 )
340 self.refactoringUseFunctionAct.triggered.connect( 372 self.refactoringUseFunctionAct.setWhatsThis(
341 self.__useFunction) 373 self.tr(
374 """<b>Use function</b>"""
375 """<p>Tries to use a function wherever possible.</p>"""
376 )
377 )
378 self.refactoringUseFunctionAct.triggered.connect(self.__useFunction)
342 self.actions.append(self.refactoringUseFunctionAct) 379 self.actions.append(self.refactoringUseFunctionAct)
343 380
344 ##################################################### 381 #####################################################
345 ## Introduce refactorings actions 382 ## Introduce refactorings actions
346 ##################################################### 383 #####################################################
347 384
348 self.refactoringIntroduceFactoryAct = EricAction( 385 self.refactoringIntroduceFactoryAct = EricAction(
349 self.tr('Introduce Factory Method'), 386 self.tr("Introduce Factory Method"),
350 self.tr('Introduce &Factory Method'), 387 self.tr("Introduce &Factory Method"),
351 0, 0, 388 0,
352 self, 'refactoring_introduce_factory_method') 389 0,
353 self.refactoringIntroduceFactoryAct.setStatusTip(self.tr( 390 self,
354 'Introduce a factory method or function')) 391 "refactoring_introduce_factory_method",
355 self.refactoringIntroduceFactoryAct.setWhatsThis(self.tr( 392 )
356 """<b>Introduce Factory Method</b>""" 393 self.refactoringIntroduceFactoryAct.setStatusTip(
357 """<p>Introduce a factory method or function.</p>""" 394 self.tr("Introduce a factory method or function")
358 )) 395 )
396 self.refactoringIntroduceFactoryAct.setWhatsThis(
397 self.tr(
398 """<b>Introduce Factory Method</b>"""
399 """<p>Introduce a factory method or function.</p>"""
400 )
401 )
359 self.refactoringIntroduceFactoryAct.triggered.connect( 402 self.refactoringIntroduceFactoryAct.triggered.connect(
360 self.__introduceFactoryMethod) 403 self.__introduceFactoryMethod
404 )
361 self.actions.append(self.refactoringIntroduceFactoryAct) 405 self.actions.append(self.refactoringIntroduceFactoryAct)
362 406
363 self.refactoringIntroduceParameterAct = EricAction( 407 self.refactoringIntroduceParameterAct = EricAction(
364 self.tr('Introduce Parameter'), 408 self.tr("Introduce Parameter"),
365 self.tr('Introduce &Parameter'), 409 self.tr("Introduce &Parameter"),
366 0, 0, 410 0,
367 self, 'refactoring_introduce_parameter_method') 411 0,
368 self.refactoringIntroduceParameterAct.setStatusTip(self.tr( 412 self,
369 'Introduce a parameter in a function')) 413 "refactoring_introduce_parameter_method",
370 self.refactoringIntroduceParameterAct.setWhatsThis(self.tr( 414 )
371 """<b>Introduce Parameter</b>""" 415 self.refactoringIntroduceParameterAct.setStatusTip(
372 """<p>Introduce a parameter in a function.</p>""" 416 self.tr("Introduce a parameter in a function")
373 )) 417 )
418 self.refactoringIntroduceParameterAct.setWhatsThis(
419 self.tr(
420 """<b>Introduce Parameter</b>"""
421 """<p>Introduce a parameter in a function.</p>"""
422 )
423 )
374 self.refactoringIntroduceParameterAct.triggered.connect( 424 self.refactoringIntroduceParameterAct.triggered.connect(
375 self.__introduceParameter) 425 self.__introduceParameter
426 )
376 self.actions.append(self.refactoringIntroduceParameterAct) 427 self.actions.append(self.refactoringIntroduceParameterAct)
377 428
378 ##################################################### 429 #####################################################
379 ## Import refactorings actions 430 ## Import refactorings actions
380 ##################################################### 431 #####################################################
381 432
382 self.refactoringImportsOrganizeAct = EricAction( 433 self.refactoringImportsOrganizeAct = EricAction(
383 self.tr('Organize Imports'), 434 self.tr("Organize Imports"),
384 self.tr('&Organize Imports'), 435 self.tr("&Organize Imports"),
385 0, 0, 436 0,
386 self, 'refactoring_organize_imports') 437 0,
387 self.refactoringImportsOrganizeAct.setStatusTip(self.tr( 438 self,
388 'Sort imports according to PEP-8')) 439 "refactoring_organize_imports",
389 self.refactoringImportsOrganizeAct.setWhatsThis(self.tr( 440 )
390 """<b>Organize Imports</b>""" 441 self.refactoringImportsOrganizeAct.setStatusTip(
391 """<p>Sort imports according to PEP-8.</p>""" 442 self.tr("Sort imports according to PEP-8")
392 )) 443 )
393 self.refactoringImportsOrganizeAct.triggered.connect( 444 self.refactoringImportsOrganizeAct.setWhatsThis(
394 self.__importsOrganize) 445 self.tr(
446 """<b>Organize Imports</b>"""
447 """<p>Sort imports according to PEP-8.</p>"""
448 )
449 )
450 self.refactoringImportsOrganizeAct.triggered.connect(self.__importsOrganize)
395 self.actions.append(self.refactoringImportsOrganizeAct) 451 self.actions.append(self.refactoringImportsOrganizeAct)
396 452
397 self.refactoringImportsStarExpandAct = EricAction( 453 self.refactoringImportsStarExpandAct = EricAction(
398 self.tr('Expand Star Imports'), 454 self.tr("Expand Star Imports"),
399 self.tr('E&xpand Star Imports'), 455 self.tr("E&xpand Star Imports"),
400 0, 0, 456 0,
401 self, 'refactoring_expand_star_imports') 457 0,
402 self.refactoringImportsStarExpandAct.setStatusTip(self.tr( 458 self,
403 'Expand imports like "from xxx import *"')) 459 "refactoring_expand_star_imports",
404 self.refactoringImportsStarExpandAct.setWhatsThis(self.tr( 460 )
405 """<b>Expand Star Imports</b>""" 461 self.refactoringImportsStarExpandAct.setStatusTip(
406 """<p>Expand imports like "from xxx import *".</p>""" 462 self.tr('Expand imports like "from xxx import *"')
407 """<p>Select the import to act on or none to do all.""" 463 )
408 """ Unused imports are deleted.</p>""" 464 self.refactoringImportsStarExpandAct.setWhatsThis(
409 )) 465 self.tr(
410 self.refactoringImportsStarExpandAct.triggered.connect( 466 """<b>Expand Star Imports</b>"""
411 self.__importsExpandStar) 467 """<p>Expand imports like "from xxx import *".</p>"""
468 """<p>Select the import to act on or none to do all."""
469 """ Unused imports are deleted.</p>"""
470 )
471 )
472 self.refactoringImportsStarExpandAct.triggered.connect(self.__importsExpandStar)
412 self.actions.append(self.refactoringImportsStarExpandAct) 473 self.actions.append(self.refactoringImportsStarExpandAct)
413 474
414 self.refactoringImportsRelativeToAbsoluteAct = EricAction( 475 self.refactoringImportsRelativeToAbsoluteAct = EricAction(
415 self.tr('Relative to Absolute'), 476 self.tr("Relative to Absolute"),
416 self.tr('Relative to &Absolute'), 477 self.tr("Relative to &Absolute"),
417 0, 0, 478 0,
418 self, 'refactoring_relative_to_absolute_imports') 479 0,
419 self.refactoringImportsRelativeToAbsoluteAct.setStatusTip(self.tr( 480 self,
420 'Transform relative imports to absolute ones')) 481 "refactoring_relative_to_absolute_imports",
421 self.refactoringImportsRelativeToAbsoluteAct.setWhatsThis(self.tr( 482 )
422 """<b>Relative to Absolute</b>""" 483 self.refactoringImportsRelativeToAbsoluteAct.setStatusTip(
423 """<p>Transform relative imports to absolute ones.</p>""" 484 self.tr("Transform relative imports to absolute ones")
424 """<p>Select the import to act on or none to do all.""" 485 )
425 """ Unused imports are deleted.</p>""" 486 self.refactoringImportsRelativeToAbsoluteAct.setWhatsThis(
426 )) 487 self.tr(
488 """<b>Relative to Absolute</b>"""
489 """<p>Transform relative imports to absolute ones.</p>"""
490 """<p>Select the import to act on or none to do all."""
491 """ Unused imports are deleted.</p>"""
492 )
493 )
427 self.refactoringImportsRelativeToAbsoluteAct.triggered.connect( 494 self.refactoringImportsRelativeToAbsoluteAct.triggered.connect(
428 self.__importsRelativeToAbsolute) 495 self.__importsRelativeToAbsolute
496 )
429 self.actions.append(self.refactoringImportsRelativeToAbsoluteAct) 497 self.actions.append(self.refactoringImportsRelativeToAbsoluteAct)
430 498
431 self.refactoringImportsFromsToImportsAct = EricAction( 499 self.refactoringImportsFromsToImportsAct = EricAction(
432 self.tr('Froms to Imports'), 500 self.tr("Froms to Imports"),
433 self.tr('Froms to &Imports'), 501 self.tr("Froms to &Imports"),
434 0, 0, 502 0,
435 self, 'refactoring_froms_to_imports') 503 0,
436 self.refactoringImportsFromsToImportsAct.setStatusTip(self.tr( 504 self,
437 'Transform From imports to plain imports')) 505 "refactoring_froms_to_imports",
438 self.refactoringImportsFromsToImportsAct.setWhatsThis(self.tr( 506 )
439 """<b>Froms to Imports</b>""" 507 self.refactoringImportsFromsToImportsAct.setStatusTip(
440 """<p>Transform From imports to plain imports.</p>""" 508 self.tr("Transform From imports to plain imports")
441 """<p>Select the import to act on or none to do all.""" 509 )
442 """ Unused imports are deleted.</p>""" 510 self.refactoringImportsFromsToImportsAct.setWhatsThis(
443 )) 511 self.tr(
512 """<b>Froms to Imports</b>"""
513 """<p>Transform From imports to plain imports.</p>"""
514 """<p>Select the import to act on or none to do all."""
515 """ Unused imports are deleted.</p>"""
516 )
517 )
444 self.refactoringImportsFromsToImportsAct.triggered.connect( 518 self.refactoringImportsFromsToImportsAct.triggered.connect(
445 self.__importsFromToImport) 519 self.__importsFromToImport
520 )
446 self.actions.append(self.refactoringImportsFromsToImportsAct) 521 self.actions.append(self.refactoringImportsFromsToImportsAct)
447 522
448 self.refactoringImportsHandleLongAct = EricAction( 523 self.refactoringImportsHandleLongAct = EricAction(
449 self.tr('Handle Long Imports'), 524 self.tr("Handle Long Imports"),
450 self.tr('Handle &Long Imports'), 525 self.tr("Handle &Long Imports"),
451 0, 0, 526 0,
452 self, 'refactoring_organize_imports') 527 0,
453 self.refactoringImportsHandleLongAct.setStatusTip(self.tr( 528 self,
454 'Transform long import statements to look better')) 529 "refactoring_organize_imports",
455 self.refactoringImportsHandleLongAct.setWhatsThis(self.tr( 530 )
456 """<b>Handle Long Imports</b>""" 531 self.refactoringImportsHandleLongAct.setStatusTip(
457 """<p>Transform long import statements to look better.</p>""" 532 self.tr("Transform long import statements to look better")
458 """<p>Select the import to act on or none to do all.""" 533 )
459 """ Unused imports are deleted.</p>""" 534 self.refactoringImportsHandleLongAct.setWhatsThis(
460 )) 535 self.tr(
461 self.refactoringImportsHandleLongAct.triggered.connect( 536 """<b>Handle Long Imports</b>"""
462 self.__importsHandleLong) 537 """<p>Transform long import statements to look better.</p>"""
538 """<p>Select the import to act on or none to do all."""
539 """ Unused imports are deleted.</p>"""
540 )
541 )
542 self.refactoringImportsHandleLongAct.triggered.connect(self.__importsHandleLong)
463 self.actions.append(self.refactoringImportsHandleLongAct) 543 self.actions.append(self.refactoringImportsHandleLongAct)
464 544
465 ##################################################### 545 #####################################################
466 ## Various refactorings actions 546 ## Various refactorings actions
467 ##################################################### 547 #####################################################
468 548
469 self.refactoringRestructureAct = EricAction( 549 self.refactoringRestructureAct = EricAction(
470 self.tr('Restructure'), 550 self.tr("Restructure"),
471 self.tr('Res&tructure'), 551 self.tr("Res&tructure"),
472 0, 0, 552 0,
473 self, 'refactoring_restructure') 553 0,
474 self.refactoringRestructureAct.setStatusTip(self.tr( 554 self,
475 'Restructure code')) 555 "refactoring_restructure",
476 self.refactoringRestructureAct.setWhatsThis(self.tr( 556 )
477 """<b>Restructure</b>""" 557 self.refactoringRestructureAct.setStatusTip(self.tr("Restructure code"))
478 """<p>Restructure code. See "Rope Help" for examples.</p>""" 558 self.refactoringRestructureAct.setWhatsThis(
479 )) 559 self.tr(
480 self.refactoringRestructureAct.triggered.connect( 560 """<b>Restructure</b>"""
481 self.__restructure) 561 """<p>Restructure code. See "Rope Help" for examples.</p>"""
562 )
563 )
564 self.refactoringRestructureAct.triggered.connect(self.__restructure)
482 self.actions.append(self.refactoringRestructureAct) 565 self.actions.append(self.refactoringRestructureAct)
483 566
484 self.refactoringChangeSignatureAct = EricAction( 567 self.refactoringChangeSignatureAct = EricAction(
485 self.tr('Change Method Signature'), 568 self.tr("Change Method Signature"),
486 self.tr('&Change Method Signature'), 569 self.tr("&Change Method Signature"),
487 0, 0, 570 0,
488 self, 'refactoring_change_method_signature') 571 0,
489 self.refactoringChangeSignatureAct.setStatusTip(self.tr( 572 self,
490 'Change the signature of the selected method or function')) 573 "refactoring_change_method_signature",
491 self.refactoringChangeSignatureAct.setWhatsThis(self.tr( 574 )
492 """<b>Change Method Signature</b>""" 575 self.refactoringChangeSignatureAct.setStatusTip(
493 """<p>Change the signature of the selected method""" 576 self.tr("Change the signature of the selected method or function")
494 """ or function.</p>""" 577 )
495 )) 578 self.refactoringChangeSignatureAct.setWhatsThis(
496 self.refactoringChangeSignatureAct.triggered.connect( 579 self.tr(
497 self.__changeSignature) 580 """<b>Change Method Signature</b>"""
581 """<p>Change the signature of the selected method"""
582 """ or function.</p>"""
583 )
584 )
585 self.refactoringChangeSignatureAct.triggered.connect(self.__changeSignature)
498 self.actions.append(self.refactoringChangeSignatureAct) 586 self.actions.append(self.refactoringChangeSignatureAct)
499 587
500 self.refactoringInlineArgumentDefaultAct = EricAction( 588 self.refactoringInlineArgumentDefaultAct = EricAction(
501 self.tr('Inline Argument Default'), 589 self.tr("Inline Argument Default"),
502 self.tr('Inline &Argument Default'), 590 self.tr("Inline &Argument Default"),
503 0, 0, 591 0,
504 self, 'refactoring_inline_argument_default') 592 0,
505 self.refactoringInlineArgumentDefaultAct.setStatusTip(self.tr( 593 self,
506 'Inline a parameters default value')) 594 "refactoring_inline_argument_default",
507 self.refactoringInlineArgumentDefaultAct.setWhatsThis(self.tr( 595 )
508 """<b>Inline Argument Default</b>""" 596 self.refactoringInlineArgumentDefaultAct.setStatusTip(
509 """<p>Inline a parameters default value.</p>""" 597 self.tr("Inline a parameters default value")
510 )) 598 )
599 self.refactoringInlineArgumentDefaultAct.setWhatsThis(
600 self.tr(
601 """<b>Inline Argument Default</b>"""
602 """<p>Inline a parameters default value.</p>"""
603 )
604 )
511 self.refactoringInlineArgumentDefaultAct.triggered.connect( 605 self.refactoringInlineArgumentDefaultAct.triggered.connect(
512 self.__inlineArgumentDefault) 606 self.__inlineArgumentDefault
607 )
513 self.actions.append(self.refactoringInlineArgumentDefaultAct) 608 self.actions.append(self.refactoringInlineArgumentDefaultAct)
514 609
515 self.refactoringTransformModuleAct = EricAction( 610 self.refactoringTransformModuleAct = EricAction(
516 self.tr('Transform Module to Package'), 611 self.tr("Transform Module to Package"),
517 self.tr('Transform Module to Package'), 612 self.tr("Transform Module to Package"),
518 0, 0, 613 0,
519 self, 'refactoring_transform_module_to_package') 614 0,
520 self.refactoringTransformModuleAct.setStatusTip(self.tr( 615 self,
521 'Transform the current module to a package')) 616 "refactoring_transform_module_to_package",
522 self.refactoringTransformModuleAct.setWhatsThis(self.tr( 617 )
523 """<b>Transform Module to Package</b>""" 618 self.refactoringTransformModuleAct.setStatusTip(
524 """<p>Transform the current module to a package.</p>""" 619 self.tr("Transform the current module to a package")
525 )) 620 )
621 self.refactoringTransformModuleAct.setWhatsThis(
622 self.tr(
623 """<b>Transform Module to Package</b>"""
624 """<p>Transform the current module to a package.</p>"""
625 )
626 )
526 self.refactoringTransformModuleAct.triggered.connect( 627 self.refactoringTransformModuleAct.triggered.connect(
527 self.__transformModuleToPackage) 628 self.__transformModuleToPackage
629 )
528 self.actions.append(self.refactoringTransformModuleAct) 630 self.actions.append(self.refactoringTransformModuleAct)
529 631
530 self.refactoringEncapsulateAttributeAct = EricAction( 632 self.refactoringEncapsulateAttributeAct = EricAction(
531 self.tr('Encapsulate Attribute'), 633 self.tr("Encapsulate Attribute"),
532 self.tr('Encap&sulate Attribute'), 634 self.tr("Encap&sulate Attribute"),
533 0, 0, 635 0,
534 self, 'refactoring_encapsulate_attribute') 636 0,
535 self.refactoringEncapsulateAttributeAct.setStatusTip(self.tr( 637 self,
536 'Generate a getter/setter for an attribute')) 638 "refactoring_encapsulate_attribute",
537 self.refactoringEncapsulateAttributeAct.setWhatsThis(self.tr( 639 )
538 """<b>Encapsulate Attribute</b>""" 640 self.refactoringEncapsulateAttributeAct.setStatusTip(
539 """<p>Generate a getter/setter for an attribute and changes""" 641 self.tr("Generate a getter/setter for an attribute")
540 """ its occurrences to use them.</p>""" 642 )
541 )) 643 self.refactoringEncapsulateAttributeAct.setWhatsThis(
644 self.tr(
645 """<b>Encapsulate Attribute</b>"""
646 """<p>Generate a getter/setter for an attribute and changes"""
647 """ its occurrences to use them.</p>"""
648 )
649 )
542 self.refactoringEncapsulateAttributeAct.triggered.connect( 650 self.refactoringEncapsulateAttributeAct.triggered.connect(
543 self.__encapsulateAttribute) 651 self.__encapsulateAttribute
652 )
544 self.actions.append(self.refactoringEncapsulateAttributeAct) 653 self.actions.append(self.refactoringEncapsulateAttributeAct)
545 654
546 self.refactoringLocalVariableToAttributeAct = EricAction( 655 self.refactoringLocalVariableToAttributeAct = EricAction(
547 self.tr('Local Variable to Attribute'), 656 self.tr("Local Variable to Attribute"),
548 self.tr('Local Varia&ble to Attribute'), 657 self.tr("Local Varia&ble to Attribute"),
549 0, 0, 658 0,
550 self, 'refactoring_local_variable_to_attribute') 659 0,
551 self.refactoringLocalVariableToAttributeAct.setStatusTip(self.tr( 660 self,
552 'Change a local variable to an attribute')) 661 "refactoring_local_variable_to_attribute",
553 self.refactoringLocalVariableToAttributeAct.setWhatsThis(self.tr( 662 )
554 """<b>Local Variable to Attribute</b>""" 663 self.refactoringLocalVariableToAttributeAct.setStatusTip(
555 """<p>Change a local variable to an attribute.</p>""" 664 self.tr("Change a local variable to an attribute")
556 )) 665 )
666 self.refactoringLocalVariableToAttributeAct.setWhatsThis(
667 self.tr(
668 """<b>Local Variable to Attribute</b>"""
669 """<p>Change a local variable to an attribute.</p>"""
670 )
671 )
557 self.refactoringLocalVariableToAttributeAct.triggered.connect( 672 self.refactoringLocalVariableToAttributeAct.triggered.connect(
558 self.__convertLocalToAttribute) 673 self.__convertLocalToAttribute
674 )
559 self.actions.append(self.refactoringLocalVariableToAttributeAct) 675 self.actions.append(self.refactoringLocalVariableToAttributeAct)
560 676
561 self.refactoringMethodToMethodObjectAct = EricAction( 677 self.refactoringMethodToMethodObjectAct = EricAction(
562 self.tr('Method To Method Object'), 678 self.tr("Method To Method Object"),
563 self.tr('Method To Method Ob&ject'), 679 self.tr("Method To Method Ob&ject"),
564 0, 0, 680 0,
565 self, 'refactoring_method_to_methodobject') 681 0,
566 self.refactoringMethodToMethodObjectAct.setStatusTip(self.tr( 682 self,
567 'Transform a function or a method to a method object')) 683 "refactoring_method_to_methodobject",
568 self.refactoringMethodToMethodObjectAct.setWhatsThis(self.tr( 684 )
569 """<b>Method To Method Object</b>""" 685 self.refactoringMethodToMethodObjectAct.setStatusTip(
570 """<p>Transform a function or a method to a method object.</p>""" 686 self.tr("Transform a function or a method to a method object")
571 )) 687 )
688 self.refactoringMethodToMethodObjectAct.setWhatsThis(
689 self.tr(
690 """<b>Method To Method Object</b>"""
691 """<p>Transform a function or a method to a method object.</p>"""
692 )
693 )
572 self.refactoringMethodToMethodObjectAct.triggered.connect( 694 self.refactoringMethodToMethodObjectAct.triggered.connect(
573 self.__methodToMethodObject) 695 self.__methodToMethodObject
696 )
574 self.actions.append(self.refactoringMethodToMethodObjectAct) 697 self.actions.append(self.refactoringMethodToMethodObjectAct)
575 698
576 ##################################################### 699 #####################################################
577 ## History actions 700 ## History actions
578 ##################################################### 701 #####################################################
579 702
580 self.refactoringProjectHistoryAct = EricAction( 703 self.refactoringProjectHistoryAct = EricAction(
581 self.tr('Show Project History'), 704 self.tr("Show Project History"),
582 self.tr('Show Project History...'), 705 self.tr("Show Project History..."),
583 0, 0, 706 0,
584 self, 'refactoring_show_project_history') 707 0,
585 self.refactoringProjectHistoryAct.setStatusTip(self.tr( 708 self,
586 'Show the refactoring history of the project')) 709 "refactoring_show_project_history",
587 self.refactoringProjectHistoryAct.setWhatsThis(self.tr( 710 )
588 """<b>Show Project History</b>""" 711 self.refactoringProjectHistoryAct.setStatusTip(
589 """<p>This opens a dialog to show the refactoring history of""" 712 self.tr("Show the refactoring history of the project")
590 """ the project.</p>""" 713 )
591 )) 714 self.refactoringProjectHistoryAct.setWhatsThis(
592 self.refactoringProjectHistoryAct.triggered.connect( 715 self.tr(
593 self.__showProjectHistory) 716 """<b>Show Project History</b>"""
717 """<p>This opens a dialog to show the refactoring history of"""
718 """ the project.</p>"""
719 )
720 )
721 self.refactoringProjectHistoryAct.triggered.connect(self.__showProjectHistory)
594 self.actions.append(self.refactoringProjectHistoryAct) 722 self.actions.append(self.refactoringProjectHistoryAct)
595 723
596 self.refactoringFileHistoryAct = EricAction( 724 self.refactoringFileHistoryAct = EricAction(
597 self.tr('Show Current File History'), 725 self.tr("Show Current File History"),
598 self.tr('Show Current File History...'), 726 self.tr("Show Current File History..."),
599 0, 0, 727 0,
600 self, 'refactoring_show_file_history') 728 0,
601 self.refactoringFileHistoryAct.setStatusTip(self.tr( 729 self,
602 'Show the refactoring history of the current file')) 730 "refactoring_show_file_history",
603 self.refactoringFileHistoryAct.setWhatsThis(self.tr( 731 )
604 """<b>Show Current File History</b>""" 732 self.refactoringFileHistoryAct.setStatusTip(
605 """<p>This opens a dialog to show the refactoring history of""" 733 self.tr("Show the refactoring history of the current file")
606 """ the current file.</p>""" 734 )
607 )) 735 self.refactoringFileHistoryAct.setWhatsThis(
608 self.refactoringFileHistoryAct.triggered.connect( 736 self.tr(
609 self.__showFileHistory) 737 """<b>Show Current File History</b>"""
738 """<p>This opens a dialog to show the refactoring history of"""
739 """ the current file.</p>"""
740 )
741 )
742 self.refactoringFileHistoryAct.triggered.connect(self.__showFileHistory)
610 self.actions.append(self.refactoringFileHistoryAct) 743 self.actions.append(self.refactoringFileHistoryAct)
611 744
612 self.refactoringClearHistoryAct = EricAction( 745 self.refactoringClearHistoryAct = EricAction(
613 self.tr('Clear History'), 746 self.tr("Clear History"),
614 self.tr('Clear History'), 747 self.tr("Clear History"),
615 0, 0, 748 0,
616 self, 'refactoring_clear_history') 749 0,
617 self.refactoringClearHistoryAct.setStatusTip(self.tr( 750 self,
618 'Clear the refactoring history')) 751 "refactoring_clear_history",
619 self.refactoringClearHistoryAct.setWhatsThis(self.tr( 752 )
620 """<b>Clear History</b>""" 753 self.refactoringClearHistoryAct.setStatusTip(
621 """<p>Clears the refactoring history.</p>""" 754 self.tr("Clear the refactoring history")
622 )) 755 )
623 self.refactoringClearHistoryAct.triggered.connect( 756 self.refactoringClearHistoryAct.setWhatsThis(
624 self.__clearHistory) 757 self.tr(
758 """<b>Clear History</b>""" """<p>Clears the refactoring history.</p>"""
759 )
760 )
761 self.refactoringClearHistoryAct.triggered.connect(self.__clearHistory)
625 self.actions.append(self.refactoringClearHistoryAct) 762 self.actions.append(self.refactoringClearHistoryAct)
626 763
627 ##################################################### 764 #####################################################
628 ## Query actions 765 ## Query actions
629 ##################################################### 766 #####################################################
630 767
631 self.queryReferencesAct = EricAction( 768 self.queryReferencesAct = EricAction(
632 self.tr('Find occurrences'), 769 self.tr("Find occurrences"),
633 self.tr('Find &Occurrences'), 770 self.tr("Find &Occurrences"),
634 0, 0, 771 0,
635 self, 'refactoring_find_occurrences') 772 0,
636 self.queryReferencesAct.setStatusTip(self.tr( 773 self,
637 'Find occurrences of the highlighted object')) 774 "refactoring_find_occurrences",
638 self.queryReferencesAct.setWhatsThis(self.tr( 775 )
639 """<b>Find occurrences</b>""" 776 self.queryReferencesAct.setStatusTip(
640 """<p>Find occurrences of the highlighted class, method,""" 777 self.tr("Find occurrences of the highlighted object")
641 """ function or variable.</p>""" 778 )
642 )) 779 self.queryReferencesAct.setWhatsThis(
643 self.queryReferencesAct.triggered.connect( 780 self.tr(
644 self.__queryReferences) 781 """<b>Find occurrences</b>"""
782 """<p>Find occurrences of the highlighted class, method,"""
783 """ function or variable.</p>"""
784 )
785 )
786 self.queryReferencesAct.triggered.connect(self.__queryReferences)
645 self.actions.append(self.queryReferencesAct) 787 self.actions.append(self.queryReferencesAct)
646 788
647 self.queryDefinitionAct = EricAction( 789 self.queryDefinitionAct = EricAction(
648 self.tr('Find definition'), 790 self.tr("Find definition"),
649 self.tr('Find &Definition'), 791 self.tr("Find &Definition"),
650 0, 0, 792 0,
651 self, 'refactoring_find_definition') 793 0,
652 self.queryDefinitionAct.setStatusTip(self.tr( 794 self,
653 'Find definition of the highlighted item')) 795 "refactoring_find_definition",
654 self.queryDefinitionAct.setWhatsThis(self.tr( 796 )
655 """<b>Find definition</b>""" 797 self.queryDefinitionAct.setStatusTip(
656 """<p>Find the definition of the highlighted class, method,""" 798 self.tr("Find definition of the highlighted item")
657 """ function or variable.</p>""" 799 )
658 )) 800 self.queryDefinitionAct.setWhatsThis(
659 self.queryDefinitionAct.triggered.connect( 801 self.tr(
660 self.__queryDefinition) 802 """<b>Find definition</b>"""
803 """<p>Find the definition of the highlighted class, method,"""
804 """ function or variable.</p>"""
805 )
806 )
807 self.queryDefinitionAct.triggered.connect(self.__queryDefinition)
661 self.actions.append(self.queryDefinitionAct) 808 self.actions.append(self.queryDefinitionAct)
662 809
663 self.queryImplementationsAct = EricAction( 810 self.queryImplementationsAct = EricAction(
664 self.tr('Find implementations'), 811 self.tr("Find implementations"),
665 self.tr('Find &Implementations'), 812 self.tr("Find &Implementations"),
666 0, 0, 813 0,
667 self, 'refactoring_find_implementations') 814 0,
668 self.queryImplementationsAct.setStatusTip(self.tr( 815 self,
669 'Find places where the selected method is overridden')) 816 "refactoring_find_implementations",
670 self.queryImplementationsAct.setWhatsThis(self.tr( 817 )
671 """<b>Find implementations</b>""" 818 self.queryImplementationsAct.setStatusTip(
672 """<p>Find places where the selected method is overridden.</p>""" 819 self.tr("Find places where the selected method is overridden")
673 )) 820 )
674 self.queryImplementationsAct.triggered.connect( 821 self.queryImplementationsAct.setWhatsThis(
675 self.__queryImplementations) 822 self.tr(
823 """<b>Find implementations</b>"""
824 """<p>Find places where the selected method is overridden.</p>"""
825 )
826 )
827 self.queryImplementationsAct.triggered.connect(self.__queryImplementations)
676 self.actions.append(self.queryImplementationsAct) 828 self.actions.append(self.queryImplementationsAct)
677 829
678 ##################################################### 830 #####################################################
679 ## Various actions 831 ## Various actions
680 ##################################################### 832 #####################################################
681 833
682 self.refactoringEditConfigAct = EricAction( 834 self.refactoringEditConfigAct = EricAction(
683 self.tr('Configure Rope'), 835 self.tr("Configure Rope"),
684 self.tr('&Configure Rope'), 836 self.tr("&Configure Rope"),
685 0, 0, 837 0,
686 self, 'refactoring_edit_config') 838 0,
687 self.refactoringEditConfigAct.setStatusTip(self.tr( 839 self,
688 'Open the rope configuration file')) 840 "refactoring_edit_config",
689 self.refactoringEditConfigAct.setWhatsThis(self.tr( 841 )
690 """<b>Configure Rope</b>""" 842 self.refactoringEditConfigAct.setStatusTip(
691 """<p>Opens the rope configuration file in an editor.</p>""" 843 self.tr("Open the rope configuration file")
692 )) 844 )
693 self.refactoringEditConfigAct.triggered.connect( 845 self.refactoringEditConfigAct.setWhatsThis(
694 self.__editConfig) 846 self.tr(
847 """<b>Configure Rope</b>"""
848 """<p>Opens the rope configuration file in an editor.</p>"""
849 )
850 )
851 self.refactoringEditConfigAct.triggered.connect(self.__editConfig)
695 self.refactoringEditConfigAct.setMenuRole(QAction.MenuRole.NoRole) 852 self.refactoringEditConfigAct.setMenuRole(QAction.MenuRole.NoRole)
696 self.actions.append(self.refactoringEditConfigAct) 853 self.actions.append(self.refactoringEditConfigAct)
697 854
698 self.refactoringHelpAct = EricAction( 855 self.refactoringHelpAct = EricAction(
699 self.tr('Rope Help'), 856 self.tr("Rope Help"), self.tr("Rope &Help"), 0, 0, self, "refactoring_help"
700 self.tr('Rope &Help'), 857 )
701 0, 0, 858 self.refactoringHelpAct.setStatusTip(
702 self, 'refactoring_help') 859 self.tr("Show help about the rope refactorings")
703 self.refactoringHelpAct.setStatusTip(self.tr( 860 )
704 'Show help about the rope refactorings')) 861 self.refactoringHelpAct.setWhatsThis(
705 self.refactoringHelpAct.setWhatsThis(self.tr( 862 self.tr(
706 """<b>Rope help</b>""" 863 """<b>Rope help</b>"""
707 """<p>Show some help text about the rope refactorings.</p>""" 864 """<p>Show some help text about the rope refactorings.</p>"""
708 )) 865 )
709 self.refactoringHelpAct.triggered.connect( 866 )
710 self.__showRopeHelp) 867 self.refactoringHelpAct.triggered.connect(self.__showRopeHelp)
711 self.actions.append(self.refactoringHelpAct) 868 self.actions.append(self.refactoringHelpAct)
712 869
713 self.refactoringAllSoaAct = EricAction( 870 self.refactoringAllSoaAct = EricAction(
714 self.tr('Analyse all modules'), 871 self.tr("Analyse all modules"),
715 self.tr('&Analyse all modules'), 872 self.tr("&Analyse all modules"),
716 0, 0, 873 0,
717 self, 'refactoring_analyze_all') 874 0,
718 self.refactoringAllSoaAct.setStatusTip(self.tr( 875 self,
719 'Perform static object analysis on all modules')) 876 "refactoring_analyze_all",
720 self.refactoringAllSoaAct.setWhatsThis(self.tr( 877 )
721 """<b>Analyse all modules</b>""" 878 self.refactoringAllSoaAct.setStatusTip(
722 """<p>Perform static object analysis (SOA) on all modules. """ 879 self.tr("Perform static object analysis on all modules")
723 """This might be time consuming. Analysis of all modules """ 880 )
724 """should only be neccessary, if the project was created """ 881 self.refactoringAllSoaAct.setWhatsThis(
725 """with the rope plugin disabled or if files were added.</p>""" 882 self.tr(
726 )) 883 """<b>Analyse all modules</b>"""
727 self.refactoringAllSoaAct.triggered.connect( 884 """<p>Perform static object analysis (SOA) on all modules. """
728 self.__performSOA) 885 """This might be time consuming. Analysis of all modules """
886 """should only be neccessary, if the project was created """
887 """with the rope plugin disabled or if files were added.</p>"""
888 )
889 )
890 self.refactoringAllSoaAct.triggered.connect(self.__performSOA)
729 self.actions.append(self.refactoringAllSoaAct) 891 self.actions.append(self.refactoringAllSoaAct)
730 892
731 self.updateConfigAct = EricAction( 893 self.updateConfigAct = EricAction(
732 self.tr('Update Configuration'), 894 self.tr("Update Configuration"),
733 self.tr('&Update Configuration'), 895 self.tr("&Update Configuration"),
734 0, 0, 896 0,
735 self, 'refactoring_update_configuration') 897 0,
736 self.updateConfigAct.setStatusTip(self.tr( 898 self,
737 'Generates a new configuration file overwriting the current one.')) 899 "refactoring_update_configuration",
738 self.updateConfigAct.setWhatsThis(self.tr( 900 )
739 """<b>Update Configuration</b>""" 901 self.updateConfigAct.setStatusTip(
740 """<p>Generates a new configuration file overwriting""" 902 self.tr("Generates a new configuration file overwriting the current one.")
741 """ the current one.</p>""" 903 )
742 )) 904 self.updateConfigAct.setWhatsThis(
743 self.updateConfigAct.triggered.connect( 905 self.tr(
744 self.__updateConfig) 906 """<b>Update Configuration</b>"""
907 """<p>Generates a new configuration file overwriting"""
908 """ the current one.</p>"""
909 )
910 )
911 self.updateConfigAct.triggered.connect(self.__updateConfig)
745 self.actions.append(self.updateConfigAct) 912 self.actions.append(self.updateConfigAct)
746 913
747 for act in self.actions: 914 for act in self.actions:
748 act.setEnabled(False) 915 act.setEnabled(False)
749 916
750 def __initMenu(self): 917 def __initMenu(self):
751 """ 918 """
752 Private slot to initialize the refactoring menu. 919 Private slot to initialize the refactoring menu.
753 920
754 @return the menu generated 921 @return the menu generated
755 @rtype QMenu 922 @rtype QMenu
756 """ 923 """
757 menu = QMenu(self.tr('&Refactoring'), self.__ui) 924 menu = QMenu(self.tr("&Refactoring"), self.__ui)
758 menu.setTearOffEnabled(True) 925 menu.setTearOffEnabled(True)
759 926
760 act = menu.addAction('rope', self.__ropeInfo) 927 act = menu.addAction("rope", self.__ropeInfo)
761 font = act.font() 928 font = act.font()
762 font.setBold(True) 929 font.setBold(True)
763 act.setFont(font) 930 act.setFont(font)
764 menu.addSeparator() 931 menu.addSeparator()
765 932
766 smenu = menu.addMenu(self.tr("&Query")) 933 smenu = menu.addMenu(self.tr("&Query"))
767 smenu.addAction(self.queryReferencesAct) 934 smenu.addAction(self.queryReferencesAct)
768 smenu.addAction(self.queryDefinitionAct) 935 smenu.addAction(self.queryDefinitionAct)
769 smenu.addAction(self.queryImplementationsAct) 936 smenu.addAction(self.queryImplementationsAct)
770 937
771 smenu = menu.addMenu(self.tr("&Refactoring")) 938 smenu = menu.addMenu(self.tr("&Refactoring"))
772 smenu.addAction(self.refactoringRenameAct) 939 smenu.addAction(self.refactoringRenameAct)
773 smenu.addAction(self.refactoringRenameLocalAct) 940 smenu.addAction(self.refactoringRenameLocalAct)
774 smenu.addAction(self.refactoringChangeOccurrencesAct) 941 smenu.addAction(self.refactoringChangeOccurrencesAct)
775 smenu.addSeparator() 942 smenu.addSeparator()
796 smenu.addSeparator() 963 smenu.addSeparator()
797 smenu.addAction(self.refactoringRenameModuleAct) 964 smenu.addAction(self.refactoringRenameModuleAct)
798 smenu.addAction(self.refactoringMoveModuleAct) 965 smenu.addAction(self.refactoringMoveModuleAct)
799 smenu.addAction(self.refactoringTransformModuleAct) 966 smenu.addAction(self.refactoringTransformModuleAct)
800 smenu.addSeparator() 967 smenu.addSeparator()
801 968
802 imenu = smenu.addMenu(self.tr("Im&ports")) 969 imenu = smenu.addMenu(self.tr("Im&ports"))
803 imenu.addAction(self.refactoringImportsOrganizeAct) 970 imenu.addAction(self.refactoringImportsOrganizeAct)
804 imenu.addAction(self.refactoringImportsStarExpandAct) 971 imenu.addAction(self.refactoringImportsStarExpandAct)
805 imenu.addAction(self.refactoringImportsRelativeToAbsoluteAct) 972 imenu.addAction(self.refactoringImportsRelativeToAbsoluteAct)
806 imenu.addAction(self.refactoringImportsFromsToImportsAct) 973 imenu.addAction(self.refactoringImportsFromsToImportsAct)
807 imenu.addAction(self.refactoringImportsHandleLongAct) 974 imenu.addAction(self.refactoringImportsHandleLongAct)
808 975
809 smenu.addSeparator() 976 smenu.addSeparator()
810 977
811 hmenu = smenu.addMenu(self.tr("History")) 978 hmenu = smenu.addMenu(self.tr("History"))
812 hmenu.aboutToShow.connect(self.__showRefactoringHistoryMenu) 979 hmenu.aboutToShow.connect(self.__showRefactoringHistoryMenu)
813 hmenu.addAction(self.refactoringProjectHistoryAct) 980 hmenu.addAction(self.refactoringProjectHistoryAct)
814 hmenu.addAction(self.refactoringFileHistoryAct) 981 hmenu.addAction(self.refactoringFileHistoryAct)
815 hmenu.addSeparator() 982 hmenu.addSeparator()
816 hmenu.addAction(self.refactoringClearHistoryAct) 983 hmenu.addAction(self.refactoringClearHistoryAct)
817 984
818 smenu = menu.addMenu(self.tr("&Utilities")) 985 smenu = menu.addMenu(self.tr("&Utilities"))
819 smenu.addAction(self.refactoringAllSoaAct) 986 smenu.addAction(self.refactoringAllSoaAct)
820 smenu.addSeparator() 987 smenu.addSeparator()
821 smenu.addAction(self.updateConfigAct) 988 smenu.addAction(self.updateConfigAct)
822 989
823 menu.addSeparator() 990 menu.addSeparator()
824 menu.addAction(self.refactoringEditConfigAct) 991 menu.addAction(self.refactoringEditConfigAct)
825 menu.addAction(self.refactoringHelpAct) 992 menu.addAction(self.refactoringHelpAct)
826 993
827 return menu 994 return menu
828 995
829 ################################################################## 996 ##################################################################
830 ## slots below implement general functionality 997 ## slots below implement general functionality
831 ################################################################## 998 ##################################################################
832 999
833 def __ropeInfo(self): 1000 def __ropeInfo(self):
834 """ 1001 """
835 Private slot to show some info about rope. 1002 Private slot to show some info about rope.
836 """ 1003 """
837 if self.__ropeConfig: 1004 if self.__ropeConfig:
838 EricMessageBox.about( 1005 EricMessageBox.about(
839 self.__ui, 1006 self.__ui,
840 self.tr("About rope"), 1007 self.tr("About rope"),
841 self.tr("{0}\nVersion {1}\n\n{2}".format( 1008 self.tr(
842 self.__ropeConfig["RopeInfo"], 1009 "{0}\nVersion {1}\n\n{2}".format(
843 self.__ropeConfig["RopeVersion"], 1010 self.__ropeConfig["RopeInfo"],
844 self.__ropeConfig["RopeCopyright"]))) 1011 self.__ropeConfig["RopeVersion"],
845 1012 self.__ropeConfig["RopeCopyright"],
1013 )
1014 ),
1015 )
1016
846 def __showRefactoringHistoryMenu(self): 1017 def __showRefactoringHistoryMenu(self):
847 """ 1018 """
848 Private slot called before the refactoring history menu is shown. 1019 Private slot called before the refactoring history menu is shown.
849 """ 1020 """
850 aw = self.__vm.activeWindow() 1021 aw = self.__vm.activeWindow()
851 enable = aw is not None and bool(aw.getFileName()) 1022 enable = aw is not None and bool(aw.getFileName())
852 1023
853 self.refactoringFileHistoryAct.setEnabled(enable) 1024 self.refactoringFileHistoryAct.setEnabled(enable)
854 1025
855 def handleRopeError(self, result): 1026 def handleRopeError(self, result):
856 """ 1027 """
857 Public method to handle a rope error. 1028 Public method to handle a rope error.
858 1029
859 @param result dictionary containing the error information 1030 @param result dictionary containing the error information
860 @type dict 1031 @type dict
861 @return flag indicating, that the error is to be ignored 1032 @return flag indicating, that the error is to be ignored
862 @rtype bool 1033 @rtype bool
863 """ 1034 """
864 if "Error" not in result: 1035 if "Error" not in result:
865 return True 1036 return True
866 1037
867 title = result.get("Title", self.tr("Rope Error")) 1038 title = result.get("Title", self.tr("Rope Error"))
868 1039
869 if result["Error"] == 'ModuleSyntaxError': 1040 if result["Error"] == "ModuleSyntaxError":
870 res = EricMessageBox.warning( 1041 res = EricMessageBox.warning(
871 self.__ui, title, 1042 self.__ui,
872 self.tr("Rope error: {0}").format( 1043 title,
873 result["ErrorString"]), 1044 self.tr("Rope error: {0}").format(result["ErrorString"]),
874 EricMessageBox.Ok | EricMessageBox.Open) 1045 EricMessageBox.Ok | EricMessageBox.Open,
1046 )
875 if res == EricMessageBox.Open: 1047 if res == EricMessageBox.Open:
876 self.__vm.openSourceFile( 1048 self.__vm.openSourceFile(
877 os.path.join(self.__ericProject.getProjectPath(), 1049 os.path.join(
878 result["ErrorFile"]), 1050 self.__ericProject.getProjectPath(), result["ErrorFile"]
879 result["ErrorLine"]) 1051 ),
1052 result["ErrorLine"],
1053 )
880 elif result["Error"] == "InterruptedTaskError": 1054 elif result["Error"] == "InterruptedTaskError":
881 return True 1055 return True
882 else: 1056 else:
883 from .ErrorDialog import ErrorDialog 1057 from .ErrorDialog import ErrorDialog
1058
884 ErrorDialog( 1059 ErrorDialog(
885 title, 1060 title,
886 self.tr("Rope error: {0}").format(result["ErrorString"]), 1061 self.tr("Rope error: {0}").format(result["ErrorString"]),
887 traceback=result["Traceback"], 1062 traceback=result["Traceback"],
888 parent=self.__ui 1063 parent=self.__ui,
889 ).exec() 1064 ).exec()
890 1065
891 return False 1066 return False
892 1067
893 def __getOffset(self, editor, line, index): 1068 def __getOffset(self, editor, line, index):
894 r""" 1069 r"""
895 Private method to get the offset into the text treating CRLF as ONE 1070 Private method to get the offset into the text treating CRLF as ONE
896 character. 1071 character.
897 1072
898 Note: rope seems to convert all EOL styles to just \n. 1073 Note: rope seems to convert all EOL styles to just \n.
899 1074
900 @param editor reference to the editor 1075 @param editor reference to the editor
901 @type Editor 1076 @type Editor
902 @param line line for the offset 1077 @param line line for the offset
903 @type int 1078 @type int
904 @param index index into line for the offset 1079 @param index index into line for the offset
913 return offset 1088 return offset
914 1089
915 ################################################################## 1090 ##################################################################
916 ## slots below implement the various refactorings 1091 ## slots below implement the various refactorings
917 ################################################################## 1092 ##################################################################
918 1093
919 def __processChanges(self, result): 1094 def __processChanges(self, result):
920 """ 1095 """
921 Private method to process the changes data sent by the refactoring 1096 Private method to process the changes data sent by the refactoring
922 client. 1097 client.
923 1098
924 @param result dictionary containing the changes data 1099 @param result dictionary containing the changes data
925 @type dict 1100 @type dict
926 """ 1101 """
927 if self.handleRopeError(result): 1102 if self.handleRopeError(result):
928 changeGroup = result["ChangeGroup"] 1103 changeGroup = result["ChangeGroup"]
929 with contextlib.suppress(KeyError): 1104 with contextlib.suppress(KeyError):
930 self.__refactoringDialogs[changeGroup].processChangeData( 1105 self.__refactoringDialogs[changeGroup].processChangeData(result)
931 result) 1106
932
933 def __refactoringDialogClosed(self, changeGroup): 1107 def __refactoringDialogClosed(self, changeGroup):
934 """ 1108 """
935 Private slot handling the closing of a refactoring dialog. 1109 Private slot handling the closing of a refactoring dialog.
936 1110
937 @param changeGroup name of the refactoring change group the dialog 1111 @param changeGroup name of the refactoring change group the dialog
938 belonged to 1112 belonged to
939 @type str 1113 @type str
940 """ 1114 """
941 with contextlib.suppress(KeyError): 1115 with contextlib.suppress(KeyError):
942 del self.__refactoringDialogs[changeGroup] 1116 del self.__refactoringDialogs[changeGroup]
943 1117
944 ##################################################### 1118 #####################################################
945 ## Rename refactorings 1119 ## Rename refactorings
946 ##################################################### 1120 #####################################################
947 1121
948 def __rename(self): 1122 def __rename(self):
949 """ 1123 """
950 Private slot to handle the Rename action. 1124 Private slot to handle the Rename action.
951 """ 1125 """
952 self.__doRename(self.tr('Rename')) 1126 self.__doRename(self.tr("Rename"))
953 1127
954 def __renameLocal(self): 1128 def __renameLocal(self):
955 """ 1129 """
956 Private slot to handle the Local Rename action. 1130 Private slot to handle the Local Rename action.
957 """ 1131 """
958 self.__doRename(self.tr('Local Rename'), isLocal=True) 1132 self.__doRename(self.tr("Local Rename"), isLocal=True)
959 1133
960 def __renameModule(self): 1134 def __renameModule(self):
961 """ 1135 """
962 Private slot to handle the Rename Current Module action. 1136 Private slot to handle the Rename Current Module action.
963 """ 1137 """
964 self.__doRename(self.tr('Rename Current Module'), 1138 self.__doRename(self.tr("Rename Current Module"), renameModule=True)
965 renameModule=True) 1139
966
967 def __doRename(self, title, isLocal=False, renameModule=False): 1140 def __doRename(self, title, isLocal=False, renameModule=False):
968 """ 1141 """
969 Private method to perform the various renaming refactorings. 1142 Private method to perform the various renaming refactorings.
970 1143
971 @param title title of the refactoring 1144 @param title title of the refactoring
972 @type str 1145 @type str
973 @param isLocal flag indicating to restrict refactoring to 1146 @param isLocal flag indicating to restrict refactoring to
974 the local file 1147 the local file
975 @type bool 1148 @type bool
976 @param renameModule flag indicating a module rename refactoring 1149 @param renameModule flag indicating a module rename refactoring
977 @type bool 1150 @type bool
978 """ 1151 """
979 aw = self.__vm.activeWindow() 1152 aw = self.__vm.activeWindow()
980 1153
981 if aw is None: 1154 if aw is None:
982 return 1155 return
983 1156
984 if not renameModule and not aw.hasSelectedText(): 1157 if not renameModule and not aw.hasSelectedText():
985 # no selection available 1158 # no selection available
986 EricMessageBox.warning( 1159 EricMessageBox.warning(
987 self.__ui, title, 1160 self.__ui,
988 self.tr("Highlight the declaration you want to rename" 1161 title,
989 " and try again.")) 1162 self.tr(
990 return 1163 "Highlight the declaration you want to rename" " and try again."
991 1164 ),
1165 )
1166 return
1167
992 if isLocal: 1168 if isLocal:
993 if not self.confirmBufferIsSaved(aw): 1169 if not self.confirmBufferIsSaved(aw):
994 return 1170 return
995 else: 1171 else:
996 if not self.confirmAllBuffersSaved(): 1172 if not self.confirmAllBuffersSaved():
997 return 1173 return
998 1174
999 filename = aw.getFileName() 1175 filename = aw.getFileName()
1000 if renameModule: 1176 if renameModule:
1001 offset = None 1177 offset = None
1002 if os.path.basename(filename) == "__init__.py": 1178 if os.path.basename(filename) == "__init__.py":
1003 filename = os.path.dirname(filename) 1179 filename = os.path.dirname(filename)
1005 else: 1181 else:
1006 line, index, line1, index1 = aw.getSelection() 1182 line, index, line1, index1 = aw.getSelection()
1007 if line != line1: 1183 if line != line1:
1008 # selection span more than one line 1184 # selection span more than one line
1009 EricMessageBox.warning( 1185 EricMessageBox.warning(
1010 self.__ui, title, 1186 self.__ui,
1011 self.tr("The selection must not extend beyond" 1187 title,
1012 " one line.")) 1188 self.tr("The selection must not extend beyond" " one line."),
1189 )
1013 return 1190 return
1014 index = int(index + (index1 - index) / 2) 1191 index = int(index + (index1 - index) / 2)
1015 # keep it inside the object 1192 # keep it inside the object
1016 offset = self.__getOffset(aw, line, index) 1193 offset = self.__getOffset(aw, line, index)
1017 selectedText = aw.selectedText() 1194 selectedText = aw.selectedText()
1018 1195
1019 from .RenameDialog import RenameDialog 1196 from .RenameDialog import RenameDialog
1020 dlg = RenameDialog(self, title, filename, offset, isLocal, 1197
1021 selectedText=selectedText, parent=self.__ui) 1198 dlg = RenameDialog(
1199 self,
1200 title,
1201 filename,
1202 offset,
1203 isLocal,
1204 selectedText=selectedText,
1205 parent=self.__ui,
1206 )
1022 changeGroup = dlg.getChangeGroupName() 1207 changeGroup = dlg.getChangeGroupName()
1023 self.__refactoringDialogs[changeGroup] = dlg 1208 self.__refactoringDialogs[changeGroup] = dlg
1024 dlg.finished.connect( 1209 dlg.finished.connect(lambda: self.__refactoringDialogClosed(changeGroup))
1025 lambda: self.__refactoringDialogClosed(changeGroup))
1026 dlg.show() 1210 dlg.show()
1027 1211
1028 def __changeOccurrences(self): 1212 def __changeOccurrences(self):
1029 """ 1213 """
1030 Private slot to perform the Change Occurrences refactoring. 1214 Private slot to perform the Change Occurrences refactoring.
1031 """ 1215 """
1032 aw = self.__vm.activeWindow() 1216 aw = self.__vm.activeWindow()
1033 1217
1034 if aw is None: 1218 if aw is None:
1035 return 1219 return
1036 1220
1037 title = self.tr("Change Occurrences") 1221 title = self.tr("Change Occurrences")
1038 if not aw.hasSelectedText(): 1222 if not aw.hasSelectedText():
1039 # no selection available 1223 # no selection available
1040 EricMessageBox.warning( 1224 EricMessageBox.warning(
1041 self.__ui, title, 1225 self.__ui,
1042 self.tr("Highlight an occurrence to be changed" 1226 title,
1043 " and try again.")) 1227 self.tr("Highlight an occurrence to be changed" " and try again."),
1044 return 1228 )
1045 1229 return
1230
1046 if not self.confirmBufferIsSaved(aw): 1231 if not self.confirmBufferIsSaved(aw):
1047 return 1232 return
1048 1233
1049 filename = aw.getFileName() 1234 filename = aw.getFileName()
1050 line, index, line1, index1 = aw.getSelection() 1235 line, index, line1, index1 = aw.getSelection()
1051 offset = self.__getOffset(aw, line, index) 1236 offset = self.__getOffset(aw, line, index)
1052 1237
1053 from .ChangeOccurrencesDialog import ChangeOccurrencesDialog 1238 from .ChangeOccurrencesDialog import ChangeOccurrencesDialog
1054 dlg = ChangeOccurrencesDialog(self, title, filename, offset, 1239
1055 parent=self.__ui) 1240 dlg = ChangeOccurrencesDialog(self, title, filename, offset, parent=self.__ui)
1056 changeGroup = dlg.getChangeGroupName() 1241 changeGroup = dlg.getChangeGroupName()
1057 self.__refactoringDialogs[changeGroup] = dlg 1242 self.__refactoringDialogs[changeGroup] = dlg
1058 dlg.finished.connect( 1243 dlg.finished.connect(lambda: self.__refactoringDialogClosed(changeGroup))
1059 lambda: self.__refactoringDialogClosed(changeGroup))
1060 dlg.show() 1244 dlg.show()
1061 1245
1062 ##################################################### 1246 #####################################################
1063 ## Extract refactorings 1247 ## Extract refactorings
1064 ##################################################### 1248 #####################################################
1065 1249
1066 def __extractMethod(self): 1250 def __extractMethod(self):
1067 """ 1251 """
1068 Private slot to handle the Extract Method action. 1252 Private slot to handle the Extract Method action.
1069 """ 1253 """
1070 self.__doExtract(self.tr("Extract Method"), "method") 1254 self.__doExtract(self.tr("Extract Method"), "method")
1071 1255
1072 def __extractLocalVariable(self): 1256 def __extractLocalVariable(self):
1073 """ 1257 """
1074 Private slot to handle the Extract Local Variable action. 1258 Private slot to handle the Extract Local Variable action.
1075 """ 1259 """
1076 self.__doExtract(self.tr("Extract Local Variable"), "variable") 1260 self.__doExtract(self.tr("Extract Local Variable"), "variable")
1077 1261
1078 def __doExtract(self, title, kind): 1262 def __doExtract(self, title, kind):
1079 """ 1263 """
1080 Private method to perform the extract refactoring. 1264 Private method to perform the extract refactoring.
1081 1265
1082 @param title title of the refactoring 1266 @param title title of the refactoring
1083 @type str 1267 @type str
1084 @param kind kind of extraction to be done 1268 @param kind kind of extraction to be done
1085 @type str ("method" or "variable") 1269 @type str ("method" or "variable")
1086 """ 1270 """
1087 aw = self.__vm.activeWindow() 1271 aw = self.__vm.activeWindow()
1088 1272
1089 if aw is None: 1273 if aw is None:
1090 return 1274 return
1091 1275
1092 if not aw.hasSelectedText(): 1276 if not aw.hasSelectedText():
1093 # no selection available 1277 # no selection available
1094 EricMessageBox.warning( 1278 EricMessageBox.warning(
1095 self.__ui, title, 1279 self.__ui,
1096 self.tr("Highlight the region of code you want to extract" 1280 title,
1097 " and try again.")) 1281 self.tr(
1098 return 1282 "Highlight the region of code you want to extract" " and try again."
1099 1283 ),
1284 )
1285 return
1286
1100 if not self.confirmBufferIsSaved(aw): 1287 if not self.confirmBufferIsSaved(aw):
1101 return 1288 return
1102 1289
1103 filename = aw.getFileName() 1290 filename = aw.getFileName()
1104 startline, startcolumn, endline, endcolumn = aw.getSelection() 1291 startline, startcolumn, endline, endcolumn = aw.getSelection()
1105 startOffset = self.__getOffset(aw, startline, startcolumn) 1292 startOffset = self.__getOffset(aw, startline, startcolumn)
1106 endOffset = self.__getOffset(aw, endline, endcolumn) 1293 endOffset = self.__getOffset(aw, endline, endcolumn)
1107 1294
1108 from .ExtractDialog import ExtractDialog 1295 from .ExtractDialog import ExtractDialog
1109 dlg = ExtractDialog(self, title, filename, startOffset, endOffset, 1296
1110 kind, parent=self.__ui) 1297 dlg = ExtractDialog(
1298 self, title, filename, startOffset, endOffset, kind, parent=self.__ui
1299 )
1111 changeGroup = dlg.getChangeGroupName() 1300 changeGroup = dlg.getChangeGroupName()
1112 self.__refactoringDialogs[changeGroup] = dlg 1301 self.__refactoringDialogs[changeGroup] = dlg
1113 dlg.finished.connect( 1302 dlg.finished.connect(lambda: self.__refactoringDialogClosed(changeGroup))
1114 lambda: self.__refactoringDialogClosed(changeGroup))
1115 dlg.show() 1303 dlg.show()
1116 1304
1117 ##################################################### 1305 #####################################################
1118 ## Inline refactorings 1306 ## Inline refactorings
1119 ##################################################### 1307 #####################################################
1120 1308
1121 def __inline(self): 1309 def __inline(self):
1122 """ 1310 """
1123 Private slot to handle the Inline Local Variable action. 1311 Private slot to handle the Inline Local Variable action.
1124 """ 1312 """
1125 aw = self.__vm.activeWindow() 1313 aw = self.__vm.activeWindow()
1126 1314
1127 if aw is None: 1315 if aw is None:
1128 return 1316 return
1129 1317
1130 title = self.tr("Inline") 1318 title = self.tr("Inline")
1131 if not aw.hasSelectedText(): 1319 if not aw.hasSelectedText():
1132 # no selection available 1320 # no selection available
1133 EricMessageBox.warning( 1321 EricMessageBox.warning(
1134 self.__ui, title, 1322 self.__ui,
1135 self.tr("Highlight the local variable, method or parameter" 1323 title,
1136 " you want to inline and try again.")) 1324 self.tr(
1137 return 1325 "Highlight the local variable, method or parameter"
1138 1326 " you want to inline and try again."
1327 ),
1328 )
1329 return
1330
1139 if not self.confirmAllBuffersSaved(): 1331 if not self.confirmAllBuffersSaved():
1140 return 1332 return
1141 1333
1142 filename = aw.getFileName() 1334 filename = aw.getFileName()
1143 line, index, line1, index1 = aw.getSelection() 1335 line, index, line1, index1 = aw.getSelection()
1144 offset = self.__getOffset(aw, line, index) 1336 offset = self.__getOffset(aw, line, index)
1145 1337
1146 from .InlineDialog import InlineDialog 1338 from .InlineDialog import InlineDialog
1339
1147 dlg = InlineDialog(self, title, filename, offset, parent=self.__ui) 1340 dlg = InlineDialog(self, title, filename, offset, parent=self.__ui)
1148 changeGroup = dlg.getChangeGroupName() 1341 changeGroup = dlg.getChangeGroupName()
1149 self.__refactoringDialogs[changeGroup] = dlg 1342 self.__refactoringDialogs[changeGroup] = dlg
1150 dlg.finished.connect( 1343 dlg.finished.connect(lambda: self.__refactoringDialogClosed(changeGroup))
1151 lambda: self.__refactoringDialogClosed(changeGroup))
1152 dlg.show() 1344 dlg.show()
1153 1345
1154 ##################################################### 1346 #####################################################
1155 ## Move refactorings 1347 ## Move refactorings
1156 ##################################################### 1348 #####################################################
1157 1349
1158 def __move(self, moveKind): 1350 def __move(self, moveKind):
1159 """ 1351 """
1160 Private slot to handle the Move Method action. 1352 Private slot to handle the Move Method action.
1161 1353
1162 @param moveKind kind of move to be performed 1354 @param moveKind kind of move to be performed
1163 @type str (one of 'move_method' or 'move_module') 1355 @type str (one of 'move_method' or 'move_module')
1164 """ 1356 """
1165 aw = self.__vm.activeWindow() 1357 aw = self.__vm.activeWindow()
1166 1358
1167 if aw is None: 1359 if aw is None:
1168 return 1360 return
1169 1361
1170 if moveKind == "move_method": 1362 if moveKind == "move_method":
1171 title = self.tr("Move Method") 1363 title = self.tr("Move Method")
1172 if not aw.hasSelectedText(): 1364 if not aw.hasSelectedText():
1173 # no selection available 1365 # no selection available
1174 EricMessageBox.warning( 1366 EricMessageBox.warning(
1175 self.__ui, title, 1367 self.__ui,
1176 self.tr("Highlight the method to move" 1368 title,
1177 " and try again.")) 1369 self.tr("Highlight the method to move" " and try again."),
1370 )
1178 return 1371 return
1179 else: 1372 else:
1180 title = self.tr("Move Current Module") 1373 title = self.tr("Move Current Module")
1181 1374
1182 if not self.confirmAllBuffersSaved(): 1375 if not self.confirmAllBuffersSaved():
1183 return 1376 return
1184 1377
1185 filename = aw.getFileName() 1378 filename = aw.getFileName()
1186 if moveKind == "move_method": 1379 if moveKind == "move_method":
1187 line, index, line1, index1 = aw.getSelection() 1380 line, index, line1, index1 = aw.getSelection()
1188 offset = self.__getOffset(aw, line, index) 1381 offset = self.__getOffset(aw, line, index)
1189 else: 1382 else:
1190 offset = None 1383 offset = None
1191 1384
1192 from .MoveDialog import MoveDialog 1385 from .MoveDialog import MoveDialog
1386
1193 dlg = MoveDialog(self, title, filename, offset, parent=self.__ui) 1387 dlg = MoveDialog(self, title, filename, offset, parent=self.__ui)
1194 changeGroup = dlg.getChangeGroupName() 1388 changeGroup = dlg.getChangeGroupName()
1195 self.__refactoringDialogs[changeGroup] = dlg 1389 self.__refactoringDialogs[changeGroup] = dlg
1196 dlg.finished.connect( 1390 dlg.finished.connect(lambda: self.__refactoringDialogClosed(changeGroup))
1197 lambda: self.__refactoringDialogClosed(changeGroup))
1198 dlg.show() 1391 dlg.show()
1199 1392
1200 ##################################################### 1393 #####################################################
1201 ## Use function refactoring 1394 ## Use function refactoring
1202 ##################################################### 1395 #####################################################
1203 1396
1204 def __useFunction(self): 1397 def __useFunction(self):
1205 """ 1398 """
1206 Private slot to use a function wherever possible. 1399 Private slot to use a function wherever possible.
1207 """ 1400 """
1208 aw = self.__vm.activeWindow() 1401 aw = self.__vm.activeWindow()
1209 1402
1210 if aw is None: 1403 if aw is None:
1211 return 1404 return
1212 1405
1213 title = self.tr("Use Function") 1406 title = self.tr("Use Function")
1214 if not aw.hasSelectedText(): 1407 if not aw.hasSelectedText():
1215 # no selection available 1408 # no selection available
1216 EricMessageBox.warning( 1409 EricMessageBox.warning(
1217 self.__ui, title, 1410 self.__ui, title, self.tr("Highlight a global function and try again.")
1218 self.tr("Highlight a global function and try again.")) 1411 )
1219 return 1412 return
1220 1413
1221 if not self.confirmAllBuffersSaved(): 1414 if not self.confirmAllBuffersSaved():
1222 return 1415 return
1223 1416
1224 filename = aw.getFileName() 1417 filename = aw.getFileName()
1225 line, index, line1, index1 = aw.getSelection() 1418 line, index, line1, index1 = aw.getSelection()
1226 offset = self.__getOffset(aw, line, index) 1419 offset = self.__getOffset(aw, line, index)
1227 1420
1228 from .UseFunctionDialog import UseFunctionDialog 1421 from .UseFunctionDialog import UseFunctionDialog
1229 dlg = UseFunctionDialog(self, title, filename, offset, 1422
1230 parent=self.__ui) 1423 dlg = UseFunctionDialog(self, title, filename, offset, parent=self.__ui)
1231 changeGroup = dlg.getChangeGroupName() 1424 changeGroup = dlg.getChangeGroupName()
1232 self.__refactoringDialogs[changeGroup] = dlg 1425 self.__refactoringDialogs[changeGroup] = dlg
1233 dlg.finished.connect( 1426 dlg.finished.connect(lambda: self.__refactoringDialogClosed(changeGroup))
1234 lambda: self.__refactoringDialogClosed(changeGroup))
1235 dlg.show() 1427 dlg.show()
1236 1428
1237 ##################################################### 1429 #####################################################
1238 ## Introduce refactorings 1430 ## Introduce refactorings
1239 ##################################################### 1431 #####################################################
1240 1432
1241 def __introduceFactoryMethod(self): 1433 def __introduceFactoryMethod(self):
1242 """ 1434 """
1243 Private slot to introduce a factory method or global function. 1435 Private slot to introduce a factory method or global function.
1244 """ 1436 """
1245 aw = self.__vm.activeWindow() 1437 aw = self.__vm.activeWindow()
1246 1438
1247 if aw is None: 1439 if aw is None:
1248 return 1440 return
1249 1441
1250 title = self.tr("Introduce Factory Method") 1442 title = self.tr("Introduce Factory Method")
1251 if not aw.hasSelectedText(): 1443 if not aw.hasSelectedText():
1252 # no selection available 1444 # no selection available
1253 EricMessageBox.warning( 1445 EricMessageBox.warning(
1254 self.__ui, title, 1446 self.__ui,
1255 self.tr("Highlight the class to introduce a factory" 1447 title,
1256 " method for and try again.")) 1448 self.tr(
1257 return 1449 "Highlight the class to introduce a factory"
1258 1450 " method for and try again."
1451 ),
1452 )
1453 return
1454
1259 if not self.confirmAllBuffersSaved(): 1455 if not self.confirmAllBuffersSaved():
1260 return 1456 return
1261 1457
1262 filename = aw.getFileName() 1458 filename = aw.getFileName()
1263 line, index, line1, index1 = aw.getSelection() 1459 line, index, line1, index1 = aw.getSelection()
1264 offset = self.__getOffset(aw, line, index) 1460 offset = self.__getOffset(aw, line, index)
1265 1461
1266 from .IntroduceFactoryDialog import IntroduceFactoryDialog 1462 from .IntroduceFactoryDialog import IntroduceFactoryDialog
1267 dlg = IntroduceFactoryDialog(self, title, filename, offset, 1463
1268 parent=self.__ui) 1464 dlg = IntroduceFactoryDialog(self, title, filename, offset, parent=self.__ui)
1269 changeGroup = dlg.getChangeGroupName() 1465 changeGroup = dlg.getChangeGroupName()
1270 self.__refactoringDialogs[changeGroup] = dlg 1466 self.__refactoringDialogs[changeGroup] = dlg
1271 dlg.finished.connect( 1467 dlg.finished.connect(lambda: self.__refactoringDialogClosed(changeGroup))
1272 lambda: self.__refactoringDialogClosed(changeGroup))
1273 dlg.show() 1468 dlg.show()
1274 1469
1275 def __introduceParameter(self): 1470 def __introduceParameter(self):
1276 """ 1471 """
1277 Private slot to introduce a parameter in a function. 1472 Private slot to introduce a parameter in a function.
1278 """ 1473 """
1279 aw = self.__vm.activeWindow() 1474 aw = self.__vm.activeWindow()
1280 1475
1281 if aw is None: 1476 if aw is None:
1282 return 1477 return
1283 1478
1284 title = self.tr("Introduce Parameter") 1479 title = self.tr("Introduce Parameter")
1285 if not aw.hasSelectedText(): 1480 if not aw.hasSelectedText():
1286 # no selection available 1481 # no selection available
1287 EricMessageBox.warning( 1482 EricMessageBox.warning(
1288 self.__ui, title, 1483 self.__ui,
1289 self.tr("Highlight the code for the new parameter" 1484 title,
1290 " and try again.")) 1485 self.tr("Highlight the code for the new parameter" " and try again."),
1291 return 1486 )
1292 1487 return
1488
1293 if not self.confirmAllBuffersSaved(): 1489 if not self.confirmAllBuffersSaved():
1294 return 1490 return
1295 1491
1296 filename = aw.getFileName() 1492 filename = aw.getFileName()
1297 line, index, line1, index1 = aw.getSelection() 1493 line, index, line1, index1 = aw.getSelection()
1298 offset = self.__getOffset(aw, line, index) 1494 offset = self.__getOffset(aw, line, index)
1299 1495
1300 from .IntroduceParameterDialog import IntroduceParameterDialog 1496 from .IntroduceParameterDialog import IntroduceParameterDialog
1301 dlg = IntroduceParameterDialog(self, title, filename, offset, 1497
1302 parent=self.__ui) 1498 dlg = IntroduceParameterDialog(self, title, filename, offset, parent=self.__ui)
1303 changeGroup = dlg.getChangeGroupName() 1499 changeGroup = dlg.getChangeGroupName()
1304 self.__refactoringDialogs[changeGroup] = dlg 1500 self.__refactoringDialogs[changeGroup] = dlg
1305 dlg.finished.connect( 1501 dlg.finished.connect(lambda: self.__refactoringDialogClosed(changeGroup))
1306 lambda: self.__refactoringDialogClosed(changeGroup))
1307 dlg.show() 1502 dlg.show()
1308 1503
1309 ##################################################### 1504 #####################################################
1310 ## Import refactorings 1505 ## Import refactorings
1311 ##################################################### 1506 #####################################################
1312 1507
1313 def __importsOrganize(self): 1508 def __importsOrganize(self):
1314 """ 1509 """
1315 Private slot to organize imports. 1510 Private slot to organize imports.
1316 """ 1511 """
1317 self.__doImports( 1512 self.__doImports(self.tr("Organize Imports"), "organize_imports")
1318 self.tr("Organize Imports"), 1513
1319 "organize_imports")
1320
1321 def __importsExpandStar(self): 1514 def __importsExpandStar(self):
1322 """ 1515 """
1323 Private slot to expand star imports. 1516 Private slot to expand star imports.
1324 """ 1517 """
1325 self.__doImports( 1518 self.__doImports(self.tr("Expand Star Imports"), "expand_star_imports")
1326 self.tr("Expand Star Imports"), 1519
1327 "expand_star_imports")
1328
1329 def __importsRelativeToAbsolute(self): 1520 def __importsRelativeToAbsolute(self):
1330 """ 1521 """
1331 Private slot to transform relative to absolute imports. 1522 Private slot to transform relative to absolute imports.
1332 """ 1523 """
1333 self.__doImports( 1524 self.__doImports(self.tr("Relative to Absolute"), "relatives_to_absolutes")
1334 self.tr("Relative to Absolute"), 1525
1335 "relatives_to_absolutes")
1336
1337 def __importsFromToImport(self): 1526 def __importsFromToImport(self):
1338 """ 1527 """
1339 Private slot to transform from imports to plain imports. 1528 Private slot to transform from imports to plain imports.
1340 """ 1529 """
1341 self.__doImports( 1530 self.__doImports(self.tr("Froms to Imports"), "froms_to_imports")
1342 self.tr("Froms to Imports"), 1531
1343 "froms_to_imports")
1344
1345 def __importsHandleLong(self): 1532 def __importsHandleLong(self):
1346 """ 1533 """
1347 Private slot to handle long imports. 1534 Private slot to handle long imports.
1348 """ 1535 """
1349 self.__doImports( 1536 self.__doImports(self.tr("Handle Long Imports"), "handle_long_imports")
1350 self.tr("Handle Long Imports"), 1537
1351 "handle_long_imports")
1352
1353 def __doImports(self, title, methodName): 1538 def __doImports(self, title, methodName):
1354 """ 1539 """
1355 Private method to perform the various imports refactorings. 1540 Private method to perform the various imports refactorings.
1356 1541
1357 @param title title to be used for the import refactoring 1542 @param title title to be used for the import refactoring
1358 @type str 1543 @type str
1359 @param methodName name of the method performing the import refactoring 1544 @param methodName name of the method performing the import refactoring
1360 @type str 1545 @type str
1361 """ 1546 """
1362 aw = self.__vm.activeWindow() 1547 aw = self.__vm.activeWindow()
1363 1548
1364 if aw is None: 1549 if aw is None:
1365 return 1550 return
1366 1551
1367 if not self.confirmBufferIsSaved(aw): 1552 if not self.confirmBufferIsSaved(aw):
1368 return 1553 return
1369 1554
1370 filename = aw.getFileName() 1555 filename = aw.getFileName()
1371 if aw.hasSelectedText(): 1556 if aw.hasSelectedText():
1372 line, index, line1, index1 = aw.getSelection() 1557 line, index, line1, index1 = aw.getSelection()
1373 offset = self.__getOffset(aw, line, index) 1558 offset = self.__getOffset(aw, line, index)
1374 else: 1559 else:
1375 offset = None 1560 offset = None
1376 1561
1377 from .ConfirmationDialog import ConfirmationDialog 1562 from .ConfirmationDialog import ConfirmationDialog
1563
1378 dlg = ConfirmationDialog( 1564 dlg = ConfirmationDialog(
1379 self, title, "Imports", "CalculateImportsChanges", { 1565 self,
1566 title,
1567 "Imports",
1568 "CalculateImportsChanges",
1569 {
1380 "MethodName": methodName, 1570 "MethodName": methodName,
1381 "FileName": filename, 1571 "FileName": filename,
1382 "Offset": offset, 1572 "Offset": offset,
1383 }, 1573 },
1384 parent=self.__ui) 1574 parent=self.__ui,
1575 )
1385 changeGroup = dlg.getChangeGroupName() 1576 changeGroup = dlg.getChangeGroupName()
1386 self.__refactoringDialogs[changeGroup] = dlg 1577 self.__refactoringDialogs[changeGroup] = dlg
1387 dlg.finished.connect( 1578 dlg.finished.connect(lambda: self.__refactoringDialogClosed(changeGroup))
1388 lambda: self.__refactoringDialogClosed(changeGroup))
1389 dlg.show() 1579 dlg.show()
1390 1580
1391 ##################################################### 1581 #####################################################
1392 ## Various refactorings 1582 ## Various refactorings
1393 ##################################################### 1583 #####################################################
1394 1584
1395 def __restructure(self): 1585 def __restructure(self):
1396 """ 1586 """
1397 Private slot to restructure code. 1587 Private slot to restructure code.
1398 """ 1588 """
1399 from .RestructureDialog import RestructureDialog 1589 from .RestructureDialog import RestructureDialog
1590
1400 title = self.tr("Restructure") 1591 title = self.tr("Restructure")
1401 dlg = RestructureDialog(self, title, parent=self.__ui) 1592 dlg = RestructureDialog(self, title, parent=self.__ui)
1402 changeGroup = dlg.getChangeGroupName() 1593 changeGroup = dlg.getChangeGroupName()
1403 self.__refactoringDialogs[changeGroup] = dlg 1594 self.__refactoringDialogs[changeGroup] = dlg
1404 dlg.finished.connect( 1595 dlg.finished.connect(lambda: self.__refactoringDialogClosed(changeGroup))
1405 lambda: self.__refactoringDialogClosed(changeGroup))
1406 dlg.show() 1596 dlg.show()
1407 1597
1408 def __changeSignature(self): 1598 def __changeSignature(self):
1409 """ 1599 """
1410 Private slot to change the signature of a method or function. 1600 Private slot to change the signature of a method or function.
1411 """ 1601 """
1412 aw = self.__vm.activeWindow() 1602 aw = self.__vm.activeWindow()
1413 1603
1414 if aw is None: 1604 if aw is None:
1415 return 1605 return
1416 1606
1417 title = self.tr("Change Method Signature") 1607 title = self.tr("Change Method Signature")
1418 if not aw.hasSelectedText(): 1608 if not aw.hasSelectedText():
1419 # no selection available 1609 # no selection available
1420 EricMessageBox.warning( 1610 EricMessageBox.warning(
1421 self.__ui, title, 1611 self.__ui,
1422 self.tr("Highlight the method or function to change" 1612 title,
1423 " and try again.")) 1613 self.tr("Highlight the method or function to change" " and try again."),
1424 return 1614 )
1425 1615 return
1616
1426 if not self.confirmAllBuffersSaved(): 1617 if not self.confirmAllBuffersSaved():
1427 return 1618 return
1428 1619
1429 filename = aw.getFileName() 1620 filename = aw.getFileName()
1430 line, index, line1, index1 = aw.getSelection() 1621 line, index, line1, index1 = aw.getSelection()
1431 offset = self.__getOffset(aw, line, index) 1622 offset = self.__getOffset(aw, line, index)
1432 1623
1433 from .ChangeSignatureDialog import ChangeSignatureDialog 1624 from .ChangeSignatureDialog import ChangeSignatureDialog
1434 dlg = ChangeSignatureDialog(self, title, filename, offset, 1625
1435 parent=self.__ui) 1626 dlg = ChangeSignatureDialog(self, title, filename, offset, parent=self.__ui)
1436 changeGroup = dlg.getChangeGroupName() 1627 changeGroup = dlg.getChangeGroupName()
1437 self.__refactoringDialogs[changeGroup] = dlg 1628 self.__refactoringDialogs[changeGroup] = dlg
1438 dlg.finished.connect( 1629 dlg.finished.connect(lambda: self.__refactoringDialogClosed(changeGroup))
1439 lambda: self.__refactoringDialogClosed(changeGroup))
1440 dlg.show() 1630 dlg.show()
1441 1631
1442 def __inlineArgumentDefault(self): 1632 def __inlineArgumentDefault(self):
1443 """ 1633 """
1444 Private slot to inline the default value of a parameter of a 1634 Private slot to inline the default value of a parameter of a
1445 method or function. 1635 method or function.
1446 """ 1636 """
1447 aw = self.__vm.activeWindow() 1637 aw = self.__vm.activeWindow()
1448 1638
1449 if aw is None: 1639 if aw is None:
1450 return 1640 return
1451 1641
1452 title = self.tr("Inline Argument Default") 1642 title = self.tr("Inline Argument Default")
1453 if not aw.hasSelectedText(): 1643 if not aw.hasSelectedText():
1454 # no selection available 1644 # no selection available
1455 EricMessageBox.warning( 1645 EricMessageBox.warning(
1456 self.__ui, title, 1646 self.__ui,
1457 self.tr("Highlight the method or function to inline" 1647 title,
1458 " a parameter's default and try again.")) 1648 self.tr(
1459 return 1649 "Highlight the method or function to inline"
1460 1650 " a parameter's default and try again."
1651 ),
1652 )
1653 return
1654
1461 if not self.confirmAllBuffersSaved(): 1655 if not self.confirmAllBuffersSaved():
1462 return 1656 return
1463 1657
1464 filename = aw.getFileName() 1658 filename = aw.getFileName()
1465 line, index, line1, index1 = aw.getSelection() 1659 line, index, line1, index1 = aw.getSelection()
1466 offset = self.__getOffset(aw, line, index) 1660 offset = self.__getOffset(aw, line, index)
1467 1661
1468 from .InlineArgumentDefaultDialog import InlineArgumentDefaultDialog 1662 from .InlineArgumentDefaultDialog import InlineArgumentDefaultDialog
1469 dlg = InlineArgumentDefaultDialog(self, title, filename, offset, 1663
1470 parent=self.__ui) 1664 dlg = InlineArgumentDefaultDialog(
1665 self, title, filename, offset, parent=self.__ui
1666 )
1471 changeGroup = dlg.getChangeGroupName() 1667 changeGroup = dlg.getChangeGroupName()
1472 self.__refactoringDialogs[changeGroup] = dlg 1668 self.__refactoringDialogs[changeGroup] = dlg
1473 dlg.finished.connect( 1669 dlg.finished.connect(lambda: self.__refactoringDialogClosed(changeGroup))
1474 lambda: self.__refactoringDialogClosed(changeGroup))
1475 dlg.show() 1670 dlg.show()
1476 1671
1477 def __transformModuleToPackage(self): 1672 def __transformModuleToPackage(self):
1478 """ 1673 """
1479 Private slot to transform a module to a package. 1674 Private slot to transform a module to a package.
1480 """ 1675 """
1481 aw = self.__vm.activeWindow() 1676 aw = self.__vm.activeWindow()
1482 1677
1483 if aw is None: 1678 if aw is None:
1484 return 1679 return
1485 1680
1486 title = self.tr("Transform Module to Package") 1681 title = self.tr("Transform Module to Package")
1487 1682
1488 if not self.confirmAllBuffersSaved(): 1683 if not self.confirmAllBuffersSaved():
1489 return 1684 return
1490 1685
1491 filename = aw.getFileName() 1686 filename = aw.getFileName()
1492 1687
1493 from .ConfirmationDialog import ConfirmationDialog 1688 from .ConfirmationDialog import ConfirmationDialog
1689
1494 dlg = ConfirmationDialog( 1690 dlg = ConfirmationDialog(
1495 self, title, "ModuleToPackage", "CalculateModuleToPackageChanges", 1691 self,
1692 title,
1693 "ModuleToPackage",
1694 "CalculateModuleToPackageChanges",
1496 { 1695 {
1497 "FileName": filename, 1696 "FileName": filename,
1498 }, 1697 },
1499 parent=self.__ui) 1698 parent=self.__ui,
1699 )
1500 changeGroup = dlg.getChangeGroupName() 1700 changeGroup = dlg.getChangeGroupName()
1501 self.__refactoringDialogs[changeGroup] = dlg 1701 self.__refactoringDialogs[changeGroup] = dlg
1502 dlg.finished.connect( 1702 dlg.finished.connect(lambda: self.__refactoringDialogClosed(changeGroup))
1503 lambda: self.__refactoringDialogClosed(changeGroup))
1504 dlg.show() 1703 dlg.show()
1505 1704
1506 def __encapsulateAttribute(self): 1705 def __encapsulateAttribute(self):
1507 """ 1706 """
1508 Private slot to encapsulate an attribute. 1707 Private slot to encapsulate an attribute.
1509 """ 1708 """
1510 aw = self.__vm.activeWindow() 1709 aw = self.__vm.activeWindow()
1511 1710
1512 if aw is None: 1711 if aw is None:
1513 return 1712 return
1514 1713
1515 title = self.tr("Encapsulate Attribute") 1714 title = self.tr("Encapsulate Attribute")
1516 if not aw.hasSelectedText(): 1715 if not aw.hasSelectedText():
1517 # no selection available 1716 # no selection available
1518 EricMessageBox.warning( 1717 EricMessageBox.warning(
1519 self.__ui, title, 1718 self.__ui,
1520 self.tr("Highlight the attribute to encapsulate" 1719 title,
1521 " and try again.")) 1720 self.tr("Highlight the attribute to encapsulate" " and try again."),
1522 return 1721 )
1523 1722 return
1723
1524 if not self.confirmAllBuffersSaved(): 1724 if not self.confirmAllBuffersSaved():
1525 return 1725 return
1526 1726
1527 filename = aw.getFileName() 1727 filename = aw.getFileName()
1528 line, index, line1, index1 = aw.getSelection() 1728 line, index, line1, index1 = aw.getSelection()
1529 offset = self.__getOffset(aw, line, index) 1729 offset = self.__getOffset(aw, line, index)
1530 1730
1531 from .GetterSetterDialog import GetterSetterDialog 1731 from .GetterSetterDialog import GetterSetterDialog
1532 dlg = GetterSetterDialog(self, title, filename, offset, 1732
1533 parent=self.__ui) 1733 dlg = GetterSetterDialog(self, title, filename, offset, parent=self.__ui)
1534 changeGroup = dlg.getChangeGroupName() 1734 changeGroup = dlg.getChangeGroupName()
1535 self.__refactoringDialogs[changeGroup] = dlg 1735 self.__refactoringDialogs[changeGroup] = dlg
1536 dlg.finished.connect( 1736 dlg.finished.connect(lambda: self.__refactoringDialogClosed(changeGroup))
1537 lambda: self.__refactoringDialogClosed(changeGroup))
1538 dlg.show() 1737 dlg.show()
1539 1738
1540 def __convertLocalToAttribute(self): 1739 def __convertLocalToAttribute(self):
1541 """ 1740 """
1542 Private slot to convert a local variable to an attribute. 1741 Private slot to convert a local variable to an attribute.
1543 """ 1742 """
1544 aw = self.__vm.activeWindow() 1743 aw = self.__vm.activeWindow()
1545 1744
1546 if aw is None: 1745 if aw is None:
1547 return 1746 return
1548 1747
1549 title = self.tr("Local Variable to Attribute") 1748 title = self.tr("Local Variable to Attribute")
1550 if not aw.hasSelectedText(): 1749 if not aw.hasSelectedText():
1551 # no selection available 1750 # no selection available
1552 EricMessageBox.warning( 1751 EricMessageBox.warning(
1553 self.__ui, title, 1752 self.__ui,
1554 self.tr("Highlight the local variable to make an attribute" 1753 title,
1555 " and try again.")) 1754 self.tr(
1556 return 1755 "Highlight the local variable to make an attribute"
1557 1756 " and try again."
1757 ),
1758 )
1759 return
1760
1558 if not self.confirmAllBuffersSaved(): 1761 if not self.confirmAllBuffersSaved():
1559 return 1762 return
1560 1763
1561 filename = aw.getFileName() 1764 filename = aw.getFileName()
1562 line, index, line1, index1 = aw.getSelection() 1765 line, index, line1, index1 = aw.getSelection()
1563 offset = self.__getOffset(aw, line, index) 1766 offset = self.__getOffset(aw, line, index)
1564 1767
1565 from .ConfirmationDialog import ConfirmationDialog 1768 from .ConfirmationDialog import ConfirmationDialog
1769
1566 dlg = ConfirmationDialog( 1770 dlg = ConfirmationDialog(
1567 self, title, "LocalToAttribute", 1771 self,
1568 "CalculateLocalToAttributeChanges", { 1772 title,
1773 "LocalToAttribute",
1774 "CalculateLocalToAttributeChanges",
1775 {
1569 "FileName": filename, 1776 "FileName": filename,
1570 "Offset": offset, 1777 "Offset": offset,
1571 }, 1778 },
1572 parent=self.__ui) 1779 parent=self.__ui,
1780 )
1573 changeGroup = dlg.getChangeGroupName() 1781 changeGroup = dlg.getChangeGroupName()
1574 self.__refactoringDialogs[changeGroup] = dlg 1782 self.__refactoringDialogs[changeGroup] = dlg
1575 dlg.finished.connect( 1783 dlg.finished.connect(lambda: self.__refactoringDialogClosed(changeGroup))
1576 lambda: self.__refactoringDialogClosed(changeGroup))
1577 dlg.show() 1784 dlg.show()
1578 1785
1579 def __methodToMethodObject(self): 1786 def __methodToMethodObject(self):
1580 """ 1787 """
1581 Private slot to change the signature of a method or function. 1788 Private slot to change the signature of a method or function.
1582 """ 1789 """
1583 aw = self.__vm.activeWindow() 1790 aw = self.__vm.activeWindow()
1584 1791
1585 if aw is None: 1792 if aw is None:
1586 return 1793 return
1587 1794
1588 title = self.tr("Replace Method With Method Object") 1795 title = self.tr("Replace Method With Method Object")
1589 if not aw.hasSelectedText(): 1796 if not aw.hasSelectedText():
1590 # no selection available 1797 # no selection available
1591 EricMessageBox.warning( 1798 EricMessageBox.warning(
1592 self.__ui, title, 1799 self.__ui,
1593 self.tr("Highlight the method or function to convert" 1800 title,
1594 " and try again.")) 1801 self.tr(
1595 return 1802 "Highlight the method or function to convert" " and try again."
1596 1803 ),
1804 )
1805 return
1806
1597 if not self.confirmAllBuffersSaved(): 1807 if not self.confirmAllBuffersSaved():
1598 return 1808 return
1599 1809
1600 filename = aw.getFileName() 1810 filename = aw.getFileName()
1601 line, index, line1, index1 = aw.getSelection() 1811 line, index, line1, index1 = aw.getSelection()
1602 offset = self.__getOffset(aw, line, index) 1812 offset = self.__getOffset(aw, line, index)
1603 1813
1604 from .MethodToMethodObjectDialog import MethodToMethodObjectDialog 1814 from .MethodToMethodObjectDialog import MethodToMethodObjectDialog
1605 dlg = MethodToMethodObjectDialog(self, title, filename, offset, 1815
1606 parent=self.__ui) 1816 dlg = MethodToMethodObjectDialog(
1817 self, title, filename, offset, parent=self.__ui
1818 )
1607 changeGroup = dlg.getChangeGroupName() 1819 changeGroup = dlg.getChangeGroupName()
1608 self.__refactoringDialogs[changeGroup] = dlg 1820 self.__refactoringDialogs[changeGroup] = dlg
1609 dlg.finished.connect( 1821 dlg.finished.connect(lambda: self.__refactoringDialogClosed(changeGroup))
1610 lambda: self.__refactoringDialogClosed(changeGroup))
1611 dlg.show() 1822 dlg.show()
1612 1823
1613 ##################################################### 1824 #####################################################
1614 ## Refactoring History 1825 ## Refactoring History
1615 ##################################################### 1826 #####################################################
1616 1827
1617 def __showProjectHistory(self): 1828 def __showProjectHistory(self):
1618 """ 1829 """
1619 Private method to show the project refactoring history. 1830 Private method to show the project refactoring history.
1620 """ 1831 """
1621 if self.__historyDialog is not None: 1832 if self.__historyDialog is not None:
1622 self.__historyDialog.close() 1833 self.__historyDialog.close()
1623 1834
1624 from .HistoryDialog import HistoryDialog 1835 from .HistoryDialog import HistoryDialog
1836
1625 self.__historyDialog = HistoryDialog(self, parent=self.__ui) 1837 self.__historyDialog = HistoryDialog(self, parent=self.__ui)
1626 self.__historyDialog.finished.connect(self.__historyDialogClosed) 1838 self.__historyDialog.finished.connect(self.__historyDialogClosed)
1627 self.__historyDialog.show() 1839 self.__historyDialog.show()
1628 1840
1629 def __showFileHistory(self): 1841 def __showFileHistory(self):
1630 """ 1842 """
1631 Private method to show the refactoring history of the current file. 1843 Private method to show the refactoring history of the current file.
1632 """ 1844 """
1633 aw = self.__vm.activeWindow() 1845 aw = self.__vm.activeWindow()
1634 1846
1635 if aw is None: 1847 if aw is None:
1636 return 1848 return
1637 1849
1638 if self.__historyDialog is not None: 1850 if self.__historyDialog is not None:
1639 self.__historyDialog.close() 1851 self.__historyDialog.close()
1640 1852
1641 from .HistoryDialog import HistoryDialog 1853 from .HistoryDialog import HistoryDialog
1854
1642 filename = aw.getFileName() 1855 filename = aw.getFileName()
1643 if filename: 1856 if filename:
1644 self.__historyDialog = HistoryDialog( 1857 self.__historyDialog = HistoryDialog(
1645 self, filename=filename, parent=self.__ui) 1858 self, filename=filename, parent=self.__ui
1859 )
1646 self.__historyDialog.show() 1860 self.__historyDialog.show()
1647 1861
1648 def __clearHistory(self): 1862 def __clearHistory(self):
1649 """ 1863 """
1650 Private slot to clear the redo and undo lists. 1864 Private slot to clear the redo and undo lists.
1651 """ 1865 """
1652 res = EricMessageBox.yesNo( 1866 res = EricMessageBox.yesNo(
1653 None, 1867 None,
1654 self.tr("Clear History"), 1868 self.tr("Clear History"),
1655 self.tr("Do you really want to clear the refactoring history?")) 1869 self.tr("Do you really want to clear the refactoring history?"),
1870 )
1656 if res: 1871 if res:
1657 self.sendJson("History", { 1872 self.sendJson(
1658 "Subcommand": "Clear", 1873 "History",
1659 }) 1874 {
1660 1875 "Subcommand": "Clear",
1876 },
1877 )
1878
1661 if self.__historyDialog is not None: 1879 if self.__historyDialog is not None:
1662 self.__historyDialog.historyCleared() 1880 self.__historyDialog.historyCleared()
1663 1881
1664 def __processHistoryResult(self, result): 1882 def __processHistoryResult(self, result):
1665 """ 1883 """
1666 Private method to process the history data sent by the refactoring 1884 Private method to process the history data sent by the refactoring
1667 client. 1885 client.
1668 1886
1669 @param result dictionary containing the history data 1887 @param result dictionary containing the history data
1670 @type dict 1888 @type dict
1671 """ 1889 """
1672 if self.handleRopeError(result) and self.__historyDialog is not None: 1890 if self.handleRopeError(result) and self.__historyDialog is not None:
1673 self.__historyDialog.processHistoryCommand(result) 1891 self.__historyDialog.processHistoryCommand(result)
1674 1892
1675 def __historyDialogClosed(self): 1893 def __historyDialogClosed(self):
1676 """ 1894 """
1677 Private slot handling the closing of the history dialog. 1895 Private slot handling the closing of the history dialog.
1678 """ 1896 """
1679 self.__historyDialog = None 1897 self.__historyDialog = None
1680 1898
1681 ##################################################### 1899 #####################################################
1682 ## Find actions including mouse click handler 1900 ## Find actions including mouse click handler
1683 ##################################################### 1901 #####################################################
1684 1902
1685 def __queryReferences(self): 1903 def __queryReferences(self):
1686 """ 1904 """
1687 Private slot to handle the Find References action. 1905 Private slot to handle the Find References action.
1688 """ 1906 """
1689 aw = self.__vm.activeWindow() 1907 aw = self.__vm.activeWindow()
1690 1908
1691 if aw is None: 1909 if aw is None:
1692 return 1910 return
1693 1911
1694 title = self.tr("Find Occurrences") 1912 title = self.tr("Find Occurrences")
1695 1913
1696 if not self.confirmAllBuffersSaved(): 1914 if not self.confirmAllBuffersSaved():
1697 return 1915 return
1698 1916
1699 filename = aw.getFileName() 1917 filename = aw.getFileName()
1700 line, index = aw.getCursorPosition() 1918 line, index = aw.getCursorPosition()
1701 offset = self.__getOffset(aw, line, index) 1919 offset = self.__getOffset(aw, line, index)
1702 1920
1703 self.sendJson("QueryReferences", { 1921 self.sendJson(
1704 "Title": title, 1922 "QueryReferences",
1705 "FileName": filename, 1923 {
1706 "Offset": offset, 1924 "Title": title,
1707 }) 1925 "FileName": filename,
1708 1926 "Offset": offset,
1927 },
1928 )
1929
1709 def __queryReferencesResult(self, result): 1930 def __queryReferencesResult(self, result):
1710 """ 1931 """
1711 Private method to handle the "Query References" result sent by 1932 Private method to handle the "Query References" result sent by
1712 the client. 1933 the client.
1713 1934
1714 @param result dictionary containing the result data 1935 @param result dictionary containing the result data
1715 @type dict 1936 @type dict
1716 """ 1937 """
1717 if self.handleRopeError(result): 1938 if self.handleRopeError(result):
1718 title = result["Title"] 1939 title = result["Title"]
1719 if result["EntriesCount"] > 0: 1940 if result["EntriesCount"] > 0:
1720 from .MatchesDialog import MatchesDialog 1941 from .MatchesDialog import MatchesDialog
1942
1721 self.dlg = MatchesDialog(self.__ui, True) 1943 self.dlg = MatchesDialog(self.__ui, True)
1722 self.dlg.show() 1944 self.dlg.show()
1723 for occurrence in result["Entries"]: 1945 for occurrence in result["Entries"]:
1724 self.dlg.addEntry( 1946 self.dlg.addEntry(
1725 # file name, lineno, unsure 1947 # file name, lineno, unsure
1726 occurrence[0], occurrence[1], occurrence[2]) 1948 occurrence[0],
1949 occurrence[1],
1950 occurrence[2],
1951 )
1727 else: 1952 else:
1728 EricMessageBox.warning( 1953 EricMessageBox.warning(
1729 self.__ui, title, 1954 self.__ui, title, self.tr("No occurrences found.")
1730 self.tr("No occurrences found.")) 1955 )
1731 1956
1732 def __queryDefinition(self): 1957 def __queryDefinition(self):
1733 """ 1958 """
1734 Private slot to handle the Find Definition action. 1959 Private slot to handle the Find Definition action.
1735 """ 1960 """
1736 aw = self.__vm.activeWindow() 1961 aw = self.__vm.activeWindow()
1737 1962
1738 if aw is None: 1963 if aw is None:
1739 return 1964 return
1740 1965
1741 title = self.tr("Find Definition") 1966 title = self.tr("Find Definition")
1742 1967
1743 if not self.confirmAllBuffersSaved(): 1968 if not self.confirmAllBuffersSaved():
1744 return 1969 return
1745 1970
1746 filename = aw.getFileName() 1971 filename = aw.getFileName()
1747 line, index = aw.getCursorPosition() 1972 line, index = aw.getCursorPosition()
1748 offset = self.__getOffset(aw, line, index) 1973 offset = self.__getOffset(aw, line, index)
1749 1974
1750 self.sendJson("QueryDefinition", { 1975 self.sendJson(
1751 "Title": title, 1976 "QueryDefinition",
1752 "FileName": filename, 1977 {
1753 "Offset": offset, 1978 "Title": title,
1754 "Source": aw.text(), 1979 "FileName": filename,
1755 }) 1980 "Offset": offset,
1756 1981 "Source": aw.text(),
1982 },
1983 )
1984
1757 def __queryDefinitionResult(self, result): 1985 def __queryDefinitionResult(self, result):
1758 """ 1986 """
1759 Private method to handle the "Query Definition" result sent by 1987 Private method to handle the "Query Definition" result sent by
1760 the client. 1988 the client.
1761 1989
1762 @param result dictionary containing the result data 1990 @param result dictionary containing the result data
1763 @type dict 1991 @type dict
1764 """ 1992 """
1765 if self.handleRopeError(result): 1993 if self.handleRopeError(result):
1766 title = result["Title"] 1994 title = result["Title"]
1767 if "Location" in result: 1995 if "Location" in result:
1768 location = result["Location"] 1996 location = result["Location"]
1769 1997
1770 from .MatchesDialog import MatchesDialog 1998 from .MatchesDialog import MatchesDialog
1999
1771 self.dlg = MatchesDialog(self.__ui, False) 2000 self.dlg = MatchesDialog(self.__ui, False)
1772 self.dlg.show() 2001 self.dlg.show()
1773 self.dlg.addEntry(location[0], location[1]) 2002 self.dlg.addEntry(location[0], location[1])
1774 # file name, lineno 2003 # file name, lineno
1775 else: 2004 else:
1776 EricMessageBox.warning( 2005 EricMessageBox.warning(
1777 self.__ui, title, 2006 self.__ui, title, self.tr("No matching definition found.")
1778 self.tr("No matching definition found.")) 2007 )
1779 2008
1780 def __queryImplementations(self): 2009 def __queryImplementations(self):
1781 """ 2010 """
1782 Private slot to handle the Find Implementations action. 2011 Private slot to handle the Find Implementations action.
1783 """ 2012 """
1784 aw = self.__vm.activeWindow() 2013 aw = self.__vm.activeWindow()
1785 2014
1786 if aw is None: 2015 if aw is None:
1787 return 2016 return
1788 2017
1789 title = self.tr("Find Implementations") 2018 title = self.tr("Find Implementations")
1790 2019
1791 if not self.confirmAllBuffersSaved(): 2020 if not self.confirmAllBuffersSaved():
1792 return 2021 return
1793 2022
1794 filename = aw.getFileName() 2023 filename = aw.getFileName()
1795 line, index = aw.getCursorPosition() 2024 line, index = aw.getCursorPosition()
1796 offset = self.__getOffset(aw, line, index) 2025 offset = self.__getOffset(aw, line, index)
1797 2026
1798 self.sendJson("QueryImplementations", { 2027 self.sendJson(
1799 "Title": title, 2028 "QueryImplementations",
1800 "FileName": filename, 2029 {
1801 "Offset": offset, 2030 "Title": title,
1802 }) 2031 "FileName": filename,
1803 2032 "Offset": offset,
2033 },
2034 )
2035
1804 def __queryImplementationsResult(self, result): 2036 def __queryImplementationsResult(self, result):
1805 """ 2037 """
1806 Private method to handle the "Query Implementations" result sent by 2038 Private method to handle the "Query Implementations" result sent by
1807 the client. 2039 the client.
1808 2040
1809 @param result dictionary containing the result data 2041 @param result dictionary containing the result data
1810 @type dict 2042 @type dict
1811 """ 2043 """
1812 if self.handleRopeError(result): 2044 if self.handleRopeError(result):
1813 title = result["Title"] 2045 title = result["Title"]
1814 if result["EntriesCount"] > 0: 2046 if result["EntriesCount"] > 0:
1815 from .MatchesDialog import MatchesDialog 2047 from .MatchesDialog import MatchesDialog
2048
1816 self.dlg = MatchesDialog(self.__ui, True) 2049 self.dlg = MatchesDialog(self.__ui, True)
1817 self.dlg.show() 2050 self.dlg.show()
1818 for occurrence in result["Entries"]: 2051 for occurrence in result["Entries"]:
1819 self.dlg.addEntry( 2052 self.dlg.addEntry(
1820 # file name, lineno, unsure 2053 # file name, lineno, unsure
1821 occurrence[0], occurrence[1], occurrence[2]) 2054 occurrence[0],
2055 occurrence[1],
2056 occurrence[2],
2057 )
1822 else: 2058 else:
1823 EricMessageBox.warning( 2059 EricMessageBox.warning(
1824 self.__ui, title, self.tr("No implementations found.")) 2060 self.__ui, title, self.tr("No implementations found.")
1825 2061 )
2062
1826 ##################################################### 2063 #####################################################
1827 ## Various actions 2064 ## Various actions
1828 ##################################################### 2065 #####################################################
1829 2066
1830 def __editConfig(self): 2067 def __editConfig(self):
1831 """ 2068 """
1832 Private slot to open the rope configuration file in an editor. 2069 Private slot to open the rope configuration file in an editor.
1833 """ 2070 """
1834 ropedir = self.__ropeConfig["RopeFolderName"] 2071 ropedir = self.__ropeConfig["RopeFolderName"]
1835 configfile = "" 2072 configfile = ""
1836 if ropedir and os.path.exists(ropedir): 2073 if ropedir and os.path.exists(ropedir):
1837 configfile = os.path.join(ropedir, "config.py") 2074 configfile = os.path.join(ropedir, "config.py")
1838 if os.path.exists(configfile): 2075 if os.path.exists(configfile):
1839 from QScintilla.MiniEditor import MiniEditor 2076 from QScintilla.MiniEditor import MiniEditor
2077
1840 self.__editor = MiniEditor(configfile) 2078 self.__editor = MiniEditor(configfile)
1841 self.__editor.show() 2079 self.__editor.show()
1842 self.__editor.editorSaved.connect(self.__configChanged) 2080 self.__editor.editorSaved.connect(self.__configChanged)
1843 else: 2081 else:
1844 EricMessageBox.critical( 2082 EricMessageBox.critical(
1845 self.__ui, 2083 self.__ui,
1846 self.tr("Configure Rope"), 2084 self.tr("Configure Rope"),
1847 self.tr("""The Rope configuration file '{0}' does""" 2085 self.tr(
1848 """ not exist.""").format(configfile)) 2086 """The Rope configuration file '{0}' does""" """ not exist."""
2087 ).format(configfile),
2088 )
1849 else: 2089 else:
1850 EricMessageBox.critical( 2090 EricMessageBox.critical(
1851 self.__ui, 2091 self.__ui,
1852 self.tr("Configure Rope"), 2092 self.tr("Configure Rope"),
1853 self.tr("""The Rope admin directory does not exist.""")) 2093 self.tr("""The Rope admin directory does not exist."""),
1854 2094 )
2095
1855 def __updateConfig(self): 2096 def __updateConfig(self):
1856 """ 2097 """
1857 Private slot to update the configuration file. 2098 Private slot to update the configuration file.
1858 """ 2099 """
1859 res = EricMessageBox.yesNo( 2100 res = EricMessageBox.yesNo(
1860 self.__ui, 2101 self.__ui,
1861 self.tr("Update Configuration"), 2102 self.tr("Update Configuration"),
1862 self.tr("""Shall rope's current configuration be replaced """ 2103 self.tr(
1863 """by a new default configuration?""")) 2104 """Shall rope's current configuration be replaced """
2105 """by a new default configuration?"""
2106 ),
2107 )
1864 if res: 2108 if res:
1865 src = self.__defaultConfig() 2109 src = self.__defaultConfig()
1866 cname = self.__ropeConfigFile() 2110 cname = self.__ropeConfigFile()
1867 if src != "" and cname is not None: 2111 if src != "" and cname is not None:
1868 try: 2112 try:
1872 self.__editConfig() 2116 self.__editConfig()
1873 except OSError as err: 2117 except OSError as err:
1874 EricMessageBox.critical( 2118 EricMessageBox.critical(
1875 None, 2119 None,
1876 self.tr("Update Configuration"), 2120 self.tr("Update Configuration"),
1877 self.tr("""<p>The configuration could not be""" 2121 self.tr(
1878 """ updated.</p><p>Reason: {0}</p>""") 2122 """<p>The configuration could not be"""
1879 .format(str(err))) 2123 """ updated.</p><p>Reason: {0}</p>"""
1880 2124 ).format(str(err)),
2125 )
2126
1881 def __showRopeHelp(self): 2127 def __showRopeHelp(self):
1882 """ 2128 """
1883 Private slot to show help about the refactorings offered by Rope. 2129 Private slot to show help about the refactorings offered by Rope.
1884 """ 2130 """
1885 if self.__helpDialog is None: 2131 if self.__helpDialog is None:
1886 from .HelpDialog import HelpDialog 2132 from .HelpDialog import HelpDialog
2133
1887 self.__helpDialog = HelpDialog( 2134 self.__helpDialog = HelpDialog(
1888 self.tr("Help about rope refactorings"), 2135 self.tr("Help about rope refactorings"),
1889 self.__ropeConfig["RopeHelpFile"] 2136 self.__ropeConfig["RopeHelpFile"],
1890 ) 2137 )
1891 self.__helpDialog.show() 2138 self.__helpDialog.show()
1892 2139
1893 def __performSOA(self): 2140 def __performSOA(self):
1894 """ 2141 """
1895 Private slot to perform SOA on all modules. 2142 Private slot to perform SOA on all modules.
1896 """ 2143 """
1897 title = self.tr("Analyse all modules") 2144 title = self.tr("Analyse all modules")
1898 res = EricMessageBox.yesNo( 2145 res = EricMessageBox.yesNo(
1899 self.__ui, 2146 self.__ui,
1900 title, 2147 title,
1901 self.tr("""This action might take some time. """ 2148 self.tr(
1902 """Do you really want to perform SOA?""")) 2149 """This action might take some time. """
2150 """Do you really want to perform SOA?"""
2151 ),
2152 )
1903 if res: 2153 if res:
1904 2154
1905 self.sendJson("PerformSoa", { 2155 self.sendJson(
1906 "Title": title, 2156 "PerformSoa",
1907 }) 2157 {
1908 2158 "Title": title,
2159 },
2160 )
2161
1909 def __soaFinished(self, result): 2162 def __soaFinished(self, result):
1910 """ 2163 """
1911 Private method to handle the "Soa Finished" result sent by 2164 Private method to handle the "Soa Finished" result sent by
1912 the client. 2165 the client.
1913 2166
1914 @param result dictionary containing the result data 2167 @param result dictionary containing the result data
1915 @type dict 2168 @type dict
1916 """ 2169 """
1917 if self.handleRopeError(result): 2170 if self.handleRopeError(result):
1918 title = result["Title"] 2171 title = result["Title"]
1919 2172
1920 EricMessageBox.information( 2173 EricMessageBox.information(
1921 self.__ui, 2174 self.__ui,
1922 title, 2175 title,
1923 self.tr("""Static object analysis (SOA) done. """ 2176 self.tr(
1924 """SOA database updated.""")) 2177 """Static object analysis (SOA) done. """
1925 2178 """SOA database updated."""
2179 ),
2180 )
2181
1926 ################################################################## 2182 ##################################################################
1927 ## methods below are private utility methods 2183 ## methods below are private utility methods
1928 ################################################################## 2184 ##################################################################
1929 2185
1930 def __processProgress(self, params): 2186 def __processProgress(self, params):
1931 """ 2187 """
1932 Private method to handle Progress commands. 2188 Private method to handle Progress commands.
1933 2189
1934 @param params dictionary containing the progress data 2190 @param params dictionary containing the progress data
1935 @type dict 2191 @type dict
1936 """ 2192 """
1937 subcommand = params["Subcommand"] 2193 subcommand = params["Subcommand"]
1938 if subcommand == "Init": 2194 if subcommand == "Init":
1939 if self.__progressDialog is not None: 2195 if self.__progressDialog is not None:
1940 self.__progressDialog.reset() 2196 self.__progressDialog.reset()
1941 2197
1942 progressDialog = RopeProgressDialog( 2198 progressDialog = RopeProgressDialog(
1943 self, params["Title"], params["Interruptable"]) 2199 self, params["Title"], params["Interruptable"]
2200 )
1944 progressDialog.show() 2201 progressDialog.show()
1945 progressDialog.raise_() 2202 progressDialog.raise_()
1946 self.__progressDialog = progressDialog 2203 self.__progressDialog = progressDialog
1947 QApplication.processEvents() 2204 QApplication.processEvents()
1948 2205
1949 elif subcommand == "Progress" and self.__progressDialog is not None: 2206 elif subcommand == "Progress" and self.__progressDialog is not None:
1950 self.__progressDialog.updateProgress(params) 2207 self.__progressDialog.updateProgress(params)
1951 self.__progressDialog.raise_() 2208 self.__progressDialog.raise_()
1952 2209
1953 elif subcommand == "Reset" and self.__progressDialog is not None: 2210 elif subcommand == "Reset" and self.__progressDialog is not None:
1954 self.__progressDialog.reset() 2211 self.__progressDialog.reset()
1955 2212
1956 def __setConfig(self, params): 2213 def __setConfig(self, params):
1957 """ 2214 """
1958 Private method to set the rope client configuration data. 2215 Private method to set the rope client configuration data.
1959 2216
1960 @param params dictionary containing the configuration data 2217 @param params dictionary containing the configuration data
1961 @type dict 2218 @type dict
1962 """ 2219 """
1963 self.__ropeConfig = params 2220 self.__ropeConfig = params
1964 # keys: RopeFolderName, DefaultConfig, RopeHelpFile, 2221 # keys: RopeFolderName, DefaultConfig, RopeHelpFile,
1965 # RopeInfo, RopeVersion, RopeCopyright, PythonVersion 2222 # RopeInfo, RopeVersion, RopeCopyright, PythonVersion
1966 2223
1967 def __ropeConfigFile(self): 2224 def __ropeConfigFile(self):
1968 """ 2225 """
1969 Private method to get the name of the rope configuration file. 2226 Private method to get the name of the rope configuration file.
1970 2227
1971 @return name of the rope configuration file 2228 @return name of the rope configuration file
1972 @rtype str 2229 @rtype str
1973 """ 2230 """
1974 configfile = None 2231 configfile = None
1975 if self.__ropeConfig: 2232 if self.__ropeConfig:
1977 if ropedir: 2234 if ropedir:
1978 configfile = os.path.join(ropedir, "config.py") 2235 configfile = os.path.join(ropedir, "config.py")
1979 if not os.path.exists(configfile): 2236 if not os.path.exists(configfile):
1980 configfile = None 2237 configfile = None
1981 return configfile 2238 return configfile
1982 2239
1983 def __configChanged(self): 2240 def __configChanged(self):
1984 """ 2241 """
1985 Private slot called, when the rope config file has changed. 2242 Private slot called, when the rope config file has changed.
1986 """ 2243 """
1987 self.sendJson("ConfigChanged", {}) 2244 self.sendJson("ConfigChanged", {})
1988 2245
1989 def __defaultConfig(self): 2246 def __defaultConfig(self):
1990 """ 2247 """
1991 Private slot to return the contents of rope's default configuration. 2248 Private slot to return the contents of rope's default configuration.
1992 2249
1993 @return string containing the source of rope's default 2250 @return string containing the source of rope's default
1994 configuration 2251 configuration
1995 @rtype str 2252 @rtype str
1996 """ 2253 """
1997 if self.__ropeConfig and "DefaultConfig" in self.__ropeConfig: 2254 if self.__ropeConfig and "DefaultConfig" in self.__ropeConfig:
1998 return self.__ropeConfig["DefaultConfig"] 2255 return self.__ropeConfig["DefaultConfig"]
1999 else: 2256 else:
2000 return "" 2257 return ""
2001 2258
2002 ################################################################## 2259 ##################################################################
2003 ## methods below are public utility methods 2260 ## methods below are public utility methods
2004 ################################################################## 2261 ##################################################################
2005 2262
2006 def getActions(self): 2263 def getActions(self):
2007 """ 2264 """
2008 Public method to get a list of all actions. 2265 Public method to get a list of all actions.
2009 2266
2010 @return list of all actions 2267 @return list of all actions
2011 @rtype list of EricAction 2268 @rtype list of EricAction
2012 """ 2269 """
2013 return self.actions[:] 2270 return self.actions[:]
2014 2271
2015 def projectOpened(self): 2272 def projectOpened(self):
2016 """ 2273 """
2017 Public slot to handle the projectOpened signal. 2274 Public slot to handle the projectOpened signal.
2018 """ 2275 """
2019 if self.__projectopen: 2276 if self.__projectopen:
2020 self.projectClosed() 2277 self.projectClosed()
2021 2278
2022 self.__projectopen = True 2279 self.__projectopen = True
2023 self.__projectpath = self.__ericProject.getProjectPath() 2280 self.__projectpath = self.__ericProject.getProjectPath()
2024 self.__projectLanguage = self.__ericProject.getProjectLanguage() 2281 self.__projectLanguage = self.__ericProject.getProjectLanguage()
2025 2282
2026 ok = False 2283 ok = False
2027 2284
2028 if self.__projectLanguage in ("Python3", "MicroPython", "Cython"): 2285 if self.__projectLanguage in ("Python3", "MicroPython", "Cython"):
2029 clientEnv = os.environ.copy() 2286 clientEnv = os.environ.copy()
2030 if "PATH" in clientEnv: 2287 if "PATH" in clientEnv:
2031 clientEnv["PATH"] = self.__ui.getOriginalPathString() 2288 clientEnv["PATH"] = self.__ui.getOriginalPathString()
2032 2289
2033 venvManager = ericApp().getObject("VirtualEnvManager") 2290 venvManager = ericApp().getObject("VirtualEnvManager")
2034 2291
2035 # get virtual environment from project first 2292 # get virtual environment from project first
2036 venvName = self.__ericProject.getDebugProperty("VIRTUALENV") 2293 venvName = self.__ericProject.getDebugProperty("VIRTUALENV")
2037 if venvName: 2294 if venvName:
2038 try: 2295 try:
2039 isRemote = venvManager.isRemoteEnvironment(venvName) 2296 isRemote = venvManager.isRemoteEnvironment(venvName)
2041 isRemote = False 2298 isRemote = False
2042 else: 2299 else:
2043 isRemote = False 2300 isRemote = False
2044 if (not venvName) or isRemote: 2301 if (not venvName) or isRemote:
2045 # get it from debugger settings next 2302 # get it from debugger settings next
2046 if self.__projectLanguage in ( 2303 if self.__projectLanguage in ("Python3", "MicroPython", "Cython"):
2047 "Python3", "MicroPython", "Cython"
2048 ):
2049 venvName = Preferences.getDebugger("Python3VirtualEnv") 2304 venvName = Preferences.getDebugger("Python3VirtualEnv")
2050 if not venvName: 2305 if not venvName:
2051 venvName, _ = venvManager.getDefaultEnvironment() 2306 venvName, _ = venvManager.getDefaultEnvironment()
2052 else: 2307 else:
2053 venvName = "" 2308 venvName = ""
2054 if venvName: 2309 if venvName:
2055 interpreter = venvManager.getVirtualenvInterpreter( 2310 interpreter = venvManager.getVirtualenvInterpreter(venvName)
2056 venvName)
2057 execPath = venvManager.getVirtualenvExecPath(venvName) 2311 execPath = venvManager.getVirtualenvExecPath(venvName)
2058 2312
2059 # build a suitable environment 2313 # build a suitable environment
2060 if execPath: 2314 if execPath:
2061 if "PATH" in clientEnv: 2315 if "PATH" in clientEnv:
2062 clientEnv["PATH"] = os.pathsep.join( 2316 clientEnv["PATH"] = os.pathsep.join(
2063 [execPath, clientEnv["PATH"]]) 2317 [execPath, clientEnv["PATH"]]
2318 )
2064 else: 2319 else:
2065 clientEnv["PATH"] = execPath 2320 clientEnv["PATH"] = execPath
2066 else: 2321 else:
2067 interpreter = "" 2322 interpreter = ""
2068 if interpreter: 2323 if interpreter:
2069 if isRemote: 2324 if isRemote:
2070 self.__ui.appendToStderr(self.tr( 2325 self.__ui.appendToStderr(
2071 "The project is configured for remote access." 2326 self.tr(
2072 " Using local interpreter instead." 2327 "The project is configured for remote access."
2073 )) 2328 " Using local interpreter instead."
2329 )
2330 )
2074 ok = self.__startRefactoringClient(interpreter, clientEnv) 2331 ok = self.__startRefactoringClient(interpreter, clientEnv)
2075 if not ok: 2332 if not ok:
2076 self.__ui.appendToStderr(self.tr( 2333 self.__ui.appendToStderr(
2077 "Project language '{0}' is not supported because" 2334 self.tr(
2078 " the configured interpreter could not be started." 2335 "Project language '{0}' is not supported because"
2079 " Refactoring is disabled." 2336 " the configured interpreter could not be started."
2080 ).format(self.__projectLanguage)) 2337 " Refactoring is disabled."
2338 ).format(self.__projectLanguage)
2339 )
2081 else: 2340 else:
2082 for act in self.actions: 2341 for act in self.actions:
2083 act.setEnabled(True) 2342 act.setEnabled(True)
2084 else: 2343 else:
2085 self.__ui.appendToStderr(self.tr( 2344 self.__ui.appendToStderr(
2086 "Project language '{0}' is not supported because no" 2345 self.tr(
2087 " suitable interpreter is configured. Refactoring is" 2346 "Project language '{0}' is not supported because no"
2088 " disabled." 2347 " suitable interpreter is configured. Refactoring is"
2089 ).format(self.__projectLanguage)) 2348 " disabled."
2349 ).format(self.__projectLanguage)
2350 )
2090 else: 2351 else:
2091 self.__ui.appendToStderr(self.tr( 2352 self.__ui.appendToStderr(
2092 "Refactoring for project language '{0}' is not supported." 2353 self.tr(
2093 ).format(self.__projectLanguage)) 2354 "Refactoring for project language '{0}' is not supported."
2094 2355 ).format(self.__projectLanguage)
2356 )
2357
2095 self.__mainMenu.menuAction().setEnabled(ok) 2358 self.__mainMenu.menuAction().setEnabled(ok)
2096 2359
2097 def projectClosed(self): 2360 def projectClosed(self):
2098 """ 2361 """
2099 Public slot to handle the projectClosed signal. 2362 Public slot to handle the projectClosed signal.
2100 """ 2363 """
2101 for act in self.actions: 2364 for act in self.actions:
2102 act.setEnabled(False) 2365 act.setEnabled(False)
2103 self.__mainMenu.menuAction().setEnabled(False) 2366 self.__mainMenu.menuAction().setEnabled(False)
2104 2367
2105 if self.__helpDialog is not None: 2368 if self.__helpDialog is not None:
2106 self.__helpDialog.close() 2369 self.__helpDialog.close()
2107 self.__helpDialog = None 2370 self.__helpDialog = None
2108 if self.__historyDialog is not None: 2371 if self.__historyDialog is not None:
2109 self.__historyDialog.close() 2372 self.__historyDialog.close()
2110 self.__historyDialog = None 2373 self.__historyDialog = None
2111 for dlg in self.__refactoringDialogs.values(): 2374 for dlg in self.__refactoringDialogs.values():
2112 dlg.close() 2375 dlg.close()
2113 self.__refactoringDialogs = {} 2376 self.__refactoringDialogs = {}
2114 2377
2115 self.sendJson("CloseProject", {}, flush=True) 2378 self.sendJson("CloseProject", {}, flush=True)
2116 2379
2117 self.__projectopen = False 2380 self.__projectopen = False
2118 self.__projectpath = '' 2381 self.__projectpath = ""
2119 self.__projectLanguage = "" 2382 self.__projectLanguage = ""
2120 self.__ropeConfig = {} 2383 self.__ropeConfig = {}
2121 2384
2122 self.stopClient() 2385 self.stopClient()
2123 2386
2124 def confirmBufferIsSaved(self, editor): 2387 def confirmBufferIsSaved(self, editor):
2125 """ 2388 """
2126 Public method to check, if an editor has unsaved changes. 2389 Public method to check, if an editor has unsaved changes.
2127 2390
2128 @param editor reference to the editor to be checked 2391 @param editor reference to the editor to be checked
2129 @type Editor 2392 @type Editor
2130 @return flag indicating, that the editor doesn't contain 2393 @return flag indicating, that the editor doesn't contain
2131 unsaved edits 2394 unsaved edits
2132 @rtype bool 2395 @rtype bool
2133 """ 2396 """
2134 res = editor.checkDirty() 2397 res = editor.checkDirty()
2135 self.sendJson("Validate", {}) 2398 self.sendJson("Validate", {})
2136 return res 2399 return res
2137 2400
2138 def confirmAllBuffersSaved(self): 2401 def confirmAllBuffersSaved(self):
2139 """ 2402 """
2140 Public method to check, if any editor has unsaved changes. 2403 Public method to check, if any editor has unsaved changes.
2141 2404
2142 @return flag indicating, that no editor contains unsaved edits 2405 @return flag indicating, that no editor contains unsaved edits
2143 @rtype bool 2406 @rtype bool
2144 """ 2407 """
2145 res = self.__vm.checkAllDirty() 2408 res = self.__vm.checkAllDirty()
2146 self.sendJson("Validate", {}) 2409 self.sendJson("Validate", {})
2147 return res 2410 return res
2148 2411
2149 def refreshEditors(self, changedFiles): 2412 def refreshEditors(self, changedFiles):
2150 """ 2413 """
2151 Public method to refresh modified editors. 2414 Public method to refresh modified editors.
2152 2415
2153 @param changedFiles list of changed files 2416 @param changedFiles list of changed files
2154 @type list of str 2417 @type list of str
2155 """ 2418 """
2156 openFiles = [Utilities.normcasepath(f) 2419 openFiles = [Utilities.normcasepath(f) for f in self.__vm.getOpenFilenames()]
2157 for f in self.__vm.getOpenFilenames()] 2420
2158
2159 for fileName in changedFiles: 2421 for fileName in changedFiles:
2160 normfile = Utilities.normcasepath(fileName) 2422 normfile = Utilities.normcasepath(fileName)
2161 if normfile in openFiles: 2423 if normfile in openFiles:
2162 editor = self.__vm.getEditor(normfile)[1] 2424 editor = self.__vm.getEditor(normfile)[1]
2163 editor.refresh() 2425 editor.refresh()
2164 2426
2165 aw = self.__vm.activeWindow() 2427 aw = self.__vm.activeWindow()
2166 if aw is not None: 2428 if aw is not None:
2167 filename = aw.getFileName() 2429 filename = aw.getFileName()
2168 if filename is not None: 2430 if filename is not None:
2169 self.__vm.openSourceFile(filename, 2431 self.__vm.openSourceFile(filename, aw.getCursorPosition()[0] + 1)
2170 aw.getCursorPosition()[0] + 1) 2432
2171
2172 def reportChanged(self, filename, oldSource): 2433 def reportChanged(self, filename, oldSource):
2173 """ 2434 """
2174 Public slot to report some changed sources. 2435 Public slot to report some changed sources.
2175 2436
2176 @param filename file name of the changed source 2437 @param filename file name of the changed source
2177 @type str 2438 @type str
2178 @param oldSource source code before the change 2439 @param oldSource source code before the change
2179 @type str 2440 @type str
2180 """ 2441 """
2181 if ( 2442 if self.__ericProject.isOpen() and self.__ericProject.isProjectFile(filename):
2182 self.__ericProject.isOpen() and
2183 self.__ericProject.isProjectFile(filename)
2184 ):
2185 editor = self.__vm.getOpenEditor(filename) 2443 editor = self.__vm.getOpenEditor(filename)
2186 if ( 2444 if (
2187 self.__ropeConfig and 2445 self.__ropeConfig
2188 editor is not None and 2446 and editor is not None
2189 editor.getLanguage() == self.__ropeConfig["PythonVersion"] 2447 and editor.getLanguage() == self.__ropeConfig["PythonVersion"]
2190 ): 2448 ):
2191 self.sendJson("ReportChanged", { 2449 self.sendJson(
2192 "FileName": filename, 2450 "ReportChanged",
2193 "OldSource": oldSource, 2451 {
2194 }) 2452 "FileName": filename,
2195 2453 "OldSource": oldSource,
2454 },
2455 )
2456
2196 ####################################################################### 2457 #######################################################################
2197 ## Methods below handle the network connection 2458 ## Methods below handle the network connection
2198 ####################################################################### 2459 #######################################################################
2199 2460
2200 def handleCall(self, method, params): 2461 def handleCall(self, method, params):
2201 """ 2462 """
2202 Public method to handle a method call from the client. 2463 Public method to handle a method call from the client.
2203 2464
2204 @param method requested method name 2465 @param method requested method name
2205 @type str 2466 @type str
2206 @param params dictionary with method specific parameters 2467 @param params dictionary with method specific parameters
2207 @type dict 2468 @type dict
2208 """ 2469 """
2209 self.__methodMapping[method](params) 2470 self.__methodMapping[method](params)
2210 2471
2211 def __processClientException(self, params): 2472 def __processClientException(self, params):
2212 """ 2473 """
2213 Private method to handle exceptions of the refactoring client. 2474 Private method to handle exceptions of the refactoring client.
2214 2475
2215 @param params dictionary containing the exception data 2476 @param params dictionary containing the exception data
2216 @type dict 2477 @type dict
2217 """ 2478 """
2218 if params["ExceptionType"] == "ProtocolError": 2479 if params["ExceptionType"] == "ProtocolError":
2219 EricMessageBox.critical( 2480 EricMessageBox.critical(
2220 None, 2481 None,
2221 self.tr("Refactoring Protocol Error"), 2482 self.tr("Refactoring Protocol Error"),
2222 self.tr("""<p>The data received from the refactoring""" 2483 self.tr(
2223 """ server could not be decoded. Please report""" 2484 """<p>The data received from the refactoring"""
2224 """ this issue with the received data to the""" 2485 """ server could not be decoded. Please report"""
2225 """ eric bugs email address.</p>""" 2486 """ this issue with the received data to the"""
2226 """<p>Error: {0}</p>""" 2487 """ eric bugs email address.</p>"""
2227 """<p>Data:<br/>{1}</p>""") 2488 """<p>Error: {0}</p>"""
2228 .format(params["ExceptionValue"], 2489 """<p>Data:<br/>{1}</p>"""
2229 Utilities.html_encode(params["ProtocolData"])), 2490 ).format(
2230 EricMessageBox.Ok 2491 params["ExceptionValue"],
2492 Utilities.html_encode(params["ProtocolData"]),
2493 ),
2494 EricMessageBox.Ok,
2231 ) 2495 )
2232 else: 2496 else:
2233 EricMessageBox.critical( 2497 EricMessageBox.critical(
2234 None, 2498 None,
2235 self.tr("Refactoring Client Error"), 2499 self.tr("Refactoring Client Error"),
2236 self.tr("<p>An exception happened in the refactoring" 2500 self.tr(
2237 " client. Please report it to the eric bugs" 2501 "<p>An exception happened in the refactoring"
2238 " email address.</p>" 2502 " client. Please report it to the eric bugs"
2239 "<p>Exception: {0}</p>" 2503 " email address.</p>"
2240 "<p>Value: {1}</p>" 2504 "<p>Exception: {0}</p>"
2241 "<p>Traceback: {2}</p>") 2505 "<p>Value: {1}</p>"
2242 .format(Utilities.html_encode(params["ExceptionType"]), 2506 "<p>Traceback: {2}</p>"
2243 params["ExceptionValue"], 2507 ).format(
2244 params["Traceback"].replace("\r\n", "<br/>") 2508 Utilities.html_encode(params["ExceptionType"]),
2245 .replace("\n", "<br/>").replace("\r", "<br/>")), 2509 params["ExceptionValue"],
2246 EricMessageBox.Ok 2510 params["Traceback"]
2247 ) 2511 .replace("\r\n", "<br/>")
2248 2512 .replace("\n", "<br/>")
2513 .replace("\r", "<br/>"),
2514 ),
2515 EricMessageBox.Ok,
2516 )
2517
2249 def __startRefactoringClient(self, interpreter, clientEnv): 2518 def __startRefactoringClient(self, interpreter, clientEnv):
2250 """ 2519 """
2251 Private method to start the refactoring client. 2520 Private method to start the refactoring client.
2252 2521
2253 @param interpreter interpreter to be used for the refactoring client 2522 @param interpreter interpreter to be used for the refactoring client
2254 @type str 2523 @type str
2255 @param clientEnv dictionary with environment variables to run the 2524 @param clientEnv dictionary with environment variables to run the
2256 interpreter with 2525 interpreter with
2257 @type dict 2526 @type dict
2258 @return flag indicating a successful client start 2527 @return flag indicating a successful client start
2259 @rtype bool 2528 @rtype bool
2260 """ 2529 """
2261 if interpreter: 2530 if interpreter:
2262 client = os.path.join(os.path.dirname(__file__), 2531 client = os.path.join(os.path.dirname(__file__), "RefactoringClient.py")
2263 "RefactoringClient.py")
2264 ok, exitCode = self.startClient( 2532 ok, exitCode = self.startClient(
2265 interpreter, client, 2533 interpreter,
2534 client,
2266 [self.__projectpath, Globals.getPythonLibraryDirectory()], 2535 [self.__projectpath, Globals.getPythonLibraryDirectory()],
2267 environment=clientEnv) 2536 environment=clientEnv,
2537 )
2268 if not ok and exitCode == 42: 2538 if not ok and exitCode == 42:
2269 self.__ui.appendToStderr("RefactoringServer: " + self.tr( 2539 self.__ui.appendToStderr(
2270 "The rope refactoring library is not installed.\n" 2540 "RefactoringServer: "
2271 )) 2541 + self.tr("The rope refactoring library is not installed.\n")
2542 )
2272 else: 2543 else:
2273 ok = False 2544 ok = False
2274 return ok 2545 return ok

eric ide

mercurial