From fb389bae6f69c79fa2da9710c94b0fe1508a8b42 Mon Sep 17 00:00:00 2001 From: Doug Schaefer Date: Mon, 27 May 2019 16:28:01 -0400 Subject: [PATCH] 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 --- bundles/org.eclipse.launchbar.core/plugin.xml | 2 +- .../DefaultLaunchDescriptor.java | 12 +-- .../DefaultLaunchDescriptorType.java | 38 +++++--- .../internal/LaunchBarLaunchConfigDialog.java | 90 +++++++++++++++++++ .../ui/internal/LaunchBarUIManager.java | 17 +++- .../launchbar/ui/internal/Messages.java | 16 ++-- .../launchbar/ui/internal/messages.properties | 9 ++ .../core/internal/LaunchBarManager2Test.java | 1 + 8 files changed, 156 insertions(+), 29 deletions(-) rename bundles/org.eclipse.launchbar.core/src/org/eclipse/launchbar/core/{internal => }/DefaultLaunchDescriptor.java (80%) rename bundles/org.eclipse.launchbar.core/src/org/eclipse/launchbar/core/{internal => }/DefaultLaunchDescriptorType.java (71%) diff --git a/bundles/org.eclipse.launchbar.core/plugin.xml b/bundles/org.eclipse.launchbar.core/plugin.xml index 13b7ef1dfd0..207ec12cd0a 100644 --- a/bundles/org.eclipse.launchbar.core/plugin.xml +++ b/bundles/org.eclipse.launchbar.core/plugin.xml @@ -10,7 +10,7 @@ id="org.eclipse.launchbar.core.objectProvider.project"> diff --git a/bundles/org.eclipse.launchbar.core/src/org/eclipse/launchbar/core/internal/DefaultLaunchDescriptor.java b/bundles/org.eclipse.launchbar.core/src/org/eclipse/launchbar/core/DefaultLaunchDescriptor.java similarity index 80% rename from bundles/org.eclipse.launchbar.core/src/org/eclipse/launchbar/core/internal/DefaultLaunchDescriptor.java rename to bundles/org.eclipse.launchbar.core/src/org/eclipse/launchbar/core/DefaultLaunchDescriptor.java index 28af5ce2d2b..fc7156d6df9 100644 --- a/bundles/org.eclipse.launchbar.core/src/org/eclipse/launchbar/core/internal/DefaultLaunchDescriptor.java +++ b/bundles/org.eclipse.launchbar.core/src/org/eclipse/launchbar/core/DefaultLaunchDescriptor.java @@ -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; } diff --git a/bundles/org.eclipse.launchbar.core/src/org/eclipse/launchbar/core/internal/DefaultLaunchDescriptorType.java b/bundles/org.eclipse.launchbar.core/src/org/eclipse/launchbar/core/DefaultLaunchDescriptorType.java similarity index 71% rename from bundles/org.eclipse.launchbar.core/src/org/eclipse/launchbar/core/internal/DefaultLaunchDescriptorType.java rename to bundles/org.eclipse.launchbar.core/src/org/eclipse/launchbar/core/DefaultLaunchDescriptorType.java index d1297d6fdd6..fab847e1fdb 100644 --- a/bundles/org.eclipse.launchbar.core/src/org/eclipse/launchbar/core/internal/DefaultLaunchDescriptorType.java +++ b/bundles/org.eclipse.launchbar.core/src/org/eclipse/launchbar/core/DefaultLaunchDescriptorType.java @@ -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); diff --git a/bundles/org.eclipse.launchbar.ui/src/org/eclipse/launchbar/ui/internal/LaunchBarLaunchConfigDialog.java b/bundles/org.eclipse.launchbar.ui/src/org/eclipse/launchbar/ui/internal/LaunchBarLaunchConfigDialog.java index 9ccb2fb23ae..b0bfcd881f1 100644 --- a/bundles/org.eclipse.launchbar.ui/src/org/eclipse/launchbar/ui/internal/LaunchBarLaunchConfigDialog.java +++ b/bundles/org.eclipse.launchbar.ui/src/org/eclipse/launchbar/ui/internal/LaunchBarLaunchConfigDialog.java @@ -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(); diff --git a/bundles/org.eclipse.launchbar.ui/src/org/eclipse/launchbar/ui/internal/LaunchBarUIManager.java b/bundles/org.eclipse.launchbar.ui/src/org/eclipse/launchbar/ui/internal/LaunchBarUIManager.java index 16e62a40677..1f60b6b8b51 100644 --- a/bundles/org.eclipse.launchbar.ui/src/org/eclipse/launchbar/ui/internal/LaunchBarUIManager.java +++ b/bundles/org.eclipse.launchbar.ui/src/org/eclipse/launchbar/ui/internal/LaunchBarUIManager.java @@ -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(); diff --git a/bundles/org.eclipse.launchbar.ui/src/org/eclipse/launchbar/ui/internal/Messages.java b/bundles/org.eclipse.launchbar.ui/src/org/eclipse/launchbar/ui/internal/Messages.java index 969bd40d01d..01a9b11775d 100644 --- a/bundles/org.eclipse.launchbar.ui/src/org/eclipse/launchbar/ui/internal/Messages.java +++ b/bundles/org.eclipse.launchbar.ui/src/org/eclipse/launchbar/ui/internal/Messages.java @@ -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; diff --git a/bundles/org.eclipse.launchbar.ui/src/org/eclipse/launchbar/ui/internal/messages.properties b/bundles/org.eclipse.launchbar.ui/src/org/eclipse/launchbar/ui/internal/messages.properties index 7d1827330b8..7e52a79713a 100644 --- a/bundles/org.eclipse.launchbar.ui/src/org/eclipse/launchbar/ui/internal/messages.properties +++ b/bundles/org.eclipse.launchbar.ui/src/org/eclipse/launchbar/ui/internal/messages.properties @@ -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 diff --git a/tests/org.eclipse.launchbar.core.tests/src/org/eclipse/launchbar/core/internal/LaunchBarManager2Test.java b/tests/org.eclipse.launchbar.core.tests/src/org/eclipse/launchbar/core/internal/LaunchBarManager2Test.java index f8eca5b4a8a..8b4cffd5a0e 100644 --- a/tests/org.eclipse.launchbar.core.tests/src/org/eclipse/launchbar/core/internal/LaunchBarManager2Test.java +++ b/tests/org.eclipse.launchbar.core.tests/src/org/eclipse/launchbar/core/internal/LaunchBarManager2Test.java @@ -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;