mirror of
https://github.com/eclipse-cdt/cdt
synced 2025-07-09 18:15:23 +02:00
Bug 547705 Implement Dup and Del of Configs. Make Default public.
Adds Duplicate and Delete buttons to our config editor. Default descriptors, which map directly to launch configs,\ differently from the others. As a result, we make the Default configs public so others can take advantage of this behavior. Change-Id: Idbe9449556e214001ac0a9e615ce684e5e5579b3
This commit is contained in:
parent
d2c9b975a5
commit
fb389bae6f
8 changed files with 156 additions and 29 deletions
|
@ -10,7 +10,7 @@
|
|||
id="org.eclipse.launchbar.core.objectProvider.project">
|
||||
</objectProvider>
|
||||
<descriptorType
|
||||
class="org.eclipse.launchbar.core.internal.DefaultLaunchDescriptorType"
|
||||
class="org.eclipse.launchbar.core.DefaultLaunchDescriptorType"
|
||||
id="org.eclipse.launchbar.core.descriptorType.default"
|
||||
priority="0">
|
||||
<enablement>
|
||||
|
|
|
@ -8,23 +8,23 @@
|
|||
* Contributors:
|
||||
* Doug Schaefer
|
||||
*******************************************************************************/
|
||||
package org.eclipse.launchbar.core.internal;
|
||||
package org.eclipse.launchbar.core;
|
||||
|
||||
import org.eclipse.core.runtime.PlatformObject;
|
||||
import org.eclipse.debug.core.ILaunchConfiguration;
|
||||
import org.eclipse.launchbar.core.ILaunchDescriptor;
|
||||
import org.eclipse.launchbar.core.ILaunchDescriptorType;
|
||||
|
||||
/**
|
||||
* A special launch descriptor that managed configurations that aren't owned by other
|
||||
* descriptors.
|
||||
* descriptors.
|
||||
*
|
||||
* @since 2.3
|
||||
*/
|
||||
public class DefaultLaunchDescriptor extends PlatformObject implements ILaunchDescriptor {
|
||||
|
||||
private final DefaultLaunchDescriptorType type;
|
||||
private final ILaunchDescriptorType type;
|
||||
private final ILaunchConfiguration configuration;
|
||||
|
||||
public DefaultLaunchDescriptor(DefaultLaunchDescriptorType type, ILaunchConfiguration configuration) {
|
||||
public DefaultLaunchDescriptor(ILaunchDescriptorType type, ILaunchConfiguration configuration) {
|
||||
this.type = type;
|
||||
this.configuration = configuration;
|
||||
}
|
|
@ -8,7 +8,7 @@
|
|||
* Contributors:
|
||||
* Doug Schaefer
|
||||
*******************************************************************************/
|
||||
package org.eclipse.launchbar.core.internal;
|
||||
package org.eclipse.launchbar.core;
|
||||
|
||||
import java.util.HashMap;
|
||||
import java.util.Map;
|
||||
|
@ -17,12 +17,13 @@ import org.eclipse.core.runtime.CoreException;
|
|||
import org.eclipse.debug.core.ILaunchConfiguration;
|
||||
import org.eclipse.debug.core.ILaunchConfigurationType;
|
||||
import org.eclipse.debug.core.ILaunchManager;
|
||||
import org.eclipse.launchbar.core.ILaunchDescriptor;
|
||||
import org.eclipse.launchbar.core.ILaunchDescriptorType;
|
||||
import org.eclipse.launchbar.core.internal.Activator;
|
||||
|
||||
/**
|
||||
* A special descriptor type that managed configurations that aren't owned by
|
||||
* other descriptor types.
|
||||
*
|
||||
* @since 2.3
|
||||
*/
|
||||
public class DefaultLaunchDescriptorType implements ILaunchDescriptorType {
|
||||
|
||||
|
@ -33,24 +34,35 @@ public class DefaultLaunchDescriptorType implements ILaunchDescriptorType {
|
|||
@Override
|
||||
public boolean supportsTargets() throws CoreException {
|
||||
// Old style launch configs do not support targets.
|
||||
// Though if yours does, you can always subclass and override this.
|
||||
return false;
|
||||
}
|
||||
|
||||
/**
|
||||
* Used to filter out private and external tools builders
|
||||
*
|
||||
* @param config
|
||||
* @return
|
||||
* @throws CoreException
|
||||
*/
|
||||
public static boolean isPublic(ILaunchConfiguration config) throws CoreException {
|
||||
ILaunchConfigurationType type = config.getType();
|
||||
if (type == null) {
|
||||
return false;
|
||||
}
|
||||
|
||||
String category = type.getCategory();
|
||||
|
||||
return type.isPublic() && !(config.getAttribute(ILaunchManager.ATTR_PRIVATE, false))
|
||||
&& !("org.eclipse.ui.externaltools.builder".equals(category)); // $NON-NLS-1$
|
||||
}
|
||||
|
||||
@Override
|
||||
public ILaunchDescriptor getDescriptor(Object launchObject) {
|
||||
if (launchObject instanceof ILaunchConfiguration) {
|
||||
ILaunchConfiguration config = (ILaunchConfiguration) launchObject;
|
||||
try {
|
||||
ILaunchConfigurationType type = config.getType();
|
||||
if (type == null) {
|
||||
return null;
|
||||
}
|
||||
|
||||
// Filter out private and external tools builders
|
||||
String category = type.getCategory();
|
||||
if (type.isPublic() && !(config.getAttribute(ILaunchManager.ATTR_PRIVATE, false))
|
||||
&& !("org.eclipse.ui.externaltools.builder".equals(category))) { //$NON-NLS-1$
|
||||
|
||||
if (isPublic(config)) {
|
||||
DefaultLaunchDescriptor descriptor = descriptors.get(config);
|
||||
if (descriptor == null) {
|
||||
descriptor = new DefaultLaunchDescriptor(this, config);
|
|
@ -12,11 +12,14 @@ import org.eclipse.debug.ui.ILaunchConfigurationTab;
|
|||
import org.eclipse.debug.ui.ILaunchConfigurationTabGroup;
|
||||
import org.eclipse.jface.dialogs.IDialogConstants;
|
||||
import org.eclipse.jface.dialogs.IMessageProvider;
|
||||
import org.eclipse.jface.dialogs.MessageDialog;
|
||||
import org.eclipse.jface.dialogs.TitleAreaDialog;
|
||||
import org.eclipse.jface.operation.IRunnableWithProgress;
|
||||
import org.eclipse.jface.operation.ModalContext;
|
||||
import org.eclipse.jface.viewers.ILabelProvider;
|
||||
import org.eclipse.jface.wizard.ProgressMonitorPart;
|
||||
import org.eclipse.launchbar.core.DefaultLaunchDescriptor;
|
||||
import org.eclipse.launchbar.core.DefaultLaunchDescriptorType;
|
||||
import org.eclipse.launchbar.core.ILaunchDescriptor;
|
||||
import org.eclipse.launchbar.core.target.ILaunchTarget;
|
||||
import org.eclipse.launchbar.ui.ILaunchBarLaunchConfigDialog;
|
||||
|
@ -53,6 +56,9 @@ public class LaunchBarLaunchConfigDialog extends TitleAreaDialog implements ILau
|
|||
private ProgressMonitorPart pmPart;
|
||||
private boolean initing;
|
||||
|
||||
public static final int ID_DUPLICATE = IDialogConstants.CLIENT_ID + 1;
|
||||
public static final int ID_DELETE = IDialogConstants.CLIENT_ID + 2;
|
||||
|
||||
public LaunchBarLaunchConfigDialog(Shell shell, ILaunchConfigurationWorkingCopy workingCopy,
|
||||
ILaunchDescriptor descriptor, ILaunchMode mode, ILaunchTarget target,
|
||||
ILaunchConfigurationTabGroup buildTabGroup) {
|
||||
|
@ -201,6 +207,90 @@ public class LaunchBarLaunchConfigDialog extends TitleAreaDialog implements ILau
|
|||
return tabItem;
|
||||
}
|
||||
|
||||
@Override
|
||||
protected Control createButtonBar(Composite parent) {
|
||||
Composite buttonBar = (Composite) super.createButtonBar(parent);
|
||||
Control[] children = buttonBar.getChildren();
|
||||
Control okCancelButtons = children[children.length - 1];
|
||||
Control configButtons = createConfigButtons(buttonBar);
|
||||
|
||||
// insert our buttons ahead of the OK/Cancel buttons
|
||||
configButtons.moveAbove(okCancelButtons);
|
||||
|
||||
return buttonBar;
|
||||
}
|
||||
|
||||
protected Control createConfigButtons(Composite parent) {
|
||||
((GridLayout) parent.getLayout()).numColumns++;
|
||||
Composite composite = new Composite(parent, SWT.NONE);
|
||||
// create a layout with spacing and margins appropriate for the font size.
|
||||
GridLayout layout = new GridLayout();
|
||||
layout.numColumns = 0; // this is incremented by createButton
|
||||
layout.makeColumnsEqualWidth = true;
|
||||
layout.marginWidth = convertHorizontalDLUsToPixels(IDialogConstants.HORIZONTAL_MARGIN);
|
||||
layout.marginHeight = convertVerticalDLUsToPixels(IDialogConstants.VERTICAL_MARGIN);
|
||||
layout.horizontalSpacing = convertHorizontalDLUsToPixels(IDialogConstants.HORIZONTAL_SPACING);
|
||||
layout.verticalSpacing = convertVerticalDLUsToPixels(IDialogConstants.VERTICAL_SPACING);
|
||||
composite.setLayout(layout);
|
||||
GridData data = new GridData(GridData.HORIZONTAL_ALIGN_CENTER
|
||||
| GridData.VERTICAL_ALIGN_CENTER);
|
||||
composite.setLayoutData(data);
|
||||
composite.setFont(parent.getFont());
|
||||
|
||||
// Allow Duplicate only if the resulting configuration is public
|
||||
try {
|
||||
if (DefaultLaunchDescriptorType.isPublic(workingCopy.getOriginal())) {
|
||||
createButton(composite, ID_DUPLICATE, Messages.LaunchBarLaunchConfigDialog_Duplicate, false);
|
||||
}
|
||||
} catch (CoreException e) {
|
||||
Activator.log(e.getStatus());
|
||||
}
|
||||
|
||||
String deleteText;
|
||||
if (descriptor instanceof DefaultLaunchDescriptor) {
|
||||
deleteText = Messages.LaunchBarLaunchConfigDialog_Delete;
|
||||
} else {
|
||||
deleteText = Messages.LaunchBarLaunchConfigDialog_Reset;
|
||||
}
|
||||
|
||||
// TODO if the descriptor is not a launch config, this should really say Reset
|
||||
createButton(composite, ID_DELETE, deleteText, false);
|
||||
|
||||
return composite;
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void buttonPressed(int buttonId) {
|
||||
if (buttonId == ID_DUPLICATE) {
|
||||
duplicatePressed();
|
||||
} else if (buttonId == ID_DELETE) {
|
||||
deletePressed();
|
||||
} else {
|
||||
super.buttonPressed(buttonId);
|
||||
}
|
||||
}
|
||||
|
||||
protected void deletePressed() {
|
||||
String title, message;
|
||||
if (descriptor instanceof DefaultLaunchDescriptor) {
|
||||
title = Messages.LaunchBarLaunchConfigDialog_DeleteTitle;
|
||||
message = Messages.LaunchBarLaunchConfigDialog_DeleteConfirm;
|
||||
} else {
|
||||
title = Messages.LaunchBarLaunchConfigDialog_ResetTitle;
|
||||
message = Messages.LaunchBarLaunchConfigDialog_ResetConfirm;
|
||||
}
|
||||
|
||||
if (MessageDialog.openConfirm(getShell(), title, String.format(message, workingCopy.getName()))) {
|
||||
setReturnCode(ID_DELETE);
|
||||
close();
|
||||
}
|
||||
}
|
||||
|
||||
protected void duplicatePressed() {
|
||||
setReturnCode(ID_DUPLICATE);
|
||||
close();
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void okPressed() {
|
||||
String newName = nameText.getText().trim();
|
||||
|
|
|
@ -20,6 +20,7 @@ import org.eclipse.core.runtime.IExtensionPoint;
|
|||
import org.eclipse.core.runtime.IStatus;
|
||||
import org.eclipse.core.runtime.Platform;
|
||||
import org.eclipse.core.runtime.Status;
|
||||
import org.eclipse.debug.core.DebugPlugin;
|
||||
import org.eclipse.debug.core.ILaunchConfiguration;
|
||||
import org.eclipse.debug.core.ILaunchConfigurationType;
|
||||
import org.eclipse.debug.core.ILaunchConfigurationWorkingCopy;
|
||||
|
@ -126,12 +127,26 @@ public class LaunchBarUIManager implements ILaunchBarUIManager {
|
|||
|
||||
LaunchBarLaunchConfigDialog dialog = new LaunchBarLaunchConfigDialog(shell, workingCopy, descriptor, mode,
|
||||
target, buildTabGroup);
|
||||
if (dialog.open() == Window.OK) {
|
||||
switch (dialog.open()) {
|
||||
case Window.OK:
|
||||
if (!workingCopy.getOriginal().equals(workingCopy)
|
||||
&& (!workingCopy.getOriginal().getAttributes().equals(workingCopy.getAttributes())
|
||||
|| !workingCopy.getOriginal().getName().equals(workingCopy.getName()))) {
|
||||
workingCopy.doSave();
|
||||
}
|
||||
break;
|
||||
case LaunchBarLaunchConfigDialog.ID_DUPLICATE:
|
||||
{
|
||||
String newName = DebugPlugin.getDefault().getLaunchManager().generateLaunchConfigurationName(workingCopy.getName());
|
||||
ILaunchConfigurationWorkingCopy newWorkingCopy = workingCopy.copy(newName);
|
||||
newWorkingCopy.doSave();
|
||||
}
|
||||
break;
|
||||
case LaunchBarLaunchConfigDialog.ID_DELETE:
|
||||
config.delete();
|
||||
break;
|
||||
default:
|
||||
break;
|
||||
}
|
||||
} catch (CoreException e) {
|
||||
return e.getStatus();
|
||||
|
|
|
@ -52,21 +52,21 @@ public class Messages extends NLS {
|
|||
public static String NoLaunchModeSelected;
|
||||
public static String NoLaunchGroupSelected;
|
||||
public static String LaunchBarLaunchConfigDialog_Edit1;
|
||||
|
||||
public static String LaunchBarLaunchConfigDialog_Edit2;
|
||||
|
||||
public static String LaunchBarLaunchConfigDialog_EditConfiguration;
|
||||
|
||||
public static String LaunchBarLaunchConfigDialog_LaunchConfigName;
|
||||
|
||||
public static String LaunchBarLaunchConfigDialog_LCMustHaveName;
|
||||
|
||||
public static String LaunchBarLaunchConfigDialog_LCNameExists;
|
||||
|
||||
public static String LaunchBarLaunchConfigDialog_LCNameNotValid;
|
||||
|
||||
public static String LaunchBarLaunchConfigDialog_SetParameters;
|
||||
|
||||
public static String LaunchBarLaunchConfigDialog_Duplicate;
|
||||
public static String LaunchBarLaunchConfigDialog_Delete;
|
||||
public static String LaunchBarLaunchConfigDialog_Reset;
|
||||
public static String LaunchBarLaunchConfigDialog_DeleteTitle;
|
||||
public static String LaunchBarLaunchConfigDialog_ResetTitle;
|
||||
public static String LaunchBarLaunchConfigDialog_DeleteConfirm;
|
||||
public static String LaunchBarLaunchConfigDialog_ResetConfirm;
|
||||
|
||||
public static String LaunchConfigurationNotFound;
|
||||
public static String LaunchConfigurationNotFoundDesc;
|
||||
|
||||
|
|
|
@ -39,6 +39,7 @@ NoLaunchConfigType=No launch configuration type matches selected launch descript
|
|||
CannotEditLaunchConfiguration=Cannot edit this configuration.
|
||||
NoLaunchModeSelected=No launch mode selected.
|
||||
NoLaunchGroupSelected=No launch group found for the current selection.
|
||||
|
||||
LaunchBarLaunchConfigDialog_Edit1=Edit configuration %s for %s
|
||||
LaunchBarLaunchConfigDialog_Edit2=Edit configuration %s for %s on %s
|
||||
LaunchBarLaunchConfigDialog_EditConfiguration=Edit Configuration
|
||||
|
@ -47,6 +48,14 @@ LaunchBarLaunchConfigDialog_LCMustHaveName=Launch configuration must have a name
|
|||
LaunchBarLaunchConfigDialog_LCNameExists=A launch configuration with that name already exists.
|
||||
LaunchBarLaunchConfigDialog_LCNameNotValid=The launch configuration name is not valid.
|
||||
LaunchBarLaunchConfigDialog_SetParameters=Set parameters for the configuration.
|
||||
LaunchBarLaunchConfigDialog_Duplicate=Duplicate
|
||||
LaunchBarLaunchConfigDialog_Delete=Delete
|
||||
LaunchBarLaunchConfigDialog_Reset=Restore Defaults
|
||||
LaunchBarLaunchConfigDialog_DeleteTitle=Delete Launch Configuration
|
||||
LaunchBarLaunchConfigDialog_ResetTitle=Restore Launch Configuration Defaults
|
||||
LaunchBarLaunchConfigDialog_DeleteConfirm=Are you sure you would like to delete %s
|
||||
LaunchBarLaunchConfigDialog_ResetConfirm=Are you sure you want to restore defaults on %s
|
||||
|
||||
LaunchConfigurationNotFound=Launch Configuration Not Found
|
||||
LaunchConfigurationNotFoundDesc=No launch configuration is found for the given launch descriptor and target.
|
||||
LaunchTargetWizardDialog_Delete=Delete
|
||||
|
|
|
@ -49,6 +49,7 @@ import org.eclipse.debug.core.ILaunchConfigurationType;
|
|||
import org.eclipse.debug.core.ILaunchManager;
|
||||
import org.eclipse.debug.core.ILaunchMode;
|
||||
import org.eclipse.launchbar.core.DefaultLaunchConfigProvider;
|
||||
import org.eclipse.launchbar.core.DefaultLaunchDescriptorType;
|
||||
import org.eclipse.launchbar.core.ILaunchBarListener;
|
||||
import org.eclipse.launchbar.core.ILaunchConfigurationProvider;
|
||||
import org.eclipse.launchbar.core.ILaunchDescriptor;
|
||||
|
|
Loading…
Add table
Reference in a new issue