1
0
Fork 0
mirror of https://github.com/eclipse-cdt/cdt synced 2025-04-29 19:45:01 +02:00

Fixed ability to disable LSP property page depending on preference

This commit is contained in:
Andrew Gvozdev 2012-04-29 23:27:59 -04:00
parent fd19e740de
commit ab036f4bfc
4 changed files with 54 additions and 27 deletions

View file

@ -494,11 +494,11 @@
<and>
` <instanceof value="org.eclipse.core.resources.IFile"/>
<test property="org.eclipse.cdt.ui.isSource" value="" />
<test property="org.eclipse.cdt.ui.isSource"/>
</and>
<and>
<instanceof value="org.eclipse.cdt.core.model.ITranslationUnit"/>
<test property="org.eclipse.cdt.ui.isSource" value="" />
<test property="org.eclipse.cdt.ui.isSource"/>
</and>
</or>

View file

@ -543,7 +543,7 @@
<test property="org.eclipse.core.resources.projectNature"
value="org.eclipse.cdt.managedbuilder.core.managedBuildNature"/>
</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>
</enabledWhen>
</page>
@ -573,7 +573,7 @@
<test property="org.eclipse.core.resources.projectNature"
value="org.eclipse.cdt.managedbuilder.core.managedBuildNature"/>
</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>
</enabledWhen>
</page>

View file

@ -3375,9 +3375,12 @@
class="org.eclipse.cdt.internal.ui.language.settings.providers.LanguageSettingsProvidersPage"
category="org.eclipse.cdt.ui.newui.Page_head_general">
<enabledWhen>
<adapt type="org.eclipse.core.resources.IResource">
<test property="org.eclipse.core.resources.projectNature" value="org.eclipse.cdt.core.cnature"/>
</adapt>
<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.cdt.ui.checkPreference" value="org.eclipse.cdt.ui:properties.providers.tab.disable=false"/>
</and>
</adapt>
</enabledWhen>
</page>
</extension>
@ -3940,10 +3943,10 @@
<extension
point="org.eclipse.core.expressions.propertyTesters">
<propertyTester
id="org.eclipse.cdt.Tester3"
id="org.eclipse.cdt.ui.preferenceTester"
class="org.eclipse.cdt.ui.newui.PropertyTester"
namespace="org.eclipse.cdt.ui"
properties="pageEnabled"
properties="checkPreference"
type="java.lang.Object"/>
<propertyTester
id="org.eclipse.cdt.Tester1"

View file

@ -10,39 +10,63 @@
*******************************************************************************/
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.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.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.
*/
public class PropertyTester extends org.eclipse.core.expressions.PropertyTester {
private static final String KEY_SRC = "isSource"; //$NON-NLS-1$
private static final String KEY_PAGE = "pageEnabled"; //$NON-NLS-1$
private static final String VAL_EXP = "export"; //$NON-NLS-1$
private static final String VAL_TOOL = "toolEdit"; //$NON-NLS-1$
private static final String KEY_SRC = "isSource"; //$NON-NLS-1$
private static final String KEY_PREF = "checkPreference"; //$NON-NLS-1$
@Override
public boolean test(Object receiver, String property, Object[] args,
Object expectedValue) {
public boolean test(Object receiver, String property, Object[] args, Object expectedValue) {
if (KEY_SRC.equals(property)) {
if (receiver instanceof ITranslationUnit) {
return ((ITranslationUnit)receiver).isSourceUnit();
}
else if (receiver instanceof IFile) {
IFile file = (IFile)receiver;
return ((ITranslationUnit) receiver).isSourceUnit();
} else if (receiver instanceof IFile) {
IFile file = (IFile) receiver;
return CoreModel.isValidSourceUnitName(file.getProject(), file.getName());
}
} else if (KEY_PAGE.equals(property)
&& expectedValue instanceof String) {
String s = (String) expectedValue;
if (VAL_EXP.equalsIgnoreCase(s))
return CDTPrefUtil.getBool(CDTPrefUtil.KEY_EXPORT);
if (VAL_TOOL.equalsIgnoreCase(s))
return !CDTPrefUtil.getBool(CDTPrefUtil.KEY_NOTOOLM);
} else if (KEY_PREF.equals(property) && expectedValue instanceof String) {
boolean result = false;
final Pattern pat = Pattern.compile("(.*):(.*)=(.*)"); //$NON-NLS-1$
Matcher matcher = pat.matcher((String) expectedValue);
if (matcher.matches()) {
String pluginId = matcher.group(1);
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;
}