1
0
Fork 0
mirror of https://github.com/eclipse-cdt/cdt synced 2025-07-02 22:55:26 +02:00

Changes to make the config dialog more specific to launch bar.

It no longer brings up the traditional launch configuration dialog.
Instead it has a new one that uses the tabs but without the other
stuff.

Change-Id: I89e2ac4e6a7575e0151c24632f26b5ee565a5449
This commit is contained in:
Doug Schaefer 2016-10-10 00:12:25 -04:00
parent 54b3fd4a5b
commit d16fcb8d49
10 changed files with 367 additions and 44 deletions

View file

@ -2,7 +2,7 @@ Manifest-Version: 1.0
Bundle-ManifestVersion: 2
Bundle-Name: LaunchBar Core
Bundle-SymbolicName: org.eclipse.launchbar.core;singleton:=true
Bundle-Version: 2.0.1.qualifier
Bundle-Version: 2.1.0.qualifier
Bundle-Activator: org.eclipse.launchbar.core.internal.Activator
Bundle-Vendor: Eclipse CDT
Require-Bundle: org.eclipse.core.runtime,

View file

@ -12,7 +12,7 @@
</parent>
<artifactId>org.eclipse.launchbar.core</artifactId>
<version>2.0.1-SNAPSHOT</version>
<version>2.1.0-SNAPSHOT</version>
<packaging>eclipse-plugin</packaging>
</project>

View file

@ -33,4 +33,15 @@ public interface ILaunchDescriptorType {
*/
ILaunchDescriptor getDescriptor(Object launchObject) throws CoreException;
/**
* Does this descriptor type support launching on targets other than Local?
*
* @return supports targets
* @throws CoreException
* @since 2.1
*/
default boolean supportsTargets() throws CoreException {
return true;
}
}

View file

@ -30,6 +30,12 @@ public class DefaultLaunchDescriptorType implements ILaunchDescriptorType {
private Map<ILaunchConfiguration, DefaultLaunchDescriptor> descriptors = new HashMap<>();
@Override
public boolean supportsTargets() throws CoreException {
// Old style launch configs do not support targets.
return false;
}
@Override
public ILaunchDescriptor getDescriptor(Object launchObject) {
if (launchObject instanceof ILaunchConfiguration) {

View file

@ -50,8 +50,10 @@ public class LaunchBarControl implements ILaunchBarListener {
private ILaunchBarManager manager = Activator.getService(ILaunchBarManager.class);
private Composite container;
private ConfigSelector configSelector;
private ModeSelector modeSelector;
private Label onLabel;
private TargetSelector targetSelector;
private static final int SELECTION_DELAY = 200;
@ -60,7 +62,7 @@ public class LaunchBarControl implements ILaunchBarListener {
public void createControl(Composite parent) {
manager.addListener(this);
Composite container = new Composite(parent, SWT.NONE);
container = new Composite(parent, SWT.NONE);
container.setLayoutData(new GridData(SWT.LEFT, SWT.CENTER, false, false));
GridLayout layout = new GridLayout(5, false);
layout.marginHeight = 2;
@ -94,20 +96,34 @@ public class LaunchBarControl implements ILaunchBarListener {
configSelector.setLayoutData(new GridData(SWT.LEFT, SWT.CENTER, false, false));
configSelector.setInput(manager);
// TODO remove
boolean enabled = store.getBoolean(Activator.PREF_ENABLE_TARGETSELECTOR);
if (enabled) {
Label label = new Label(container, SWT.NONE);
label.setLayoutData(new GridData(SWT.LEFT, SWT.CENTER, false, false));
label.setText(Messages.LaunchBarControl_0 + ":"); //$NON-NLS-1$
targetSelector = new TargetSelector(container, SWT.NONE);
targetSelector.setLayoutData(new GridData(SWT.LEFT, SWT.CENTER, false, false));
targetSelector.setInput(manager);
boolean supportsTargets = true;
try {
ILaunchDescriptor desc = manager.getActiveLaunchDescriptor();
supportsTargets = desc.getType().supportsTargets();
} catch (CoreException e) {
Activator.log(e);
}
if (supportsTargets) {
createTargetSelector();
}
syncSelectors();
}
private void createTargetSelector() {
onLabel = new Label(container, SWT.NONE);
onLabel.setLayoutData(new GridData(SWT.LEFT, SWT.CENTER, false, false));
onLabel.setText(Messages.LaunchBarControl_0 + ":"); //$NON-NLS-1$
targetSelector = new TargetSelector(container, SWT.NONE);
targetSelector.setLayoutData(new GridData(SWT.LEFT, SWT.CENTER, false, false));
targetSelector.setInput(manager);
}
protected void syncSelectors() {
try {
if (configSelector != null)
@ -145,13 +161,13 @@ public class LaunchBarControl implements ILaunchBarListener {
final Event trigger = new Event();
final IHandlerService handlerService = PlatformUI.getWorkbench().getService(IHandlerService.class);
ExecutionEvent executionEvent = handlerService.createExecutionEvent(command, trigger);
try {
command.executeWithChecks(executionEvent);
} catch (OperationCanceledException ex) {
// abort
} catch (Exception ex) {
Activator.log(ex);
}
try {
command.executeWithChecks(executionEvent);
} catch (OperationCanceledException ex) {
// abort
} catch (Exception ex) {
Activator.log(ex);
}
};
});
button.addDisposeListener(new DisposeListener() {
@ -165,9 +181,32 @@ public class LaunchBarControl implements ILaunchBarListener {
@Override
public void activeLaunchDescriptorChanged(ILaunchDescriptor descriptor) {
if (configSelector != null) {
configSelector.setDelayedSelection(descriptor, SELECTION_DELAY);
}
container.getDisplay().syncExec(() -> {
if (configSelector != null) {
configSelector.setDelayedSelection(descriptor, SELECTION_DELAY);
}
boolean supportsTargets = true;
try {
supportsTargets = descriptor.getType().supportsTargets();
} catch (CoreException e) {
Activator.log(e);
}
if (supportsTargets) {
if (targetSelector == null || targetSelector.isDisposed()) {
createTargetSelector();
syncSelectors();
container.getParent().layout(true);
}
} else {
if (targetSelector != null && !targetSelector.isDisposed()) {
onLabel.dispose();
targetSelector.dispose();
container.getParent().layout(true);
}
}
});
}
@Override
@ -194,5 +233,5 @@ public class LaunchBarControl implements ILaunchBarListener {
public ConfigSelector getConfigSelector() {
return configSelector;
}
}

View file

@ -2,7 +2,7 @@ Manifest-Version: 1.0
Bundle-ManifestVersion: 2
Bundle-Name: LaunchBar UI
Bundle-SymbolicName: org.eclipse.launchbar.ui;singleton:=true
Bundle-Version: 2.0.1.qualifier
Bundle-Version: 2.1.0.qualifier
Bundle-Activator: org.eclipse.launchbar.ui.internal.Activator
Bundle-Vendor: Eclipse CDT
Require-Bundle: org.eclipse.core.runtime,

View file

@ -12,7 +12,7 @@
</parent>
<artifactId>org.eclipse.launchbar.ui</artifactId>
<version>2.0.1-SNAPSHOT</version>
<version>2.1.0-SNAPSHOT</version>
<packaging>eclipse-plugin</packaging>
</project>

View file

@ -0,0 +1,29 @@
/*******************************************************************************
* Copyright (c) 2016 QNX Software Systems 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
*******************************************************************************/
package org.eclipse.launchbar.ui;
import org.eclipse.debug.ui.ILaunchConfigurationDialog;
import org.eclipse.launchbar.core.target.ILaunchTarget;
/**
* The edit dialog for launch configurations created by the launch bar. Allows tabs to get the
* target associated with the edit session.
*
* @since 2.1
*/
public interface ILaunchBarLaunchConfigDialog extends ILaunchConfigurationDialog {
/**
* The target associated with the edit session, usually the active target when the session was
* started.
*
* @return launch target
*/
ILaunchTarget getLaunchTarget();
}

View file

@ -0,0 +1,213 @@
package org.eclipse.launchbar.ui.internal;
import java.lang.reflect.InvocationTargetException;
import org.eclipse.core.runtime.CoreException;
import org.eclipse.debug.core.ILaunchConfigurationWorkingCopy;
import org.eclipse.debug.core.ILaunchMode;
import org.eclipse.debug.internal.ui.launchConfigurations.LaunchConfigurationPresentationManager;
import org.eclipse.debug.ui.ILaunchConfigurationTab;
import org.eclipse.debug.ui.ILaunchConfigurationTabGroup;
import org.eclipse.jface.dialogs.TitleAreaDialog;
import org.eclipse.jface.operation.IRunnableWithProgress;
import org.eclipse.launchbar.core.ILaunchDescriptor;
import org.eclipse.launchbar.core.target.ILaunchTarget;
import org.eclipse.launchbar.ui.ILaunchBarLaunchConfigDialog;
import org.eclipse.swt.SWT;
import org.eclipse.swt.custom.CTabFolder;
import org.eclipse.swt.custom.CTabItem;
import org.eclipse.swt.events.FocusAdapter;
import org.eclipse.swt.events.FocusEvent;
import org.eclipse.swt.events.SelectionAdapter;
import org.eclipse.swt.events.SelectionEvent;
import org.eclipse.swt.layout.GridData;
import org.eclipse.swt.layout.GridLayout;
import org.eclipse.swt.widgets.Composite;
import org.eclipse.swt.widgets.Control;
import org.eclipse.swt.widgets.Shell;
public class LaunchBarLaunchConfigDialog extends TitleAreaDialog implements ILaunchBarLaunchConfigDialog {
private final ILaunchConfigurationWorkingCopy workingCopy;
private final ILaunchDescriptor descriptor;
private final ILaunchMode mode;
private final ILaunchTarget target;
private ILaunchConfigurationTabGroup group;
private CTabFolder tabFolder;
private CTabItem lastSelection;
public LaunchBarLaunchConfigDialog(Shell shell, ILaunchConfigurationWorkingCopy workingCopy,
ILaunchDescriptor descriptor, ILaunchMode mode, ILaunchTarget target) {
super(shell);
this.workingCopy = workingCopy;
this.descriptor = descriptor;
this.mode = mode;
this.target = target;
setShellStyle(getShellStyle() | SWT.RESIZE);
}
@Override
protected int getDialogBoundsStrategy() {
// Don't persist the size since it'll be different for every config
return DIALOG_PERSISTLOCATION;
}
@Override
protected Control createDialogArea(Composite parent) {
// create the top level composite for the dialog area
Composite composite = new Composite(parent, SWT.NONE);
GridLayout layout = new GridLayout();
layout.verticalSpacing = 0;
composite.setLayout(layout);
composite.setLayoutData(new GridData(GridData.FILL_BOTH));
composite.setFont(parent.getFont());
getShell().setText("Edit Configuration");
boolean supportsTargets = true;
try {
supportsTargets = descriptor.getType().supportsTargets();
} catch (CoreException e) {
Activator.log(e);
}
if (supportsTargets) {
setTitle(String.format("Edit %s for %s on %s", descriptor.getName(), mode.getLabel(), target.getId()));
} else {
setTitle(String.format("Edit %s for %s", descriptor.getName(), mode.getLabel()));
}
setMessage("Set parameters for the configuration.");
tabFolder = new CTabFolder(composite, SWT.NONE);
tabFolder.setLayoutData(new GridData(SWT.FILL, SWT.FILL, true, true));
tabFolder.addFocusListener(new FocusAdapter() {
@Override
public void focusGained(FocusEvent e) {
CTabItem selItem = tabFolder.getSelection();
if (selItem != null) {
selItem.getControl().setFocus();
}
}
});
tabFolder.addSelectionListener(new SelectionAdapter() {
@Override
public void widgetSelected(SelectionEvent e) {
ILaunchConfigurationTab oldTab = (ILaunchConfigurationTab) lastSelection.getData();
oldTab.deactivated(workingCopy);
CTabItem selItem = tabFolder.getSelection();
ILaunchConfigurationTab newTab = (ILaunchConfigurationTab) selItem.getData();
newTab.activated(workingCopy);
selItem.getControl().setFocus();
}
});
try {
group = LaunchConfigurationPresentationManager.getDefault().getTabGroup(workingCopy, mode.getIdentifier());
group.createTabs(this, mode.getIdentifier());
for (ILaunchConfigurationTab configTab : group.getTabs()) {
configTab.setLaunchConfigurationDialog(this);
CTabItem tabItem = new CTabItem(tabFolder, SWT.NONE);
tabItem.setData(configTab);
tabItem.setText(configTab.getName());
Composite tabComp = new Composite(tabFolder, SWT.NONE);
tabComp.setLayout(new GridLayout());
tabItem.setControl(tabComp);
configTab.createControl(tabComp);
Control configControl = configTab.getControl();
configControl.setLayoutData(new GridData(SWT.FILL, SWT.FILL, true, true));
if (lastSelection == null) {
// Assuming the first one ends up selected
lastSelection = tabItem;
}
}
group.initializeFrom(workingCopy);
} catch (CoreException e) {
Activator.log(e.getStatus());
}
return composite;
}
@Override
protected void okPressed() {
group.performApply(workingCopy);
super.okPressed();
}
@Override
public void run(boolean fork, boolean cancelable, IRunnableWithProgress runnable)
throws InvocationTargetException, InterruptedException {
// TODO Auto-generated method stub
}
@Override
public void updateButtons() {
// TODO
}
@Override
public void updateMessage() {
// TODO Auto-generated method stub
}
@Override
public void setName(String name) {
// Names aren't setable from this dialog
}
@Override
public String generateName(String name) {
// Names aren't setable from this dialog
return null;
}
@Override
public ILaunchConfigurationTab[] getTabs() {
return group.getTabs();
}
@Override
public ILaunchConfigurationTab getActiveTab() {
CTabItem selItem = tabFolder.getSelection();
if (selItem != null) {
return (ILaunchConfigurationTab) selItem.getData();
} else {
return null;
}
}
@Override
public String getMode() {
return mode.getIdentifier();
}
@Override
public ILaunchTarget getLaunchTarget() {
return target;
}
@Override
public void setActiveTab(ILaunchConfigurationTab tab) {
for (CTabItem item : tabFolder.getItems()) {
if (tab.equals(item.getData())) {
tabFolder.setSelection(item);
return;
}
}
}
@Override
public void setActiveTab(int index) {
tabFolder.setSelection(index);
}
}

View file

@ -32,6 +32,7 @@ import org.eclipse.debug.ui.ILaunchGroup;
import org.eclipse.jface.dialogs.MessageDialog;
import org.eclipse.jface.viewers.ILabelProvider;
import org.eclipse.jface.viewers.StructuredSelection;
import org.eclipse.jface.window.Window;
import org.eclipse.launchbar.core.ILaunchBarManager;
import org.eclipse.launchbar.core.ILaunchDescriptor;
import org.eclipse.launchbar.core.internal.ExecutableExtension;
@ -48,14 +49,16 @@ public class LaunchBarUIManager implements ILaunchBarUIManager {
private void init() {
if (descriptorLabelProviders == null) {
descriptorLabelProviders = new HashMap<>();
IExtensionPoint point = Platform.getExtensionRegistry().getExtensionPoint(Activator.PLUGIN_ID, "launchBarUIContributions"); //$NON-NLS-1$
IExtensionPoint point = Platform.getExtensionRegistry().getExtensionPoint(Activator.PLUGIN_ID,
"launchBarUIContributions"); //$NON-NLS-1$
IExtension[] extensions = point.getExtensions();
for (IExtension extension : extensions) {
for (IConfigurationElement element : extension.getConfigurationElements()) {
String elementName = element.getName();
if (elementName.equals("descriptorUI")) { //$NON-NLS-1$
String descriptorTypeId = element.getAttribute("descriptorTypeId"); //$NON-NLS-1$
ExecutableExtension<ILabelProvider> labelProvider = new ExecutableExtension<>(element, "labelProvider"); //$NON-NLS-1$
ExecutableExtension<ILabelProvider> labelProvider = new ExecutableExtension<>(element,
"labelProvider"); //$NON-NLS-1$
descriptorLabelProviders.put(descriptorTypeId, labelProvider);
}
}
@ -66,7 +69,8 @@ public class LaunchBarUIManager implements ILaunchBarUIManager {
@Override
public ILabelProvider getLabelProvider(ILaunchDescriptor descriptor) throws CoreException {
init();
ExecutableExtension<ILabelProvider> provider = descriptorLabelProviders.get(manager.getDescriptorTypeId(descriptor.getType()));
ExecutableExtension<ILabelProvider> provider = descriptorLabelProviders
.get(manager.getDescriptorTypeId(descriptor.getType()));
return provider != null ? provider.get() : null;
}
@ -84,26 +88,47 @@ public class LaunchBarUIManager implements ILaunchBarUIManager {
return s;
}
// At this point, no error handling should be needed.
try {
ILaunchBarManager manager = Activator.getService(ILaunchBarManager.class);
ILaunchMode mode = manager.getActiveLaunchMode();
ILaunchTarget target = manager.getActiveLaunchTarget();
ILaunchConfigurationType configType = manager.getLaunchConfigurationType(descriptor, target);
ILaunchGroup group = DebugUIPlugin.getDefault().getLaunchConfigurationManager().getLaunchGroup(configType,
mode.getIdentifier());
ILaunchConfiguration config = manager.getLaunchConfiguration(descriptor, target);
if (config instanceof ILaunchConfigurationWorkingCopy
&& ((ILaunchConfigurationWorkingCopy) config).isDirty()) {
config = ((ILaunchConfigurationWorkingCopy) config).doSave();
if (true) {
try {
ILaunchMode mode = manager.getActiveLaunchMode();
ILaunchTarget target = manager.getActiveLaunchTarget();
ILaunchConfiguration config = manager.getLaunchConfiguration(descriptor, target);
ILaunchConfigurationWorkingCopy workingCopy = config.getWorkingCopy();
LaunchBarLaunchConfigDialog dialog = new LaunchBarLaunchConfigDialog(shell, workingCopy, descriptor,
mode, target);
if (dialog.open() == Window.OK) {
if (!workingCopy.getOriginal().equals(workingCopy)
&& !workingCopy.getOriginal().getAttributes().equals(workingCopy.getAttributes())) {
workingCopy.doSave();
}
}
} catch (CoreException e) {
return e.getStatus();
}
} else {
// At this point, no error handling should be needed.
try {
ILaunchBarManager manager = Activator.getService(ILaunchBarManager.class);
ILaunchMode mode = manager.getActiveLaunchMode();
ILaunchTarget target = manager.getActiveLaunchTarget();
ILaunchConfigurationType configType = manager.getLaunchConfigurationType(descriptor, target);
ILaunchGroup group = DebugUIPlugin.getDefault().getLaunchConfigurationManager().getLaunchGroup(
configType,
mode.getIdentifier());
ILaunchConfiguration config = manager.getLaunchConfiguration(descriptor, target);
if (config instanceof ILaunchConfigurationWorkingCopy
&& ((ILaunchConfigurationWorkingCopy) config).isDirty()) {
config = ((ILaunchConfigurationWorkingCopy) config).doSave();
}
// open real eclipse launch configurations dialog
DebugUIPlugin.openLaunchConfigurationsDialog(shell, new StructuredSelection(config),
group.getIdentifier(), false);
} catch (CoreException e2) {
return e2.getStatus();
}
// open real eclipse launch configurations dialog
DebugUIPlugin.openLaunchConfigurationsDialog(shell, new StructuredSelection(config),
group.getIdentifier(), false);
return Status.OK_STATUS;
} catch (CoreException e2) {
return e2.getStatus();
}
return Status.OK_STATUS;
}
private IStatus canOpenConfigurationEditor(ILaunchDescriptor desc) {