mirror of
https://github.com/eclipse-cdt/cdt
synced 2025-08-21 15:23:59 +02:00
launch-bar: added some guards for mode selection and API for setting
mode * added API for setting mode and target without changing active descriptor * used this API in the config selector to set the mode * added guard against mismatched mode Change-Id: I58da4aac12950c21192385820683623f9e939786 Signed-off-by: Alena Laskavaia <elaskavaia.cdt@gmail.com>
This commit is contained in:
parent
28985bd18d
commit
17fff835d1
4 changed files with 98 additions and 38 deletions
|
@ -558,24 +558,28 @@ public class LaunchBarManager implements ILaunchBarManager, ILaunchConfiguration
|
||||||
descriptors.put(id, descriptor);
|
descriptors.put(id, descriptor);
|
||||||
}
|
}
|
||||||
// store in persistent storage
|
// store in persistent storage
|
||||||
|
storeActiveDescriptor(activeLaunchDesc);
|
||||||
|
|
||||||
|
// Send notifications
|
||||||
|
fireActiveLaunchDescriptorChanged();
|
||||||
|
// Set active target
|
||||||
|
syncActiveTarget();
|
||||||
|
// Set active mode
|
||||||
|
syncActiveMode();
|
||||||
|
}
|
||||||
|
|
||||||
|
private void storeActiveDescriptor(ILaunchDescriptor descriptor) {
|
||||||
Activator.trace("new active config is stored " + descriptor);
|
Activator.trace("new active config is stored " + descriptor);
|
||||||
|
|
||||||
// Store the desc order
|
// Store the desc order, active one is the last one
|
||||||
StringBuffer buff = new StringBuffer();
|
StringBuffer buff = new StringBuffer();
|
||||||
for (Pair<String, String> key : descriptors.keySet()) {
|
for (Pair<String, String> key : descriptors.keySet()) {// TODO: this can be very long string
|
||||||
if (buff.length() > 0) {
|
if (buff.length() > 0) {
|
||||||
buff.append(',');
|
buff.append(',');
|
||||||
}
|
}
|
||||||
buff.append(toString(key));
|
buff.append(toString(key));
|
||||||
}
|
}
|
||||||
setPreference(getPreferenceStore(), PREF_CONFIG_DESC_ORDER, buff.toString());
|
setPreference(getPreferenceStore(), PREF_CONFIG_DESC_ORDER, buff.toString());
|
||||||
|
|
||||||
// Send notifications
|
|
||||||
updateLaunchDescriptor(activeLaunchDesc);
|
|
||||||
// Set active target
|
|
||||||
syncActiveTarget();
|
|
||||||
// Set active mode
|
|
||||||
syncActiveMode();
|
|
||||||
}
|
}
|
||||||
|
|
||||||
private void syncActiveTarget() throws CoreException {
|
private void syncActiveTarget() throws CoreException {
|
||||||
|
@ -602,7 +606,7 @@ public class LaunchBarManager implements ILaunchBarManager, ILaunchConfiguration
|
||||||
}
|
}
|
||||||
|
|
||||||
private void syncActiveMode() throws CoreException {
|
private void syncActiveMode() throws CoreException {
|
||||||
if (activeLaunchDesc == null) {
|
if (activeLaunchDesc == null || activeLaunchTarget == null) {
|
||||||
setActiveLaunchMode(null);
|
setActiveLaunchMode(null);
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
@ -654,9 +658,20 @@ public class LaunchBarManager implements ILaunchBarManager, ILaunchConfiguration
|
||||||
}
|
}
|
||||||
|
|
||||||
private Preferences getPerDescriptorStore() {
|
private Preferences getPerDescriptorStore() {
|
||||||
if (activeLaunchDesc == null)
|
return getPerDescriptorStore(activeLaunchDesc);
|
||||||
|
}
|
||||||
|
|
||||||
|
private Preferences getPerDescriptorStore(ILaunchDescriptor launchDesc) {
|
||||||
|
if (launchDesc == null)
|
||||||
return getPreferenceStore();
|
return getPreferenceStore();
|
||||||
return getPreferenceStore().node(toString(getDescriptorId(activeLaunchDesc)));
|
String string;
|
||||||
|
try {
|
||||||
|
string = toString(getDescriptorId(launchDesc));
|
||||||
|
} catch (Exception e) {
|
||||||
|
Activator.log(e);
|
||||||
|
string = launchDesc.getName();
|
||||||
|
}
|
||||||
|
return getPreferenceStore().node(string);
|
||||||
}
|
}
|
||||||
|
|
||||||
// package private so tests can access it
|
// package private so tests can access it
|
||||||
|
@ -664,7 +679,7 @@ public class LaunchBarManager implements ILaunchBarManager, ILaunchConfiguration
|
||||||
return InstanceScope.INSTANCE.getNode(Activator.PLUGIN_ID);
|
return InstanceScope.INSTANCE.getNode(Activator.PLUGIN_ID);
|
||||||
}
|
}
|
||||||
|
|
||||||
private void updateLaunchDescriptor(ILaunchDescriptor configDesc) {
|
private void fireActiveLaunchDescriptorChanged() {
|
||||||
for (Listener listener : listeners) {
|
for (Listener listener : listeners) {
|
||||||
try {
|
try {
|
||||||
listener.activeLaunchDescriptorChanged();
|
listener.activeLaunchDescriptorChanged();
|
||||||
|
@ -695,6 +710,21 @@ public class LaunchBarManager implements ILaunchBarManager, ILaunchConfiguration
|
||||||
return activeLaunchMode;
|
return activeLaunchMode;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Sets the preferred mode for the given descriptor
|
||||||
|
*
|
||||||
|
* @param desc
|
||||||
|
* @param mode
|
||||||
|
* @throws CoreException
|
||||||
|
*/
|
||||||
|
public void setLaunchMode(ILaunchDescriptor desc, ILaunchMode mode) throws CoreException {
|
||||||
|
if (desc == activeLaunchDesc) {
|
||||||
|
setActiveLaunchMode(mode);
|
||||||
|
} else {
|
||||||
|
storeLaunchMode(desc, mode);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
public void setActiveLaunchMode(ILaunchMode mode) throws CoreException {
|
public void setActiveLaunchMode(ILaunchMode mode) throws CoreException {
|
||||||
if (activeLaunchMode == mode)
|
if (activeLaunchMode == mode)
|
||||||
return;
|
return;
|
||||||
|
@ -702,7 +732,11 @@ public class LaunchBarManager implements ILaunchBarManager, ILaunchConfiguration
|
||||||
throw new IllegalStateException("Mode is not supported by descriptor");
|
throw new IllegalStateException("Mode is not supported by descriptor");
|
||||||
// change mode
|
// change mode
|
||||||
activeLaunchMode = mode;
|
activeLaunchMode = mode;
|
||||||
// notify listeners
|
storeLaunchMode(activeLaunchDesc, mode);
|
||||||
|
fireActiveLaunchModeChanged(); // notify listeners
|
||||||
|
}
|
||||||
|
|
||||||
|
private void fireActiveLaunchModeChanged() {
|
||||||
for (Listener listener : listeners) {
|
for (Listener listener : listeners) {
|
||||||
try {
|
try {
|
||||||
listener.activeLaunchModeChanged();
|
listener.activeLaunchModeChanged();
|
||||||
|
@ -710,10 +744,14 @@ public class LaunchBarManager implements ILaunchBarManager, ILaunchConfiguration
|
||||||
Activator.log(e);
|
Activator.log(e);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
if (mode == null)
|
}
|
||||||
return;
|
|
||||||
// store mode
|
|
||||||
setPreference(getPerDescriptorStore(), PREF_ACTIVE_LAUNCH_MODE, mode.getIdentifier()); // per desc store
|
private void storeLaunchMode(ILaunchDescriptor desc, ILaunchMode mode) {
|
||||||
|
if (mode != null) {
|
||||||
|
// per desc store, desc can null if will be stored globally
|
||||||
|
setPreference(getPerDescriptorStore(desc), PREF_ACTIVE_LAUNCH_MODE, mode.getIdentifier());
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
public List<IRemoteConnection> getLaunchTargets(ILaunchDescriptor descriptor) throws CoreException {
|
public List<IRemoteConnection> getLaunchTargets(ILaunchDescriptor descriptor) throws CoreException {
|
||||||
|
@ -756,27 +794,38 @@ public class LaunchBarManager implements ILaunchBarManager, ILaunchConfiguration
|
||||||
return activeLaunchTarget;
|
return activeLaunchTarget;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Sets preferred target for launch descriptor
|
||||||
|
* @param desc
|
||||||
|
* @param target
|
||||||
|
* @throws CoreException
|
||||||
|
*/
|
||||||
|
public void setLaunchTarget(ILaunchDescriptor desc, IRemoteConnection target) throws CoreException {
|
||||||
|
if (desc == activeLaunchDesc) {
|
||||||
|
setActiveLaunchTarget(target);
|
||||||
|
} else {
|
||||||
|
storeLaunchTarget(desc, target);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
public void setActiveLaunchTarget(IRemoteConnection target) throws CoreException {
|
public void setActiveLaunchTarget(IRemoteConnection target) throws CoreException {
|
||||||
if (activeLaunchTarget == target) {
|
if (activeLaunchTarget == target) {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
activeLaunchTarget = target;
|
activeLaunchTarget = target;
|
||||||
launchTargetChanged(activeLaunchTarget);
|
storeLaunchTarget(activeLaunchDesc, target);
|
||||||
|
fireActiveLaunchTargetChanged(); // notify listeners
|
||||||
|
}
|
||||||
|
|
||||||
|
private void storeLaunchTarget(ILaunchDescriptor desc, IRemoteConnection target) {
|
||||||
if (target == null) {
|
if (target == null) {
|
||||||
return; // no point storing null, if stored id is invalid it won't be used anyway
|
return; // no point storing null, if stored id is invalid it won't be used anyway
|
||||||
}
|
}
|
||||||
|
// per desc store, desc can be null means it store globally
|
||||||
if (activeLaunchDesc == null)
|
setPreference(getPerDescriptorStore(desc), PREF_ACTIVE_LAUNCH_TARGET, toString(getTargetId(target)));
|
||||||
return;
|
|
||||||
|
|
||||||
// per desc store
|
|
||||||
if (supportsTargetType(activeLaunchDesc, target))
|
|
||||||
setPreference(getPerDescriptorStore(),
|
|
||||||
PREF_ACTIVE_LAUNCH_TARGET, toString(getTargetId(target)));
|
|
||||||
}
|
}
|
||||||
|
|
||||||
private void launchTargetChanged(IRemoteConnection target) {
|
private void fireActiveLaunchTargetChanged() {
|
||||||
for (Listener listener : listeners) {
|
for (Listener listener : listeners) {
|
||||||
try {
|
try {
|
||||||
listener.activeLaunchTargetChanged();
|
listener.activeLaunchTargetChanged();
|
||||||
|
@ -1015,4 +1064,7 @@ public class LaunchBarManager implements ILaunchBarManager, ILaunchConfiguration
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public DefaultLaunchDescriptorType getDefaultDescriptorType(){
|
||||||
|
return defaultDescriptorType;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -17,7 +17,7 @@ import org.eclipse.core.runtime.IProgressMonitor;
|
||||||
import org.eclipse.core.runtime.IStatus;
|
import org.eclipse.core.runtime.IStatus;
|
||||||
import org.eclipse.core.runtime.Status;
|
import org.eclipse.core.runtime.Status;
|
||||||
import org.eclipse.core.runtime.jobs.Job;
|
import org.eclipse.core.runtime.jobs.Job;
|
||||||
import org.eclipse.debug.core.ILaunchMode;
|
import org.eclipse.debug.core.ILaunchConfiguration;
|
||||||
import org.eclipse.jface.viewers.ILabelProvider;
|
import org.eclipse.jface.viewers.ILabelProvider;
|
||||||
import org.eclipse.jface.viewers.IStructuredContentProvider;
|
import org.eclipse.jface.viewers.IStructuredContentProvider;
|
||||||
import org.eclipse.jface.viewers.LabelProvider;
|
import org.eclipse.jface.viewers.LabelProvider;
|
||||||
|
@ -25,6 +25,7 @@ import org.eclipse.jface.viewers.Viewer;
|
||||||
import org.eclipse.jface.window.Window;
|
import org.eclipse.jface.window.Window;
|
||||||
import org.eclipse.jface.wizard.WizardDialog;
|
import org.eclipse.jface.wizard.WizardDialog;
|
||||||
import org.eclipse.launchbar.core.ILaunchDescriptor;
|
import org.eclipse.launchbar.core.ILaunchDescriptor;
|
||||||
|
import org.eclipse.launchbar.core.internal.LaunchBarManager;
|
||||||
import org.eclipse.launchbar.ui.internal.Activator;
|
import org.eclipse.launchbar.ui.internal.Activator;
|
||||||
import org.eclipse.launchbar.ui.internal.DefaultDescriptorLabelProvider;
|
import org.eclipse.launchbar.ui.internal.DefaultDescriptorLabelProvider;
|
||||||
import org.eclipse.launchbar.ui.internal.LaunchBarUIManager;
|
import org.eclipse.launchbar.ui.internal.LaunchBarUIManager;
|
||||||
|
@ -198,9 +199,11 @@ public class ConfigSelector extends CSelector {
|
||||||
new Job("Create Launch Configuration") {
|
new Job("Create Launch Configuration") {
|
||||||
protected IStatus run(IProgressMonitor monitor) {
|
protected IStatus run(IProgressMonitor monitor) {
|
||||||
try {
|
try {
|
||||||
wizard.getWorkingCopy().doSave();
|
ILaunchConfiguration config = wizard.getWorkingCopy().doSave();
|
||||||
ILaunchMode lm = wizard.getLaunchMode();
|
final LaunchBarManager barManager = uiManager.getManager();
|
||||||
uiManager.getManager().setActiveLaunchMode(lm);
|
final ILaunchDescriptor desc = barManager.getDefaultDescriptorType().getDescriptor(config);
|
||||||
|
barManager.setLaunchMode(desc, wizard.getLaunchMode());
|
||||||
|
barManager.setActiveLaunchDescriptor(desc);
|
||||||
return Status.OK_STATUS;
|
return Status.OK_STATUS;
|
||||||
} catch (CoreException e) {
|
} catch (CoreException e) {
|
||||||
return e.getStatus();
|
return e.getStatus();
|
||||||
|
|
|
@ -154,6 +154,9 @@ public class ModeSelector extends CSelector {
|
||||||
manager.setActiveLaunchMode(mode);
|
manager.setActiveLaunchMode(mode);
|
||||||
} catch (CoreException e) {
|
} catch (CoreException e) {
|
||||||
Activator.log(e.getStatus());
|
Activator.log(e.getStatus());
|
||||||
|
} catch (Exception e) {
|
||||||
|
// manager can throw illegal state exception hopefully we never get it
|
||||||
|
Activator.log(e);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -68,12 +68,12 @@ public class TargetSelector extends CSelector {
|
||||||
public Object[] getElements(Object inputElement) {
|
public Object[] getElements(Object inputElement) {
|
||||||
LaunchBarManager manager = uiManager.getManager();
|
LaunchBarManager manager = uiManager.getManager();
|
||||||
try {
|
try {
|
||||||
List<IRemoteConnection> targets;
|
List<IRemoteConnection> targets = manager.getLaunchTargets(manager.getActiveLaunchDescriptor());
|
||||||
targets = manager.getLaunchTargets(manager.getActiveLaunchDescriptor());
|
|
||||||
if (!targets.isEmpty()) {
|
if (!targets.isEmpty()) {
|
||||||
return targets.toArray();
|
return targets.toArray();
|
||||||
}
|
}
|
||||||
} catch (CoreException e) {
|
} catch (CoreException e) {
|
||||||
|
Activator.log(e);
|
||||||
}
|
}
|
||||||
return noTargets;
|
return noTargets;
|
||||||
}
|
}
|
||||||
|
@ -103,7 +103,9 @@ public class TargetSelector extends CSelector {
|
||||||
@Override
|
@Override
|
||||||
public int compare(Object o1, Object o2) {
|
public int compare(Object o1, Object o2) {
|
||||||
// Sort by name
|
// Sort by name
|
||||||
return 0;
|
String s1 = String.valueOf(o1);
|
||||||
|
String s2 = String.valueOf(o2);
|
||||||
|
return s1.compareTo(s2);
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
@ -193,7 +195,7 @@ public class TargetSelector extends CSelector {
|
||||||
try {
|
try {
|
||||||
uiManager.getManager().setActiveLaunchTarget(target);
|
uiManager.getManager().setActiveLaunchTarget(target);
|
||||||
} catch (CoreException e) {
|
} catch (CoreException e) {
|
||||||
Activator.log(e.getStatus());
|
Activator.log(e);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
Loading…
Add table
Reference in a new issue