From 597c1dbc696c1c0b73c346b97151226e07689e64 Mon Sep 17 00:00:00 2001 From: mazab Date: Thu, 29 May 2014 11:36:04 +0200 Subject: [PATCH] Bug 436147. Changed the way of handling "Restore Defaults" to reset the values to default values instead of removing the options. Change-Id: I748206ab90aa07d161a437af0b6fc4e3d3a7161b Signed-off-by: mazab Reviewed-on: https://git.eclipse.org/r/27519 Tested-by: Hudson CI Reviewed-by: Elena Laskavaia --- .../internal/core/FolderInfo.java | 47 +++++++++++++------ 1 file changed, 33 insertions(+), 14 deletions(-) diff --git a/build/org.eclipse.cdt.managedbuilder.core/src/org/eclipse/cdt/managedbuilder/internal/core/FolderInfo.java b/build/org.eclipse.cdt.managedbuilder.core/src/org/eclipse/cdt/managedbuilder/internal/core/FolderInfo.java index 987b7c4cb33..3a6f865ddc8 100644 --- a/build/org.eclipse.cdt.managedbuilder.core/src/org/eclipse/cdt/managedbuilder/internal/core/FolderInfo.java +++ b/build/org.eclipse.cdt.managedbuilder.core/src/org/eclipse/cdt/managedbuilder/internal/core/FolderInfo.java @@ -36,6 +36,7 @@ import org.eclipse.cdt.managedbuilder.core.IBuildObjectProperties; import org.eclipse.cdt.managedbuilder.core.IBuildPropertiesRestriction; import org.eclipse.cdt.managedbuilder.core.IConfiguration; import org.eclipse.cdt.managedbuilder.core.IFolderInfo; +import org.eclipse.cdt.managedbuilder.core.IHoldsOptions; import org.eclipse.cdt.managedbuilder.core.IInputType; import org.eclipse.cdt.managedbuilder.core.IManagedConfigElement; import org.eclipse.cdt.managedbuilder.core.IManagedProject; @@ -47,6 +48,7 @@ import org.eclipse.cdt.managedbuilder.core.ITargetPlatform; 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.core.ManagedBuilderCorePlugin; import org.eclipse.cdt.managedbuilder.internal.buildproperties.BuildPropertyManager; import org.eclipse.cdt.managedbuilder.internal.dataprovider.BuildFolderData; import org.eclipse.cdt.managedbuilder.internal.dataprovider.BuildLanguageData; @@ -1325,28 +1327,45 @@ public class FolderInfo extends ResourceInfo implements IFolderInfo { toolChain.resolveProjectReferences(onLoad); } + /** + * Reset the options of the given holder to the default values + */ + private void resetOptionSettings(IHoldsOptions holder) { + IOption[] opts = holder.getOptions(); + for (IOption opt : opts) { + Object val = opt.getDefaultValue(); + if (val instanceof Boolean) { + ManagedBuildManager.setOption(toolChain.getParent(), holder, opt, (Boolean)val); + } else if (val instanceof String[]) { + ManagedBuildManager.setOption(toolChain.getParent(), holder, opt, (String[])val); + } else if (val instanceof String){ + ManagedBuildManager.setOption(toolChain.getParent(), holder, opt, (String)val); + } else if (val == null) { + holder.removeOption(opt); + } else { + ManagedBuilderCorePlugin.error("Unknown type of value " + val + " for " + opt); //$NON-NLS-1$ //$NON-NLS-2$ + } + } + } + public void resetOptionSettings() { - // We just need to remove all Options + // (Bug 438367) Removing all the options and relying on automatic creating when modifying/using the option + // will result in problems in the following cases: + // - When changing an option affects values of other options. + // - When the option has a FieldEditor that holds an instance of the option, that + // will result on having multiple copies of the option in some cases. + // Instead, will reset the value of each option to its default value. ITool[] tools = getTools(); IToolChain toolChain = getToolChain(); - IOption[] opts; + for (ITool tool : tools) { + resetOptionSettings(tool); + } + resetOptionSettings(toolChain); // Send out the event to notify the options that they are about to be removed. // Do not do this for the child resource configurations as they are handled when // the configuration itself is destroyed. // ManagedBuildManager.performValueHandlerEvent(this, IManagedOptionValueHandler.EVENT_CLOSE, false); - // Remove the configurations - for (ITool tool : tools) { - opts = tool.getOptions(); - for (IOption opt : opts) { - tool.removeOption(opt); - } - } - opts = toolChain.getOptions(); - for (IOption opt : opts) { - toolChain.removeOption(opt); - } - // rebuildNeeded = true; }