1
0
Fork 0
mirror of https://github.com/eclipse-cdt/cdt synced 2025-08-11 02:05:39 +02:00

Fix for a problem with the round-tripping of string options

This commit is contained in:
Sean Evoy 2004-03-23 16:31:21 +00:00
parent a8e503869c
commit 2ef3540b31

View file

@ -12,7 +12,10 @@ package org.eclipse.cdt.managedbuilder.ui.properties;
* **********************************************************************/ * **********************************************************************/
import java.util.ArrayList; import java.util.ArrayList;
import java.util.Arrays; import java.util.Arrays;
import java.util.HashMap;
import java.util.Iterator;
import java.util.List; import java.util.List;
import java.util.Set;
import org.eclipse.cdt.managedbuilder.core.BuildException; import org.eclipse.cdt.managedbuilder.core.BuildException;
import org.eclipse.cdt.managedbuilder.core.IConfiguration; import org.eclipse.cdt.managedbuilder.core.IConfiguration;
@ -37,6 +40,10 @@ public class BuildToolSettingsPage extends BuildSettingsPage {
// field editor that displays all the build options for a particular tool // field editor that displays all the build options for a particular tool
private MultiLineTextFieldEditor allOptionFieldEditor; private MultiLineTextFieldEditor allOptionFieldEditor;
private static final String DEFAULT_SEPERATOR = ";"; //$NON-NLS-1$ private static final String DEFAULT_SEPERATOR = ";"; //$NON-NLS-1$
// Map that holds all string options and its values
private HashMap stringOptionsMap;
// Map that holds all user object options and its values
private HashMap userObjsMap;
// Tool the settings belong to // Tool the settings belong to
private ITool tool; private ITool tool;
// all build options preference store id // all build options preference store id
@ -47,12 +54,12 @@ public class BuildToolSettingsPage extends BuildSettingsPage {
super(configuration); super(configuration);
this.tool = tool; this.tool = tool;
allOptionsId = tool.getId() + ".allOptions"; //$NON-NLS-1$ allOptionsId = tool.getId() + ".allOptions"; //$NON-NLS-1$
stringOptionsMap = new HashMap();
userObjsMap = new HashMap();
} }
/* /* (non-Javadoc)
* (non-Javadoc) * @see org.eclipse.jface.preference.IPreferencePage#computeSize()
*
* @see org.eclipse.jface.preference.PreferencePage#computeSize()
*/ */
public Point computeSize() { public Point computeSize() {
return super.computeSize(); return super.computeSize();
@ -102,8 +109,8 @@ public class BuildToolSettingsPage extends BuildSettingsPage {
/** /**
* Returns all the build options string * Returns all the build options string
* *
* @return @throws * @return String
* BuildException * @throws BuildException
*/ */
private String getToolFlags() throws BuildException { private String getToolFlags() throws BuildException {
ITool[] tools = configuration.getTools(); ITool[] tools = configuration.getTools();
@ -141,6 +148,8 @@ public class BuildToolSettingsPage extends BuildSettingsPage {
break; break;
case IOption.STRING : case IOption.STRING :
String val = getPreferenceStore().getString(option.getId()); String val = getPreferenceStore().getString(option.getId());
// add this string option value to the list
stringOptionsMap.put(option, val);
if (val.length() > 0) { if (val.length() > 0) {
buf.append(val + ITool.WHITE_SPACE); buf.append(val + ITool.WHITE_SPACE);
} }
@ -152,6 +161,8 @@ public class BuildToolSettingsPage extends BuildSettingsPage {
case IOption.OBJECTS : case IOption.OBJECTS :
String cmd = option.getCommand(); String cmd = option.getCommand();
listStr = getPreferenceStore().getString(option.getId()); listStr = getPreferenceStore().getString(option.getId());
if (cmd == null)
userObjsMap.put(option, listStr);
listVal = BuildToolsSettingsStore.parseString(listStr); listVal = BuildToolsSettingsStore.parseString(listStr);
for (int j = 0; j < listVal.length; j++) { for (int j = 0; j < listVal.length; j++) {
String temp = listVal[j]; String temp = listVal[j];
@ -216,62 +227,60 @@ public class BuildToolSettingsPage extends BuildSettingsPage {
for (int k = 0; k < options.length; ++k) { for (int k = 0; k < options.length; ++k) {
IOption opt = options[k]; IOption opt = options[k];
String name = opt.getId(); String name = opt.getId();
// check whether the option value is already exist // check whether the option value is "STRING" type
// and also change the preference store based on Iterator stringOptsIter = stringOptionsMap.values().iterator();
// the option value while (stringOptsIter.hasNext()) {
switch (opt.getValueType()) { if (((String) stringOptsIter.next()).indexOf(optionsArr[j]) != -1)
case IOption.BOOLEAN : optionValueExist = true;
if (opt.getCommand().equals(optionsArr[j])) { }
getPreferenceStore().setValue(opt.getId(), true); // check whether the option value is "OBJECTS" type
optionValueExist = true; Iterator userObjsIter = userObjsMap.values().iterator();
} while (userObjsIter.hasNext()) {
break; if (((String) userObjsIter.next()).indexOf(optionsArr[j]) != -1)
case IOption.ENUMERATED : optionValueExist = true;
String enum = ""; //$NON-NLS-1$ }
String[] enumValues = opt.getApplicableValues(); // if the value does not exist in string option or user objects
for (int i = 0; i < enumValues.length; i++) { // option
if (opt.getEnumCommand(enumValues[i]).equals( if (!optionValueExist) {
optionsArr[j])) { // check whether the option value is already exist
enum = enumValues[i]; // and also change the preference store based on
// the option value
switch (opt.getValueType()) {
case IOption.BOOLEAN :
if (opt.getCommand().equals(optionsArr[j])) {
getPreferenceStore()
.setValue(opt.getId(), true);
optionValueExist = true; optionValueExist = true;
} }
} break;
if (!enum.equals("")) //$NON-NLS-1$ case IOption.ENUMERATED :
getPreferenceStore().setValue(opt.getId(), enum); String enum = ""; //$NON-NLS-1$
break; String[] enumValues = opt.getApplicableValues();
case IOption.STRING : for (int i = 0; i < enumValues.length; i++) {
String str = getPreferenceStore() if (opt.getEnumCommand(enumValues[i]).equals(
.getString(opt.getId()); optionsArr[j])) {
if (alloptions.indexOf(str) == -1) { enum = enumValues[i];
getPreferenceStore().setValue(opt.getId(), ""); //$NON-NLS-1$ optionValueExist = true;
} }
if (str.indexOf(optionsArr[j]) != -1) { }
optionValueExist = true; if (!enum.equals("")) //$NON-NLS-1$
} getPreferenceStore()
break; .setValue(opt.getId(), enum);
case IOption.STRING_LIST : break;
case IOption.INCLUDE_PATH : case IOption.STRING_LIST :
case IOption.PREPROCESSOR_SYMBOLS : case IOption.INCLUDE_PATH :
case IOption.LIBRARIES : case IOption.PREPROCESSOR_SYMBOLS :
if (opt.getCommand() != null case IOption.LIBRARIES :
&& optionsArr[j].startsWith(opt.getCommand()) if (opt.getCommand() != null
&& !optionsList.contains(optionsArr[j])) { && optionsArr[j].startsWith(opt
optionsList.add(optionsArr[j]); .getCommand())) {
optionValueExist = true; optionsList.add(optionsArr[j]);
}
break;
case IOption.OBJECTS :
String userObjStr = getPreferenceStore().getString(
opt.getId());
String[] userObjs = BuildToolsSettingsStore
.parseString(userObjStr);
for (int m = 0; m < userObjs.length; m++) {
if (userObjs[m].equalsIgnoreCase(optionsArr[j]))
optionValueExist = true; optionValueExist = true;
} }
break; break;
default : default :
break; break;
}
} }
} }
// If the parsed string does not match with any previous option // If the parsed string does not match with any previous option
@ -280,6 +289,46 @@ public class BuildToolSettingsPage extends BuildSettingsPage {
addnOptions.append(optionsArr[j] + ITool.WHITE_SPACE); addnOptions.append(optionsArr[j] + ITool.WHITE_SPACE);
} }
} }
// check whether some of the "STRING" option value or "OBJECTS" type
// option value removed
// by the user from all build option field
Set set = stringOptionsMap.keySet();
for (int s = 0; s < set.size(); s++) {
Iterator iterator = set.iterator();
while (iterator.hasNext()) {
Object key = iterator.next();
String val = (String) stringOptionsMap.get(key);
if (alloptions.indexOf(val) == -1) {
StringBuffer buf = new StringBuffer();
String[] vals = val.split(WHITESPACE);
for (int t = 0; t < vals.length; t++) {
if (alloptions.indexOf(vals[t]) != -1)
buf.append(vals[t] + ITool.WHITE_SPACE);
}
getPreferenceStore().setValue(((IOption) key).getId(),
buf.toString().trim());
}
}
}
// "OBJECTS" type
Set objSet = userObjsMap.keySet();
for (int s = 0; s < objSet.size(); s++) {
Iterator iterator = objSet.iterator();
while (iterator.hasNext()) {
Object key = iterator.next();
String val = (String) userObjsMap.get(key);
ArrayList list = new ArrayList();
String[] vals = BuildToolsSettingsStore.parseString(val);
for (int t = 0; t < vals.length; t++) {
if (alloptions.indexOf(vals[t]) != -1)
list.add(vals[t]);
}
String listArr[] = new String[list.size()];
list.toArray(listArr);
String liststr = BuildToolsSettingsStore.createList(listArr);
getPreferenceStore().setValue(((IOption) key).getId(), liststr);
}
}
// Now update the preference store with parsed options // Now update the preference store with parsed options
// Get the options for this tool // Get the options for this tool
IOption[] options = tool.getOptions(); IOption[] options = tool.getOptions();
@ -377,34 +426,25 @@ public class BuildToolSettingsPage extends BuildSettingsPage {
// Transfer value from preference store to options // Transfer value from preference store to options
switch (option.getValueType()) { switch (option.getValueType()) {
case IOption.BOOLEAN : case IOption.BOOLEAN :
boolean boolVal = getPreferenceStore().getBoolean( boolean boolVal = getPreferenceStore().getBoolean(option.getId());
option.getId()); ManagedBuildManager.setOption(configuration, option, boolVal);
ManagedBuildManager.setOption(configuration, option,
boolVal);
break; break;
case IOption.ENUMERATED : case IOption.ENUMERATED :
String enumVal = getPreferenceStore().getString( String enumVal = getPreferenceStore().getString(option.getId());
option.getId()); ManagedBuildManager.setOption(configuration, option, enumVal);
ManagedBuildManager.setOption(configuration, option,
enumVal);
break; break;
case IOption.STRING : case IOption.STRING :
String strVal = getPreferenceStore().getString( String strVal = getPreferenceStore().getString(option.getId());
option.getId()); ManagedBuildManager.setOption(configuration, option, strVal);
ManagedBuildManager
.setOption(configuration, option, strVal);
break; break;
case IOption.STRING_LIST : case IOption.STRING_LIST :
case IOption.INCLUDE_PATH : case IOption.INCLUDE_PATH :
case IOption.PREPROCESSOR_SYMBOLS : case IOption.PREPROCESSOR_SYMBOLS :
case IOption.LIBRARIES : case IOption.LIBRARIES :
case IOption.OBJECTS : case IOption.OBJECTS :
String listStr = getPreferenceStore().getString( String listStr = getPreferenceStore().getString(option.getId());
option.getId()); String[] listVal = BuildToolsSettingsStore.parseString(listStr);
String[] listVal = BuildToolsSettingsStore ManagedBuildManager.setOption(configuration, option, listVal);
.parseString(listStr);
ManagedBuildManager.setOption(configuration, option,
listVal);
break; break;
default : default :
break; break;