mirror of
https://github.com/eclipse-cdt/cdt
synced 2025-07-06 08:35:26 +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);
|
||||
}
|
||||
// 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);
|
||||
|
||||
// Store the desc order
|
||||
// Store the desc order, active one is the last one
|
||||
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) {
|
||||
buff.append(',');
|
||||
}
|
||||
buff.append(toString(key));
|
||||
}
|
||||
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 {
|
||||
|
@ -602,7 +606,7 @@ public class LaunchBarManager implements ILaunchBarManager, ILaunchConfiguration
|
|||
}
|
||||
|
||||
private void syncActiveMode() throws CoreException {
|
||||
if (activeLaunchDesc == null) {
|
||||
if (activeLaunchDesc == null || activeLaunchTarget == null) {
|
||||
setActiveLaunchMode(null);
|
||||
return;
|
||||
}
|
||||
|
@ -652,11 +656,22 @@ public class LaunchBarManager implements ILaunchBarManager, ILaunchConfiguration
|
|||
Activator.log(e);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
private Preferences getPerDescriptorStore() {
|
||||
if (activeLaunchDesc == null)
|
||||
return getPerDescriptorStore(activeLaunchDesc);
|
||||
}
|
||||
|
||||
private Preferences getPerDescriptorStore(ILaunchDescriptor launchDesc) {
|
||||
if (launchDesc == null)
|
||||
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
|
||||
|
@ -664,7 +679,7 @@ public class LaunchBarManager implements ILaunchBarManager, ILaunchConfiguration
|
|||
return InstanceScope.INSTANCE.getNode(Activator.PLUGIN_ID);
|
||||
}
|
||||
|
||||
private void updateLaunchDescriptor(ILaunchDescriptor configDesc) {
|
||||
private void fireActiveLaunchDescriptorChanged() {
|
||||
for (Listener listener : listeners) {
|
||||
try {
|
||||
listener.activeLaunchDescriptorChanged();
|
||||
|
@ -695,6 +710,21 @@ public class LaunchBarManager implements ILaunchBarManager, ILaunchConfiguration
|
|||
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 {
|
||||
if (activeLaunchMode == mode)
|
||||
return;
|
||||
|
@ -702,7 +732,11 @@ public class LaunchBarManager implements ILaunchBarManager, ILaunchConfiguration
|
|||
throw new IllegalStateException("Mode is not supported by descriptor");
|
||||
// change mode
|
||||
activeLaunchMode = mode;
|
||||
// notify listeners
|
||||
storeLaunchMode(activeLaunchDesc, mode);
|
||||
fireActiveLaunchModeChanged(); // notify listeners
|
||||
}
|
||||
|
||||
private void fireActiveLaunchModeChanged() {
|
||||
for (Listener listener : listeners) {
|
||||
try {
|
||||
listener.activeLaunchModeChanged();
|
||||
|
@ -710,10 +744,14 @@ public class LaunchBarManager implements ILaunchBarManager, ILaunchConfiguration
|
|||
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 {
|
||||
|
@ -755,28 +793,39 @@ public class LaunchBarManager implements ILaunchBarManager, ILaunchConfiguration
|
|||
public IRemoteConnection getActiveLaunchTarget() {
|
||||
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 {
|
||||
if (activeLaunchTarget == target) {
|
||||
return;
|
||||
}
|
||||
|
||||
activeLaunchTarget = target;
|
||||
launchTargetChanged(activeLaunchTarget);
|
||||
storeLaunchTarget(activeLaunchDesc, target);
|
||||
fireActiveLaunchTargetChanged(); // notify listeners
|
||||
}
|
||||
|
||||
private void storeLaunchTarget(ILaunchDescriptor desc, IRemoteConnection target) {
|
||||
if (target == null) {
|
||||
return; // no point storing null, if stored id is invalid it won't be used anyway
|
||||
}
|
||||
|
||||
if (activeLaunchDesc == null)
|
||||
return;
|
||||
|
||||
// per desc store
|
||||
if (supportsTargetType(activeLaunchDesc, target))
|
||||
setPreference(getPerDescriptorStore(),
|
||||
PREF_ACTIVE_LAUNCH_TARGET, toString(getTargetId(target)));
|
||||
// per desc store, desc can be null means it store globally
|
||||
setPreference(getPerDescriptorStore(desc), PREF_ACTIVE_LAUNCH_TARGET, toString(getTargetId(target)));
|
||||
}
|
||||
|
||||
private void launchTargetChanged(IRemoteConnection target) {
|
||||
private void fireActiveLaunchTargetChanged() {
|
||||
for (Listener listener : listeners) {
|
||||
try {
|
||||
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.Status;
|
||||
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.IStructuredContentProvider;
|
||||
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.wizard.WizardDialog;
|
||||
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.DefaultDescriptorLabelProvider;
|
||||
import org.eclipse.launchbar.ui.internal.LaunchBarUIManager;
|
||||
|
@ -198,9 +199,11 @@ public class ConfigSelector extends CSelector {
|
|||
new Job("Create Launch Configuration") {
|
||||
protected IStatus run(IProgressMonitor monitor) {
|
||||
try {
|
||||
wizard.getWorkingCopy().doSave();
|
||||
ILaunchMode lm = wizard.getLaunchMode();
|
||||
uiManager.getManager().setActiveLaunchMode(lm);
|
||||
ILaunchConfiguration config = wizard.getWorkingCopy().doSave();
|
||||
final LaunchBarManager barManager = uiManager.getManager();
|
||||
final ILaunchDescriptor desc = barManager.getDefaultDescriptorType().getDescriptor(config);
|
||||
barManager.setLaunchMode(desc, wizard.getLaunchMode());
|
||||
barManager.setActiveLaunchDescriptor(desc);
|
||||
return Status.OK_STATUS;
|
||||
} catch (CoreException e) {
|
||||
return e.getStatus();
|
||||
|
|
|
@ -154,6 +154,9 @@ public class ModeSelector extends CSelector {
|
|||
manager.setActiveLaunchMode(mode);
|
||||
} catch (CoreException e) {
|
||||
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) {
|
||||
LaunchBarManager manager = uiManager.getManager();
|
||||
try {
|
||||
List<IRemoteConnection> targets;
|
||||
targets = manager.getLaunchTargets(manager.getActiveLaunchDescriptor());
|
||||
List<IRemoteConnection> targets = manager.getLaunchTargets(manager.getActiveLaunchDescriptor());
|
||||
if (!targets.isEmpty()) {
|
||||
return targets.toArray();
|
||||
}
|
||||
} catch (CoreException e) {
|
||||
Activator.log(e);
|
||||
}
|
||||
return noTargets;
|
||||
}
|
||||
|
@ -103,7 +103,9 @@ public class TargetSelector extends CSelector {
|
|||
@Override
|
||||
public int compare(Object o1, Object o2) {
|
||||
// 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 {
|
||||
uiManager.getManager().setActiveLaunchTarget(target);
|
||||
} catch (CoreException e) {
|
||||
Activator.log(e.getStatus());
|
||||
Activator.log(e);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Add table
Reference in a new issue