1
0
Fork 0
mirror of https://github.com/eclipse-cdt/cdt synced 2025-06-08 10:16:03 +02:00

Terminals: Bug 460064 - The Ctrl+Alt+T shortcut should pick up the

directory of the editor in focus
This commit is contained in:
Uwe Stieber 2015-02-17 16:02:41 +01:00
parent 3c24c4231f
commit cf87ee533b
10 changed files with 82 additions and 9 deletions

View file

@ -3,4 +3,15 @@
<plugin> <plugin>
<extension-point id="contextPropertiesProviders" name="%contextPropertiesProviders" schema="schema/contextPropertiesProviders.exsd"/> <extension-point id="contextPropertiesProviders" name="%contextPropertiesProviders" schema="schema/contextPropertiesProviders.exsd"/>
<!-- Property tester contributions -->
<extension point="org.eclipse.core.expressions.propertyTesters">
<propertyTester
class="org.eclipse.tcf.te.core.terminals.internal.PropertyTester"
id="org.eclipse.tcf.te.core.terminals.PropertyTester"
namespace="org.eclipse.tcf.te.core.terminals"
properties="hasContextPropertiesProvider"
type="java.lang.Object">
</propertyTester>
</extension>
</plugin> </plugin>

View file

@ -0,0 +1,36 @@
/*******************************************************************************
* Copyright (c) 2011, 2014 Wind River Systems, Inc. and others. 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:
* Wind River Systems - initial API and implementation
*******************************************************************************/
package org.eclipse.tcf.te.core.terminals.internal;
import org.eclipse.tcf.te.core.terminals.TerminalContextPropertiesProviderFactory;
/**
* Property tester implementation.
*/
public class PropertyTester extends org.eclipse.core.expressions.PropertyTester {
/* (non-Javadoc)
* @see org.eclipse.core.expressions.IPropertyTester#test(java.lang.Object, java.lang.String, java.lang.Object[], java.lang.Object)
*/
@Override
public boolean test(Object receiver, String property, Object[] args, Object expectedValue) {
// "hasContextPropertiesProvider": Checks if a context properties provider is available for the given receiver.
if ("hasContextPropertiesProvider".equals(property)) { //$NON-NLS-1$
boolean hasProvider = TerminalContextPropertiesProviderFactory.getProvider(receiver) != null;
return expectedValue instanceof Boolean ? ((Boolean)expectedValue).equals(Boolean.valueOf(hasProvider)) : hasProvider;
}
return false;
}
}

View file

@ -173,6 +173,14 @@ public class LocalLauncherDelegate extends AbstractLauncherDelegate {
break; break;
} }
} }
if (element instanceof IPath || element instanceof File) {
File f = element instanceof IPath ? ((IPath)element).toFile() : (File)element;
if (f.isDirectory() && f.canRead()) {
dir = f.getAbsolutePath();
break;
}
}
} }
} }
if (dir != null) { if (dir != null) {

View file

@ -15,10 +15,15 @@ import java.util.Map;
import org.eclipse.core.commands.AbstractHandler; import org.eclipse.core.commands.AbstractHandler;
import org.eclipse.core.commands.ExecutionEvent; import org.eclipse.core.commands.ExecutionEvent;
import org.eclipse.core.commands.ExecutionException; import org.eclipse.core.commands.ExecutionException;
import org.eclipse.core.runtime.IPath;
import org.eclipse.jface.viewers.ISelection; import org.eclipse.jface.viewers.ISelection;
import org.eclipse.jface.viewers.IStructuredSelection;
import org.eclipse.jface.viewers.StructuredSelection;
import org.eclipse.tcf.te.core.terminals.interfaces.constants.ITerminalsConnectorConstants; import org.eclipse.tcf.te.core.terminals.interfaces.constants.ITerminalsConnectorConstants;
import org.eclipse.tcf.te.ui.terminals.interfaces.ILauncherDelegate; import org.eclipse.tcf.te.ui.terminals.interfaces.ILauncherDelegate;
import org.eclipse.tcf.te.ui.terminals.launcher.LauncherDelegateManager; import org.eclipse.tcf.te.ui.terminals.launcher.LauncherDelegateManager;
import org.eclipse.ui.IEditorInput;
import org.eclipse.ui.IPathEditorInput;
import org.eclipse.ui.handlers.HandlerUtil; import org.eclipse.ui.handlers.HandlerUtil;
/** /**
@ -34,6 +39,19 @@ public class LocalLauncherHandler extends AbstractHandler {
// Get the current selection // Get the current selection
ISelection selection = HandlerUtil.getCurrentSelection(event); ISelection selection = HandlerUtil.getCurrentSelection(event);
// If the selection is not a structured selection, check if there is an active
// editor and get the path from the editor input
if (!(selection instanceof IStructuredSelection)) {
IEditorInput input = HandlerUtil.getActiveEditorInput(event);
if (input instanceof IPathEditorInput) {
IPath path = ((IPathEditorInput)input).getPath();
if (path != null) {
if (path.toFile().isFile()) path = path.removeLastSegments(1);
if (path.toFile().isDirectory() && path.toFile().canRead()) selection = new StructuredSelection(path);
}
}
}
// Get all applicable launcher delegates for the current selection // Get all applicable launcher delegates for the current selection
ILauncherDelegate[] delegates = LauncherDelegateManager.getInstance().getApplicableLauncherDelegates(selection); ILauncherDelegate[] delegates = LauncherDelegateManager.getInstance().getApplicableLauncherDelegates(selection);
// Find the local terminal launcher delegate // Find the local terminal launcher delegate

View file

@ -14,8 +14,8 @@
<iterate operator="and" ifEmpty="false"> <iterate operator="and" ifEmpty="false">
<test <test
forcePluginActivation="true" forcePluginActivation="true"
property="org.eclipse.tcf.te.runtime.services.hasService" property="org.eclipse.tcf.te.core.terminals.hasContextPropertiesProvider"
value="org.eclipse.tcf.te.runtime.services.interfaces.IPropertiesAccessService"/> value="true"/>
</iterate> </iterate>
</with> </with>
</enablement> </enablement>

View file

@ -14,8 +14,8 @@
<iterate operator="and" ifEmpty="false"> <iterate operator="and" ifEmpty="false">
<test <test
forcePluginActivation="true" forcePluginActivation="true"
property="org.eclipse.tcf.te.runtime.services.hasService" property="org.eclipse.tcf.te.core.terminals.hasContextPropertiesProvider"
value="org.eclipse.tcf.te.runtime.services.interfaces.IPropertiesAccessService"/> value="true"/>
</iterate> </iterate>
</with> </with>
</enablement> </enablement>

View file

@ -14,8 +14,8 @@
<iterate operator="and" ifEmpty="false"> <iterate operator="and" ifEmpty="false">
<test <test
forcePluginActivation="true" forcePluginActivation="true"
property="org.eclipse.tcf.te.runtime.services.hasService" property="org.eclipse.tcf.te.core.terminals.hasContextPropertiesProvider"
value="org.eclipse.tcf.te.runtime.services.interfaces.IPropertiesAccessService"/> value="true"/>
</iterate> </iterate>
</with> </with>
</enablement> </enablement>

View file

@ -151,7 +151,7 @@ public class InputStreamMonitor extends OutputStream implements IDisposable {
} }
/* (non-Javadoc) /* (non-Javadoc)
* @see org.eclipse.tcf.te.runtime.interfaces.IDisposable#dispose() * @see org.eclipse.ui.services.IDisposable#dispose()
*/ */
@Override @Override
public void dispose() { public void dispose() {

View file

@ -125,7 +125,7 @@ public class OutputStreamMonitor implements IDisposable {
} }
/* (non-Javadoc) /* (non-Javadoc)
* @see org.eclipse.tcf.te.runtime.interfaces.IDisposable#dispose() * @see org.eclipse.ui.services.IDisposable#dispose()
*/ */
@Override @Override
public void dispose() { public void dispose() {

View file

@ -70,7 +70,7 @@ public class StreamsConnector extends AbstractStreamsConnector implements IDispo
} }
/* (non-Javadoc) /* (non-Javadoc)
* @see org.eclipse.tcf.te.runtime.interfaces.IDisposable#dispose() * @see org.eclipse.ui.services.IDisposable#dispose()
*/ */
@Override @Override
public void dispose() { public void dispose() {