diff --git a/plugins/org.eclipse.tm.terminal.control/src/org/eclipse/tm/internal/terminal/control/ITerminalMouseListener.java b/plugins/org.eclipse.tm.terminal.control/src/org/eclipse/tm/internal/terminal/control/ITerminalMouseListener.java
new file mode 100644
index 00000000000..3c2e0af1576
--- /dev/null
+++ b/plugins/org.eclipse.tm.terminal.control/src/org/eclipse/tm/internal/terminal/control/ITerminalMouseListener.java
@@ -0,0 +1,42 @@
+/*******************************************************************************
+ * Copyright (c) 2015 CWI. All rights reserved.
+ * This program and the accompanying materials are made available under the terms
+ * of the Eclipse Public License v1.0 which accompanies this distribution, and is
+ * available at http://www.eclipse.org/legal/epl-v10.html
+ *
+ * Contributors:
+ * Davy Landman (CWI) - [475267][api] Initial definition of interface
+ *******************************************************************************/
+package org.eclipse.tm.internal.terminal.control;
+
+import org.eclipse.tm.terminal.model.ITerminalTextDataReadOnly;
+
+/**
+ * Terminal specific version of {@link org.eclipse.swt.events.MouseListener}
+ */
+public interface ITerminalMouseListener {
+ /**
+ * Invoked when a double-click has happend inside the terminal control.
+ *
+ * Important: the event fires for every click, even outside the text region.
+ * @param terminalText a read-only view of the current terminal text
+ * @param button see {@link org.eclipse.swt.events.MouseEvent#button} for the meaning of the button values
+ */
+ void mouseDoubleClick(ITerminalTextDataReadOnly terminalText, int line, int column, int button);
+ /**
+ * Invoked when a mouse button is pushed down inside the terminal control.
+ *
+ * Important: the event fires for every mouse down, even outside the text region.
+ * @param terminalText a read-only view of the current terminal text
+ * @param button see {@link org.eclipse.swt.events.MouseEvent#button} for the meaning of the button values
+ */
+ void mouseDown(ITerminalTextDataReadOnly terminalText, int line, int column, int button);
+ /**
+ * Invoked when a mouse button is released inside the terminal control.
+ *
+ * Important: the event fires for every mouse up, even outside the text region.
+ * @param terminalText a read-only view of the current terminal text
+ * @param button see {@link org.eclipse.swt.events.MouseEvent#button} for the meaning of the button values
+ */
+ void mouseUp(ITerminalTextDataReadOnly terminalText, int line, int column, int button);
+}
diff --git a/plugins/org.eclipse.tm.terminal.control/src/org/eclipse/tm/internal/terminal/control/ITerminalViewControl.java b/plugins/org.eclipse.tm.terminal.control/src/org/eclipse/tm/internal/terminal/control/ITerminalViewControl.java
index 3a293cc4df2..d56dc35cf5f 100644
--- a/plugins/org.eclipse.tm.terminal.control/src/org/eclipse/tm/internal/terminal/control/ITerminalViewControl.java
+++ b/plugins/org.eclipse.tm.terminal.control/src/org/eclipse/tm/internal/terminal/control/ITerminalViewControl.java
@@ -10,6 +10,7 @@
* Martin Oberhuber (Wind River) - fixed copyright headers and beautified
* Martin Oberhuber (Wind River) - [204796] Terminal should allow setting the encoding to use
* Martin Oberhuber (Wind River) - [265352][api] Allow setting fonts programmatically
+ * Davy Landman (CWI) - [475267][api] Allow custom mouse listeners
******************************************************************************/
package org.eclipse.tm.internal.terminal.control;
@@ -118,4 +119,7 @@ public interface ITerminalViewControl {
public void setBufferLineLimit(int bufferLineLimit);
boolean isScrollLock();
void setScrollLock(boolean on);
+
+ void addMouseListener(ITerminalMouseListener listener);
+ void removeMouseListener(ITerminalMouseListener listener);
}
diff --git a/plugins/org.eclipse.tm.terminal.control/src/org/eclipse/tm/internal/terminal/emulator/VT100TerminalControl.java b/plugins/org.eclipse.tm.terminal.control/src/org/eclipse/tm/internal/terminal/emulator/VT100TerminalControl.java
index ea75b13e4cf..316aaa1d897 100644
--- a/plugins/org.eclipse.tm.terminal.control/src/org/eclipse/tm/internal/terminal/emulator/VT100TerminalControl.java
+++ b/plugins/org.eclipse.tm.terminal.control/src/org/eclipse/tm/internal/terminal/emulator/VT100TerminalControl.java
@@ -39,6 +39,7 @@
* Martin Oberhuber (Wind River) - [436612] Restore Eclipse 3.4 compatibility by using Reflection
* Anton Leherbauer (Wind River) - [458398] Add support for normal/application cursor keys mode
* Anton Leherbauer (Wind River) - [420928] Terminal widget leaks memory
+ * Davy Landman (CWI) - [475267][api] Allow custom mouse listeners
*******************************************************************************/
package org.eclipse.tm.internal.terminal.emulator;
@@ -90,6 +91,7 @@ import org.eclipse.swt.widgets.Shell;
import org.eclipse.tm.internal.terminal.control.ICommandInputField;
import org.eclipse.tm.internal.terminal.control.ITerminalListener;
import org.eclipse.tm.internal.terminal.control.ITerminalListener2;
+import org.eclipse.tm.internal.terminal.control.ITerminalMouseListener;
import org.eclipse.tm.internal.terminal.control.ITerminalViewControl;
import org.eclipse.tm.internal.terminal.control.impl.ITerminalControlForText;
import org.eclipse.tm.internal.terminal.control.impl.TerminalMessages;
@@ -1407,5 +1409,15 @@ public class VT100TerminalControl implements ITerminalControlForText, ITerminalC
public void enableApplicationCursorKeys(boolean enable) {
fApplicationCursorKeys = enable;
}
+
+ @Override
+ public void addMouseListener(ITerminalMouseListener listener) {
+ getCtlText().addTerminalMouseListener(listener);
+ }
+
+ @Override
+ public void removeMouseListener(ITerminalMouseListener listener) {
+ getCtlText().removeTerminalMouseListener(listener);
+ }
}
diff --git a/plugins/org.eclipse.tm.terminal.control/src/org/eclipse/tm/internal/terminal/textcanvas/TextCanvas.java b/plugins/org.eclipse.tm.terminal.control/src/org/eclipse/tm/internal/terminal/textcanvas/TextCanvas.java
index 9854d88c809..a8b950820c1 100644
--- a/plugins/org.eclipse.tm.terminal.control/src/org/eclipse/tm/internal/terminal/textcanvas/TextCanvas.java
+++ b/plugins/org.eclipse.tm.terminal.control/src/org/eclipse/tm/internal/terminal/textcanvas/TextCanvas.java
@@ -17,10 +17,14 @@
* Anton Leherbauer (Wind River) - [324608] Terminal has strange scrolling behaviour
* Martin Oberhuber (Wind River) - [265352][api] Allow setting fonts programmatically
* Anton Leherbauer (Wind River) - [434749] UnhandledEventLoopException when copying to clipboard while the selection is empty
+ * Davy Landman (CWI) - [475267][api] Allow custom mouse listeners
*******************************************************************************/
package org.eclipse.tm.internal.terminal.textcanvas;
+import java.util.ArrayList;
+import java.util.List;
+
import org.eclipse.swt.SWT;
import org.eclipse.swt.dnd.Clipboard;
import org.eclipse.swt.dnd.TextTransfer;
@@ -35,6 +39,7 @@ import org.eclipse.swt.graphics.GC;
import org.eclipse.swt.graphics.Point;
import org.eclipse.swt.graphics.Rectangle;
import org.eclipse.swt.widgets.Composite;
+import org.eclipse.tm.internal.terminal.control.ITerminalMouseListener;
/**
* A cell oriented Canvas. Maintains a list of "cells".
@@ -50,6 +55,7 @@ public class TextCanvas extends GridCanvas {
private Point fDraggingEnd;
private boolean fHasSelection;
private ResizeListener fResizeListener;
+ private final List fMouseListeners;
// The minSize is meant to determine the minimum size of the backing store
// (grid) into which remote data is rendered. If the viewport is smaller
@@ -116,8 +122,17 @@ public class TextCanvas extends GridCanvas {
public void focusLost(FocusEvent e) {
fCellCanvasModel.setCursorEnabled(false);
}});
+ fMouseListeners = new ArrayList();
addMouseListener(new MouseListener(){
public void mouseDoubleClick(MouseEvent e) {
+ if (fMouseListeners.size() > 0) {
+ Point pt = screenPointToCell(e.x, e.y);
+ if (pt != null) {
+ for (ITerminalMouseListener l : fMouseListeners) {
+ l.mouseDoubleClick(fCellCanvasModel.getTerminalText(), pt.y, pt.x, e.button);
+ }
+ }
+ }
}
public void mouseDown(MouseEvent e) {
if(e.button==1) { // left button
@@ -132,6 +147,14 @@ public class TextCanvas extends GridCanvas {
}
fDraggingEnd=null;
}
+ if (fMouseListeners.size() > 0) {
+ Point pt = screenPointToCell(e.x, e.y);
+ if (pt != null) {
+ for (ITerminalMouseListener l : fMouseListeners) {
+ l.mouseDown(fCellCanvasModel.getTerminalText(), pt.y, pt.x, e.button);
+ }
+ }
+ }
}
public void mouseUp(MouseEvent e) {
if(e.button==1) { // left button
@@ -142,6 +165,14 @@ public class TextCanvas extends GridCanvas {
fCellCanvasModel.setSelection(-1,-1,-1,-1);
fDraggingStart=null;
}
+ if (fMouseListeners.size() > 0) {
+ Point pt = screenPointToCell(e.x, e.y);
+ if (pt != null) {
+ for (ITerminalMouseListener l : fMouseListeners) {
+ l.mouseUp(fCellCanvasModel.getTerminalText(), pt.y, pt.x, e.button);
+ }
+ }
+ }
}
});
addMouseMoveListener(new MouseMoveListener() {
@@ -428,5 +459,12 @@ public class TextCanvas extends GridCanvas {
}
+ public void addTerminalMouseListener(final ITerminalMouseListener listener) {
+ fMouseListeners.add(listener);
+ }
+
+ public void removeTerminalMouseListener(ITerminalMouseListener listener) {
+ fMouseListeners.remove(listener);
+ }
}