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

bug 328007: [sd90] Disablement of property pages depending on preference

This commit is contained in:
Andrew Gvozdev 2012-05-01 19:10:32 -04:00
parent 2b5e3e6a20
commit 5edeb05a5b
6 changed files with 106 additions and 28 deletions

View file

@ -502,11 +502,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

@ -534,7 +534,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>
@ -564,7 +564,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

@ -24,10 +24,13 @@ import org.eclipse.cdt.build.core.scannerconfig.ICfgScannerConfigBuilderInfo2Set
import org.eclipse.cdt.build.internal.core.scannerconfig.CfgDiscoveredPathManager;
import org.eclipse.cdt.build.internal.core.scannerconfig.CfgScannerConfigUtil;
import org.eclipse.cdt.build.internal.core.scannerconfig2.CfgScannerConfigProfileManager;
import org.eclipse.cdt.core.language.settings.providers.ScannerDiscoveryLegacySupport;
import org.eclipse.cdt.core.model.util.CDTListComparator;
import org.eclipse.cdt.core.settings.model.ICConfigurationDescription;
import org.eclipse.cdt.core.settings.model.ICResourceDescription;
import org.eclipse.cdt.core.settings.model.util.CDataUtil;
import org.eclipse.cdt.internal.ui.language.settings.providers.LanguageSettingsProvidersPage;
import org.eclipse.cdt.internal.ui.newui.StatusMessageLine;
import org.eclipse.cdt.make.core.MakeCorePlugin;
import org.eclipse.cdt.make.core.scannerconfig.IScannerConfigBuilderInfo2;
import org.eclipse.cdt.make.core.scannerconfig.IScannerConfigBuilderInfo2Set;
@ -46,7 +49,9 @@ import org.eclipse.cdt.managedbuilder.core.IInputType;
import org.eclipse.cdt.managedbuilder.core.IResourceInfo;
import org.eclipse.cdt.managedbuilder.core.ITool;
import org.eclipse.cdt.managedbuilder.core.IToolChain;
import org.eclipse.cdt.managedbuilder.core.ManagedBuildManager;
import org.eclipse.cdt.managedbuilder.internal.ui.Messages;
import org.eclipse.cdt.ui.CUIPlugin;
import org.eclipse.cdt.ui.newui.CDTPrefUtil;
import org.eclipse.cdt.utils.ui.controls.ControlFactory;
import org.eclipse.cdt.utils.ui.controls.TabFolderLayout;
@ -103,6 +108,7 @@ public class DiscoveryTab extends AbstractCBuildPropertyTab implements IBuildInf
private Button reportProblemsCheckBox;
private Combo profileComboBox;
private Composite profileOptionsComposite;
private Button clearButton;
private ICfgScannerConfigBuilderInfo2Set cbi;
private Map<InfoContext, IScannerConfigBuilderInfo2> baseInfoMap;
@ -116,6 +122,8 @@ public class DiscoveryTab extends AbstractCBuildPropertyTab implements IBuildInf
private DiscoveryPageWrapper wrapper = null;
private StatusMessageLine fStatusLine;
/*
* (non-Javadoc)
*
@ -184,6 +192,9 @@ public class DiscoveryTab extends AbstractCBuildPropertyTab implements IBuildInf
profileOptionsComposite.setLayoutData(gd);
profileOptionsComposite.setLayout(new TabFolderLayout());
fStatusLine = new StatusMessageLine(usercomp, SWT.LEFT, 2);
setEnablement();
sashForm.setWeights(DEFAULT_SASH_WEIGHTS);
}
@ -204,6 +215,7 @@ public class DiscoveryTab extends AbstractCBuildPropertyTab implements IBuildInf
buildInfo.setSelectedProfileId(id);
handleDiscoveryProfileChanged();
}
showStatusLine();
}
});
reportProblemsCheckBox = setupCheck(autoDiscoveryGroup,
@ -236,7 +248,7 @@ public class DiscoveryTab extends AbstractCBuildPropertyTab implements IBuildInf
Label clearLabel = ControlFactory.createLabel(autoDiscoveryGroup, Messages.DiscoveryTab_ClearDisoveredEntries);
// "Clear" button
Button clearButton = ControlFactory.createPushButton(autoDiscoveryGroup, Messages.DiscoveryTab_Clear);
clearButton = ControlFactory.createPushButton(autoDiscoveryGroup, Messages.DiscoveryTab_Clear);
GridData gd = (GridData) clearButton.getLayoutData();
gd.grabExcessHorizontalSpace = true;
//Bug 331783 - NLS: "Clear" button label in Makefile Project preferences truncated
@ -334,6 +346,37 @@ public class DiscoveryTab extends AbstractCBuildPropertyTab implements IBuildInf
} else {
setVisibility(Messages.DiscoveryTab_6);
}
setEnablement();
}
private void setEnablement() {
ICConfigurationDescription cfgDescription = page.getResDesc().getConfiguration();
boolean isEnabled = !LanguageSettingsProvidersPage.isLanguageSettingsProvidersEnabled(getProject()) || ScannerDiscoveryLegacySupport.isMbsLanguageSettingsProviderOn(cfgDescription);
scopeComboBox.setEnabled(isEnabled);
resTable.setEnabled(isEnabled);
boolean isSCDEnabled = autoDiscoveryCheckBox.getSelection();
reportProblemsCheckBox.setEnabled(isEnabled && isSCDEnabled);
autoDiscoveryCheckBox.setEnabled(isEnabled);
autoDiscoveryGroup.setEnabled(isEnabled);
clearButton.setEnabled(isEnabled);
showStatusLine();
}
private void showStatusLine() {
ICConfigurationDescription cfgDescription = page.getResDesc().getConfiguration();
boolean isEnabled = !LanguageSettingsProvidersPage.isLanguageSettingsProvidersEnabled(getProject()) || ScannerDiscoveryLegacySupport.isMbsLanguageSettingsProviderOn(cfgDescription);
IStatus status = null;
if (isEnabled) {
if (autoDiscoveryCheckBox.getSelection()) {
status = new Status(IStatus.WARNING, CUIPlugin.PLUGIN_ID, "This discovery method is deprecated, use 'Preprocessor Include Paths' instead.");
}
} else {
status = new Status(IStatus.INFO, CUIPlugin.PLUGIN_ID, "Managed Build language settings provider is not enabled (see 'Preprocessor Include Paths' page).");
}
fStatusLine.setErrorStatus(status);
}
private void setVisibility(String errMsg) {
@ -372,7 +415,13 @@ public class DiscoveryTab extends AbstractCBuildPropertyTab implements IBuildInf
buildInfo = (IScannerConfigBuilderInfo2) ti.getData("info"); //$NON-NLS-1$
String selectedProfileId = buildInfo.getSelectedProfileId();
iContext = (CfgInfoContext) ti.getData("cont"); //$NON-NLS-1$
autoDiscoveryCheckBox.setSelection(buildInfo.isAutoDiscoveryEnabled()
boolean autodiscoveryEnabled2 = buildInfo.isAutoDiscoveryEnabled();
if (autodiscoveryEnabled2) {
IConfiguration cfg = iContext.getConfiguration();
ICConfigurationDescription cfgDescription = ManagedBuildManager.getDescriptionForConfiguration(cfg);
autodiscoveryEnabled2 = ScannerDiscoveryLegacySupport.isLegacyScannerDiscoveryOn(cfgDescription);
}
autoDiscoveryCheckBox.setSelection(autodiscoveryEnabled2
&& !selectedProfileId.equals(ScannerConfigProfileManager.NULL_PROFILE_ID));
reportProblemsCheckBox.setSelection(buildInfo.isProblemReportingEnabled());

View file

@ -91,8 +91,10 @@ public class ScannerDiscoveryLegacySupport {
/**
* Check if legacy Scanner Discovery in MBS should be active.
* @noreference This is internal helper method to support compatibility with previous versions
* which is not intended to be referenced by clients.
*/
private static boolean isMbsLanguageSettingsProviderOn(ICConfigurationDescription cfgDescription) {
public static boolean isMbsLanguageSettingsProviderOn(ICConfigurationDescription cfgDescription) {
if (cfgDescription instanceof ILanguageSettingsProvidersKeeper) {
List<ILanguageSettingsProvider> lsProviders = ((ILanguageSettingsProvidersKeeper) cfgDescription).getLanguageSettingProviders();
for (ILanguageSettingsProvider lsp : lsProviders) {

View file

@ -3376,7 +3376,10 @@
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"/>
<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>
@ -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;
}