10 from __future__ import unicode_literals |
10 from __future__ import unicode_literals |
11 |
11 |
12 import os |
12 import os |
13 import sys |
13 import sys |
14 |
14 |
15 from PyQt5.QtCore import QObject, QTranslator, QCoreApplication, QTimer |
15 from PyQt5.QtCore import Qt, QObject, QTranslator, QCoreApplication, QTimer |
16 |
16 |
17 from E5Gui.E5Application import e5App |
17 from E5Gui.E5Application import e5App |
18 |
18 |
19 import Preferences |
19 import Preferences |
20 import Utilities |
20 import Utilities |
24 # Start-Of-Header |
24 # Start-Of-Header |
25 name = "Refactoring Rope Plugin" |
25 name = "Refactoring Rope Plugin" |
26 author = "Detlev Offenbach <detlev@die-offenbachs.de>" |
26 author = "Detlev Offenbach <detlev@die-offenbachs.de>" |
27 autoactivate = True |
27 autoactivate = True |
28 deactivateable = True |
28 deactivateable = True |
29 version = "4.1.1" |
29 version = "4.2.0" |
30 className = "RefactoringRopePlugin" |
30 className = "RefactoringRopePlugin" |
31 packageName = "RefactoringRope" |
31 packageName = "RefactoringRope" |
32 internalPackages = "rope" |
32 internalPackages = "rope" |
33 shortDescription = "Refactoring using the Rope library." |
33 shortDescription = "Refactoring using the Rope library." |
34 longDescription = """This plug-in implements refactoring functionality""" \ |
34 longDescription = """This plug-in implements refactoring functionality""" \ |
72 import CallTipsRopePage |
72 import CallTipsRopePage |
73 page = CallTipsRopePage(refactoringRopePluginObject) |
73 page = CallTipsRopePage(refactoringRopePluginObject) |
74 return page |
74 return page |
75 |
75 |
76 |
76 |
|
77 def createMouseClickHandlerPage(configDlg): |
|
78 """ |
|
79 Module function to create the mouse click handler configuration page. |
|
80 |
|
81 @param configDlg reference to the configuration dialog |
|
82 @return reference to the configuration page |
|
83 """ |
|
84 global refactoringRopePluginObject |
|
85 from RefactoringRope.ConfigurationPage.MouseClickHandlerRopePage \ |
|
86 import MouseClickHandlerRopePage |
|
87 page = MouseClickHandlerRopePage(refactoringRopePluginObject) |
|
88 return page |
|
89 |
|
90 |
77 def getConfigData(): |
91 def getConfigData(): |
78 """ |
92 """ |
79 Module function returning data as required by the configuration dialog. |
93 Module function returning data as required by the configuration dialog. |
80 |
94 |
81 @return dictionary containing the relevant data |
95 @return dictionary containing the relevant data |
82 """ |
96 """ |
83 return { |
97 data = { |
84 "ropeAutoCompletionPage": [ |
98 "ropeAutoCompletionPage": [ |
85 QCoreApplication.translate("RefactoringRopePlugin", "Rope"), |
99 QCoreApplication.translate("RefactoringRopePlugin", "Rope"), |
86 os.path.join("RefactoringRope", "ConfigurationPage", |
100 os.path.join("RefactoringRope", "ConfigurationPage", |
87 "preferences-refactoring.png"), |
101 "preferences-refactoring.png"), |
88 createAutoCompletionPage, "editorAutocompletionPage", None], |
102 createAutoCompletionPage, "editorAutocompletionPage", None], |
90 QCoreApplication.translate("RefactoringRopePlugin", "Rope"), |
104 QCoreApplication.translate("RefactoringRopePlugin", "Rope"), |
91 os.path.join("RefactoringRope", "ConfigurationPage", |
105 os.path.join("RefactoringRope", "ConfigurationPage", |
92 "preferences-refactoring.png"), |
106 "preferences-refactoring.png"), |
93 createCallTipsPage, "editorCalltipsPage", None], |
107 createCallTipsPage, "editorCalltipsPage", None], |
94 } |
108 } |
|
109 |
|
110 if e5App().getObject("UserInterface").versionIsNewer("6.0.99", "20150625"): |
|
111 data["ropeMouseClickHandlerPage"] = [ |
|
112 QCoreApplication.translate("RefactoringRopePlugin", "Rope"), |
|
113 os.path.join("RefactoringRope", "ConfigurationPage", |
|
114 "preferences-refactoring.png"), |
|
115 createMouseClickHandlerPage, "1editorMouseClickHandlers", None] |
|
116 |
|
117 return data |
95 |
118 |
96 |
119 |
97 def prepareUninstall(): |
120 def prepareUninstall(): |
98 """ |
121 """ |
99 Module function to prepare for an uninstallation. |
122 Module function to prepare for an uninstallation. |
123 "CodeAssistTimeout": 100, |
146 "CodeAssistTimeout": 100, |
124 "ShowQScintillaCompletions": True, |
147 "ShowQScintillaCompletions": True, |
125 |
148 |
126 "CodeAssistCalltipsEnabled": False, |
149 "CodeAssistCalltipsEnabled": False, |
127 "CalltipsMaxFixes": 10, |
150 "CalltipsMaxFixes": 10, |
|
151 |
|
152 "MouseClickEnabled": True, |
|
153 "MouseClickGotoModifiers": int(Qt.ControlModifier), |
|
154 "MouseClickGotoButton": int(Qt.LeftButton), |
128 } |
155 } |
129 |
156 |
130 self.__translator = None |
157 self.__translator = None |
131 self.__loadTranslator() |
158 self.__loadTranslator() |
132 |
159 |
297 |
324 |
298 @param key the key of the value to get |
325 @param key the key of the value to get |
299 @return the requested refactoring setting |
326 @return the requested refactoring setting |
300 """ |
327 """ |
301 if key in ["CodeAssistEnabled", "CodeAssistCalltipsEnabled", |
328 if key in ["CodeAssistEnabled", "CodeAssistCalltipsEnabled", |
302 "ShowQScintillaCompletions"]: |
329 "ShowQScintillaCompletions", "MouseClickEnabled"]: |
303 return Preferences.toBool(Preferences.Prefs.settings.value( |
330 return Preferences.toBool(Preferences.Prefs.settings.value( |
304 self.PreferencesKey + "/" + key, self.__defaults[key])) |
331 self.PreferencesKey + "/" + key, self.__defaults[key])) |
305 else: |
332 else: |
306 return int(Preferences.Prefs.settings.value( |
333 return int(Preferences.Prefs.settings.value( |
307 self.PreferencesKey + "/" + key, self.__defaults[key])) |
334 self.PreferencesKey + "/" + key, self.__defaults[key])) |
314 @param value the value to be set |
341 @param value the value to be set |
315 """ |
342 """ |
316 Preferences.Prefs.settings.setValue( |
343 Preferences.Prefs.settings.setValue( |
317 self.PreferencesKey + "/" + key, value) |
344 self.PreferencesKey + "/" + key, value) |
318 |
345 |
319 if key in ["CodeAssistEnabled", "CodeAssistCalltipsEnabled"]: |
346 if key in ["CodeAssistEnabled", "CodeAssistCalltipsEnabled", |
|
347 "MouseClickEnabled"]: |
320 if value: |
348 if value: |
321 if e5App().getObject("Project").isOpen(): |
349 if e5App().getObject("Project").isOpen(): |
322 for editor in e5App().getObject("ViewManager")\ |
350 for editor in e5App().getObject("ViewManager")\ |
323 .getOpenEditors(): |
351 .getOpenEditors(): |
324 if editor not in self.__editors: |
352 if editor not in self.__editors: |
325 self.__editorOpened(editor) |
353 self.__editorOpened(editor) |
326 else: |
354 else: |
327 for editor in self.__editors[:]: |
355 for editor in self.__editors[:]: |
328 self.__editorClosed(editor) |
356 self.__editorClosed(editor) |
|
357 elif key in ["MouseClickGotoModifiers", "MouseClickGotoButton"]: |
|
358 for editor in self.__editors: |
|
359 self.__disconnectMouseClickHandler(editor) |
|
360 self.__connectMouseClickHandler(editor) |
329 elif key == "CodeAssistTimeout": |
361 elif key == "CodeAssistTimeout": |
330 self.__acTimer.setInterval(value) |
362 self.__acTimer.setInterval(value) |
331 |
363 |
332 def __determineLanguage(self): |
364 def __determineLanguage(self): |
333 """ |
365 """ |
419 |
451 |
420 if self.getPreferences("CodeAssistEnabled"): |
452 if self.getPreferences("CodeAssistEnabled"): |
421 self.__setAutoCompletionHook(editor) |
453 self.__setAutoCompletionHook(editor) |
422 if self.getPreferences("CodeAssistCalltipsEnabled"): |
454 if self.getPreferences("CodeAssistCalltipsEnabled"): |
423 self.__setCalltipsHook(editor) |
455 self.__setCalltipsHook(editor) |
|
456 |
|
457 if self.getPreferences("MouseClickEnabled"): |
|
458 self.__connectMouseClickHandler(editor) |
|
459 |
|
460 def __connectMouseClickHandler(self, editor): |
|
461 """ |
|
462 Private method to connect the mouse click handler to an editor. |
|
463 |
|
464 @param editor reference to the editor (QScintilla.Editor) |
|
465 """ |
|
466 if self.getPreferences("MouseClickGotoButton"): |
|
467 try: |
|
468 editor.setMouseClickHandler( |
|
469 "rope", |
|
470 self.getPreferences("MouseClickGotoModifiers"), |
|
471 self.getPreferences("MouseClickGotoButton"), |
|
472 self.__object.gotoDefinition |
|
473 ) |
|
474 except AttributeError: |
|
475 # eric versions before 6.1.0 don't support this |
|
476 pass |
424 |
477 |
425 def __disconnectEditor(self, editor): |
478 def __disconnectEditor(self, editor): |
426 """ |
479 """ |
427 Private method to disconnect an editor. |
480 Private method to disconnect an editor. |
428 |
481 |
447 self.__unsetCalltipsHook(editor) |
500 self.__unsetCalltipsHook(editor) |
448 except AttributeError: |
501 except AttributeError: |
449 # old interface (before 6.1.0) |
502 # old interface (before 6.1.0) |
450 if editor.callTipHook() == self.codeAssistCallTip: |
503 if editor.callTipHook() == self.codeAssistCallTip: |
451 self.__unsetCalltipsHook(editor) |
504 self.__unsetCalltipsHook(editor) |
|
505 |
|
506 self.__disconnectMouseClickHandler(editor) |
|
507 |
|
508 def __disconnectMouseClickHandler(self, editor): |
|
509 """ |
|
510 Private method to disconnect the mouse click handler from an editor. |
|
511 |
|
512 @param editor reference to the editor (QScintilla.Editor) |
|
513 """ |
|
514 try: |
|
515 editor.removeMouseClickHandlers("rope") |
|
516 except AttributeError: |
|
517 # eric versions before 6.1.0 don't support this |
|
518 pass |
452 |
519 |
453 def __completionListSelected(self, id, txt): |
520 def __completionListSelected(self, id, txt): |
454 """ |
521 """ |
455 Private slot to handle the selection from the completion list. |
522 Private slot to handle the selection from the completion list. |
456 |
523 |