mirror of
https://github.com/eclipse-cdt/cdt
synced 2025-07-10 18:45:26 +02:00
Bug 457086" launchbar: proper support for launch groups
- unfortunately same mode is re-used for different launch group, which have different images - so we cannot cash icons by mode since it show wrong icon - we also has to notify mode select that mode change event it is "equals" so it can update launch group image - also fixed resource leak for launch bar button Change-Id: Iaa7b80d74963e4d0d1ccef5e6e4cd54a3ae5a4d4
This commit is contained in:
parent
32bcbba8bb
commit
4b42a1d050
4 changed files with 99 additions and 82 deletions
|
@ -648,8 +648,12 @@ public class LaunchBarManager implements ILaunchBarManager, ILaunchTargetListene
|
|||
}
|
||||
|
||||
public void setActiveLaunchMode(ILaunchMode mode) throws CoreException {
|
||||
if (activeLaunchMode == mode)
|
||||
if (activeLaunchMode == mode) {
|
||||
// we have to modify listeners here because same mode does not mean
|
||||
// same launch group. ModeSelector has to update.
|
||||
fireActiveLaunchModeChanged(); // notify listeners
|
||||
return;
|
||||
}
|
||||
if (activeLaunchDesc != null && mode != null && !supportsMode(mode))
|
||||
throw new IllegalStateException(Messages.LaunchBarManager_2);
|
||||
// change mode
|
||||
|
|
|
@ -0,0 +1,51 @@
|
|||
/*******************************************************************************
|
||||
* 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
|
||||
*
|
||||
* Contributors:
|
||||
* Doug Schaefer - initial API and implementation
|
||||
* Elena Laskavaia - moved to a separate class
|
||||
*******************************************************************************/
|
||||
package org.eclipse.launchbar.ui.internal.controls;
|
||||
|
||||
import org.eclipse.jface.resource.CompositeImageDescriptor;
|
||||
import org.eclipse.swt.graphics.Image;
|
||||
import org.eclipse.swt.graphics.Point;
|
||||
import org.eclipse.swt.graphics.Rectangle;
|
||||
|
||||
/**
|
||||
* This class will take two images and create descriptor that will overlay them, mainImage will be centered
|
||||
*/
|
||||
public class LaunchBarButtonImageDescriptor extends CompositeImageDescriptor {
|
||||
private Image bgImage;
|
||||
private Image mainImage;
|
||||
|
||||
/**
|
||||
* @param mainImage - main image, will be centered
|
||||
* @param bgImage - background image
|
||||
*/
|
||||
public LaunchBarButtonImageDescriptor(Image mainImage, Image bgImage) {
|
||||
super();
|
||||
this.bgImage = bgImage;
|
||||
this.mainImage = mainImage;
|
||||
}
|
||||
|
||||
@Override
|
||||
protected Point getSize() {
|
||||
Rectangle bounds = bgImage.getBounds();
|
||||
return new Point(bounds.width - bounds.y, bounds.height - bounds.x);
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void drawCompositeImage(int width, int height) {
|
||||
drawImage(bgImage.getImageData(), 0, 0);
|
||||
Rectangle bgBounds = bgImage.getBounds();
|
||||
Rectangle modeBounds = mainImage.getBounds();
|
||||
int x = ((bgBounds.width - bgBounds.x) - (modeBounds.width - modeBounds.x)) / 2;
|
||||
int y = ((bgBounds.height - bgBounds.y) - (modeBounds.height - modeBounds.y)) / 2;
|
||||
drawImage(mainImage.getImageData(), x, y);
|
||||
}
|
||||
}
|
|
@ -16,7 +16,6 @@ import javax.annotation.PreDestroy;
|
|||
|
||||
import org.eclipse.debug.core.ILaunchMode;
|
||||
import org.eclipse.jface.preference.IPreferenceStore;
|
||||
import org.eclipse.jface.resource.CompositeImageDescriptor;
|
||||
import org.eclipse.jface.resource.ImageDescriptor;
|
||||
import org.eclipse.launchbar.core.ILaunchBarListener;
|
||||
import org.eclipse.launchbar.core.ILaunchDescriptor;
|
||||
|
@ -29,8 +28,6 @@ import org.eclipse.swt.events.DisposeEvent;
|
|||
import org.eclipse.swt.events.DisposeListener;
|
||||
import org.eclipse.swt.events.SelectionAdapter;
|
||||
import org.eclipse.swt.graphics.Image;
|
||||
import org.eclipse.swt.graphics.Point;
|
||||
import org.eclipse.swt.graphics.Rectangle;
|
||||
import org.eclipse.swt.layout.GridData;
|
||||
import org.eclipse.swt.layout.GridLayout;
|
||||
import org.eclipse.swt.widgets.Composite;
|
||||
|
@ -116,26 +113,9 @@ public class LaunchBarControl implements ILaunchBarListener {
|
|||
Image bgImage = Activator.getDefault().getImage(Activator.IMG_BUTTON_BACKGROUND);
|
||||
Image fgImage = Activator.getDefault().getImage(imageName);
|
||||
|
||||
ImageDescriptor imageDesc = new CompositeImageDescriptor() {
|
||||
@Override
|
||||
protected Point getSize() {
|
||||
Rectangle bounds = bgImage.getBounds();
|
||||
return new Point(bounds.width - bounds.y, bounds.height - bounds.x);
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void drawCompositeImage(int width, int height) {
|
||||
drawImage(bgImage.getImageData(), 0, 0);
|
||||
|
||||
Rectangle bgBounds = bgImage.getBounds();
|
||||
Rectangle modeBounds = fgImage.getBounds();
|
||||
int x = ((bgBounds.width - bgBounds.x) - (modeBounds.width - modeBounds.x)) / 2;
|
||||
int y = ((bgBounds.height - bgBounds.y) - (modeBounds.height - modeBounds.y)) / 2;
|
||||
drawImage(fgImage.getImageData(), x, y);
|
||||
}
|
||||
};
|
||||
|
||||
button.setImage(imageDesc.createImage());
|
||||
ImageDescriptor imageDesc = new LaunchBarButtonImageDescriptor(fgImage, bgImage);
|
||||
Image image = imageDesc.createImage();
|
||||
button.setImage(image);
|
||||
button.setToolTipText(toolTipText);
|
||||
button.setData("command", command); //$NON-NLS-1$
|
||||
button.addSelectionListener(new SelectionAdapter() {
|
||||
|
@ -144,6 +124,12 @@ public class LaunchBarControl implements ILaunchBarListener {
|
|||
Activator.runCommand(command);
|
||||
};
|
||||
});
|
||||
button.addDisposeListener(new DisposeListener() {
|
||||
@Override
|
||||
public void widgetDisposed(DisposeEvent e) {
|
||||
image.dispose();
|
||||
}
|
||||
});
|
||||
return button;
|
||||
}
|
||||
|
||||
|
|
|
@ -21,7 +21,6 @@ import org.eclipse.debug.core.ILaunchMode;
|
|||
import org.eclipse.debug.internal.ui.DebugUIPlugin;
|
||||
import org.eclipse.debug.ui.IDebugUIConstants;
|
||||
import org.eclipse.debug.ui.ILaunchGroup;
|
||||
import org.eclipse.jface.resource.CompositeImageDescriptor;
|
||||
import org.eclipse.jface.resource.ImageDescriptor;
|
||||
import org.eclipse.jface.viewers.IStructuredContentProvider;
|
||||
import org.eclipse.jface.viewers.LabelProvider;
|
||||
|
@ -32,7 +31,6 @@ import org.eclipse.launchbar.ui.internal.Messages;
|
|||
import org.eclipse.osgi.util.NLS;
|
||||
import org.eclipse.swt.graphics.Image;
|
||||
import org.eclipse.swt.graphics.Point;
|
||||
import org.eclipse.swt.graphics.Rectangle;
|
||||
import org.eclipse.swt.widgets.Composite;
|
||||
import org.eclipse.swt.widgets.Control;
|
||||
import org.eclipse.swt.widgets.ToolBar;
|
||||
|
@ -83,24 +81,17 @@ public class ModeSelector extends CSelector {
|
|||
public Image getImage(Object element) {
|
||||
if (element instanceof ILaunchMode) {
|
||||
ILaunchMode mode = (ILaunchMode) element;
|
||||
try {
|
||||
ILaunchGroup group = getLaunchGroup(mode.getIdentifier());
|
||||
if (group == null) {
|
||||
group = getDefaultLaunchGroup(mode.getIdentifier());
|
||||
ILaunchGroup group = getLaunchGroup(mode);
|
||||
if (group != null) {
|
||||
ImageDescriptor imageDesc = group.getImageDescriptor();
|
||||
if (imageDesc == null)
|
||||
return null;
|
||||
Image image = images.get(imageDesc);
|
||||
if (image == null) {
|
||||
image = imageDesc.createImage();
|
||||
images.put(imageDesc, image);
|
||||
}
|
||||
if (group != null) {
|
||||
ImageDescriptor imageDesc = group.getImageDescriptor();
|
||||
if (imageDesc == null)
|
||||
return null;
|
||||
Image image = images.get(imageDesc);
|
||||
if (image == null) {
|
||||
image = imageDesc.createImage();
|
||||
images.put(imageDesc, image);
|
||||
}
|
||||
return image;
|
||||
}
|
||||
} catch (CoreException e) {
|
||||
Activator.log(e.getStatus());
|
||||
return image;
|
||||
}
|
||||
}
|
||||
return super.getImage(element);
|
||||
|
@ -110,16 +101,9 @@ public class ModeSelector extends CSelector {
|
|||
public String getText(Object element) {
|
||||
if (element instanceof ILaunchMode) {
|
||||
ILaunchMode mode = (ILaunchMode) element;
|
||||
try {
|
||||
ILaunchGroup group = getLaunchGroup(mode.getIdentifier());
|
||||
if (group == null) {
|
||||
group = getDefaultLaunchGroup(mode.getIdentifier());
|
||||
}
|
||||
if (group != null) {
|
||||
return group.getLabel().replace("&", ""); //$NON-NLS-1$ //$NON-NLS-2$
|
||||
}
|
||||
} catch (CoreException e) {
|
||||
Activator.log(e.getStatus());
|
||||
ILaunchGroup group = getLaunchGroup(mode);
|
||||
if (group != null) {
|
||||
return group.getLabel().replace("&", ""); //$NON-NLS-1$ //$NON-NLS-2$
|
||||
}
|
||||
}
|
||||
return super.getText(element);
|
||||
|
@ -164,7 +148,7 @@ public class ModeSelector extends CSelector {
|
|||
}
|
||||
|
||||
protected ILaunchGroup getDefaultLaunchGroup(String mode) {
|
||||
String groupId = null;
|
||||
String groupId;
|
||||
if (mode.equals(ILaunchManager.DEBUG_MODE)) {
|
||||
groupId = IDebugUIConstants.ID_DEBUG_LAUNCH_GROUP;
|
||||
} else if (mode.equals(ILaunchManager.PROFILE_MODE)) {
|
||||
|
@ -172,9 +156,7 @@ public class ModeSelector extends CSelector {
|
|||
} else {
|
||||
groupId = IDebugUIConstants.ID_RUN_LAUNCH_GROUP;
|
||||
}
|
||||
if (groupId != null)
|
||||
return DebugUIPlugin.getDefault().getLaunchConfigurationManager().getLaunchGroup(groupId);
|
||||
return null;
|
||||
return DebugUIPlugin.getDefault().getLaunchConfigurationManager().getLaunchGroup(groupId);
|
||||
}
|
||||
|
||||
protected ILaunchGroup getLaunchGroup(String mode) throws CoreException {
|
||||
|
@ -237,42 +219,36 @@ public class ModeSelector extends CSelector {
|
|||
if (toolItem == null || isDisposed()) {
|
||||
return;
|
||||
}
|
||||
|
||||
Object selection = getSelection();
|
||||
if (selection instanceof ILaunchMode) {
|
||||
ILaunchMode mode = (ILaunchMode) selection;
|
||||
toolItem.setToolTipText(NLS.bind(Messages.ModeSelector_ToolTip, mode.getLabel()));
|
||||
|
||||
Image image = modeButtonImages.get(mode.getIdentifier());
|
||||
ILaunchGroup group = getLaunchGroup(mode);
|
||||
// we cannot use mode id as id, since external tool group and run group have same "run" id for the mode
|
||||
// but different images
|
||||
String id = group.getIdentifier();
|
||||
Image image = modeButtonImages.get(id);
|
||||
if (image == null) {
|
||||
Image bgImage = Activator.getDefault().getImage(Activator.IMG_BUTTON_BACKGROUND);
|
||||
Image modeImage = getLabelProvider().getImage(mode);
|
||||
|
||||
ImageDescriptor imageDesc = new CompositeImageDescriptor() {
|
||||
@Override
|
||||
protected Point getSize() {
|
||||
Rectangle bounds = bgImage.getBounds();
|
||||
return new Point(bounds.width - bounds.y, bounds.height - bounds.x);
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void drawCompositeImage(int width, int height) {
|
||||
drawImage(bgImage.getImageData(), 0, 0);
|
||||
|
||||
Rectangle bgBounds = bgImage.getBounds();
|
||||
Rectangle modeBounds = modeImage.getBounds();
|
||||
int x = ((bgBounds.width - bgBounds.x) - (modeBounds.width - modeBounds.x)) / 2;
|
||||
int y = ((bgBounds.height - bgBounds.y) - (modeBounds.height - modeBounds.y)) / 2;
|
||||
drawImage(modeImage.getImageData(), x, y);
|
||||
}
|
||||
};
|
||||
|
||||
ImageDescriptor imageDesc = new LaunchBarButtonImageDescriptor(modeImage, bgImage);
|
||||
image = imageDesc.createImage();
|
||||
modeButtonImages.put(mode.getIdentifier(), image);
|
||||
modeButtonImages.put(id, image);
|
||||
}
|
||||
|
||||
toolItem.setImage(image);
|
||||
}
|
||||
}
|
||||
|
||||
public ILaunchGroup getLaunchGroup(ILaunchMode mode) {
|
||||
ILaunchGroup group = null;
|
||||
try {
|
||||
group = getLaunchGroup(mode.getIdentifier());
|
||||
} catch (CoreException e) {
|
||||
Activator.log(e.getStatus());
|
||||
}
|
||||
if (group == null) {
|
||||
group = getDefaultLaunchGroup(mode.getIdentifier());
|
||||
}
|
||||
return group;
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Add table
Reference in a new issue