PluginRefactoringRope.py

changeset 129
23ee57a96ea3
parent 127
9b9bd5b7f100
child 131
01f2fda78d75
diff -r 3911c0966e07 -r 23ee57a96ea3 PluginRefactoringRope.py
--- a/PluginRefactoringRope.py	Sun Jun 14 13:55:57 2015 +0200
+++ b/PluginRefactoringRope.py	Sat Jun 27 11:15:48 2015 +0200
@@ -12,7 +12,7 @@
 import os
 import sys
 
-from PyQt5.QtCore import QObject, QTranslator, QCoreApplication, QTimer
+from PyQt5.QtCore import Qt, QObject, QTranslator, QCoreApplication, QTimer
 
 from E5Gui.E5Application import e5App
 
@@ -26,7 +26,7 @@
 author = "Detlev Offenbach <detlev@die-offenbachs.de>"
 autoactivate = True
 deactivateable = True
-version = "4.1.1"
+version = "4.2.0"
 className = "RefactoringRopePlugin"
 packageName = "RefactoringRope"
 internalPackages = "rope"
@@ -74,13 +74,27 @@
     return page
 
 
+def createMouseClickHandlerPage(configDlg):
+    """
+    Module function to create the mouse click handler configuration page.
+    
+    @param configDlg reference to the configuration dialog
+    @return reference to the configuration page
+    """
+    global refactoringRopePluginObject
+    from RefactoringRope.ConfigurationPage.MouseClickHandlerRopePage \
+        import MouseClickHandlerRopePage
+    page = MouseClickHandlerRopePage(refactoringRopePluginObject)
+    return page
+
+
 def getConfigData():
     """
     Module function returning data as required by the configuration dialog.
     
     @return dictionary containing the relevant data
     """
-    return {
+    data = {
         "ropeAutoCompletionPage": [
             QCoreApplication.translate("RefactoringRopePlugin", "Rope"),
             os.path.join("RefactoringRope", "ConfigurationPage",
@@ -92,6 +106,15 @@
                          "preferences-refactoring.png"),
             createCallTipsPage, "editorCalltipsPage", None],
     }
+    
+    if e5App().getObject("UserInterface").versionIsNewer("6.0.99", "20150625"):
+        data["ropeMouseClickHandlerPage"] = [
+            QCoreApplication.translate("RefactoringRopePlugin", "Rope"),
+            os.path.join("RefactoringRope", "ConfigurationPage",
+                         "preferences-refactoring.png"),
+            createMouseClickHandlerPage, "1editorMouseClickHandlers", None]
+    
+    return data
 
 
 def prepareUninstall():
@@ -125,6 +148,10 @@
             
             "CodeAssistCalltipsEnabled": False,
             "CalltipsMaxFixes": 10,
+            
+            "MouseClickEnabled": True,
+            "MouseClickGotoModifiers": int(Qt.ControlModifier),
+            "MouseClickGotoButton": int(Qt.LeftButton),
         }
         
         self.__translator = None
@@ -299,7 +326,7 @@
         @return the requested refactoring setting
         """
         if key in ["CodeAssistEnabled", "CodeAssistCalltipsEnabled",
-                   "ShowQScintillaCompletions"]:
+                   "ShowQScintillaCompletions", "MouseClickEnabled"]:
             return Preferences.toBool(Preferences.Prefs.settings.value(
                 self.PreferencesKey + "/" + key, self.__defaults[key]))
         else:
@@ -316,7 +343,8 @@
         Preferences.Prefs.settings.setValue(
             self.PreferencesKey + "/" + key, value)
         
-        if key in ["CodeAssistEnabled", "CodeAssistCalltipsEnabled"]:
+        if key in ["CodeAssistEnabled", "CodeAssistCalltipsEnabled",
+                   "MouseClickEnabled"]:
             if value:
                 if e5App().getObject("Project").isOpen():
                     for editor in e5App().getObject("ViewManager")\
@@ -326,6 +354,10 @@
             else:
                 for editor in self.__editors[:]:
                     self.__editorClosed(editor)
+        elif key in ["MouseClickGotoModifiers", "MouseClickGotoButton"]:
+            for editor in self.__editors:
+                self.__disconnectMouseClickHandler(editor)
+                self.__connectMouseClickHandler(editor)
         elif key == "CodeAssistTimeout":
             self.__acTimer.setInterval(value)
     
@@ -421,6 +453,27 @@
             self.__setAutoCompletionHook(editor)
         if self.getPreferences("CodeAssistCalltipsEnabled"):
             self.__setCalltipsHook(editor)
+        
+        if self.getPreferences("MouseClickEnabled"):
+            self.__connectMouseClickHandler(editor)
+    
+    def __connectMouseClickHandler(self, editor):
+        """
+        Private method to connect the mouse click handler to an editor.
+        
+        @param editor reference to the editor (QScintilla.Editor)
+        """
+        if self.getPreferences("MouseClickGotoButton"):
+            try:
+                editor.setMouseClickHandler(
+                    "rope",
+                    self.getPreferences("MouseClickGotoModifiers"),
+                    self.getPreferences("MouseClickGotoButton"),
+                    self.__object.gotoDefinition
+                )
+            except AttributeError:
+                # eric versions before 6.1.0 don't support this
+                pass
     
     def __disconnectEditor(self, editor):
         """
@@ -449,6 +502,20 @@
             # old interface (before 6.1.0)
             if editor.callTipHook() == self.codeAssistCallTip:
                 self.__unsetCalltipsHook(editor)
+        
+        self.__disconnectMouseClickHandler(editor)
+    
+    def __disconnectMouseClickHandler(self, editor):
+        """
+        Private method to disconnect the mouse click handler from an editor.
+        
+        @param editor reference to the editor (QScintilla.Editor)
+        """
+        try:
+            editor.removeMouseClickHandlers("rope")
+        except AttributeError:
+            # eric versions before 6.1.0 don't support this
+            pass
     
     def __completionListSelected(self, id, txt):
         """

eric ide

mercurial