mirror of
https://github.com/eclipse-cdt/cdt
synced 2025-06-08 02:06:01 +02:00
Fixed ability to disable LSP property page depending on preference
This commit is contained in:
parent
fd19e740de
commit
ab036f4bfc
4 changed files with 54 additions and 27 deletions
|
@ -494,11 +494,11 @@
|
||||||
|
|
||||||
<and>
|
<and>
|
||||||
` <instanceof value="org.eclipse.core.resources.IFile"/>
|
` <instanceof value="org.eclipse.core.resources.IFile"/>
|
||||||
<test property="org.eclipse.cdt.ui.isSource" value="" />
|
<test property="org.eclipse.cdt.ui.isSource"/>
|
||||||
</and>
|
</and>
|
||||||
<and>
|
<and>
|
||||||
<instanceof value="org.eclipse.cdt.core.model.ITranslationUnit"/>
|
<instanceof value="org.eclipse.cdt.core.model.ITranslationUnit"/>
|
||||||
<test property="org.eclipse.cdt.ui.isSource" value="" />
|
<test property="org.eclipse.cdt.ui.isSource"/>
|
||||||
</and>
|
</and>
|
||||||
|
|
||||||
</or>
|
</or>
|
||||||
|
|
|
@ -543,7 +543,7 @@
|
||||||
<test property="org.eclipse.core.resources.projectNature"
|
<test property="org.eclipse.core.resources.projectNature"
|
||||||
value="org.eclipse.cdt.managedbuilder.core.managedBuildNature"/>
|
value="org.eclipse.cdt.managedbuilder.core.managedBuildNature"/>
|
||||||
</adapt>
|
</adapt>
|
||||||
<test property="org.eclipse.cdt.ui.pageEnabled" value="export" />
|
<test property="org.eclipse.cdt.ui.checkPreference" value="org.eclipse.cdt.ui:properties.export.page.enable=true"/>
|
||||||
</and>
|
</and>
|
||||||
</enabledWhen>
|
</enabledWhen>
|
||||||
</page>
|
</page>
|
||||||
|
@ -573,7 +573,7 @@
|
||||||
<test property="org.eclipse.core.resources.projectNature"
|
<test property="org.eclipse.core.resources.projectNature"
|
||||||
value="org.eclipse.cdt.managedbuilder.core.managedBuildNature"/>
|
value="org.eclipse.cdt.managedbuilder.core.managedBuildNature"/>
|
||||||
</adapt>
|
</adapt>
|
||||||
<test property="org.eclipse.cdt.ui.pageEnabled" value="toolEdit" />
|
<test property="org.eclipse.cdt.ui.checkPreference" value="org.eclipse.cdt.ui:properties.toolchain.modification.disable=false"/>
|
||||||
</and>
|
</and>
|
||||||
</enabledWhen>
|
</enabledWhen>
|
||||||
</page>
|
</page>
|
||||||
|
|
|
@ -3376,7 +3376,10 @@
|
||||||
category="org.eclipse.cdt.ui.newui.Page_head_general">
|
category="org.eclipse.cdt.ui.newui.Page_head_general">
|
||||||
<enabledWhen>
|
<enabledWhen>
|
||||||
<adapt type="org.eclipse.core.resources.IResource">
|
<adapt type="org.eclipse.core.resources.IResource">
|
||||||
|
<and>
|
||||||
<test property="org.eclipse.core.resources.projectNature" value="org.eclipse.cdt.core.cnature"/>
|
<test property="org.eclipse.core.resources.projectNature" value="org.eclipse.cdt.core.cnature"/>
|
||||||
|
<test property="org.eclipse.cdt.ui.checkPreference" value="org.eclipse.cdt.ui:properties.providers.tab.disable=false"/>
|
||||||
|
</and>
|
||||||
</adapt>
|
</adapt>
|
||||||
</enabledWhen>
|
</enabledWhen>
|
||||||
</page>
|
</page>
|
||||||
|
@ -3940,10 +3943,10 @@
|
||||||
<extension
|
<extension
|
||||||
point="org.eclipse.core.expressions.propertyTesters">
|
point="org.eclipse.core.expressions.propertyTesters">
|
||||||
<propertyTester
|
<propertyTester
|
||||||
id="org.eclipse.cdt.Tester3"
|
id="org.eclipse.cdt.ui.preferenceTester"
|
||||||
class="org.eclipse.cdt.ui.newui.PropertyTester"
|
class="org.eclipse.cdt.ui.newui.PropertyTester"
|
||||||
namespace="org.eclipse.cdt.ui"
|
namespace="org.eclipse.cdt.ui"
|
||||||
properties="pageEnabled"
|
properties="checkPreference"
|
||||||
type="java.lang.Object"/>
|
type="java.lang.Object"/>
|
||||||
<propertyTester
|
<propertyTester
|
||||||
id="org.eclipse.cdt.Tester1"
|
id="org.eclipse.cdt.Tester1"
|
||||||
|
|
|
@ -10,39 +10,63 @@
|
||||||
*******************************************************************************/
|
*******************************************************************************/
|
||||||
package org.eclipse.cdt.ui.newui;
|
package org.eclipse.cdt.ui.newui;
|
||||||
|
|
||||||
|
import java.util.Arrays;
|
||||||
|
import java.util.regex.Matcher;
|
||||||
|
import java.util.regex.Pattern;
|
||||||
|
|
||||||
import org.eclipse.core.resources.IFile;
|
import org.eclipse.core.resources.IFile;
|
||||||
|
import org.eclipse.core.runtime.preferences.IEclipsePreferences;
|
||||||
|
import org.eclipse.core.runtime.preferences.InstanceScope;
|
||||||
|
import org.osgi.service.prefs.BackingStoreException;
|
||||||
|
|
||||||
import org.eclipse.cdt.core.model.CoreModel;
|
import org.eclipse.cdt.core.model.CoreModel;
|
||||||
import org.eclipse.cdt.core.model.ITranslationUnit;
|
import org.eclipse.cdt.core.model.ITranslationUnit;
|
||||||
|
import org.eclipse.cdt.ui.CUIPlugin;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Checks whether given object is a source file.
|
* Property tester to test expressions in plugin.xml. Tests following expressions:
|
||||||
|
* 1. Checks whether given object is a source file. Usage:
|
||||||
|
* <test property="org.eclipse.cdt.ui.isSource"/>
|
||||||
|
* 2. Checks value of a preference. Usage:
|
||||||
|
* <test property="org.eclipse.cdt.ui.checkPreference" value="org.eclipse.cdt.ui:properties.export.page.enable=true"/>
|
||||||
|
*
|
||||||
* @noextend This class is not intended to be subclassed by clients.
|
* @noextend This class is not intended to be subclassed by clients.
|
||||||
*/
|
*/
|
||||||
public class PropertyTester extends org.eclipse.core.expressions.PropertyTester {
|
public class PropertyTester extends org.eclipse.core.expressions.PropertyTester {
|
||||||
private static final String KEY_SRC = "isSource"; //$NON-NLS-1$
|
private static final String KEY_SRC = "isSource"; //$NON-NLS-1$
|
||||||
private static final String KEY_PAGE = "pageEnabled"; //$NON-NLS-1$
|
private static final String KEY_PREF = "checkPreference"; //$NON-NLS-1$
|
||||||
private static final String VAL_EXP = "export"; //$NON-NLS-1$
|
|
||||||
private static final String VAL_TOOL = "toolEdit"; //$NON-NLS-1$
|
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public boolean test(Object receiver, String property, Object[] args,
|
public boolean test(Object receiver, String property, Object[] args, Object expectedValue) {
|
||||||
Object expectedValue) {
|
|
||||||
if (KEY_SRC.equals(property)) {
|
if (KEY_SRC.equals(property)) {
|
||||||
if (receiver instanceof ITranslationUnit) {
|
if (receiver instanceof ITranslationUnit) {
|
||||||
return ((ITranslationUnit) receiver).isSourceUnit();
|
return ((ITranslationUnit) receiver).isSourceUnit();
|
||||||
}
|
} else if (receiver instanceof IFile) {
|
||||||
else if (receiver instanceof IFile) {
|
|
||||||
IFile file = (IFile) receiver;
|
IFile file = (IFile) receiver;
|
||||||
return CoreModel.isValidSourceUnitName(file.getProject(), file.getName());
|
return CoreModel.isValidSourceUnitName(file.getProject(), file.getName());
|
||||||
}
|
}
|
||||||
} else if (KEY_PAGE.equals(property)
|
} else if (KEY_PREF.equals(property) && expectedValue instanceof String) {
|
||||||
&& expectedValue instanceof String) {
|
boolean result = false;
|
||||||
String s = (String) expectedValue;
|
final Pattern pat = Pattern.compile("(.*):(.*)=(.*)"); //$NON-NLS-1$
|
||||||
if (VAL_EXP.equalsIgnoreCase(s))
|
Matcher matcher = pat.matcher((String) expectedValue);
|
||||||
return CDTPrefUtil.getBool(CDTPrefUtil.KEY_EXPORT);
|
if (matcher.matches()) {
|
||||||
if (VAL_TOOL.equalsIgnoreCase(s))
|
String pluginId = matcher.group(1);
|
||||||
return !CDTPrefUtil.getBool(CDTPrefUtil.KEY_NOTOOLM);
|
String preference = matcher.group(2);
|
||||||
|
String wantedValue = matcher.group(3);
|
||||||
|
|
||||||
|
IEclipsePreferences node = InstanceScope.INSTANCE.getNode(pluginId);
|
||||||
|
if (wantedValue != null) {
|
||||||
|
String actualValue = node.get(preference, ""); //$NON-NLS-1$
|
||||||
|
result = wantedValue.equals(actualValue) || (wantedValue.equals("false") && actualValue.isEmpty()); //$NON-NLS-1$
|
||||||
|
} else {
|
||||||
|
try {
|
||||||
|
result = Arrays.asList(node.keys()).contains(preference);
|
||||||
|
} catch (BackingStoreException e) {
|
||||||
|
CUIPlugin.log(e);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return result;
|
||||||
}
|
}
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
Loading…
Add table
Reference in a new issue