mirror of
https://github.com/eclipse-cdt/cdt
synced 2025-07-13 03:55:22 +02:00
Merge "LaunchBar: prevent repaint storm during initialization"
This commit is contained in:
commit
40b6b6c05c
2 changed files with 48 additions and 40 deletions
|
@ -73,6 +73,7 @@ public abstract class CSelector extends Composite {
|
||||||
private Label currentLabel;
|
private Label currentLabel;
|
||||||
private Shell popup;
|
private Shell popup;
|
||||||
private LaunchBarListViewer listViewer;
|
private LaunchBarListViewer listViewer;
|
||||||
|
private Job delayJob;
|
||||||
private MouseTrackListener mouseTrackListener = new MouseTrackListener() {
|
private MouseTrackListener mouseTrackListener = new MouseTrackListener() {
|
||||||
@Override
|
@Override
|
||||||
public void mouseEnter(MouseEvent e) {
|
public void mouseEnter(MouseEvent e) {
|
||||||
|
@ -202,6 +203,7 @@ public abstract class CSelector extends Composite {
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|
||||||
public CSelector(Composite parent, int style) {
|
public CSelector(Composite parent, int style) {
|
||||||
super(parent, style);
|
super(parent, style);
|
||||||
backgroundColor = getDisplay().getSystemColor(SWT.COLOR_LIST_BACKGROUND);
|
backgroundColor = getDisplay().getSystemColor(SWT.COLOR_LIST_BACKGROUND);
|
||||||
|
@ -241,6 +243,30 @@ public abstract class CSelector extends Composite {
|
||||||
popup.dispose();
|
popup.dispose();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public void setDelayedSelection(final Object element, long millis) {
|
||||||
|
if (delayJob != null)
|
||||||
|
delayJob.cancel();
|
||||||
|
delayJob = new Job("Updating launch bar selection") {
|
||||||
|
@Override
|
||||||
|
protected IStatus run(final IProgressMonitor monitor) {
|
||||||
|
if (monitor.isCanceled())
|
||||||
|
return Status.CANCEL_STATUS;
|
||||||
|
if (isDisposed())
|
||||||
|
return Status.CANCEL_STATUS;
|
||||||
|
getDisplay().asyncExec(new Runnable() {
|
||||||
|
@Override
|
||||||
|
public void run() {
|
||||||
|
if (monitor.isCanceled())
|
||||||
|
return;
|
||||||
|
setSelection(element);
|
||||||
|
}
|
||||||
|
});
|
||||||
|
return Status.OK_STATUS;
|
||||||
|
}
|
||||||
|
};
|
||||||
|
delayJob.schedule(millis);
|
||||||
|
}
|
||||||
|
|
||||||
public void setSelection(Object element) {
|
public void setSelection(Object element) {
|
||||||
this.selection = element;
|
this.selection = element;
|
||||||
if (buttonComposite != null)
|
if (buttonComposite != null)
|
||||||
|
|
|
@ -23,8 +23,7 @@ import org.eclipse.launchbar.ui.internal.Messages;
|
||||||
import org.eclipse.swt.SWT;
|
import org.eclipse.swt.SWT;
|
||||||
import org.eclipse.swt.events.DisposeEvent;
|
import org.eclipse.swt.events.DisposeEvent;
|
||||||
import org.eclipse.swt.events.DisposeListener;
|
import org.eclipse.swt.events.DisposeListener;
|
||||||
import org.eclipse.swt.events.MouseAdapter;
|
import org.eclipse.swt.events.SelectionAdapter;
|
||||||
import org.eclipse.swt.events.MouseEvent;
|
|
||||||
import org.eclipse.swt.graphics.Image;
|
import org.eclipse.swt.graphics.Image;
|
||||||
import org.eclipse.swt.layout.GridData;
|
import org.eclipse.swt.layout.GridData;
|
||||||
import org.eclipse.swt.layout.GridLayout;
|
import org.eclipse.swt.layout.GridLayout;
|
||||||
|
@ -32,7 +31,6 @@ import org.eclipse.swt.widgets.Composite;
|
||||||
import org.eclipse.swt.widgets.Label;
|
import org.eclipse.swt.widgets.Label;
|
||||||
|
|
||||||
public class LaunchBarControl implements Listener {
|
public class LaunchBarControl implements Listener {
|
||||||
|
|
||||||
public static final String ID = "org.eclipse.launchbar"; //$NON-NLS-1$
|
public static final String ID = "org.eclipse.launchbar"; //$NON-NLS-1$
|
||||||
public static final String CLASS_URI = "bundleclass://" + Activator.PLUGIN_ID + "/" + LaunchBarControl.class.getName(); //$NON-NLS-1$ //$NON-NLS-2$
|
public static final String CLASS_URI = "bundleclass://" + Activator.PLUGIN_ID + "/" + LaunchBarControl.class.getName(); //$NON-NLS-1$ //$NON-NLS-2$
|
||||||
|
|
||||||
|
@ -42,6 +40,8 @@ public class LaunchBarControl implements Listener {
|
||||||
private ModeSelector modeSelector;
|
private ModeSelector modeSelector;
|
||||||
private TargetSelector targetSelector;
|
private TargetSelector targetSelector;
|
||||||
|
|
||||||
|
private static final int SELECTION_DELAY = 200;
|
||||||
|
|
||||||
@PostConstruct
|
@PostConstruct
|
||||||
public void createControl(Composite parent) {
|
public void createControl(Composite parent) {
|
||||||
manager.addListener(this);
|
manager.addListener(this);
|
||||||
|
@ -79,14 +79,16 @@ public class LaunchBarControl implements Listener {
|
||||||
targetSelector.setLayoutData(new GridData(SWT.LEFT, SWT.CENTER, false, false));
|
targetSelector.setLayoutData(new GridData(SWT.LEFT, SWT.CENTER, false, false));
|
||||||
targetSelector.setInput(manager);
|
targetSelector.setInput(manager);
|
||||||
|
|
||||||
ILaunchDescriptor configDesc = manager.getActiveLaunchDescriptor();
|
syncSelectors();
|
||||||
configSelector.setSelection(configDesc == null ? null : configDesc);
|
}
|
||||||
|
|
||||||
ILaunchMode mode = manager.getActiveLaunchMode();
|
protected void syncSelectors() {
|
||||||
modeSelector.setSelection(mode == null ? null : mode);
|
if (configSelector != null)
|
||||||
|
configSelector.setSelection(manager.getActiveLaunchDescriptor());
|
||||||
ILaunchTarget target = manager.getActiveLaunchTarget();
|
if (modeSelector != null)
|
||||||
targetSelector.setSelection(target == null ? null : target);
|
modeSelector.setSelection(manager.getActiveLaunchMode());
|
||||||
|
if (targetSelector != null)
|
||||||
|
targetSelector.setSelection(manager.getActiveLaunchTarget());
|
||||||
}
|
}
|
||||||
|
|
||||||
@PreDestroy
|
@PreDestroy
|
||||||
|
@ -101,53 +103,34 @@ public class LaunchBarControl implements Listener {
|
||||||
Image image = new Image(parent.getDisplay(), srcImage, SWT.IMAGE_COPY);
|
Image image = new Image(parent.getDisplay(), srcImage, SWT.IMAGE_COPY);
|
||||||
button.setHotImage(image);
|
button.setHotImage(image);
|
||||||
button.setToolTipText(toolTipText);
|
button.setToolTipText(toolTipText);
|
||||||
button.addMouseListener(new MouseAdapter() {
|
button.addSelectionListener(new SelectionAdapter() {
|
||||||
@Override
|
public void widgetSelected(org.eclipse.swt.events.SelectionEvent e) {
|
||||||
public void mouseUp(MouseEvent e) {
|
|
||||||
Activator.runCommand(command);
|
Activator.runCommand(command);
|
||||||
}
|
};
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void activeLaunchDescriptorChanged() {
|
public void activeLaunchDescriptorChanged() {
|
||||||
if (configSelector != null && !configSelector.isDisposed()) {
|
if (configSelector != null) {
|
||||||
final ILaunchDescriptor configDesc = manager.getActiveLaunchDescriptor();
|
final ILaunchDescriptor descriptor = manager.getActiveLaunchDescriptor();
|
||||||
configSelector.getDisplay().asyncExec(new Runnable() {
|
configSelector.setDelayedSelection(descriptor, SELECTION_DELAY);
|
||||||
@Override
|
|
||||||
public void run() {
|
|
||||||
if (!configSelector.isDisposed())
|
|
||||||
configSelector.setSelection(configDesc == null ? null : configDesc);
|
|
||||||
}
|
|
||||||
});
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void activeLaunchModeChanged() {
|
public void activeLaunchModeChanged() {
|
||||||
if (modeSelector != null && !modeSelector.isDisposed()) {
|
if (modeSelector != null) {
|
||||||
final ILaunchMode mode = manager.getActiveLaunchMode();
|
final ILaunchMode mode = manager.getActiveLaunchMode();
|
||||||
modeSelector.getDisplay().asyncExec(new Runnable() {
|
modeSelector.setDelayedSelection(mode, SELECTION_DELAY);
|
||||||
@Override
|
|
||||||
public void run() {
|
|
||||||
if (!modeSelector.isDisposed())
|
|
||||||
modeSelector.setSelection(mode == null ? null : mode);
|
|
||||||
}
|
|
||||||
});
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void activeLaunchTargetChanged() {
|
public void activeLaunchTargetChanged() {
|
||||||
if (targetSelector != null && !targetSelector.isDisposed()) {
|
if (targetSelector != null) {
|
||||||
final ILaunchTarget target = manager.getActiveLaunchTarget();
|
final ILaunchTarget target = manager.getActiveLaunchTarget();
|
||||||
targetSelector.getDisplay().asyncExec(new Runnable() {
|
targetSelector.setDelayedSelection(target, SELECTION_DELAY);
|
||||||
@Override
|
|
||||||
public void run() {
|
|
||||||
if (!targetSelector.isDisposed())
|
|
||||||
targetSelector.setSelection(target == null ? null : target);
|
|
||||||
}
|
|
||||||
});
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -162,5 +145,4 @@ public class LaunchBarControl implements Listener {
|
||||||
// TODO Auto-generated method stub
|
// TODO Auto-generated method stub
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
Loading…
Add table
Reference in a new issue