Started implementing support for mouse click handlers into the Editor. This can be used by plug-ins to implement function executed by a mouse click (e.g. goto definition upon Ctrl+Left Button).

Mon, 22 Jun 2015 19:50:05 +0200

author
Detlev Offenbach <detlev@die-offenbachs.de>
date
Mon, 22 Jun 2015 19:50:05 +0200
changeset 4286
255f56eb7f05
parent 4284
d61eba7a3b58
child 4287
12274edd3050

Started implementing support for mouse click handlers into the Editor. This can be used by plug-ins to implement function executed by a mouse click (e.g. goto definition upon Ctrl+Left Button).

Documentation/Help/source.qch file | annotate | diff | comparison | revisions
Documentation/Help/source.qhp file | annotate | diff | comparison | revisions
Documentation/Source/eric6.QScintilla.Editor.html file | annotate | diff | comparison | revisions
QScintilla/Editor.py file | annotate | diff | comparison | revisions
Binary file Documentation/Help/source.qch has changed
--- a/Documentation/Help/source.qhp	Sun Jun 21 21:07:47 2015 +0200
+++ b/Documentation/Help/source.qhp	Mon Jun 22 19:50:05 2015 +0200
@@ -4266,6 +4266,7 @@
       <keyword name="Editor.__modificationChanged" id="Editor.__modificationChanged" ref="eric6.QScintilla.Editor.html#Editor.__modificationChanged" />
       <keyword name="Editor.__modificationReadOnly" id="Editor.__modificationReadOnly" ref="eric6.QScintilla.Editor.html#Editor.__modificationReadOnly" />
       <keyword name="Editor.__modified" id="Editor.__modified" ref="eric6.QScintilla.Editor.html#Editor.__modified" />
+      <keyword name="Editor.__mouseClickToString" id="Editor.__mouseClickToString" ref="eric6.QScintilla.Editor.html#Editor.__mouseClickToString" />
       <keyword name="Editor.__newView" id="Editor.__newView" ref="eric6.QScintilla.Editor.html#Editor.__newView" />
       <keyword name="Editor.__newViewNewSplit" id="Editor.__newViewNewSplit" ref="eric6.QScintilla.Editor.html#Editor.__newViewNewSplit" />
       <keyword name="Editor.__normalizedEncoding" id="Editor.__normalizedEncoding" ref="eric6.QScintilla.Editor.html#Editor.__normalizedEncoding" />
@@ -4403,6 +4404,8 @@
       <keyword name="Editor.getLanguage" id="Editor.getLanguage" ref="eric6.QScintilla.Editor.html#Editor.getLanguage" />
       <keyword name="Editor.getLexer" id="Editor.getLexer" ref="eric6.QScintilla.Editor.html#Editor.getLexer" />
       <keyword name="Editor.getMenu" id="Editor.getMenu" ref="eric6.QScintilla.Editor.html#Editor.getMenu" />
+      <keyword name="Editor.getMouseClickHandler" id="Editor.getMouseClickHandler" ref="eric6.QScintilla.Editor.html#Editor.getMouseClickHandler" />
+      <keyword name="Editor.getMouseClickHandlers" id="Editor.getMouseClickHandlers" ref="eric6.QScintilla.Editor.html#Editor.getMouseClickHandlers" />
       <keyword name="Editor.getNoName" id="Editor.getNoName" ref="eric6.QScintilla.Editor.html#Editor.getNoName" />
       <keyword name="Editor.getSearchText" id="Editor.getSearchText" ref="eric6.QScintilla.Editor.html#Editor.getSearchText" />
       <keyword name="Editor.getSharingStatus" id="Editor.getSharingStatus" ref="eric6.QScintilla.Editor.html#Editor.getSharingStatus" />
@@ -4453,6 +4456,7 @@
       <keyword name="Editor.menuToggleBookmark" id="Editor.menuToggleBookmark" ref="eric6.QScintilla.Editor.html#Editor.menuToggleBookmark" />
       <keyword name="Editor.menuToggleBreakpoint" id="Editor.menuToggleBreakpoint" ref="eric6.QScintilla.Editor.html#Editor.menuToggleBreakpoint" />
       <keyword name="Editor.mousePressEvent" id="Editor.mousePressEvent" ref="eric6.QScintilla.Editor.html#Editor.mousePressEvent" />
+      <keyword name="Editor.mouseReleaseEvent" id="Editor.mouseReleaseEvent" ref="eric6.QScintilla.Editor.html#Editor.mouseReleaseEvent" />
       <keyword name="Editor.newBreakpointWithProperties" id="Editor.newBreakpointWithProperties" ref="eric6.QScintilla.Editor.html#Editor.newBreakpointWithProperties" />
       <keyword name="Editor.nextBookmark" id="Editor.nextBookmark" ref="eric6.QScintilla.Editor.html#Editor.nextBookmark" />
       <keyword name="Editor.nextChange" id="Editor.nextChange" ref="eric6.QScintilla.Editor.html#Editor.nextChange" />
@@ -4478,6 +4482,8 @@
       <keyword name="Editor.removeCallTipHook" id="Editor.removeCallTipHook" ref="eric6.QScintilla.Editor.html#Editor.removeCallTipHook" />
       <keyword name="Editor.removeClone" id="Editor.removeClone" ref="eric6.QScintilla.Editor.html#Editor.removeClone" />
       <keyword name="Editor.removeCompletionListHook" id="Editor.removeCompletionListHook" ref="eric6.QScintilla.Editor.html#Editor.removeCompletionListHook" />
+      <keyword name="Editor.removeMouseClickHandler" id="Editor.removeMouseClickHandler" ref="eric6.QScintilla.Editor.html#Editor.removeMouseClickHandler" />
+      <keyword name="Editor.removeMouseClickHandlers" id="Editor.removeMouseClickHandlers" ref="eric6.QScintilla.Editor.html#Editor.removeMouseClickHandlers" />
       <keyword name="Editor.resizeEvent" id="Editor.resizeEvent" ref="eric6.QScintilla.Editor.html#Editor.resizeEvent" />
       <keyword name="Editor.revertToUnmodified" id="Editor.revertToUnmodified" ref="eric6.QScintilla.Editor.html#Editor.revertToUnmodified" />
       <keyword name="Editor.saveFile" id="Editor.saveFile" ref="eric6.QScintilla.Editor.html#Editor.saveFile" />
@@ -4493,6 +4499,7 @@
       <keyword name="Editor.setCallTipHook" id="Editor.setCallTipHook" ref="eric6.QScintilla.Editor.html#Editor.setCallTipHook" />
       <keyword name="Editor.setLanguage" id="Editor.setLanguage" ref="eric6.QScintilla.Editor.html#Editor.setLanguage" />
       <keyword name="Editor.setMonospaced" id="Editor.setMonospaced" ref="eric6.QScintilla.Editor.html#Editor.setMonospaced" />
+      <keyword name="Editor.setMouseClickHandler" id="Editor.setMouseClickHandler" ref="eric6.QScintilla.Editor.html#Editor.setMouseClickHandler" />
       <keyword name="Editor.setNoName" id="Editor.setNoName" ref="eric6.QScintilla.Editor.html#Editor.setNoName" />
       <keyword name="Editor.setSearchIndicator" id="Editor.setSearchIndicator" ref="eric6.QScintilla.Editor.html#Editor.setSearchIndicator" />
       <keyword name="Editor.setSpellingForProject" id="Editor.setSpellingForProject" ref="eric6.QScintilla.Editor.html#Editor.setSpellingForProject" />
--- a/Documentation/Source/eric6.QScintilla.Editor.html	Sun Jun 21 21:07:47 2015 +0200
+++ b/Documentation/Source/eric6.QScintilla.Editor.html	Mon Jun 22 19:50:05 2015 +0200
@@ -398,6 +398,9 @@
 <td><a href="#Editor.__modified">__modified</a></td>
 <td>Private method to handle changes of the number of lines.</td>
 </tr><tr>
+<td><a href="#Editor.__mouseClickToString">__mouseClickToString</a></td>
+<td>Private method to generate a display string for the given modifiers and button combination.</td>
+</tr><tr>
 <td><a href="#Editor.__newView">__newView</a></td>
 <td>Private slot to create a new view to an open document.</td>
 </tr><tr>
@@ -809,6 +812,12 @@
 <td><a href="#Editor.getMenu">getMenu</a></td>
 <td>Public method to get a reference to the main context menu or a submenu.</td>
 </tr><tr>
+<td><a href="#Editor.getMouseClickHandler">getMouseClickHandler</a></td>
+<td></td>
+</tr><tr>
+<td><a href="#Editor.getMouseClickHandlers">getMouseClickHandlers</a></td>
+<td></td>
+</tr><tr>
 <td><a href="#Editor.getNoName">getNoName</a></td>
 <td>Public method to get the display string for an unnamed editor.</td>
 </tr><tr>
@@ -959,6 +968,9 @@
 <td><a href="#Editor.mousePressEvent">mousePressEvent</a></td>
 <td>Protected method to handle the mouse press event.</td>
 </tr><tr>
+<td><a href="#Editor.mouseReleaseEvent">mouseReleaseEvent</a></td>
+<td>Protected method calling a registered mouse click handler function.</td>
+</tr><tr>
 <td><a href="#Editor.newBreakpointWithProperties">newBreakpointWithProperties</a></td>
 <td>Public method to set a new breakpoint and its properties.</td>
 </tr><tr>
@@ -1034,6 +1046,12 @@
 <td><a href="#Editor.removeCompletionListHook">removeCompletionListHook</a></td>
 <td>Public method to remove a previously registered completion list provider.</td>
 </tr><tr>
+<td><a href="#Editor.removeMouseClickHandler">removeMouseClickHandler</a></td>
+<td></td>
+</tr><tr>
+<td><a href="#Editor.removeMouseClickHandlers">removeMouseClickHandlers</a></td>
+<td></td>
+</tr><tr>
 <td><a href="#Editor.resizeEvent">resizeEvent</a></td>
 <td>Protected method handling resize events.</td>
 </tr><tr>
@@ -1079,6 +1097,9 @@
 <td><a href="#Editor.setMonospaced">setMonospaced</a></td>
 <td>Public method to set/reset a monospaced font.</td>
 </tr><tr>
+<td><a href="#Editor.setMouseClickHandler">setMouseClickHandler</a></td>
+<td>Public method to set a mouse click handler.</td>
+</tr><tr>
 <td><a href="#Editor.setNoName">setNoName</a></td>
 <td>Public method to set the display string for an unnamed editor.</td>
 </tr><tr>
@@ -2020,6 +2041,30 @@
 number of added/deleted annotation lines
             (integer)
 </dd>
+</dl><a NAME="Editor.__mouseClickToString" ID="Editor.__mouseClickToString"></a>
+<h4>Editor.__mouseClickToString</h4>
+<b>__mouseClickToString</b>(<i>modifiers, button</i>)
+<p>
+        Private method to generate a display string for the given modifiers
+        and button combination.
+</p><dl>
+<dt><i>modifiers</i> (Qt.KeyboardModifiers)</dt>
+<dd>
+keyboard modifiers of the handler
+</dd><dt><i>button</i> (Qt.MouseButton)</dt>
+<dd>
+mouse button of the handler
+</dd>
+</dl><dl>
+<dt>Returns:</dt>
+<dd>
+display string
+</dd>
+</dl><dl>
+<dt>Return Type:</dt>
+<dd>
+str
+</dd>
 </dl><a NAME="Editor.__newView" ID="Editor.__newView"></a>
 <h4>Editor.__newView</h4>
 <b>__newView</b>(<i></i>)
@@ -3193,7 +3238,21 @@
 <dd>
 reference to the requested menu (QMenu) or None
 </dd>
-</dl><a NAME="Editor.getNoName" ID="Editor.getNoName"></a>
+</dl><a NAME="Editor.getMouseClickHandler" ID="Editor.getMouseClickHandler"></a>
+<h4>Editor.getMouseClickHandler</h4>
+<b>getMouseClickHandler</b>(<i>modifiers, button</i>)
+<p>
+
+</p><p>
+
+</p><a NAME="Editor.getMouseClickHandlers" ID="Editor.getMouseClickHandlers"></a>
+<h4>Editor.getMouseClickHandlers</h4>
+<b>getMouseClickHandlers</b>(<i>name</i>)
+<p>
+
+</p><p>
+
+</p><a NAME="Editor.getNoName" ID="Editor.getNoName"></a>
 <h4>Editor.getNoName</h4>
 <b>getNoName</b>(<i></i>)
 <p>
@@ -3690,6 +3749,16 @@
 <dd>
 the mouse press event (QMouseEvent)
 </dd>
+</dl><a NAME="Editor.mouseReleaseEvent" ID="Editor.mouseReleaseEvent"></a>
+<h4>Editor.mouseReleaseEvent</h4>
+<b>mouseReleaseEvent</b>(<i>evt</i>)
+<p>
+        Protected method calling a registered mouse click handler function.
+</p><dl>
+<dt><i>evt</i></dt>
+<dd>
+event object (QMouseEvent)
+</dd>
 </dl><a NAME="Editor.newBreakpointWithProperties" ID="Editor.newBreakpointWithProperties"></a>
 <h4>Editor.newBreakpointWithProperties</h4>
 <b>newBreakpointWithProperties</b>(<i>line, properties</i>)
@@ -3858,7 +3927,21 @@
 <dd>
 name of the provider
 </dd>
-</dl><a NAME="Editor.resizeEvent" ID="Editor.resizeEvent"></a>
+</dl><a NAME="Editor.removeMouseClickHandler" ID="Editor.removeMouseClickHandler"></a>
+<h4>Editor.removeMouseClickHandler</h4>
+<b>removeMouseClickHandler</b>(<i>modifiers, button</i>)
+<p>
+
+</p><p>
+
+</p><a NAME="Editor.removeMouseClickHandlers" ID="Editor.removeMouseClickHandlers"></a>
+<h4>Editor.removeMouseClickHandlers</h4>
+<b>removeMouseClickHandlers</b>(<i>name</i>)
+<p>
+
+</p><p>
+
+</p><a NAME="Editor.resizeEvent" ID="Editor.resizeEvent"></a>
 <h4>Editor.resizeEvent</h4>
 <b>resizeEvent</b>(<i>evt</i>)
 <p>
@@ -4018,6 +4101,35 @@
 <dd>
 flag to indicate usage of a monospace font (boolean)
 </dd>
+</dl><a NAME="Editor.setMouseClickHandler" ID="Editor.setMouseClickHandler"></a>
+<h4>Editor.setMouseClickHandler</h4>
+<b>setMouseClickHandler</b>(<i>name, modifiers, button, function</i>)
+<p>
+        Public method to set a mouse click handler.
+</p><dl>
+<dt><i>name</i> (str)</dt>
+<dd>
+name of the plug-in (or 'internal') setting this handler
+</dd><dt><i>modifiers</i> (Qt.KeyboardModifiers)</dt>
+<dd>
+keyboard modifiers of the handler
+</dd><dt><i>button</i> (Qt.MouseButton)</dt>
+<dd>
+mouse button of the handler
+</dd><dt><i>function</i> (func)</dt>
+<dd>
+handler function
+</dd>
+</dl><dl>
+<dt>Returns:</dt>
+<dd>
+flag indicating success
+</dd>
+</dl><dl>
+<dt>Return Type:</dt>
+<dd>
+bool
+</dd>
 </dl><a NAME="Editor.setNoName" ID="Editor.setNoName"></a>
 <h4>Editor.setNoName</h4>
 <b>setNoName</b>(<i>noName</i>)
--- a/QScintilla/Editor.py	Sun Jun 21 21:07:47 2015 +0200
+++ b/QScintilla/Editor.py	Mon Jun 22 19:50:05 2015 +0200
@@ -375,6 +375,24 @@
         self.__ctHookFunctions = {}
         self.__setCallTips()
         
+        # set the mouse click handlers (fired on mouse release)
+        self.__mouseClickHandlers = {}
+        # dictionary with tuple of keyboard modifier and mouse button as key
+        # and tuple of plug-in name and function as value
+        self.__modifier2String = {
+            Qt.ShiftModifier: self.tr("Shift"),
+            Qt.ControlModifier: self.tr("Ctrl"),
+            Qt.AltModifier: self.tr("Alt"),
+            Qt.MetaModifier: self.tr("Meta"),
+        }
+        self.__button2String = {
+            Qt.LeftButton: self.tr("Left Button"),
+            Qt.RightButton: self.tr("Right Button"),
+            Qt.MidButton: self.tr("Middle Button"),
+            Qt.XButton1: self.tr("X Button 1"),
+            Qt.XButton2: self.tr("X Button 2"),
+        }
+        
         sh = self.sizeHint()
         if sh.height() < 300:
             sh.setHeight(300)
@@ -7564,3 +7582,119 @@
             self.setRectangularSelection(origStartLine, origStartIndex,
                                          origEndLine, origEndIndex)
             self.selectionChanged.emit()
+    
+    #######################################################################
+    ## Mouse click handler related methods
+    #######################################################################
+    
+    def __mouseClickToString(self, modifiers, button):
+        """
+        Private method to generate a display string for the given modifiers
+        and button combination.
+        
+        @param modifiers keyboard modifiers of the handler
+        @type Qt.KeyboardModifiers
+        @param button mouse button of the handler
+        @type Qt.MouseButton
+        @return display string
+        @rtype str
+        """
+        parts = []
+        for mod in sorted(self.__modifier2String.keys()):
+            if modifiers & mod:
+                parts.append(self.__modifier2String[mod])
+        parts.append(self.__button2String[button])
+        return "+".join(parts)
+    
+    def mouseReleaseEvent(self, evt):
+        """
+        Protected method calling a registered mouse click handler function.
+        
+        @param evt event object
+        @type QMouseEvent
+        """
+        modifiers = evt.modifiers()
+        button = evt.button()
+        key = (modifiers, button)
+        
+        if button != Qt.NoButton and key in self.__mouseClickHandlers:
+            self.__mouseClickHandlers[key][1]()
+            evt.accept()
+        else:
+            self.vm.eventFilter(self, evt)
+            super(Editor, self).mouseReleaseEvent(evt)
+    
+    def setMouseClickHandler(self, name, modifiers, button, function):
+        """
+        Public method to set a mouse click handler.
+        
+        @param name name of the plug-in (or 'internal') setting this handler
+        @type str
+        @param modifiers keyboard modifiers of the handler
+        @type Qt.KeyboardModifiers
+        @param button mouse button of the handler
+        @type Qt.MouseButton
+        @param function handler function
+        @type func
+        @return flag indicating success
+        @rtype bool
+        """
+        key = (modifiers, button)
+        if key in self.__mouseClickHandlers:
+            E5MessageBox.warning(
+                self,
+                self.tr("Register Mouse Click Handler"),
+                self.tr("""A mouse click handler for "{0}" was already"""
+                        """ registered by {1}". Aborting request by"""
+                        """ "{2}"...""").format(
+                    self.__mouseClickToString(modifiers, button),
+                    self.__mouseClickHandlers[key][0],
+                    name))
+            return False
+        
+        self.__mouseClickHandlers[key] = (name, function)
+        return True
+    
+    def getMouseClickHandler(self, modifiers, button):
+        """
+        Public method to get a registered mouse click handler.
+        
+        @param modifiers keyboard modifiers of the handler
+        @type Qt.KeyboardModifiers
+        @param button mouse button of the handler
+        @type Qt.MouseButton
+        @return plug-in name and registered function
+        @rtype tuple of str and func
+        """
+        key = (modifiers, button)
+        if key in self.__mouseClickHandlers:
+            return self.__mouseClickHandlers[key]
+        else:
+            return ("", None)
+    
+    def getMouseClickHandlers(self, name):
+        """
+        Public method to get all registered mouse click handlers of
+        a plug-in.
+        
+        @param name name of the plug-in
+        @type str
+        @return registered mouse click handlers as list of modifiers,
+            mouse button and function
+        @rtype list of tuple of (Qt.KeyboardModifiers, Qt.MouseButton,func)
+        """
+        lst = []
+        for key, value in self.__mouseClickHandlers.items():
+            if value[0] == name:
+                lst.append((key[0], key[1], value[1]))
+        return lst
+    
+    def removeMouseClickHandler(self, modifiers, button):
+        """
+        
+        """
+    
+    def removeMouseClickHandlers(self, name):
+        """
+        
+        """

eric ide

mercurial