Skip to content

Commit 0c7ffd4

Browse files
fabrizioiannettijonahgraham
authored andcommitted
Bug 563015: terminal: open files/links with ctrl-click
- hover with ctrl+mouse underlines word under cursor - ctrl-click tries to open the word: - if a relative path (not starting with /) a full path is obtained by prepending the shell cwd - if the fullpath maps to a workspace file, it is opened - otherwise open the OpenResource dialog with the word as filter text - if there is line/column information (separated by colons) then the opened editor jumps to that line - http and https words are opened in a browser window Change-Id: I3f46accbf1eac6743d7b0c3b34bf30ac5e7523bb Signed-off-by: Fabrizio Iannetti <[email protected]> Also-by: Jonah Graham <[email protected]> Signed-off-by: Jonah Graham <[email protected]>
1 parent b341beb commit 0c7ffd4

File tree

15 files changed

+419
-6
lines changed

15 files changed

+419
-6
lines changed
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
11
org.eclipse.tm.terminal.control/debug/log = false
22
org.eclipse.tm.terminal.control/debug/log/char = false
33
org.eclipse.tm.terminal.control/debug/log/VT100Backend = false
4+
org.eclipse.tm.terminal.control/debug/log/hover = false

terminal/plugins/org.eclipse.tm.terminal.control/META-INF/MANIFEST.MF

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@ Manifest-Version: 1.0
22
Bundle-ManifestVersion: 2
33
Bundle-Name: %pluginName
44
Bundle-SymbolicName: org.eclipse.tm.terminal.control; singleton:=true
5-
Bundle-Version: 5.1.0.qualifier
5+
Bundle-Version: 5.2.0.qualifier
66
Bundle-Activator: org.eclipse.tm.internal.terminal.control.impl.TerminalPlugin
77
Bundle-Vendor: %providerName
88
Bundle-Localization: plugin

terminal/plugins/org.eclipse.tm.terminal.control/src/org/eclipse/tm/internal/terminal/connector/TerminalConnector.java

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,7 @@
1616
package org.eclipse.tm.internal.terminal.connector;
1717

1818
import java.io.OutputStream;
19+
import java.util.Optional;
1920

2021
import org.eclipse.core.runtime.IAdaptable;
2122
import org.eclipse.core.runtime.Platform;
@@ -260,4 +261,12 @@ public <T> T getAdapter(Class<T> adapter) {
260261
// maybe we have to be adapted....
261262
return Platform.getAdapterManager().getAdapter(this, adapter);
262263
}
264+
265+
@Override
266+
public Optional<String> getWorkingDirectory() {
267+
if (fConnector != null) {
268+
return fConnector.getWorkingDirectory();
269+
}
270+
return Optional.empty();
271+
}
263272
}

terminal/plugins/org.eclipse.tm.terminal.control/src/org/eclipse/tm/internal/terminal/control/ITerminalMouseListener.java

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,7 @@
1616
/**
1717
* Terminal specific version of {@link org.eclipse.swt.events.MouseListener}
1818
* @since 4.1
19+
* @see ITerminalMouseListener2
1920
*/
2021
public interface ITerminalMouseListener {
2122
/**
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,74 @@
1+
/*******************************************************************************
2+
* Copyright (c) 2021 Kichwa Coders Canada Inc. and others.
3+
* This program and the accompanying materials are made available under the terms
4+
* of the Eclipse Public License 2.0 which accompanies this distribution, and is
5+
* available at https://www.eclipse.org/legal/epl-2.0/
6+
*
7+
* SPDX-License-Identifier: EPL-2.0
8+
*******************************************************************************/
9+
package org.eclipse.tm.internal.terminal.control;
10+
11+
import org.eclipse.tm.terminal.model.ITerminalTextDataReadOnly;
12+
13+
/**
14+
* Extension of {@link ITerminalMouseListener} for consumers that need the stateMask for a button mouse action.
15+
*
16+
* If ITerminalMouseListener2 is used, the methods in ITerminalMouseListener will not be called.
17+
*
18+
* @since 5.2
19+
* @see ITerminalMouseListener
20+
*/
21+
public interface ITerminalMouseListener2 extends ITerminalMouseListener {
22+
/**
23+
* Invoked when a double-click has happend inside the terminal control.<br>
24+
* <br>
25+
* <strong>Important:</strong> the event fires for every click, even outside the text region.
26+
* @param terminalText a read-only view of the current terminal text
27+
* @param button see {@link org.eclipse.swt.events.MouseEvent#button} for the meaning of the button values
28+
* @param stateMask see {@link org.eclipse.swt.events.MouseEvent#stateMask} for the meaning of the values
29+
*/
30+
default void mouseDoubleClick(ITerminalTextDataReadOnly terminalText, int line, int column, int button,
31+
int stateMask) {
32+
// do nothing by default so that implementors only need to implement methods they care about
33+
}
34+
35+
@Override
36+
default void mouseDoubleClick(ITerminalTextDataReadOnly terminalText, int line, int column, int button) {
37+
throw new UnsupportedOperationException();
38+
}
39+
40+
/**
41+
* Invoked when a mouse button is pushed down inside the terminal control.<br>
42+
* <br>
43+
* <strong>Important:</strong> the event fires for every mouse down, even outside the text region.
44+
* @param terminalText a read-only view of the current terminal text
45+
* @param button see {@link org.eclipse.swt.events.MouseEvent#button} for the meaning of the button values
46+
* @param stateMask see {@link org.eclipse.swt.events.MouseEvent#stateMask} for the meaning of the values
47+
*/
48+
default void mouseDown(ITerminalTextDataReadOnly terminalText, int line, int column, int button, int stateMask) {
49+
// do nothing by default so that implementors only need to implement methods they care about
50+
}
51+
52+
@Override
53+
default void mouseDown(ITerminalTextDataReadOnly terminalText, int line, int column, int button) {
54+
throw new UnsupportedOperationException();
55+
}
56+
57+
/**
58+
* Invoked when a mouse button is released inside the terminal control.<br>
59+
* <br>
60+
* <strong>Important:</strong> the event fires for every mouse up, even outside the text region.
61+
* @param terminalText a read-only view of the current terminal text
62+
* @param button see {@link org.eclipse.swt.events.MouseEvent#button} for the meaning of the button values
63+
* @param stateMask see {@link org.eclipse.swt.events.MouseEvent#stateMask} for the meaning of the values
64+
*/
65+
default void mouseUp(ITerminalTextDataReadOnly terminalText, int line, int column, int button, int stateMask) {
66+
// do nothing by default so that implementors only need to implement methods they care about
67+
}
68+
69+
@Override
70+
default void mouseUp(ITerminalTextDataReadOnly terminalText, int line, int column, int button) {
71+
throw new UnsupportedOperationException();
72+
}
73+
74+
}

terminal/plugins/org.eclipse.tm.terminal.control/src/org/eclipse/tm/internal/terminal/control/ITerminalViewControl.java

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -159,16 +159,23 @@ public interface ITerminalViewControl {
159159

160160
/**
161161
* @since 4.1
162+
* @param listener may be a {@link ITerminalMouseListener2} for extra callbacks
162163
*/
163164
void addMouseListener(ITerminalMouseListener listener);
164165

165166
/**
166167
* @since 4.1
168+
* @param listener may be a {@link ITerminalMouseListener2} for extra callbacks
167169
*/
168170
void removeMouseListener(ITerminalMouseListener listener);
169171

170172
/**
171173
* @since 5.1
172174
*/
173175
void setTerminalTitle(String newTitle);
176+
177+
/**
178+
* @since 5.2
179+
*/
180+
String getHoverSelection();
174181
}

terminal/plugins/org.eclipse.tm.terminal.control/src/org/eclipse/tm/internal/terminal/emulator/VT100TerminalControl.java

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1405,4 +1405,9 @@ public void removeMouseListener(ITerminalMouseListener listener) {
14051405
getCtlText().removeTerminalMouseListener(listener);
14061406
}
14071407

1408+
@Override
1409+
public String getHoverSelection() {
1410+
return fCtlText.getHoverSelection();
1411+
}
1412+
14081413
}

terminal/plugins/org.eclipse.tm.terminal.control/src/org/eclipse/tm/internal/terminal/provisional/api/ITerminalConnector.java

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,7 @@
1616
package org.eclipse.tm.internal.terminal.provisional.api;
1717

1818
import java.io.OutputStream;
19+
import java.util.Optional;
1920

2021
import org.eclipse.core.runtime.IAdaptable;
2122
import org.eclipse.tm.internal.terminal.control.ITerminalViewControl;
@@ -146,4 +147,12 @@ public interface ITerminalConnector extends IAdaptable {
146147
*/
147148
String getSettingsSummary();
148149

150+
/**
151+
* @return An optional with the absolute path if available of the current working dir, empty otherwise.
152+
* @since 5.2
153+
*/
154+
default Optional<String> getWorkingDirectory() {
155+
return Optional.empty();
156+
}
157+
149158
}

terminal/plugins/org.eclipse.tm.terminal.control/src/org/eclipse/tm/internal/terminal/provisional/api/Logger.java

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -47,14 +47,17 @@ public final class Logger {
4747
public static final String TRACE_DEBUG_LOG = "org.eclipse.tm.terminal.control/debug/log"; //$NON-NLS-1$
4848
public static final String TRACE_DEBUG_LOG_CHAR = "org.eclipse.tm.terminal.control/debug/log/char"; //$NON-NLS-1$
4949
public static final String TRACE_DEBUG_LOG_VT100BACKEND = "org.eclipse.tm.terminal.control/debug/log/VT100Backend"; //$NON-NLS-1$
50+
/** @since 5.2 */
51+
public static final String TRACE_DEBUG_LOG_HOVER = "org.eclipse.tm.terminal.control/debug/log/hover"; //$NON-NLS-1$
5052

5153
private static PrintStream logStream;
5254

5355
static {
54-
// Any of the three known debugging options turns on the creation of the log file
56+
// Any of the known debugging options turns on the creation of the log file
5557
boolean createLogFile = TerminalPlugin.isOptionEnabled(TRACE_DEBUG_LOG)
5658
|| TerminalPlugin.isOptionEnabled(TRACE_DEBUG_LOG_CHAR)
57-
|| TerminalPlugin.isOptionEnabled(TRACE_DEBUG_LOG_VT100BACKEND);
59+
|| TerminalPlugin.isOptionEnabled(TRACE_DEBUG_LOG_VT100BACKEND)
60+
|| TerminalPlugin.isOptionEnabled(TRACE_DEBUG_LOG_HOVER);
5861

5962
// Log only if tracing is enabled
6063
if (createLogFile && TerminalPlugin.getDefault() != null) {

terminal/plugins/org.eclipse.tm.terminal.control/src/org/eclipse/tm/internal/terminal/provisional/api/provider/TerminalConnectorImpl.java

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,7 @@
1414
package org.eclipse.tm.internal.terminal.provisional.api.provider;
1515

1616
import java.io.OutputStream;
17+
import java.util.Optional;
1718

1819
import org.eclipse.tm.internal.terminal.provisional.api.ISettingsStore;
1920
import org.eclipse.tm.internal.terminal.provisional.api.ITerminalControl;
@@ -151,4 +152,12 @@ public void save(ISettingsStore store) {
151152
*/
152153
public void setTerminalSize(int newWidth, int newHeight) {
153154
}
155+
156+
/**
157+
* @since 5.2
158+
*/
159+
public Optional<String> getWorkingDirectory() {
160+
return Optional.empty();
161+
}
162+
154163
}

0 commit comments

Comments
 (0)