1
0
Fork 0
mirror of https://github.com/eclipse-cdt/cdt synced 2025-06-08 18:26:01 +02:00

Bug 309899 - New local terminal launch configurations should have reasonable default values

This commit is contained in:
Martin Oberhuber 2010-05-24 07:11:56 +00:00
parent d0e0ec6893
commit c143c839dd
6 changed files with 80 additions and 27 deletions

View file

@ -1,7 +1,7 @@
<?xml version="1.0" encoding="UTF-8"?>
<?eclipse version="3.3"?>
<!--
# Copyright (c) 2008 Mirko Raner and others
# Copyright (c) 2008, 2010 Mirko Raner 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
@ -37,6 +37,7 @@
id="org.eclipse.tm.terminal.local.launch"
delegate="org.eclipse.tm.internal.terminal.local.launch.LocalTerminalLaunchDelegate"
category="org.eclipse.ui.externaltools"
public="false"
modes="run"
/>
</extension>

View file

@ -50,7 +50,7 @@ import org.eclipse.tm.internal.terminal.provisional.api.provider.TerminalConnect
* <code>vi</code> editor).
*
* @author Mirko Raner
* @version $Revision: 1.2 $
* @version $Revision: 1.3 $
*/
public class LocalTerminalConnector extends TerminalConnectorImpl
implements IDebugEventSetListener {
@ -269,6 +269,9 @@ implements IDebugEventSetListener {
}
catch (CoreException exception) {
control.setState(TerminalState.CLOSED);
Shell shell = LocalTerminalSettingsPage.getShell();
ErrorDialog.openError(shell, null, null, exception.getStatus());
Logger.logException(exception);
}
}

View file

@ -18,7 +18,7 @@ import org.eclipse.osgi.util.NLS;
* messages used by the Local Terminal Connector.
*
* @author Mirko Raner
* @version $Revision: 1.2 $
* @version $Revision: 1.3 $
*/
public class LocalTerminalMessages extends NLS {
@ -41,6 +41,9 @@ public class LocalTerminalMessages extends NLS {
/** The label for the "Edit..." button. */
public static String labelEdit;
/** The label for the "Delete" button. */
public static String labelDelete;
/** The label for the "Enable terminal echo" check box. */
public static String enableLocalEcho;
@ -80,6 +83,12 @@ public class LocalTerminalMessages extends NLS {
/** The error message for an invalid working directory location. */
public static String invalidWorkingDirectory;
/** The question message for confirming deletion of a launch configuration. */
public static String questionDeleteLaunchConfiguration;
/** The question title for confirming deletion of a launch configuration. */
public static String questionTitleDeleteLaunchConfiguration;
/** The error message for attempting to directly launch a Terminal launch configuration. */
public static String errorDirectLaunch;

View file

@ -18,6 +18,7 @@ lineSeparatorLF=LF
lineSeparatorCR=CR
labelNew=New...
labelEdit=Edit...
labelDelete=Delete
terminalTabName=Terminal
terminalSettings=Terminal settings\:
newTerminalLaunchName=New Terminal Launch
@ -28,6 +29,8 @@ locationNotSpecified=Executable location was not specified in configuration ''{0
invalidLocation=Executable does not exist for the external tool named ''{0}''
invalidWorkingDirectory=The path {0} is not a directory and cannot be used as working directory \
for ''{1}''
questionDeleteLaunchConfiguration=Do you wish to delete the selected launch configuration?
questionTitleDeleteLaunchConfiguration=Confirm Launch Configuration Deletion
errorDirectLaunch=Terminal launch configurations can only be launched from the Terminal view. \
Please open the Terminal view and click the view's Settings button to select and launch a local \
Terminal.

View file

@ -12,14 +12,13 @@
package org.eclipse.tm.internal.terminal.local;
import org.eclipse.core.runtime.CoreException;
import org.eclipse.debug.core.DebugPlugin;
import org.eclipse.debug.core.ILaunchConfiguration;
import org.eclipse.debug.core.ILaunchConfigurationType;
import org.eclipse.debug.core.ILaunchConfigurationWorkingCopy;
import org.eclipse.debug.core.ILaunchManager;
import org.eclipse.debug.internal.ui.DebugUIPlugin;
import org.eclipse.debug.ui.DebugUITools;
import org.eclipse.debug.ui.ILaunchGroup;
import org.eclipse.jface.dialogs.ErrorDialog;
import org.eclipse.jface.dialogs.MessageDialog;
import org.eclipse.jface.viewers.ISelectionChangedListener;
import org.eclipse.jface.viewers.IStructuredSelection;
import org.eclipse.jface.viewers.SelectionChangedEvent;
@ -41,13 +40,16 @@ import org.eclipse.tm.internal.terminal.local.launch.LocalTerminalLaunchUtilitie
import org.eclipse.tm.internal.terminal.local.ui.DependentHeightComposite;
import org.eclipse.tm.internal.terminal.provisional.api.ISettingsPage;
import org.eclipse.tm.internal.terminal.provisional.api.Logger;
import org.eclipse.ui.IWorkbench;
import org.eclipse.ui.IWorkbenchWindow;
import org.eclipse.ui.PlatformUI;
/**
* The class {@link LocalTerminalSettingsPage} is an implementation {@link ISettingsPage} for
* local program connections.
*
* @author Mirko Raner
* @version $Revision: 1.2 $
* @version $Revision: 1.3 $
*/
public class LocalTerminalSettingsPage
implements ISettingsPage, ISelectionChangedListener, SelectionListener {
@ -56,6 +58,7 @@ implements ISettingsPage, ISelectionChangedListener, SelectionListener {
private TableViewer viewer;
private Button buttonEdit;
private Button buttonNew;
private Button buttonDelete;
/**
* Creates a new {@link LocalTerminalSettingsPage} that reflects the settings of the specified
@ -117,10 +120,12 @@ implements ISettingsPage, ISelectionChangedListener, SelectionListener {
viewer.setContentProvider(new LocalTerminalLaunchListProvider());
viewer.setInput(new Object());
viewer.addSelectionChangedListener(this);
table.setLayoutData(new GridData(GridData.FILL, GridData.FILL, true, true, 0, 2));
table.setLayoutData(new GridData(GridData.FILL, GridData.FILL, true, true, 0, 3));
buttonNew = pushButton(tableAndButtons, LocalTerminalMessages.labelNew, false);
buttonEdit = pushButton(tableAndButtons, LocalTerminalMessages.labelEdit, true);
buttonEdit = pushButton(tableAndButtons, LocalTerminalMessages.labelEdit, false);
buttonEdit.setEnabled(settings.getLaunchConfigurationName() != null);
buttonDelete = pushButton(tableAndButtons, LocalTerminalMessages.labelDelete, true);
buttonDelete.setEnabled(settings.getLaunchConfigurationName() != null);
//
// NOTE: echo and line separator settings were moved to the launch configuration!
@ -196,14 +201,15 @@ implements ISettingsPage, ISelectionChangedListener, SelectionListener {
}
/**
* Enables or disables the Edit... button depending on whether a launch configuration is
* currently selected in the viewer.
* Enables or disables the Edit... and Delete buttons depending on whether a launch
* configuration is currently selected in the viewer.
*
* @see ISelectionChangedListener#selectionChanged(SelectionChangedEvent)
*/
public void selectionChanged(SelectionChangedEvent event) {
buttonEdit.setEnabled(!event.getSelection().isEmpty());
buttonDelete.setEnabled(!event.getSelection().isEmpty());
}
/**
@ -236,15 +242,11 @@ implements ISettingsPage, ISelectionChangedListener, SelectionListener {
}
if (widget.equals(buttonNew)) {
ILaunchConfigurationWorkingCopy newlyCreatedConfiguration;
ILaunchManager launchManager = DebugPlugin.getDefault().getLaunchManager();
String baseName = LocalTerminalMessages.newTerminalLaunchName;
String uniqueName = launchManager.generateLaunchConfigurationName(baseName);
ILaunchConfigurationType type = LocalTerminalUtilities.TERMINAL_LAUNCH_TYPE;
try {
newlyCreatedConfiguration = type.newInstance(null, uniqueName);
configuration = newlyCreatedConfiguration.doSave();
ILaunchConfigurationWorkingCopy newLaunch;
newLaunch = LocalTerminalLaunchUtilities.createNewLaunchConfigurationWorkingCopy();
configuration = newLaunch.doSave();
}
catch (CoreException couldNotCreateNewLaunchConfiguration) {
@ -254,7 +256,6 @@ implements ISettingsPage, ISelectionChangedListener, SelectionListener {
if (widget.equals(buttonEdit) || configuration != null) {
ILaunchGroup group;
Shell shell = DebugUIPlugin.getShell();
IStructuredSelection selection = (IStructuredSelection)viewer.getSelection();
if (configuration == null) {
@ -262,14 +263,11 @@ implements ISettingsPage, ISelectionChangedListener, SelectionListener {
}
group = DebugUITools.getLaunchGroup(configuration, ILaunchManager.RUN_MODE);
String groupID = group.getIdentifier();
DebugUITools.openLaunchConfigurationDialog(shell, configuration, groupID, null);
DebugUITools.openLaunchConfigurationDialog(getShell(), configuration, groupID, null);
//
// TODO: handle return value (maybe start terminal right away if "Run" was selected)
// - a return value of Window.CANCEL indicates that "Close" was selected
// - a return value of Window.OK indicates that "Run" was selected
// TODO: prevent "Run" button from launching in the regular console
// (maybe tweak process factory settings before opening the configuration in the
// dialog?)
viewer.refresh();
viewer.setSelection(new StructuredSelection(configuration), true);
@ -279,6 +277,37 @@ implements ISettingsPage, ISelectionChangedListener, SelectionListener {
// creates a different ILaunchConfiguration object, rather than just renaming the
// existing one)
}
if (widget.equals(buttonDelete)) {
String title = LocalTerminalMessages.questionTitleDeleteLaunchConfiguration;
String question = LocalTerminalMessages.questionDeleteLaunchConfiguration;
if (MessageDialog.openQuestion(getShell(), title, question)) {
IStructuredSelection selection = (IStructuredSelection)viewer.getSelection();
configuration = (ILaunchConfiguration)selection.getFirstElement();
try {
configuration.delete();
}
catch (CoreException exception) {
ErrorDialog.openError(getShell(), null, null, exception.getStatus());
}
viewer.refresh();
}
}
}
static Shell getShell() {
IWorkbench workbench = PlatformUI.getWorkbench();
IWorkbenchWindow activeWindow = workbench.getActiveWorkbenchWindow();
if (activeWindow != null) {
return activeWindow.getShell();
}
IWorkbenchWindow[] allWindows = workbench.getWorkbenchWindows();
return allWindows.length > 0? allWindows[0].getShell():null;
}
//------------------------------------ PRIVATE SECTION ---------------------------------------//

View file

@ -39,7 +39,7 @@ import org.eclipse.tm.internal.terminal.provisional.api.Logger;
* because the original class is not part of the public API of its plug-in.
*
* @author Mirko Raner and others
* @version $Revision: 1.2 $
* @version $Revision: 1.3 $
*/
public class LocalTerminalLaunchUtilities {
@ -226,10 +226,13 @@ public class LocalTerminalLaunchUtilities {
ILaunchConfigurationWorkingCopy workingCopy;
ILaunchManager manager = LocalTerminalUtilities.LAUNCH_MANAGER;
String userHome = System.getProperty("user.home", "/"); //$NON-NLS-1$//$NON-NLS-2$
String name = manager.generateLaunchConfigurationName("Terminal"); //$NON-NLS-1$
String defaultShell = getDefaultShell().getAbsolutePath();
String name = defaultShell.substring(defaultShell.lastIndexOf(File.separator) + 1);
name = manager.generateLaunchConfigurationName("Terminal (" + name + ')'); //$NON-NLS-1$
workingCopy = LocalTerminalUtilities.TERMINAL_LAUNCH_TYPE.newInstance(null, name);
workingCopy.setAttribute(ATTR_LOCATION, getDefaultShell().getAbsolutePath());
workingCopy.setAttribute(ATTR_LOCATION, defaultShell);
workingCopy.setAttribute(ATTR_WORKING_DIRECTORY, userHome);
workingCopy.setAttribute(ATTR_LOCAL_ECHO, runningOnWindows());
return workingCopy;
}
@ -246,7 +249,7 @@ public class LocalTerminalLaunchUtilities {
String shell = System.getenv("SHELL"); //$NON-NLS-1$
if (shell == null) {
if (Platform.OS_WIN32.equals(Platform.getOS())) {
if (runningOnWindows()) {
shell = "C:\\Windows\\System32\\cmd.exe"; //$NON-NLS-1$
}
@ -260,6 +263,11 @@ public class LocalTerminalLaunchUtilities {
//------------------------------------- PRIVATE SECTION --------------------------------------//
private static boolean runningOnWindows() {
return Platform.OS_WIN32.equals(Platform.getOS());
}
private static IStringVariableManager getStringVariableManager() {
return VariablesPlugin.getDefault().getStringVariableManager();