1
0
Fork 0
mirror of https://github.com/eclipse-cdt/cdt synced 2025-07-24 01:15:29 +02:00

bug 300539: Add ability to specify filter-path to build-options that support browsing

Patch from Baltasar Belyavsky
This commit is contained in:
Andrew Gvozdev 2010-03-26 17:45:42 +00:00
parent 9f723276c7
commit 55d9c94968
7 changed files with 162 additions and 1 deletions

View file

@ -1306,6 +1306,13 @@ Additional special types exist to flag options of special relevance to the build
</restriction> </restriction>
</simpleType> </simpleType>
</attribute> </attribute>
<attribute name="browseFilterPath" type="string">
<annotation>
<documentation>
An optional value that specifies the default filter-path for the underlying file or directory browse-dialog. Macros in the value will be expanded. This attribute only applies when user chooses to browse the file-system.
</documentation>
</annotation>
</attribute>
<attribute name="browseFilterExtensions" type="string"> <attribute name="browseFilterExtensions" type="string">
<annotation> <annotation>
<documentation> <documentation>

View file

@ -12,6 +12,8 @@
*******************************************************************************/ *******************************************************************************/
package org.eclipse.cdt.managedbuilder.core; package org.eclipse.cdt.managedbuilder.core;
import org.eclipse.cdt.managedbuilder.macros.IOptionContextData;
/** /**
* Basic Tool / Toolchain Option type. * Basic Tool / Toolchain Option type.
* *
@ -76,6 +78,8 @@ public interface IOption extends IBuildObject {
// Schema attribute names for option elements // Schema attribute names for option elements
public static final String BROWSE_TYPE = "browseType"; //$NON-NLS-1$ public static final String BROWSE_TYPE = "browseType"; //$NON-NLS-1$
/** @since 7.0 */ /** @since 7.0 */
public static final String BROWSE_FILTER_PATH = "browseFilterPath"; //$NON-NLS-1$
/** @since 7.0 */
public static final String BROWSE_FILTER_EXTENSIONS = "browseFilterExtensions"; //$NON-NLS-1$ public static final String BROWSE_FILTER_EXTENSIONS = "browseFilterExtensions"; //$NON-NLS-1$
public static final String CATEGORY = "category"; //$NON-NLS-1$ public static final String CATEGORY = "category"; //$NON-NLS-1$
public static final String COMMAND = "command"; //$NON-NLS-1$ public static final String COMMAND = "command"; //$NON-NLS-1$
@ -139,6 +143,14 @@ public interface IOption extends IBuildObject {
*/ */
public IOption getSuperClass(); public IOption getSuperClass();
/**
* @param holder - the actual option-holder for the context-data. This holder
* is usually a subclass of this option's {@link #getOptionHolder() holder}.
* @return the option context-data to be used for macro resolution.
* @since 7.0
*/
public IOptionContextData getOptionContextData(IHoldsOptions holder);
/** /**
* @return If this option is defined as an enumeration, this function returns * @return If this option is defined as an enumeration, this function returns
* the list of possible values for that enum. * the list of possible values for that enum.
@ -165,6 +177,19 @@ public interface IOption extends IBuildObject {
*/ */
public void setBrowseType(int type); public void setBrowseType(int type);
/**
* @return the setting of the browseFilterPath attribute. For options of {@link #BROWSE_FILE} and {@link #BROWSE_DIR} types.
* @since 7.0
*/
public String getBrowseFilterPath();
/**
* Sets the browseFilterPath attribute. For options of {@link #BROWSE_FILE} and {@link #BROWSE_DIR} types.
* @param path - default filter-path for the underlying browse dialog
* @since 7.0
*/
public void setBrowseFilterPath(String path);
/** /**
* @return the setting of the browseFilterExtensions attribute. For options of {@link #BROWSE_FILE} type. * @return the setting of the browseFilterExtensions attribute. For options of {@link #BROWSE_FILE} type.
* @since 7.0 * @since 7.0

View file

@ -36,6 +36,8 @@ import org.eclipse.cdt.managedbuilder.core.ManagedBuilderCorePlugin;
import org.eclipse.cdt.managedbuilder.core.ManagedOptionValueHandler; import org.eclipse.cdt.managedbuilder.core.ManagedOptionValueHandler;
import org.eclipse.cdt.managedbuilder.core.OptionStringValue; import org.eclipse.cdt.managedbuilder.core.OptionStringValue;
import org.eclipse.cdt.managedbuilder.internal.enablement.OptionEnablementExpression; import org.eclipse.cdt.managedbuilder.internal.enablement.OptionEnablementExpression;
import org.eclipse.cdt.managedbuilder.internal.macros.OptionContextData;
import org.eclipse.cdt.managedbuilder.macros.IOptionContextData;
import org.eclipse.core.runtime.CoreException; import org.eclipse.core.runtime.CoreException;
import org.eclipse.core.runtime.IConfigurationElement; import org.eclipse.core.runtime.IConfigurationElement;
import org.eclipse.core.runtime.PluginVersionIdentifier; import org.eclipse.core.runtime.PluginVersionIdentifier;
@ -54,6 +56,7 @@ public class Option extends BuildObject implements IOption, IBuildPropertiesRest
// Managed Build model attributes // Managed Build model attributes
private String unusedChildren; private String unusedChildren;
private Integer browseType; private Integer browseType;
private String browseFilterPath;
private String[] browseFilterExtensions; private String[] browseFilterExtensions;
private List<OptionStringValue> builtIns; private List<OptionStringValue> builtIns;
private IOptionCategory category; private IOptionCategory category;
@ -201,6 +204,9 @@ public class Option extends BuildObject implements IOption, IBuildPropertiesRest
if (option.browseType != null) { if (option.browseType != null) {
browseType = new Integer(option.browseType.intValue()); browseType = new Integer(option.browseType.intValue());
} }
if (option.browseFilterPath != null) {
browseFilterPath = option.browseFilterPath;
}
if (option.browseFilterExtensions != null) { if (option.browseFilterExtensions != null) {
browseFilterExtensions = option.browseFilterExtensions.clone(); browseFilterExtensions = option.browseFilterExtensions.clone();
} }
@ -360,6 +366,9 @@ public class Option extends BuildObject implements IOption, IBuildPropertiesRest
browseType = new Integer(BROWSE_DIR); browseType = new Integer(BROWSE_DIR);
} }
// Get the browseFilterPath attribute
this.browseFilterPath = element.getAttribute(BROWSE_FILTER_PATH);
// Get the browseFilterExtensions attribute // Get the browseFilterExtensions attribute
String browseFilterExtensionsStr = element.getAttribute(BROWSE_FILTER_EXTENSIONS); String browseFilterExtensionsStr = element.getAttribute(BROWSE_FILTER_EXTENSIONS);
if (browseFilterExtensionsStr != null) { if (browseFilterExtensionsStr != null) {
@ -599,6 +608,11 @@ public class Option extends BuildObject implements IOption, IBuildPropertiesRest
} }
} }
// Get the browseFilterPath attribute
if (element.getAttribute(BROWSE_FILTER_PATH) != null) {
this.browseFilterPath = element.getAttribute(BROWSE_FILTER_PATH);
}
// Get the browseFilterExtensions attribute // Get the browseFilterExtensions attribute
if (element.getAttribute(BROWSE_FILTER_EXTENSIONS) != null) { if (element.getAttribute(BROWSE_FILTER_EXTENSIONS) != null) {
String browseFilterExtensionsStr = element.getAttribute(BROWSE_FILTER_EXTENSIONS); String browseFilterExtensionsStr = element.getAttribute(BROWSE_FILTER_EXTENSIONS);
@ -877,6 +891,11 @@ public class Option extends BuildObject implements IOption, IBuildPropertiesRest
element.setAttribute(BROWSE_TYPE, str); element.setAttribute(BROWSE_TYPE, str);
} }
// browse filter path
if (browseFilterPath != null) {
element.setAttribute(BROWSE_FILTER_PATH, browseFilterPath);
}
// browse filter extensions // browse filter extensions
if (browseFilterExtensions != null) { if (browseFilterExtensions != null) {
StringBuilder sb = new StringBuilder(); StringBuilder sb = new StringBuilder();
@ -930,6 +949,13 @@ public class Option extends BuildObject implements IOption, IBuildPropertiesRest
isDirty = false; isDirty = false;
} }
/* (non-Javadoc)
* @see org.eclipse.cdt.managedbuilder.core.IOption#getOptionContextData(org.eclipse.cdt.managedbuilder.core.IHoldsOptions)
*/
public IOptionContextData getOptionContextData(IHoldsOptions holder) {
return new OptionContextData(this, holder);
}
/* /*
* P A R E N T A N D C H I L D H A N D L I N G * P A R E N T A N D C H I L D H A N D L I N G
*/ */
@ -1011,6 +1037,20 @@ public class Option extends BuildObject implements IOption, IBuildPropertiesRest
return browseType.intValue(); return browseType.intValue();
} }
/* (non-Javadoc)
* @see org.eclipse.cdt.managedbuilder.core.IOption#getBrowseFilterPath()
*/
public String getBrowseFilterPath() {
if (browseFilterPath == null) {
if (superClass != null) {
return superClass.getBrowseFilterPath();
} else {
return null;
}
}
return browseFilterPath;
}
/* (non-Javadoc) /* (non-Javadoc)
* @see org.eclipse.cdt.managedbuilder.core.IOption#getBrowseFilterExtensions() * @see org.eclipse.cdt.managedbuilder.core.IOption#getBrowseFilterExtensions()
*/ */
@ -1743,6 +1783,19 @@ public class Option extends BuildObject implements IOption, IBuildPropertiesRest
} }
} }
/* (non-Javadoc)
* @see org.eclipse.cdt.managedbuilder.core.IOption#setBrowseFilterPath(java.lang.String)
*/
public void setBrowseFilterPath(String path) {
if (browseFilterPath == null || !(browseFilterPath.equals(path))) {
browseFilterPath = path;
if(!isExtensionElement()) {
isDirty = true;
rebuildState = true;
}
}
}
/* (non-Javadoc) /* (non-Javadoc)
* @see org.eclipse.cdt.managedbuilder.core.IOption#setBrowseFilterExtensions(java.lang.String[]) * @see org.eclipse.cdt.managedbuilder.core.IOption#setBrowseFilterExtensions(java.lang.String[])
*/ */

View file

@ -24,6 +24,7 @@ import org.eclipse.cdt.managedbuilder.core.IOptionApplicability;
import org.eclipse.cdt.managedbuilder.core.IOptionCategory; import org.eclipse.cdt.managedbuilder.core.IOptionCategory;
import org.eclipse.cdt.managedbuilder.core.ManagedBuildManager; import org.eclipse.cdt.managedbuilder.core.ManagedBuildManager;
import org.eclipse.cdt.managedbuilder.core.OptionStringValue; import org.eclipse.cdt.managedbuilder.core.OptionStringValue;
import org.eclipse.cdt.managedbuilder.macros.IOptionContextData;
import org.eclipse.core.runtime.IConfigurationElement; import org.eclipse.core.runtime.IConfigurationElement;
import org.eclipse.core.runtime.PluginVersionIdentifier; import org.eclipse.core.runtime.PluginVersionIdentifier;
import org.w3c.dom.Document; import org.w3c.dom.Document;
@ -293,6 +294,13 @@ public class OptionReference implements IOption {
} }
} }
/* (non-Javadoc)
* @see org.eclipse.cdt.managedbuilder.core.IOption#getOptionContextData(org.eclipse.cdt.managedbuilder.core.IHoldsOptions)
*/
public IOptionContextData getOptionContextData(IHoldsOptions holder) {
return option.getOptionContextData(holder);
}
/* (non-Javadoc) /* (non-Javadoc)
* @see org.eclipse.cdt.core.build.managed.IOption#getApplicableValues() * @see org.eclipse.cdt.core.build.managed.IOption#getApplicableValues()
*/ */
@ -489,6 +497,13 @@ public class OptionReference implements IOption {
return option.getBrowseType(); return option.getBrowseType();
} }
/* (non-Javadoc)
* @see org.eclipse.cdt.managedbuilder.core.IOption#getBrowseFilterPath()
*/
public String getBrowseFilterPath() {
return option.getBrowseFilterPath();
}
/* (non-Javadoc) /* (non-Javadoc)
* @see org.eclipse.cdt.managedbuilder.core.IOption#getBrowseFilterExtensions() * @see org.eclipse.cdt.managedbuilder.core.IOption#getBrowseFilterExtensions()
*/ */
@ -803,6 +818,12 @@ public class OptionReference implements IOption {
public void setBrowseType(int type) { public void setBrowseType(int type) {
} }
/* (non-Javadoc)
* @see org.eclipse.cdt.managedbuilder.core.IOption#setBrowseFilterPath(java.lang.String)
*/
public void setBrowseFilterPath(String path) {
}
/* (non-Javadoc) /* (non-Javadoc)
* @see org.eclipse.cdt.managedbuilder.core.IOption#setBrowseFilterExtensions(java.lang.String[]) * @see org.eclipse.cdt.managedbuilder.core.IOption#setBrowseFilterExtensions(java.lang.String[])
*/ */

View file

@ -12,6 +12,7 @@
*******************************************************************************/ *******************************************************************************/
package org.eclipse.cdt.managedbuilder.ui.properties; package org.eclipse.cdt.managedbuilder.ui.properties;
import java.io.File;
import java.util.ArrayList; import java.util.ArrayList;
import java.util.Collection; import java.util.Collection;
import java.util.HashMap; import java.util.HashMap;
@ -33,6 +34,8 @@ import org.eclipse.cdt.managedbuilder.core.ITool;
import org.eclipse.cdt.managedbuilder.core.IToolChain; import org.eclipse.cdt.managedbuilder.core.IToolChain;
import org.eclipse.cdt.managedbuilder.core.ManagedBuildManager; import org.eclipse.cdt.managedbuilder.core.ManagedBuildManager;
import org.eclipse.cdt.managedbuilder.internal.core.MultiResourceInfo; import org.eclipse.cdt.managedbuilder.internal.core.MultiResourceInfo;
import org.eclipse.cdt.managedbuilder.macros.BuildMacroException;
import org.eclipse.cdt.managedbuilder.macros.IBuildMacroProvider;
import org.eclipse.cdt.ui.newui.AbstractPage; import org.eclipse.cdt.ui.newui.AbstractPage;
import org.eclipse.jface.preference.BooleanFieldEditor; import org.eclipse.jface.preference.BooleanFieldEditor;
import org.eclipse.jface.preference.DirectoryFieldEditor; import org.eclipse.jface.preference.DirectoryFieldEditor;
@ -222,6 +225,15 @@ public class BuildOptionSettingsUI extends AbstractToolSettingUI {
switch (opt.getBrowseType()) { switch (opt.getBrowseType()) {
case IOption.BROWSE_DIR: { case IOption.BROWSE_DIR: {
stringField = new DirectoryFieldEditor(optId, nameStr, fieldEditorParent); stringField = new DirectoryFieldEditor(optId, nameStr, fieldEditorParent);
if(opt.getBrowseFilterPath() != null) {
try {
String filterPath = ManagedBuildManager.getBuildMacroProvider().resolveValue(opt.getBrowseFilterPath(),
null, null, IBuildMacroProvider.CONTEXT_OPTION, opt.getOptionContextData(holder));
((DirectoryFieldEditor)stringField).setFilterPath(new File(filterPath));
} catch(BuildMacroException bmx) {
ManagedBuilderUIPlugin.log(bmx);
}
}
} break; } break;
case IOption.BROWSE_FILE: { case IOption.BROWSE_FILE: {
@ -236,6 +248,15 @@ public class BuildOptionSettingsUI extends AbstractToolSettingUI {
return true; return true;
} }
}; };
if(opt.getBrowseFilterPath() != null) {
try {
String filterPath = ManagedBuildManager.getBuildMacroProvider().resolveValue(opt.getBrowseFilterPath(),
null, null, IBuildMacroProvider.CONTEXT_OPTION, opt.getOptionContextData(holder));
((FileFieldEditor)stringField).setFilterPath(new File(filterPath));
} catch(BuildMacroException bmx) {
ManagedBuilderUIPlugin.log(bmx);
}
}
((FileFieldEditor)stringField).setFileExtensions(opt.getBrowseFilterExtensions()); ((FileFieldEditor)stringField).setFileExtensions(opt.getBrowseFilterExtensions());
} break; } break;
@ -336,8 +357,17 @@ public class BuildOptionSettingsUI extends AbstractToolSettingUI {
String tooltipHoverStr = displayFixedTip ? null : tipStr; String tooltipHoverStr = displayFixedTip ? null : tipStr;
fieldEditor = new FileListControlFieldEditor(optId, nameStr, fieldEditor = new FileListControlFieldEditor(optId, nameStr,
tooltipHoverStr, contextId, fieldEditorParent, opt.getBrowseType()); tooltipHoverStr, contextId, fieldEditorParent, opt.getBrowseType());
if(opt.getBrowseFilterPath() != null) {
try {
String filterPath = ManagedBuildManager.getBuildMacroProvider().resolveValue(opt.getBrowseFilterPath(),
null, null, IBuildMacroProvider.CONTEXT_OPTION, opt.getOptionContextData(holder));
((FileListControlFieldEditor)fieldEditor).setFilterPath(filterPath);
} catch(BuildMacroException bmx) {
ManagedBuilderUIPlugin.log(bmx);
}
}
((FileListControlFieldEditor)fieldEditor).setFilterExtensions(opt.getBrowseFilterExtensions()); ((FileListControlFieldEditor)fieldEditor).setFilterExtensions(opt.getBrowseFilterExtensions());
if (pageHasToolTipBox) { if (pageHasToolTipBox) {
Label label = fieldEditor.getLabelControl(fieldEditorParent); Label label = fieldEditor.getLabelControl(fieldEditorParent);
label.setData(new TipInfo(nameStr,tipStr)); label.setData(new TipInfo(nameStr,tipStr));

View file

@ -142,6 +142,16 @@ public class FileListControlFieldEditor extends FieldEditor {
// this.values = parseString(value); // this.values = parseString(value);
} }
/**
* Sets the filter-path for the underlying Browse dialog. Only applies when browseType is 'file' or 'dir'.
* @param filterPath
*
* @since 7.0
*/
public void setFilterPath(String filterPath) {
list.setFilterPath(filterPath);
}
/** /**
* Sets the filter-extensions for the underlying Browse dialog. Only applies when browseType is 'file'. * Sets the filter-extensions for the underlying Browse dialog. Only applies when browseType is 'file'.
* @param filterExtensions * @param filterExtensions

View file

@ -305,6 +305,8 @@ public class FileListControl {
currentName = getText().getText(); currentName = getText().getText();
if(currentName != null && currentName.trim().length() != 0) { if(currentName != null && currentName.trim().length() != 0) {
dialog.setFilterPath(currentName); dialog.setFilterPath(currentName);
} else if(FileListControl.this.filterPath != null) {
dialog.setFilterPath(FileListControl.this.filterPath);
} }
dialog.setMessage(FILESYSTEM_DIR_DIALOG_MSG); dialog.setMessage(FILESYSTEM_DIR_DIALOG_MSG);
result = dialog.open(); result = dialog.open();
@ -318,6 +320,8 @@ public class FileListControl {
currentName = getText().getText(); currentName = getText().getText();
if (currentName != null && currentName.trim().length() != 0) { if (currentName != null && currentName.trim().length() != 0) {
browseDialog.setFilterPath(currentName); browseDialog.setFilterPath(currentName);
} else if (FileListControl.this.filterPath != null) {
browseDialog.setFilterPath(FileListControl.this.filterPath);
} }
if (FileListControl.this.filterExtensions != null) { if (FileListControl.this.filterExtensions != null) {
browseDialog.setFilterExtensions(FileListControl.this.filterExtensions); browseDialog.setFilterExtensions(FileListControl.this.filterExtensions);
@ -468,6 +472,7 @@ public class FileListControl {
// The type of browse support that is required // The type of browse support that is required
private int browseType; private int browseType;
private String filterPath;
private String[] filterExtensions; private String[] filterExtensions;
/** The base path that should be used when adding new resources */ /** The base path that should be used when adding new resources */
private IPath path = new Path(""); //$NON-NLS-1$ private IPath path = new Path(""); //$NON-NLS-1$
@ -959,6 +964,16 @@ public class FileListControl {
promptForDelete = type == BROWSE_FILE || type == BROWSE_DIR; promptForDelete = type == BROWSE_FILE || type == BROWSE_DIR;
} }
/**
* Sets the default filter-path for the underlying Browse dialog. Only applies when browseType is 'file' or 'dir'.
* @param filterPath
*
* @since 5.2
*/
public void setFilterPath(String filterPath) {
this.filterPath = filterPath;
}
/** /**
* Sets the filter-extensions for the underlying Browse dialog. Only applies when browseType is 'file'. * Sets the filter-extensions for the underlying Browse dialog. Only applies when browseType is 'file'.
* @param filterExtensions * @param filterExtensions