mirror of
https://github.com/eclipse-cdt/cdt
synced 2025-08-03 14:25:37 +02:00
Allow rename of launch targets. Add property tester for target type.
Change-Id: I1e87f8012e4c5bcd11cf1fce62c8a0dcf1d25e1e
This commit is contained in:
parent
3ad5cd3e42
commit
1f95c6cd61
5 changed files with 74 additions and 9 deletions
|
@ -33,5 +33,15 @@
|
|||
provider="org.eclipse.launchbar.core.internal.target.LocalLaunchTargetProvider">
|
||||
</launchTargetType>
|
||||
</extension>
|
||||
<extension
|
||||
point="org.eclipse.core.expressions.propertyTesters">
|
||||
<propertyTester
|
||||
class="org.eclipse.launchbar.core.internal.target.LaunchTargetPropertyTester"
|
||||
id="org.eclipse.launchbar.core.targetPropertyTester"
|
||||
namespace="org.eclipse.launchbar.core"
|
||||
properties="launchTargetType"
|
||||
type="org.eclipse.launchbar.core.target.ILaunchTarget">
|
||||
</propertyTester>
|
||||
</extension>
|
||||
|
||||
</plugin>
|
||||
|
|
|
@ -0,0 +1,25 @@
|
|||
/*******************************************************************************
|
||||
* 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.core.internal.target;
|
||||
|
||||
import org.eclipse.core.expressions.PropertyTester;
|
||||
import org.eclipse.launchbar.core.target.ILaunchTarget;
|
||||
|
||||
public class LaunchTargetPropertyTester extends PropertyTester {
|
||||
|
||||
@Override
|
||||
public boolean test(Object receiver, String property, Object[] args, Object expectedValue) {
|
||||
if (receiver instanceof ILaunchTarget) {
|
||||
if (property.equals("launchTargetType")) { //$NON-NLS-1$
|
||||
return ((ILaunchTarget) receiver).getTypeId().equals(expectedValue);
|
||||
}
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
}
|
|
@ -13,6 +13,7 @@ import java.util.Map;
|
|||
import org.eclipse.core.runtime.PlatformObject;
|
||||
import org.eclipse.launchbar.core.internal.Activator;
|
||||
import org.eclipse.launchbar.core.target.ILaunchTarget;
|
||||
import org.eclipse.launchbar.core.target.ILaunchTargetManager;
|
||||
import org.eclipse.launchbar.core.target.ILaunchTargetWorkingCopy;
|
||||
import org.osgi.service.prefs.BackingStoreException;
|
||||
|
||||
|
@ -20,6 +21,7 @@ public class LaunchTargetWorkingCopy extends PlatformObject implements ILaunchTa
|
|||
|
||||
private final LaunchTarget original;
|
||||
private final Map<String, String> changes = new HashMap<>();
|
||||
private String newId;
|
||||
|
||||
public LaunchTargetWorkingCopy(LaunchTarget original) {
|
||||
this.original = original;
|
||||
|
@ -37,7 +39,12 @@ public class LaunchTargetWorkingCopy extends PlatformObject implements ILaunchTa
|
|||
|
||||
@Override
|
||||
public String getId() {
|
||||
return original.getId();
|
||||
return newId != null ? newId : original.getId();
|
||||
}
|
||||
|
||||
@Override
|
||||
public void setId(String id) {
|
||||
newId = id;
|
||||
}
|
||||
|
||||
@Override
|
||||
|
@ -62,14 +69,29 @@ public class LaunchTargetWorkingCopy extends PlatformObject implements ILaunchTa
|
|||
@Override
|
||||
public ILaunchTarget save() {
|
||||
try {
|
||||
for (Map.Entry<String, String> entry : changes.entrySet()) {
|
||||
original.attributes.put(entry.getKey(), entry.getValue());
|
||||
LaunchTarget target;
|
||||
if (newId == null) {
|
||||
target = original;
|
||||
} else {
|
||||
// make a new one and remove the old one
|
||||
ILaunchTargetManager manager = Activator.getLaunchTargetManager();
|
||||
target = (LaunchTarget) manager.addLaunchTarget(original.getTypeId(), newId);
|
||||
for (String key : original.attributes.keys()) {
|
||||
target.attributes.put(key, original.getAttribute(key, "")); //$NON-NLS-1$
|
||||
}
|
||||
manager.removeLaunchTarget(original);
|
||||
}
|
||||
original.attributes.flush();
|
||||
|
||||
// set the changed attributes
|
||||
for (Map.Entry<String, String> entry : changes.entrySet()) {
|
||||
target.attributes.put(entry.getKey(), entry.getValue());
|
||||
}
|
||||
target.attributes.flush();
|
||||
return target;
|
||||
} catch (BackingStoreException e) {
|
||||
Activator.log(e);
|
||||
return original;
|
||||
}
|
||||
return original;
|
||||
}
|
||||
|
||||
}
|
||||
|
|
|
@ -65,8 +65,8 @@ public interface ILaunchTarget extends IAdaptable {
|
|||
String getAttribute(String key, String defValue);
|
||||
|
||||
/**
|
||||
* Create a working copy of this launch target to allow setting of attributes. Note that when
|
||||
* saving the attributes this target is updated. A new one is not created.
|
||||
* Create a working copy of this launch target to allow setting of attributes. It also allows
|
||||
* changing the id, which results in a new launch target when saved.
|
||||
*
|
||||
* @return launch target working copy
|
||||
*/
|
||||
|
|
|
@ -19,6 +19,14 @@ public interface ILaunchTargetWorkingCopy extends ILaunchTarget {
|
|||
*/
|
||||
ILaunchTarget getOriginal();
|
||||
|
||||
/**
|
||||
* Gives the target a new ID. The save method will return a new target with the given name.e
|
||||
*
|
||||
* @param id
|
||||
* new target ID
|
||||
*/
|
||||
void setId(String id);
|
||||
|
||||
/**
|
||||
* Set an attribute.
|
||||
*
|
||||
|
@ -30,9 +38,9 @@ public interface ILaunchTargetWorkingCopy extends ILaunchTarget {
|
|||
void setAttribute(String key, String value);
|
||||
|
||||
/**
|
||||
* Save the changed attributes to the original working copy.
|
||||
* Save the changes to the original working copy.
|
||||
*
|
||||
* @return original launch target
|
||||
* @return original launch target unless the id was changed in which case returns a new target
|
||||
*/
|
||||
ILaunchTarget save();
|
||||
|
||||
|
|
Loading…
Add table
Reference in a new issue