diff options
Diffstat (limited to 'core/org.eclipse.cdt.ui/browser/org/eclipse/cdt/ui')
8 files changed, 472 insertions, 919 deletions
diff --git a/core/org.eclipse.cdt.ui/browser/org/eclipse/cdt/ui/browser/typeinfo/AllTypesCache.java b/core/org.eclipse.cdt.ui/browser/org/eclipse/cdt/ui/browser/typeinfo/AllTypesCache.java deleted file mode 100644 index c8812ee1e57..00000000000 --- a/core/org.eclipse.cdt.ui/browser/org/eclipse/cdt/ui/browser/typeinfo/AllTypesCache.java +++ /dev/null @@ -1,483 +0,0 @@ -/******************************************************************************* - * Copyright (c) 2004 IBM Corporation and others. - * All rights reserved. This program and the accompanying materials - * are made available under the terms of the Common Public License v1.0 - * which accompanies this distribution, and is available at - * http://www.eclipse.org/legal/cpl-v10.html - * - * Contributors: - * IBM Corporation - initial API and implementation - * QNX Software Systems - adapted for use in CDT - *******************************************************************************/ -package org.eclipse.cdt.ui.browser.typeinfo; - -import java.util.Arrays; -import java.util.Collection; -import java.util.Comparator; -import java.util.Set; - -import org.eclipse.cdt.core.CCorePlugin; -import org.eclipse.cdt.core.model.CoreModel; -import org.eclipse.cdt.core.model.ElementChangedEvent; -import org.eclipse.cdt.core.model.ICElement; -import org.eclipse.cdt.core.model.ICElementDelta; -import org.eclipse.cdt.core.model.IElementChangedListener; -import org.eclipse.cdt.core.parser.ISourceElementCallbackDelegate; -import org.eclipse.cdt.core.search.BasicSearchResultCollector; -import org.eclipse.cdt.core.search.ICSearchConstants; -import org.eclipse.cdt.core.search.ICSearchPattern; -import org.eclipse.cdt.core.search.ICSearchScope; -import org.eclipse.cdt.core.search.IMatch; -import org.eclipse.cdt.core.search.OrPattern; -import org.eclipse.cdt.core.search.SearchEngine; -import org.eclipse.cdt.internal.ui.browser.util.ArrayUtil; -import org.eclipse.cdt.internal.ui.browser.util.ProgressMonitorMultiWrapper; -import org.eclipse.core.resources.IWorkspace; -import org.eclipse.core.runtime.CoreException; -import org.eclipse.core.runtime.IPath; -import org.eclipse.core.runtime.IProgressMonitor; -import org.eclipse.core.runtime.IStatus; -import org.eclipse.core.runtime.Status; -import org.eclipse.core.runtime.SubProgressMonitor; -import org.eclipse.core.runtime.jobs.ISchedulingRule; -import org.eclipse.core.runtime.jobs.Job; - -/** - * Manages a search cache for types in the workspace. Instead of returning objects of type <code>ICElement</code> - * the methods of this class returns a list of the lightweight objects <code>TypeInfo</code>. - * <P> - * AllTypesCache runs asynchronously using a background job to rebuild the cache as needed. - * If the cache becomes dirty again while the background job is running, the job is restarted. - * <P> - * If <code>getAllTypes</code> is called in response to a user action, a progress dialog is shown. - * If called before the background job has finished, getAllTypes waits - * for the completion of the background job. - */ -public class AllTypesCache { - - /** - * Background job for filling the type cache. - * @see org.eclipse.core.runtime.jobs.Job - * @since 3.0 - */ - private static class TypeCacherJob extends Job { - - /** - * An "identity rule" that forces jobs to be queued. - * @see org.eclipse.core.runtime.jobs.ISchedulingRule - * @since 3.0 - */ - final static ISchedulingRule MUTEX_RULE= new ISchedulingRule() { - public boolean contains(ISchedulingRule rule) { - return rule == this; - } - public boolean isConflicting(ISchedulingRule rule) { - return rule == this; - } - }; - - /** - * A comparator for simple type names - */ - private static class TypeNameComparator implements Comparator { - public int compare(Object o1, Object o2) { - return ((TypeInfo)o1).getName().compareTo(((TypeInfo)o2).getName()); - } - } - - /** - * A search result collector for type info. - * @see org.eclipse.cdt.core.search.ICSearchResultCollector - */ - private static class TypeSearchResultCollector extends BasicSearchResultCollector { - - public TypeSearchResultCollector() { - super(); - } - - public TypeSearchResultCollector(IProgressMonitor monitor) { - super(monitor); - } - - public IMatch createMatch(Object fileResource, int start, int end, ISourceElementCallbackDelegate node, IPath realPath ) - { - TypeInfo result= new TypeInfo(); - return super.createMatch( result, fileResource, start, end, node, realPath); - } - - public boolean acceptMatch(IMatch match) throws CoreException { - // filter out unnamed structs - TypeInfo result= (TypeInfo) match; - String name= result.getName(); - if (name == null || name.length() == 0) - return false; - - // make sure we've got a valid type - if (!TypeInfo.isValidCElementType(result.getElementType())) - return false; - - return super.acceptMatch(match); - } - } - - /** - * Constant identifying the job family identifier for the background job. - * @see IJobManager#join(Object, IProgressMonitor) - * @since 3.0 - */ - public static final Object FAMILY= new Object(); - - final static Comparator TYPE_COMPARATOR= new TypeNameComparator(); - - private ProgressMonitorMultiWrapper progressMonitor; - - public TypeCacherJob() { - super(TypeInfoMessages.getString("TypeCacherJob.jobName")); //$NON-NLS-1$ - setPriority(BUILD); - setSystem(true); - //setRule(MUTEX_RULE); - } - - /* (non-Javadoc) - * @see org.eclipse.core.internal.jobs.InternalJob#belongsTo(java.lang.Object) - */ - public boolean belongsTo(Object family) { - return family == FAMILY; - } - - /* (non-Javadoc) - * @see org.eclipse.core.runtime.jobs.Job#shouldRun() - */ - public boolean shouldRun() { - return isCacheDirty(); - } - - /* (non-Javadoc) - * @see org.eclipse.core.runtime.jobs.Job#run(IProgressMonitor) - */ - public IStatus run(IProgressMonitor monitor) { - progressMonitor= new ProgressMonitorMultiWrapper(monitor); - progressMonitor.beginTask(TypeInfoMessages.getString("TypeCacherJob.taskName"), 100); //$NON-NLS-1$ - - SubProgressMonitor subMonitor= new SubProgressMonitor(progressMonitor, 100); - TypeSearchResultCollector collector= new TypeSearchResultCollector(subMonitor); - - IWorkspace workspace= CCorePlugin.getWorkspace(); - if (workspace == null) { - return Status.CANCEL_STATUS; - } - - ICSearchScope scope= SearchEngine.createWorkspaceScope(); - SearchEngine engine= new SearchEngine(); - - ICSearchPattern pattern= createSearchPattern(); - try { - flushCache(); - // start the search engine - if (progressMonitor.isCanceled()) - throw new InterruptedException(); - engine.search(workspace, pattern, scope, collector, true); - if (progressMonitor.isCanceled()) - throw new InterruptedException(); - progressMonitor.done(); - } catch(InterruptedException ex) { - return Status.CANCEL_STATUS; - } finally { - progressMonitor= null; - } - - Set searchResults= collector.getSearchResults(); - - if (searchResults != null) { - TypeInfo[] result= (TypeInfo[]) searchResults.toArray(new TypeInfo[searchResults.size()]); - Arrays.sort(result, TYPE_COMPARATOR); - setCache(result); - } - else { - TypeInfo[] result= new TypeInfo[0]; - setCache(result); - } - return Status.OK_STATUS; - } - - /* - * creates a search pattern based on the cache types - */ - private ICSearchPattern createSearchPattern() { - OrPattern pattern= new OrPattern(); - int[] types= getCacheTypes(); - for (int i= 0; i < types.length; ++i) { - switch (types[i]) { - case ICElement.C_NAMESPACE: - pattern.addPattern(SearchEngine.createSearchPattern("*", ICSearchConstants.NAMESPACE, ICSearchConstants.DECLARATIONS, false)); //$NON-NLS-1$ - break; - - case ICElement.C_CLASS: // fall through - case ICElement.C_TEMPLATE_CLASS: - pattern.addPattern(SearchEngine.createSearchPattern("*", ICSearchConstants.CLASS, ICSearchConstants.DECLARATIONS, false)); //$NON-NLS-1$ - break; - - case ICElement.C_STRUCT: // fall through - case ICElement.C_TEMPLATE_STRUCT: - pattern.addPattern(SearchEngine.createSearchPattern("*", ICSearchConstants.STRUCT, ICSearchConstants.DECLARATIONS, false)); //$NON-NLS-1$ - break; - - case ICElement.C_UNION: // fall through - case ICElement.C_TEMPLATE_UNION: - pattern.addPattern(SearchEngine.createSearchPattern("*", ICSearchConstants.UNION, ICSearchConstants.DECLARATIONS, false)); //$NON-NLS-1$ - break; - - case ICElement.C_ENUMERATION: - pattern.addPattern(SearchEngine.createSearchPattern("*", ICSearchConstants.ENUM, ICSearchConstants.DECLARATIONS, false)); //$NON-NLS-1$ - break; - - case ICElement.C_TYPEDEF: - pattern.addPattern(SearchEngine.createSearchPattern("*", ICSearchConstants.TYPEDEF, ICSearchConstants.DECLARATIONS, false)); //$NON-NLS-1$ - break; - - default: - break; - } - } - return pattern; - } - - /** - * Forwards progress info to the progress monitor and - * blocks until the job is finished. - * - * @param monitor Optional progress monitor. - * @throws InterruptedException - * - * @see Job#join - */ - public void join(IProgressMonitor monitor) throws InterruptedException { - if (progressMonitor != null) - progressMonitor.addProgressMonitor(monitor); - super.join(); - } - } - - /** - * Listener for changes to CModel. - * @see org.eclipse.cdt.core.model.IElementChangedListener - * @since 3.0 - */ - private static class TypeCacheDeltaListener implements IElementChangedListener { - /* - * @see IElementChangedListener#elementChanged - */ - public void elementChanged(ElementChangedEvent event) { - //TODO optimization: calculate deltas per file and - // update the cache selectively - boolean needsFlushing= processDelta(event.getDelta()); - if (needsFlushing) { - // mark cache as dirty and reschedule the - // background job - setCacheDirty(); - if (fgJob.getState() == Job.RUNNING) - fgJob.cancel(); - fgJob.setPriority(Job.BUILD); - fgJob.schedule(); - } - } - - /* - * returns true if the cache needs to be flushed - */ - private boolean processDelta(ICElementDelta delta) { - ICElement elem= delta.getElement(); - int pathEntryChanged= ICElementDelta.F_ADDED_PATHENTRY_SOURCE | ICElementDelta.F_REMOVED_PATHENTRY_SOURCE | - ICElementDelta.F_CHANGED_PATHENTRY_INCLUDE | ICElementDelta.F_CHANGED_PATHENTRY_MACRO; - boolean isAddedOrRemoved= (delta.getKind() != ICElementDelta.CHANGED) - || ((delta.getFlags() & pathEntryChanged) != 0); - - switch (elem.getElementType()) { - case ICElement.C_MODEL: - case ICElement.C_PROJECT: - case ICElement.C_CCONTAINER: - case ICElement.C_NAMESPACE: - case ICElement.C_TEMPLATE_CLASS: - case ICElement.C_CLASS: - case ICElement.C_STRUCT: - case ICElement.C_UNION: - case ICElement.C_ENUMERATION: - case ICElement.C_TYPEDEF: - case ICElement.C_INCLUDE: - case ICElement.C_UNIT: - if (isAddedOrRemoved) { - return true; - } - return processChildrenDelta(delta); - default: - // fields, methods, imports ect - return false; - } - } - - private boolean isPossibleStructuralChange(int flags) { - return (flags & (ICElementDelta.F_CONTENT | ICElementDelta.F_FINE_GRAINED)) == ICElementDelta.F_CONTENT; - } - - private boolean processChildrenDelta(ICElementDelta delta) { - ICElementDelta[] children= delta.getAffectedChildren(); - for (int i= 0; i < children.length; i++) { - if (processDelta(children[i])) { - return true; - } - } - return false; - } - } - - private static final int INITIAL_DELAY= 5000; - private static final TypeCacherJob fgJob= new TypeCacherJob(); - private static final TypeCacheDeltaListener fgDeltaListener= new TypeCacheDeltaListener(); - private static int[] fgCacheTypes= TypeInfo.getAllCElementTypes(); - private static TypeInfo[] fgCacheData; - private static int fgNumberOfCacheFlushes; - private static boolean cacheIsDirty= true; - - /** - * Initializes the AllTypesCache service. - */ - public static void initialize() { - // add delta listener - CoreModel.getDefault().addElementChangedListener(fgDeltaListener); - - // schedule job to run after INITIAL_DELAY - if (fgJob.getState() != Job.RUNNING) { - fgJob.setPriority(Job.BUILD); - fgJob.schedule(INITIAL_DELAY); - } - } - - /** - * Terminates the service provided by AllTypesCache. - */ - public static void terminate() { - // remove delta listener - CoreModel.getDefault().removeElementChangedListener(fgDeltaListener); - - // terminate background job - fgJob.cancel(); - } - - /* - * Sets the cache contents. - */ - private static synchronized void setCache(TypeInfo[] cache) { - fgCacheData= cache; - cacheIsDirty= false; - } - - /* - * Gets the cache contents. - */ - private static synchronized TypeInfo[] getCache() { - return fgCacheData; - } - - /* - * Clears the cache. - */ - private static synchronized void flushCache() { - fgCacheData= null; - ++fgNumberOfCacheFlushes; - cacheIsDirty= true; - } - - /* - * Marks cache as dirty. - */ - private static synchronized void setCacheDirty() { - cacheIsDirty= true; - } - - /* - * Tests if cache is dirty. - */ - private static synchronized boolean isCacheDirty() { - return cacheIsDirty; - } - - /* - * Sets which types are stored in the cache. - */ - private static synchronized void setCacheTypes(int[] cElementTypes) { - fgCacheTypes= ArrayUtil.clone(cElementTypes); - } - - /* - * Gets types stored in the cache. - */ - private static synchronized int[] getCacheTypes() { - return fgCacheTypes; - } - - /** - * Returns all types in the given scope, matching the given filter. - * @param filter Filter for the type info. - * @param monitor Progress monitor. - * @param typesFound The resulting <code>TypeInfo</code> elements are added to this collection - */ - public static void getTypes(ICSearchScope scope, ITypeInfoFilter filter, IProgressMonitor monitor, Collection typesFound) { - TypeInfo[] allTypes= getAllTypes(filter, monitor); - if (allTypes != null) { - boolean isWorkspaceScope= scope.equals(SearchEngine.createWorkspaceScope()); - for (int i= 0; i < allTypes.length; i++) { - TypeInfo info= allTypes[i]; - if (isWorkspaceScope || info.isEnclosed(scope)) { - if (filter.match(info)) - typesFound.add(info); - } - } - } - } - - /** - * Returns all types in the workspace. The returned array must not be - * modified. The elements in the array are sorted by simple type name. - */ - public static TypeInfo[] getAllTypes(ITypeInfoFilter filter, IProgressMonitor monitor) { - - // check if requested types are in cache - if (!ArrayUtil.containsAll(getCacheTypes(), filter.getCElementTypes())) - { - // mark cache dirty and cancel the running job - setCacheDirty(); - if (fgJob.getState() == Job.RUNNING) - fgJob.cancel(); - setCacheTypes(filter.getCElementTypes()); - } - - if (isCacheDirty()) { - // start job if not already running - if (fgJob.getState() != Job.RUNNING) { - // boost priority since action was user-initiated - fgJob.setPriority(Job.SHORT); - fgJob.schedule(); - } - - // wait for job to finish - try { - fgJob.join(monitor); - if (monitor != null) - monitor.done(); - } catch (InterruptedException ex) { - return null; - } - } - return getCache(); - } - - /** - * Returns true if the type cache is up to date. - */ - public static boolean isCacheUpToDate(ITypeInfoFilter filter) { - // check if requested types are in cache - if (!ArrayUtil.containsAll(getCacheTypes(), filter.getCElementTypes())) - return false; - return !isCacheDirty(); - } -} diff --git a/core/org.eclipse.cdt.ui/browser/org/eclipse/cdt/ui/browser/typeinfo/ITypeInfo.java b/core/org.eclipse.cdt.ui/browser/org/eclipse/cdt/ui/browser/typeinfo/ITypeInfo.java deleted file mode 100644 index 2621ab982a4..00000000000 --- a/core/org.eclipse.cdt.ui/browser/org/eclipse/cdt/ui/browser/typeinfo/ITypeInfo.java +++ /dev/null @@ -1,76 +0,0 @@ -/******************************************************************************* - * Copyright (c) 2004 QNX Software Systems and others. - * All rights reserved. This program and the accompanying materials - * are made available under the terms of the Common Public License v1.0 - * which accompanies this distribution, and is available at - * http://www.eclipse.org/legal/cpl-v10.html - * - * Contributors: - * QNX Software Systems - initial API and implementation - *******************************************************************************/ -package org.eclipse.cdt.ui.browser.typeinfo; - -import org.eclipse.cdt.core.model.ICElement; -import org.eclipse.cdt.core.search.ICSearchScope; -import org.eclipse.cdt.core.search.IMatch; - -/** - * Type information. - */ -public interface ITypeInfo extends IMatch { - - /** - * Returns true if type is enclosed in the given scope - */ - public boolean isEnclosed(ICSearchScope scope); - - /** - * Returns true if the type is a low-level system type. - * e.g. __FILE - */ - public boolean isSystemType(); - - /** - * Gets the enclosing type names. - */ - public String[] getEnclosingNames(); - - /** - * Gets the filename where this type is located. - */ - public String getFileName(); - - /** - * Gets the file path where this type is located. - */ - public String getFilePath(); - - /** - * Gets the extension of the file where this type is located. - */ - public String getFileExtension(); - - /** - * Gets the type qualified name: Includes enclosing type names, but - * not filename. Identifiers are separated by colons. - */ - public String getQualifiedName(); - - /** - * Gets the fully qualified type container name: Filename or - * enclosing type name with filename. - * All identifiers are separated by colons. - */ - public String getQualifiedParentName(); - - /** - * Gets the fully qualified type name: Includes enclosing type names and - * filename. All identifiers are separated by colons. - */ - public String getFullyQualifiedName(); - - /** - * Gets the CElement which corresponds to this type. - */ - public ICElement getCElement(); -} diff --git a/core/org.eclipse.cdt.ui/browser/org/eclipse/cdt/ui/browser/typeinfo/ITypeInfoFilter.java b/core/org.eclipse.cdt.ui/browser/org/eclipse/cdt/ui/browser/typeinfo/ITypeInfoFilter.java deleted file mode 100644 index e4895d22ab7..00000000000 --- a/core/org.eclipse.cdt.ui/browser/org/eclipse/cdt/ui/browser/typeinfo/ITypeInfoFilter.java +++ /dev/null @@ -1,36 +0,0 @@ -/******************************************************************************* - * Copyright (c) 2004 QNX Software Systems and others. - * All rights reserved. This program and the accompanying materials - * are made available under the terms of the Common Public License v1.0 - * which accompanies this distribution, and is available at - * http://www.eclipse.org/legal/cpl-v10.html - * - * Contributors: - * QNX Software Systems - initial API and implementation - *******************************************************************************/ -package org.eclipse.cdt.ui.browser.typeinfo; - -/** - * Filter for type info. - */ -public interface ITypeInfoFilter { - - /** - * Gets the C types handled by this filter. - * - * @return An array of ICElement types. - * - */ - public int[] getCElementTypes(); - - /** - * Matches type info against filter. - * - * @param info The object to filter. - * @return <code>true</code> if successful match. - */ - public boolean match(ITypeInfo info); - /** - * Returns <code>true</code> if <code>info</code> matches the filter. - */ -} diff --git a/core/org.eclipse.cdt.ui/browser/org/eclipse/cdt/ui/browser/typeinfo/TypeInfo.java b/core/org.eclipse.cdt.ui/browser/org/eclipse/cdt/ui/browser/typeinfo/TypeInfo.java deleted file mode 100644 index 1bd7d00848d..00000000000 --- a/core/org.eclipse.cdt.ui/browser/org/eclipse/cdt/ui/browser/typeinfo/TypeInfo.java +++ /dev/null @@ -1,210 +0,0 @@ -/******************************************************************************* - * Copyright (c) 2004 QNX Software Systems and others. - * All rights reserved. This program and the accompanying materials - * are made available under the terms of the Common Public License v1.0 - * which accompanies this distribution, and is available at - * http://www.eclipse.org/legal/cpl-v10.html - * - * Contributors: - * QNX Software Systems - initial API and implementation - *******************************************************************************/ -package org.eclipse.cdt.ui.browser.typeinfo; - -import java.util.ArrayList; - -import org.eclipse.cdt.core.model.CoreModel; -import org.eclipse.cdt.core.model.ICElement; -import org.eclipse.cdt.core.model.IParent; -import org.eclipse.cdt.core.search.BasicSearchMatch; -import org.eclipse.cdt.core.search.ICSearchScope; -import org.eclipse.cdt.internal.core.index.StringMatcher; -import org.eclipse.cdt.internal.ui.browser.util.ArrayUtil; -import org.eclipse.core.resources.IFile; -import org.eclipse.core.resources.IResource; - - -/** - * To change the template for this generated type comment go to - * Window>Preferences>Java>Code Generation>Code and Comments - */ -public class TypeInfo extends BasicSearchMatch implements ITypeInfo -{ - private final static int[] cElementTypes= { - ICElement.C_NAMESPACE, - ICElement.C_CLASS, - ICElement.C_TEMPLATE_CLASS, - ICElement.C_STRUCT, - ICElement.C_TEMPLATE_STRUCT, - ICElement.C_UNION, - ICElement.C_TEMPLATE_UNION, - ICElement.C_ENUMERATION, - ICElement.C_TYPEDEF - }; - - public static int[] getAllCElementTypes() { - return cElementTypes; - } - - public static boolean isValidCElementType(int type) { - return ArrayUtil.contains(cElementTypes, type); - } - - private final static String scopeResolutionOperator= "::"; //$NON-NLS-1$ - private final static String fileScopeSeparator= " : "; //$NON-NLS-1$ - private static final StringMatcher fSystemTypeMatcher= new StringMatcher("_*", true, false); //$NON-NLS-1$ - - public TypeInfo() { - super(); - } - - public boolean isEnclosed(ICSearchScope scope) { - return scope.encloses(getFilePath()); - } - - public boolean isSystemType() { - // recognized low-level system types eg __FILE - String[] names= getEnclosingNames(); - if (names != null) { - for (int i= 0; i < names.length; ++i) { - if (fSystemTypeMatcher.match(names[i])) - return true; - } - } - return fSystemTypeMatcher.match(getName()); - } - - public String getFileName() { - if (resource != null) - return resource.getName(); - else if (path != null) - return path.lastSegment(); - else - return null; - } - - public String getFilePath() { - if (resource != null) - return resource.getFullPath().toString(); - else if (path != null) - return path.toString(); - else - return null; - } - - public String getFileExtension() { - if (resource != null) - return resource.getFileExtension(); - else if (path != null) - return path.getFileExtension(); - else - return null; - } - - public String getQualifiedParentName() { - StringBuffer buf= new StringBuffer(); - String fileName = getFileName(); - if (fileName != null && fileName.length() > 0) - buf.append(fileName); - String parentName = getParentName(); - if (parentName != null && parentName.length() > 0) { - buf.append(fileScopeSeparator); //$NON-NLS-1$ - buf.append(parentName); - } - return buf.toString(); - } - - public String getFullyQualifiedName() { - StringBuffer buf= new StringBuffer(); - String fileName = getFileName(); - if (fileName != null && fileName.length() > 0) - buf.append(fileName); - String parentName = getParentName(); - if (parentName != null && parentName.length() > 0) { - buf.append(fileScopeSeparator); //$NON-NLS-1$ - buf.append(parentName); - buf.append(scopeResolutionOperator); //$NON-NLS-1$ - } - String name = getName(); - if (name != null && name.length() > 0) - buf.append(name); - return buf.toString(); - } - - public String getQualifiedName() { - StringBuffer buf= new StringBuffer(); - String parentName = getParentName(); - if (parentName != null && parentName.length() > 0) { - buf.append(parentName); - buf.append(scopeResolutionOperator); //$NON-NLS-1$ - } - String name = getName(); - if (name != null && name.length() > 0) - buf.append(name); - return buf.toString(); - } - - public String[] getEnclosingNames() { - //TODO pull up this method into BasicSearchMatch - //since it already has access to this info - String parentName= getParentName(); - if (parentName == null) - return null; - - ArrayList names= new ArrayList(5); - int lastIndex= 0; - String nextName; - int qualifierIndex= parentName.indexOf(scopeResolutionOperator, 0); - while (qualifierIndex >= 0) { - nextName= parentName.substring(lastIndex, qualifierIndex); - lastIndex= qualifierIndex + scopeResolutionOperator.length(); - names.add(nextName); - qualifierIndex= parentName.indexOf(scopeResolutionOperator, lastIndex); - } - nextName= parentName.substring(lastIndex); - names.add(nextName); - - return (String[]) names.toArray(new String[names.size()]); - } - - public String toString() { - return getFullyQualifiedName(); - } - - private boolean matchesCType(ICElement celement, String name) { - if (isValidCElementType(celement.getElementType())) - return celement.getElementName().equals(name); - return false; - } - - private ICElement findCElement(ICElement celement, String name) { - if (matchesCType(celement, name)) - return celement; - else if (celement instanceof IParent) { - ICElement[] children = ((IParent)celement).getChildren(); - for (int i = 0; i < children.length; i++) { - if (matchesCType(children[i], name)) - return children[i]; - } - } - return null; - } - - public ICElement getCElement() { - if (resource != null && resource.getType() == IResource.FILE) { - ICElement parentElement= CoreModel.getDefault().create((IFile)resource); - if (parentElement instanceof IParent) { - String[] names= getEnclosingNames(); - if (names != null) { - for (int i= 0; i < names.length; ++i) { - parentElement= findCElement(parentElement, names[i]); - if (parentElement == null) - break; - } - } - if (parentElement != null) - return findCElement(parentElement, getName()); - } - } - return null; - } -} diff --git a/core/org.eclipse.cdt.ui/browser/org/eclipse/cdt/ui/browser/typeinfo/TypeInfoFilter.java b/core/org.eclipse.cdt.ui/browser/org/eclipse/cdt/ui/browser/typeinfo/TypeInfoFilter.java deleted file mode 100644 index 81a24f9209b..00000000000 --- a/core/org.eclipse.cdt.ui/browser/org/eclipse/cdt/ui/browser/typeinfo/TypeInfoFilter.java +++ /dev/null @@ -1,43 +0,0 @@ -/******************************************************************************* - * Copyright (c) 2004 QNX Software Systems and others. - * All rights reserved. This program and the accompanying materials - * are made available under the terms of the Common Public License v1.0 - * which accompanies this distribution, and is available at - * http://www.eclipse.org/legal/cpl-v10.html - * - * Contributors: - * QNX Software Systems - initial API and implementation - *******************************************************************************/ -package org.eclipse.cdt.ui.browser.typeinfo; - -import org.eclipse.cdt.internal.ui.browser.util.ArrayUtil; - -/** - * The default type filter. - */ -public class TypeInfoFilter implements ITypeInfoFilter { - - public int[] getCElementTypes() { - return TypeInfo.getAllCElementTypes(); - } - - public TypeInfoFilter() { - } - - protected boolean hideSystemTypes() { - return true; - } - - public boolean match(ITypeInfo info) { - // check if type is handled - if (!ArrayUtil.contains(getCElementTypes(), info.getElementType())) - return false; - - // filter out low-level system types eg __FILE - //TODO make this a preferences option - if (hideSystemTypes() && info.isSystemType()) - return false; - - return true; - } -} diff --git a/core/org.eclipse.cdt.ui/browser/org/eclipse/cdt/ui/browser/typeinfo/TypeInfoLabelProvider.java b/core/org.eclipse.cdt.ui/browser/org/eclipse/cdt/ui/browser/typeinfo/TypeInfoLabelProvider.java index 89dcb588ab2..091f3946395 100644 --- a/core/org.eclipse.cdt.ui/browser/org/eclipse/cdt/ui/browser/typeinfo/TypeInfoLabelProvider.java +++ b/core/org.eclipse.cdt.ui/browser/org/eclipse/cdt/ui/browser/typeinfo/TypeInfoLabelProvider.java @@ -11,9 +11,11 @@ *******************************************************************************/ package org.eclipse.cdt.ui.browser.typeinfo; +import org.eclipse.cdt.core.browser.ITypeInfo; import org.eclipse.cdt.core.model.CoreModel; import org.eclipse.cdt.core.model.ICElement; import org.eclipse.cdt.internal.ui.CPluginImages; +import org.eclipse.core.runtime.IPath; import org.eclipse.jface.viewers.LabelProvider; import org.eclipse.swt.graphics.Image; @@ -90,32 +92,57 @@ public class TypeInfoLabelProvider extends LabelProvider { } if (isSet(SHOW_ROOT_POSTFIX)) { - String path= typeRef.getFilePath(); - if (path != null && path.length() > 0) { + IPath path= typeRef.getPath(); + if (path != null) { buf.append(TypeInfoMessages.getString("TypeInfoLabelProvider.dash"));//$NON-NLS-1$ - buf.append(path); + buf.append(path.toString()); } } return buf.toString(); } - private Image getFileIcon(ITypeInfo typeRef) + /* non java-doc + * @see ILabelProvider#getImage + */ + public Image getImage(Object element) { + if (!(element instanceof ITypeInfo)) + return super.getImage(element); + + ITypeInfo typeRef= (ITypeInfo) element; + if (isSet(SHOW_TYPE_CONTAINER_ONLY)) { + return getContainerIcon(typeRef); + } else if (isSet(SHOW_FILENAME_ONLY)) { + return getFileIcon(typeRef.getPath()); + } else { + return getTypeIcon(typeRef.getType()); + } + } + + public static Image getContainerIcon(ITypeInfo typeRef) { - String ext = typeRef.getFileExtension(); - if (ext != null) { - String[] exts = CoreModel.getDefault().getHeaderExtensions(); - for (int i = 0; i < exts.length; i++) { - if (exts[i].equalsIgnoreCase(ext)) { - return HEADER_ICON; + //TODO get enclosing types and parent type icon + return getFileIcon(typeRef.getPath()); + } + + public static Image getFileIcon(IPath path) + { + if (path != null) { + String ext= path.getFileExtension(); + if (ext != null) { + String[] exts = CoreModel.getDefault().getHeaderExtensions(); + for (int i = 0; i < exts.length; i++) { + if (exts[i].equalsIgnoreCase(ext)) { + return HEADER_ICON; + } } } } return SOURCE_ICON; } - private Image getIcon(ITypeInfo typeRef) + public static Image getTypeIcon(int type) { - switch (typeRef.getElementType()) + switch (type) { case ICElement.C_NAMESPACE: return NAMESPACE_ICON; @@ -142,21 +169,4 @@ public class TypeInfoLabelProvider extends LabelProvider { return CLASS_ICON; } } - - /* non java-doc - * @see ILabelProvider#getImage - */ - public Image getImage(Object element) { - if (!(element instanceof ITypeInfo)) - return super.getImage(element); - - ITypeInfo typeRef= (ITypeInfo) element; - if (isSet(SHOW_TYPE_CONTAINER_ONLY)) { - return getFileIcon(typeRef); - } else if (isSet(SHOW_FILENAME_ONLY)) { - return getFileIcon(typeRef); - } else { - return getIcon(typeRef); - } - } } diff --git a/core/org.eclipse.cdt.ui/browser/org/eclipse/cdt/ui/browser/typeinfo/TypeInfoMessages.properties b/core/org.eclipse.cdt.ui/browser/org/eclipse/cdt/ui/browser/typeinfo/TypeInfoMessages.properties index 544dfe5a680..0fa80b8eed7 100644 --- a/core/org.eclipse.cdt.ui/browser/org/eclipse/cdt/ui/browser/typeinfo/TypeInfoMessages.properties +++ b/core/org.eclipse.cdt.ui/browser/org/eclipse/cdt/ui/browser/typeinfo/TypeInfoMessages.properties @@ -9,11 +9,16 @@ # QNX Software Systems - Initial API and implementation ############################################################################### -TypeCacherJob.jobName=TypeCache -TypeCacherJob.taskName=Updating Type Info... - TypeSelectionDialog.lowerLabel=&Qualifier: TypeSelectionDialog.upperLabel=&Matching types: +TypeSelectionDialog.filterLabel=Visible types: +TypeSelectionDialog.filterNamespaces=namespace +TypeSelectionDialog.filterClasses=class +TypeSelectionDialog.filterStructs=struct +TypeSelectionDialog.filterTypedefs=typedef +TypeSelectionDialog.filterEnums=enum +TypeSelectionDialog.filterUnions=union +TypeSelectionDialog.filterLowLevelTypes=Show low-level types TypeInfoLabelProvider.default_filename=default TypeInfoLabelProvider.dash=\ - diff --git a/core/org.eclipse.cdt.ui/browser/org/eclipse/cdt/ui/browser/typeinfo/TypeSelectionDialog.java b/core/org.eclipse.cdt.ui/browser/org/eclipse/cdt/ui/browser/typeinfo/TypeSelectionDialog.java index e1e3f1b2736..52e249dae72 100644 --- a/core/org.eclipse.cdt.ui/browser/org/eclipse/cdt/ui/browser/typeinfo/TypeSelectionDialog.java +++ b/core/org.eclipse.cdt.ui/browser/org/eclipse/cdt/ui/browser/typeinfo/TypeSelectionDialog.java @@ -12,12 +12,29 @@ package org.eclipse.cdt.ui.browser.typeinfo; import java.util.ArrayList; +import java.util.Collection; import java.util.Comparator; +import java.util.HashSet; import java.util.List; +import java.util.Set; +import org.eclipse.cdt.core.browser.*; +import org.eclipse.cdt.core.model.ICElement; import org.eclipse.cdt.internal.ui.util.StringMatcher; +import org.eclipse.cdt.ui.CUIPlugin; +import org.eclipse.jface.dialogs.IDialogSettings; +import org.eclipse.swt.SWT; +import org.eclipse.swt.events.SelectionAdapter; +import org.eclipse.swt.events.SelectionEvent; +import org.eclipse.swt.graphics.Image; +import org.eclipse.swt.graphics.Point; +import org.eclipse.swt.graphics.Rectangle; +import org.eclipse.swt.layout.RowLayout; +import org.eclipse.swt.widgets.Button; import org.eclipse.swt.widgets.Composite; +import org.eclipse.swt.widgets.Control; import org.eclipse.swt.widgets.Shell; +import org.eclipse.swt.widgets.Text; import org.eclipse.ui.dialogs.FilteredList; import org.eclipse.ui.dialogs.TwoPaneElementSelector; @@ -29,40 +46,70 @@ public class TypeSelectionDialog extends TwoPaneElementSelector { private static class TypeFilterMatcher implements FilteredList.FilterMatcher { - private static final char END_SYMBOL= '<'; - private static final char ANY_STRING= '*'; - private final static String scopeResolutionOperator= "::"; //$NON-NLS-1$ + private static final char END_SYMBOL = '<'; + private static final char ANY_STRING = '*'; + private final static String scopeResolutionOperator = "::"; //$NON-NLS-1$ private StringMatcher fMatcher; private StringMatcher fQualifierMatcher; private StringMatcher fScopedQualifierMatcher; + private Collection fVisibleTypes = new HashSet(); + private boolean fShowLowLevelTypes = false; /* * @see FilteredList.FilterMatcher#setFilter(String, boolean) */ public void setFilter(String pattern, boolean ignoreCase, boolean ignoreWildCards) { - int qualifierIndex= pattern.lastIndexOf(scopeResolutionOperator); //$NON-NLS-1$ + int qualifierIndex = pattern.lastIndexOf(scopeResolutionOperator); // type if (qualifierIndex == -1) { - fQualifierMatcher= null; - fScopedQualifierMatcher= null; - fMatcher= new StringMatcher(adjustPattern(pattern), ignoreCase, ignoreWildCards); - + fQualifierMatcher = null; + fScopedQualifierMatcher = null; + fMatcher = new StringMatcher(adjustPattern(pattern), ignoreCase, ignoreWildCards); // qualified type } else { - String pattern1 = pattern.substring(0, qualifierIndex + scopeResolutionOperator.length()); - fQualifierMatcher= new StringMatcher(adjustPattern(pattern1), ignoreCase, ignoreWildCards); + String prefixPattern = pattern.substring(0, qualifierIndex + scopeResolutionOperator.length()); + fQualifierMatcher = new StringMatcher(adjustPattern(prefixPattern), ignoreCase, ignoreWildCards); StringBuffer buf = new StringBuffer(); buf.append(ANY_STRING); buf.append(scopeResolutionOperator); - buf.append(pattern1); - String pattern2= buf.toString(); - fScopedQualifierMatcher= new StringMatcher(adjustPattern(pattern2), ignoreCase, ignoreWildCards); - String pattern3 = pattern.substring(qualifierIndex + scopeResolutionOperator.length()); - fMatcher= new StringMatcher(adjustPattern(pattern3), ignoreCase, ignoreWildCards); + buf.append(prefixPattern); + String scopedPattern = buf.toString(); + fScopedQualifierMatcher = new StringMatcher(adjustPattern(scopedPattern), ignoreCase, ignoreWildCards); + String namePattern = pattern.substring(qualifierIndex + scopeResolutionOperator.length()); + fMatcher = new StringMatcher(adjustPattern(namePattern), ignoreCase, ignoreWildCards); } } + + public void setVisibleTypes(Collection visibleTypes) { + fVisibleTypes.clear(); + fVisibleTypes.addAll(visibleTypes); + } + + public Collection getVisibleTypes() { + return fVisibleTypes; + } + + public void setShowLowLevelTypes(boolean show) { + fShowLowLevelTypes = show; + } + + public boolean getShowLowLevelTypes() { + return fShowLowLevelTypes; + } + + private boolean isLowLevelType(ITypeInfo info) { + String[] enclosingNames = info.getEnclosingNames(); + // filter out low-level system types eg __FILE + if (enclosingNames != null) { + for (int i = 0; i < enclosingNames.length; ++i) { + if (enclosingNames[i].startsWith("_")) //$NON-NLS-1$ + return true; + } + } + return info.getName().startsWith("_"); //$NON-NLS-1$ + } /* * @see FilteredList.FilterMatcher#match(Object) @@ -71,31 +118,37 @@ public class TypeSelectionDialog extends TwoPaneElementSelector { if (!(element instanceof ITypeInfo)) return false; - TypeInfo type= (TypeInfo) element; + TypeInfo info = (TypeInfo) element; + + if (fVisibleTypes != null && !fVisibleTypes.contains(new Integer(info.getType()))) + return false; - if (!fMatcher.match(type.getName())) + if (!fShowLowLevelTypes && isLowLevelType(info)) + return false; + + if (!fMatcher.match(info.getName())) return false; if (fQualifierMatcher == null) return true; - if (fQualifierMatcher.match(type.getQualifiedName())) + if (fQualifierMatcher.match(info.getQualifiedName())) return true; else - return fScopedQualifierMatcher.match(type.getQualifiedName()); + return fScopedQualifierMatcher.match(info.getQualifiedName()); } private String adjustPattern(String pattern) { - int length= pattern.length(); + int length = pattern.length(); if (length > 0) { switch (pattern.charAt(length - 1)) { case END_SYMBOL: - pattern= pattern.substring(0, length - 1); + pattern = pattern.substring(0, length - 1); break; case ANY_STRING: break; default: - pattern= pattern + ANY_STRING; + pattern = pattern + ANY_STRING; } } return pattern; @@ -104,51 +157,384 @@ public class TypeSelectionDialog extends TwoPaneElementSelector { private static class StringComparator implements Comparator { public int compare(Object left, Object right) { - String leftString= (String) left; - String rightString= (String) right; + String leftString = (String) left; + String rightString = (String) right; - int result= leftString.compareToIgnoreCase(rightString); + int result = leftString.compareToIgnoreCase(rightString); if (result == 0) - result= leftString.compareTo(rightString); + result = leftString.compareTo(rightString); return result; } } + + private static final String DIALOG_SETTINGS = TypeSelectionDialog.class.getName(); + private static final String SETTINGS_X_POS = "x"; //$NON-NLS-1$ + private static final String SETTINGS_Y_POS = "y"; //$NON-NLS-1$ + private static final String SETTINGS_WIDTH = "width"; //$NON-NLS-1$ + private static final String SETTINGS_HEIGHT = "height"; //$NON-NLS-1$ + private static final String SETTINGS_SHOW_NAMESPACES = "show_namespaces"; //$NON-NLS-1$ + private static final String SETTINGS_SHOW_CLASSES = "show_classes"; //$NON-NLS-1$ + private static final String SETTINGS_SHOW_STRUCTS = "show_structs"; //$NON-NLS-1$ + private static final String SETTINGS_SHOW_TYPEDEFS = "show_typedefs"; //$NON-NLS-1$ + private static final String SETTINGS_SHOW_ENUMS = "show_enums"; //$NON-NLS-1$ + private static final String SETTINGS_SHOW_UNIONS = "show_unions"; //$NON-NLS-1$ + private static final String SETTINGS_SHOW_LOWLEVEL = "show_lowlevel"; //$NON-NLS-1$ + + private static final TypeInfoLabelProvider fElementRenderer = new TypeInfoLabelProvider(TypeInfoLabelProvider.SHOW_TYPE_ONLY); + private static final TypeInfoLabelProvider fQualifierRenderer = new TypeInfoLabelProvider(TypeInfoLabelProvider.SHOW_TYPE_CONTAINER_ONLY + TypeInfoLabelProvider.SHOW_ROOT_POSTFIX); + private static final TypeFilterMatcher fFilterMatcher = new TypeFilterMatcher(); + private static final StringComparator fStringComparator = new StringComparator(); + + private static final int[] fAllTypes = { ICElement.C_NAMESPACE, ICElement.C_CLASS, + ICElement.C_STRUCT, ICElement.C_TYPEDEF, ICElement.C_ENUMERATION, + ICElement.C_UNION }; + + private Set fKnownTypes = new HashSet(fAllTypes.length); + private Text fTextWidget; + private boolean fSelectFilterText = false; + private FilteredList fNewFilteredList; + private String fDialogSection; + private Point fLocation; + private Point fSize; + /** * Constructs a type selection dialog. * @param parent the parent shell. - * @param context the runnable context. - * @param scope the C search scope. */ public TypeSelectionDialog(Shell parent) { - super(parent, new TypeInfoLabelProvider(TypeInfoLabelProvider.SHOW_TYPE_ONLY), - new TypeInfoLabelProvider(TypeInfoLabelProvider.SHOW_TYPE_CONTAINER_ONLY + TypeInfoLabelProvider.SHOW_ROOT_POSTFIX)); + super(parent, fElementRenderer, fQualifierRenderer); setUpperListLabel(TypeInfoMessages.getString("TypeSelectionDialog.upperLabel")); //$NON-NLS-1$ setLowerListLabel(TypeInfoMessages.getString("TypeSelectionDialog.lowerLabel")); //$NON-NLS-1$ + setVisibleTypes(fAllTypes); + setDialogSettings(DIALOG_SETTINGS); + } + + /** + * Sets the filter pattern. + * @param filter the filter pattern. + * @param selectText <code>true</code> if filter text should be initially selected + * @see org.eclipse.ui.dialogs.AbstractElementListSelectionDialog#setFilter(java.lang.String) + */ + public void setFilter(String filter, boolean selectText) { + super.setFilter(filter); + fSelectFilterText = selectText; } - /* - * @see AbstractElementListSelectionDialog#createFilteredList(Composite) + /** + * Sets which CElement types are visible in the dialog. + * + * @param types Array of CElement types. + */ + public void setVisibleTypes(int[] types) { + fKnownTypes.clear(); + for (int i = 0; i < types.length; ++i) { + fKnownTypes.add(new Integer(types[i])); + } + } + + /** + * Sets section name to use when storing the dialog settings. + * + * @param section Name of section. + */ + public void setDialogSettings(String section) { + fDialogSection = section + "Settings"; //$NON-NLS-1$ + } + + /* (non-Javadoc) + * @see org.eclipse.ui.dialogs.AbstractElementListSelectionDialog#createFilterText(org.eclipse.swt.widgets.Composite) + */ + protected Text createFilterText(Composite parent) { + fTextWidget = super.createFilterText(parent); + + // create type checkboxes below filter text + createTypeFilterArea(parent); + + return fTextWidget; + } + + /* (non-Javadoc) + * @see org.eclipse.ui.dialogs.AbstractElementListSelectionDialog#createFilteredList(org.eclipse.swt.widgets.Composite) */ protected FilteredList createFilteredList(Composite parent) { - FilteredList list= super.createFilteredList(parent); - - fFilteredList.setFilterMatcher(new TypeFilterMatcher()); - fFilteredList.setComparator(new StringComparator()); + fNewFilteredList = super.createFilteredList(parent); + fNewFilteredList.setFilterMatcher(fFilterMatcher); + fNewFilteredList.setComparator(fStringComparator); + return fNewFilteredList; + } + + /* (non-Javadoc) + * @see org.eclipse.jface.window.Window#create() + */ + public void create() { + super.create(); + if (!fSelectFilterText) + fTextWidget.setSelection(0,0); + } + + /* + * @see Window#close() + */ + public boolean close() { + writeSettings(getDialogSettings()); + return super.close(); + } + + /* + * @see org.eclipse.jface.window.Window#createContents(org.eclipse.swt.widgets.Composite) + */ + protected Control createContents(Composite parent) { + readSettings(getDialogSettings()); + return super.createContents(parent); + } + + /** + * Creates a type filter checkbox. + */ + private Button createTypeCheckbox(Composite parent, Integer typeObject) { + String name; + int type = typeObject.intValue(); + switch (type) { + case ICElement.C_NAMESPACE: + name = TypeInfoMessages.getString("TypeSelectionDialog.filterNamespaces"); //$NON-NLS-1$ + break; + case ICElement.C_CLASS: + name = TypeInfoMessages.getString("TypeSelectionDialog.filterClasses"); //$NON-NLS-1$ + break; + case ICElement.C_STRUCT: + name = TypeInfoMessages.getString("TypeSelectionDialog.filterStructs"); //$NON-NLS-1$ + break; + case ICElement.C_TYPEDEF: + name = TypeInfoMessages.getString("TypeSelectionDialog.filterTypedefs"); //$NON-NLS-1$ + break; + case ICElement.C_ENUMERATION: + name = TypeInfoMessages.getString("TypeSelectionDialog.filterEnums"); //$NON-NLS-1$ + break; + case ICElement.C_UNION: + name = TypeInfoMessages.getString("TypeSelectionDialog.filterUnions"); //$NON-NLS-1$ + break; + default: + return null; + }; + Image icon = TypeInfoLabelProvider.getTypeIcon(type); + + final Integer fTypeObject = typeObject; + Button checkbox = new Button(parent, SWT.CHECK); + checkbox.setFont(parent.getFont()); + checkbox.setText(name); + checkbox.setImage(icon); + checkbox.setSelection(fFilterMatcher.getVisibleTypes().contains(fTypeObject)); + checkbox.addSelectionListener(new SelectionAdapter() { + public void widgetSelected(SelectionEvent e) { + if (e.widget instanceof Button) { + Button checkbox = (Button) e.widget; + if (checkbox.getSelection()) + fFilterMatcher.getVisibleTypes().add(fTypeObject); + else + fFilterMatcher.getVisibleTypes().remove(fTypeObject); + updateElements(); + } + } + }); + return checkbox; + } + + /** + * Creates an area to filter types. + * + * @param parent area to create controls in + */ + private void createTypeFilterArea(Composite parent) { + createLabel(parent, TypeInfoMessages.getString("TypeSelectionDialog.filterLabel")); //$NON-NLS-1$ - return list; + Composite upperRow = new Composite(parent, SWT.NONE); + RowLayout layout = new RowLayout(); + layout.spacing = 10; + layout.marginTop = 0; + layout.marginLeft = 0; + upperRow.setLayout(layout); + + // the for loop is here to guarantee we always + // create the checkboxes in the same order + for (int i = 0; i < fAllTypes.length; ++i) { + Integer typeObject = new Integer(fAllTypes[i]); + if (fKnownTypes.contains(typeObject)) + createTypeCheckbox(upperRow, typeObject); + } + + Composite lowerRow = new Composite(parent, SWT.NONE); + lowerRow.setLayout(layout); + + String name = TypeInfoMessages.getString("TypeSelectionDialog.filterLowLevelTypes"); //$NON-NLS-1$ + Button checkbox = new Button(lowerRow, SWT.CHECK); + checkbox.setFont(lowerRow.getFont()); + checkbox.setText(name); + checkbox.setSelection(fFilterMatcher.getShowLowLevelTypes()); + checkbox.addSelectionListener(new SelectionAdapter() { + public void widgetSelected(SelectionEvent e) { + if (e.widget instanceof Button) { + Button button = (Button) e.widget; + fFilterMatcher.setShowLowLevelTypes(button.getSelection()); + updateElements(); + } + } + }); } + /** + * Forces redraw of elements list. + */ + private void updateElements() { + fNewFilteredList.setFilter(fTextWidget.getText()); + } + + /** + * Returns the dialog settings object used to save state + * for this dialog. + * + * @return the dialog settings to be used + */ + protected IDialogSettings getDialogSettings() { + IDialogSettings allSettings = CUIPlugin.getDefault().getDialogSettings(); + IDialogSettings section = allSettings.getSection(fDialogSection); + if (section == null) { + section = allSettings.addNewSection(fDialogSection); + writeDefaultSettings(section); + } + return section; + } + + /** + * Stores current configuration in the dialog store. + */ + protected void writeSettings(IDialogSettings section) { + Point location = getShell().getLocation(); + section.put(SETTINGS_X_POS, location.x); + section.put(SETTINGS_Y_POS, location.y); + + Point size = getShell().getSize(); + section.put(SETTINGS_WIDTH, size.x); + section.put(SETTINGS_HEIGHT, size.y); + + section.put(SETTINGS_SHOW_NAMESPACES, fFilterMatcher.getVisibleTypes().contains(new Integer(ICElement.C_NAMESPACE))); + section.put(SETTINGS_SHOW_CLASSES, fFilterMatcher.getVisibleTypes().contains(new Integer(ICElement.C_CLASS))); + section.put(SETTINGS_SHOW_STRUCTS, fFilterMatcher.getVisibleTypes().contains(new Integer(ICElement.C_STRUCT))); + section.put(SETTINGS_SHOW_TYPEDEFS, fFilterMatcher.getVisibleTypes().contains(new Integer(ICElement.C_TYPEDEF))); + section.put(SETTINGS_SHOW_ENUMS, fFilterMatcher.getVisibleTypes().contains(new Integer(ICElement.C_ENUMERATION))); + section.put(SETTINGS_SHOW_UNIONS, fFilterMatcher.getVisibleTypes().contains(new Integer(ICElement.C_UNION))); + section.put(SETTINGS_SHOW_LOWLEVEL, fFilterMatcher.getShowLowLevelTypes()); + } + + /** + * Stores default dialog settings. + */ + protected void writeDefaultSettings(IDialogSettings section) { + section.put(SETTINGS_SHOW_NAMESPACES, true); + section.put(SETTINGS_SHOW_CLASSES, true); + section.put(SETTINGS_SHOW_STRUCTS, true); + section.put(SETTINGS_SHOW_TYPEDEFS, true); + section.put(SETTINGS_SHOW_ENUMS, true); + section.put(SETTINGS_SHOW_UNIONS, true); + section.put(SETTINGS_SHOW_LOWLEVEL, false); + } + + /** + * Initializes itself from the dialog settings with the same state + * as at the previous invocation. + */ + protected void readSettings(IDialogSettings section) { + try { + int x = section.getInt(SETTINGS_X_POS); + int y = section.getInt(SETTINGS_Y_POS); + fLocation = new Point(x, y); + int width = section.getInt(SETTINGS_WIDTH); + int height = section.getInt(SETTINGS_HEIGHT); + fSize = new Point(width, height); + } catch (NumberFormatException e) { + fLocation = null; + fSize = null; + } + + if (section.getBoolean(SETTINGS_SHOW_NAMESPACES)) { + Integer typeObject = new Integer(ICElement.C_NAMESPACE); + if (fKnownTypes.contains(typeObject)) + fFilterMatcher.getVisibleTypes().add(typeObject); + } + if (section.getBoolean(SETTINGS_SHOW_CLASSES)) { + Integer typeObject = new Integer(ICElement.C_CLASS); + if (fKnownTypes.contains(typeObject)) + fFilterMatcher.getVisibleTypes().add(typeObject); + } + if (section.getBoolean(SETTINGS_SHOW_STRUCTS)) { + Integer typeObject = new Integer(ICElement.C_STRUCT); + if (fKnownTypes.contains(typeObject)) + fFilterMatcher.getVisibleTypes().add(typeObject); + } + if (section.getBoolean(SETTINGS_SHOW_TYPEDEFS)) { + Integer typeObject = new Integer(ICElement.C_TYPEDEF); + if (fKnownTypes.contains(typeObject)) + fFilterMatcher.getVisibleTypes().add(typeObject); + } + if (section.getBoolean(SETTINGS_SHOW_ENUMS)) { + Integer typeObject = new Integer(ICElement.C_ENUMERATION); + if (fKnownTypes.contains(typeObject)) + fFilterMatcher.getVisibleTypes().add(typeObject); + } + if (section.getBoolean(SETTINGS_SHOW_UNIONS)) { + Integer typeObject = new Integer(ICElement.C_UNION); + if (fKnownTypes.contains(typeObject)) + fFilterMatcher.getVisibleTypes().add(typeObject); + } + fFilterMatcher.setShowLowLevelTypes(section.getBoolean(SETTINGS_SHOW_LOWLEVEL)); + } + + /* (non-Cdoc) + * @see org.eclipse.jface.window.Window#getInitialSize() + */ + protected Point getInitialSize() { + Point result = super.getInitialSize(); + if (fSize != null) { + result.x = Math.max(result.x, fSize.x); + result.y = Math.max(result.y, fSize.y); + Rectangle display = getShell().getDisplay().getClientArea(); + result.x = Math.min(result.x, display.width); + result.y = Math.min(result.y, display.height); + } + return result; + } + + /* (non-Cdoc) + * @see org.eclipse.jface.window.Window#getInitialLocation(org.eclipse.swt.graphics.Point) + */ + protected Point getInitialLocation(Point initialSize) { + Point result = super.getInitialLocation(initialSize); + if (fLocation != null) { + result.x = fLocation.x; + result.y = fLocation.y; + Rectangle display = getShell().getDisplay().getClientArea(); + int xe = result.x + initialSize.x; + if (xe > display.width) { + result.x -= xe - display.width; + } + int ye = result.y + initialSize.y; + if (ye > display.height) { + result.y -= ye - display.height; + } + } + return result; + } + /* * @see org.eclipse.ui.dialogs.SelectionStatusDialog#computeResult() */ protected void computeResult() { - ITypeInfo selection= (ITypeInfo) getLowerSelectedElement(); + ITypeInfo selection = (ITypeInfo) getLowerSelectedElement(); if (selection == null) return; - List result= new ArrayList(1); + List result = new ArrayList(1); result.add(selection); setResult(result); } |