From 1f5832d033ef6e95f5e408ae4a7e662d5a0475de Mon Sep 17 00:00:00 2001 From: Anton Leherbauer Date: Wed, 18 Apr 2007 10:53:48 +0000 Subject: [PATCH] Fix for 182294: Open Type should allow to open functions and variables --- .../opentype/ElementSelectionDialog.java | 333 ++++++++++++++++++ .../ui/browser/opentype/OpenTypeAction.java | 9 +- .../ui/browser/opentype/OpenTypeDialog.java | 111 +----- .../opentype/OpenTypeMessages.properties | 19 +- .../typeinfo/TypeInfoLabelProvider.java | 81 ++++- .../ui/browser/typeinfo/TypeInfoMessages.java | 60 ++-- .../typeinfo/TypeInfoMessages.properties | 33 +- .../browser/typeinfo/TypeSelectionDialog.java | 143 +++++--- core/org.eclipse.cdt.ui/plugin.properties | 11 +- .../editor/AddIncludeOnSelectionAction.java | 4 +- 10 files changed, 579 insertions(+), 225 deletions(-) create mode 100644 core/org.eclipse.cdt.ui/browser/org/eclipse/cdt/internal/ui/browser/opentype/ElementSelectionDialog.java diff --git a/core/org.eclipse.cdt.ui/browser/org/eclipse/cdt/internal/ui/browser/opentype/ElementSelectionDialog.java b/core/org.eclipse.cdt.ui/browser/org/eclipse/cdt/internal/ui/browser/opentype/ElementSelectionDialog.java new file mode 100644 index 00000000000..8402b9b0c5e --- /dev/null +++ b/core/org.eclipse.cdt.ui/browser/org/eclipse/cdt/internal/ui/browser/opentype/ElementSelectionDialog.java @@ -0,0 +1,333 @@ +/******************************************************************************* + * Copyright (c) 2007 Wind River Systems, Inc. and others. + * All rights reserved. This program and the accompanying materials + * are made available under the terms of the Eclipse Public License v1.0 + * which accompanies this distribution, and is available at + * http://www.eclipse.org/legal/epl-v10.html + * + * Contributors: + * Anton Leherbauer (Wind River Systems) - initial API and implementation + *******************************************************************************/ + +package org.eclipse.cdt.internal.ui.browser.opentype; + +import java.util.ArrayList; +import java.util.Arrays; +import java.util.List; + +import org.eclipse.core.runtime.CoreException; +import org.eclipse.core.runtime.IProgressMonitor; +import org.eclipse.core.runtime.IStatus; +import org.eclipse.core.runtime.Status; +import org.eclipse.core.runtime.jobs.IJobChangeEvent; +import org.eclipse.core.runtime.jobs.ISchedulingRule; +import org.eclipse.core.runtime.jobs.Job; +import org.eclipse.core.runtime.jobs.JobChangeAdapter; +import org.eclipse.jface.wizard.ProgressMonitorPart; +import org.eclipse.swt.SWT; +import org.eclipse.swt.layout.GridData; +import org.eclipse.swt.layout.GridLayout; +import org.eclipse.swt.widgets.Composite; +import org.eclipse.swt.widgets.Event; +import org.eclipse.swt.widgets.Listener; +import org.eclipse.swt.widgets.Shell; +import org.eclipse.swt.widgets.Text; +import org.eclipse.ui.dialogs.FilteredList; + +import org.eclipse.cdt.core.CCorePlugin; +import org.eclipse.cdt.core.browser.ITypeInfo; +import org.eclipse.cdt.core.browser.IndexTypeInfo; +import org.eclipse.cdt.core.browser.QualifiedTypeName; +import org.eclipse.cdt.core.dom.ast.DOMException; +import org.eclipse.cdt.core.dom.ast.IBinding; +import org.eclipse.cdt.core.dom.ast.IFunction; +import org.eclipse.cdt.core.dom.ast.cpp.ICPPBinding; +import org.eclipse.cdt.core.index.IIndex; +import org.eclipse.cdt.core.index.IndexFilter; +import org.eclipse.cdt.core.model.CoreModel; +import org.eclipse.cdt.ui.browser.typeinfo.TypeInfoMessages; +import org.eclipse.cdt.ui.browser.typeinfo.TypeSelectionDialog; + +import org.eclipse.cdt.internal.core.browser.util.IndexModelUtil; + +/** + * A dialog to select a element from a filterable list of elements. + * + * @since 4.0 + */ +public class ElementSelectionDialog extends TypeSelectionDialog { + + /** + * Job to update the element list in the background. + */ + private class UpdateElementsJob extends Job { + + public UpdateElementsJob(String name) { + super(name); + setSystem(true); + setUser(false); + setPriority(Job.LONG); + } + + public IStatus run(final IProgressMonitor monitor) { + monitor.beginTask(TypeInfoMessages.OpenSymbolDialog_UpdateSymbolsJob_inProgress, IProgressMonitor.UNKNOWN); + final ITypeInfo[] elements= getElementsByPrefix(fCurrentPrefix, monitor); + if (elements != null && !monitor.isCanceled()) { + final Shell shell= getShell(); + if (shell != null && !shell.isDisposed()) { + Runnable update= new Runnable() { + public void run() { + if (!shell.isDisposed() && !monitor.isCanceled()) { + setListElements(elements); + done(Status.OK_STATUS); + updateOkState(); + } + }}; + shell.getDisplay().asyncExec(update); + monitor.done(); + return Job.ASYNC_FINISH; + } + } + return Status.CANCEL_STATUS; + } + + } + + /** + * A job listener for simple job status reporting. + */ + private final class UpdateJobListener extends JobChangeAdapter { + + boolean fDone; + private IProgressMonitor fMonitor; + + private UpdateJobListener(IProgressMonitor monitor) { + fMonitor= monitor; + } + + public void done(IJobChangeEvent event) { + fDone= true; + final Shell shell= getShell(); + if (shell != null && !shell.isDisposed()) { + Runnable update= new Runnable() { + public void run() { + if (!shell.isDisposed() && fDone) { + fMonitor.done(); + } + }}; + shell.getDisplay().asyncExec(update); + } + } + + public void running(final IJobChangeEvent event) { + fDone= false; + final Shell shell= getShell(); + if (shell != null && !shell.isDisposed()) { + Runnable update= new Runnable() { + public void run() { + if (!shell.isDisposed() && !fDone) { + fMonitor.beginTask(TypeInfoMessages.OpenSymbolDialog_UpdateSymbolsJob_inProgress, IProgressMonitor.UNKNOWN); + } + }}; + shell.getDisplay().asyncExec(update); + } + } + } + + private static final ISchedulingRule SINGLE_INSTANCE_RULE = new ISchedulingRule() { + public boolean contains(ISchedulingRule rule) { + return rule == this; + } + public boolean isConflicting(ISchedulingRule rule) { + return rule == this; + }}; + + private char[] fCurrentPrefix= {}; + private Job fUpdateJob; + private boolean fAllowEmptyPrefix; + private ProgressMonitorPart fProgressMonitorPart; + + /** + * Constructs an instance of OpenTypeDialog. + * @param parent the parent shell. + */ + public ElementSelectionDialog(Shell parent) { + super(parent); + fUpdateJob= new UpdateElementsJob(TypeInfoMessages.OpenSymbolDialog_UpdateSymbolsJob_name); + fUpdateJob.setRule(SINGLE_INSTANCE_RULE); + } + + /* + * @see org.eclipse.cdt.ui.browser.typeinfo.TypeSelectionDialog#create() + */ + public void create() { + super.create(); + // trigger initial query + scheduleUpdate(getFilter()); + } + + /* + * @see org.eclipse.cdt.ui.browser.typeinfo.TypeSelectionDialog#close() + */ + public boolean close() { + fUpdateJob.cancel(); + return super.close(); + } + + /* + * @see org.eclipse.ui.dialogs.AbstractElementListSelectionDialog#setMatchEmptyString(boolean) + */ + public void setMatchEmptyString(boolean matchEmptyString) { + super.setMatchEmptyString(matchEmptyString); + setAllowEmptyPrefix(matchEmptyString); + } + /** + * Set whether an empty prefix should be allowed for queries. + * + * @param allowEmptyPrefix + */ + public void setAllowEmptyPrefix(boolean allowEmptyPrefix) { + fAllowEmptyPrefix = allowEmptyPrefix; + } + + /* + * @see org.eclipse.cdt.ui.browser.typeinfo.TypeSelectionDialog#showLowLevelFilter() + */ + protected boolean showLowLevelFilter() { + return false; + } + + /* + * @see org.eclipse.cdt.ui.browser.typeinfo.TypeSelectionDialog#createFilteredList(org.eclipse.swt.widgets.Composite) + */ + protected FilteredList createFilteredList(Composite parent) { + FilteredList list= super.createFilteredList(parent); + createProgressMonitorPart(parent); + return list; + } + + /** + * Create the control for progress reporting. + * @param parent + */ + private void createProgressMonitorPart(Composite parent) { + fProgressMonitorPart= new ProgressMonitorPart(parent, new GridLayout(2, false)); + GridData gridData= new GridData(GridData.FILL_HORIZONTAL); + gridData.horizontalIndent= 0; + gridData.verticalAlignment= GridData.BEGINNING; + fProgressMonitorPart.setLayoutData(gridData); + fUpdateJob.addJobChangeListener(new UpdateJobListener(fProgressMonitorPart)); + } + + /** + * Query the elements for the given prefix. + * + * @param prefix + * @param monitor + */ + protected ITypeInfo[] getElementsByPrefix(char[] prefix, IProgressMonitor monitor) { + if (monitor.isCanceled()) { + return null; + } + List types = new ArrayList(); + if(prefix.length > 0 || fAllowEmptyPrefix) { + try { + IIndex index = CCorePlugin.getIndexManager().getIndex(CoreModel.getDefault().getCModel().getCProjects()); + try { + index.acquireReadLock(); + IBinding[] bindings= index.findBindingsForPrefix(prefix, false, IndexFilter.ALL); +// IBinding[] bindings= index.findBindingsForPrefix(prefix, false, IndexFilter.ALL, monitor); + for(int i=0; i 1) { + userFilter= qualifiedName.lastSegment(); + } + userFilter= userFilter.trim().replaceAll("^(\\*)*", ""); //$NON-NLS-1$//$NON-NLS-2$ + int asterix= userFilter.indexOf("*"); //$NON-NLS-1$ + return (asterix==-1 ? userFilter : userFilter.substring(0, asterix)).toCharArray(); + } + + private boolean isEquivalentPrefix(char[] currentPrefix, char[] newPrefix) { + if (currentPrefix.length == 0 || currentPrefix.length > newPrefix.length) { + return false; + } else if (newPrefix.length == currentPrefix.length) { + return Arrays.equals(currentPrefix, newPrefix); + } + return new String(currentPrefix).equals(new String(newPrefix, 0, currentPrefix.length)); + } +} diff --git a/core/org.eclipse.cdt.ui/browser/org/eclipse/cdt/internal/ui/browser/opentype/OpenTypeAction.java b/core/org.eclipse.cdt.ui/browser/org/eclipse/cdt/internal/ui/browser/opentype/OpenTypeAction.java index 20c280c26f3..11e0427e062 100644 --- a/core/org.eclipse.cdt.ui/browser/org/eclipse/cdt/internal/ui/browser/opentype/OpenTypeAction.java +++ b/core/org.eclipse.cdt.ui/browser/org/eclipse/cdt/internal/ui/browser/opentype/OpenTypeAction.java @@ -1,5 +1,5 @@ /******************************************************************************* - * Copyright (c) 2004, 2006 QNX Software Systems and others. + * Copyright (c) 2004, 2007 QNX Software Systems and others. * All rights reserved. This program and the accompanying materials * are made available under the terms of the Eclipse Public License v1.0 * which accompanies this distribution, and is available at @@ -8,6 +8,7 @@ * Contributors: * QNX Software Systems - initial API and implementation * Andrew Ferguson (Symbian) + * Anton Leherbauer (Wind River Systems) *******************************************************************************/ package org.eclipse.cdt.internal.ui.browser.opentype; @@ -48,7 +49,7 @@ public class OpenTypeAction implements IWorkbenchWindowActionDelegate { * @see org.eclipse.ui.IActionDelegate#run(org.eclipse.jface.action.IAction) */ public void run(IAction action) { - OpenTypeDialog dialog = new OpenTypeDialog(getShell()); + ElementSelectionDialog dialog = new ElementSelectionDialog(getShell()); configureDialog(dialog); int result = dialog.open(); if (result != IDialogConstants.OK_ID) @@ -72,7 +73,9 @@ public class OpenTypeAction implements IWorkbenchWindowActionDelegate { } } - private void configureDialog(OpenTypeDialog dialog) { + private void configureDialog(ElementSelectionDialog dialog) { + dialog.setTitle(OpenTypeMessages.getString("OpenTypeDialog.title")); //$NON-NLS-1$ + dialog.setMessage(OpenTypeMessages.getString("OpenTypeDialog.message")); //$NON-NLS-1$ dialog.setDialogSettings(getClass().getName()); if (fWorkbenchWindow != null) { IWorkbenchPage page= fWorkbenchWindow.getActivePage(); diff --git a/core/org.eclipse.cdt.ui/browser/org/eclipse/cdt/internal/ui/browser/opentype/OpenTypeDialog.java b/core/org.eclipse.cdt.ui/browser/org/eclipse/cdt/internal/ui/browser/opentype/OpenTypeDialog.java index 385c11b52a9..4bfa0c06825 100644 --- a/core/org.eclipse.cdt.ui/browser/org/eclipse/cdt/internal/ui/browser/opentype/OpenTypeDialog.java +++ b/core/org.eclipse.cdt.ui/browser/org/eclipse/cdt/internal/ui/browser/opentype/OpenTypeDialog.java @@ -1,5 +1,5 @@ /******************************************************************************* - * Copyright (c) 2004, 2006, 2007 IBM Corporation and others. + * Copyright (c) 2004, 2007 IBM Corporation and others. * All rights reserved. This program and the accompanying materials * are made available under the terms of the Eclipse Public License v1.0 * which accompanies this distribution, and is available at @@ -9,40 +9,19 @@ * IBM Corporation - initial API and implementation * QNX Software Systems - adapted for use in CDT * Andrew Ferguson (Symbian) + * Anton Leherbauer (Wind River Systems) *******************************************************************************/ package org.eclipse.cdt.internal.ui.browser.opentype; -import java.util.ArrayList; -import java.util.List; - -import org.eclipse.core.runtime.CoreException; -import org.eclipse.swt.SWT; -import org.eclipse.swt.widgets.Composite; -import org.eclipse.swt.widgets.Event; -import org.eclipse.swt.widgets.Listener; import org.eclipse.swt.widgets.Shell; -import org.eclipse.swt.widgets.Text; -import org.eclipse.cdt.core.CCorePlugin; -import org.eclipse.cdt.core.browser.ITypeInfo; -import org.eclipse.cdt.core.browser.IndexTypeInfo; -import org.eclipse.cdt.core.dom.ast.DOMException; -import org.eclipse.cdt.core.dom.ast.IBinding; -import org.eclipse.cdt.core.dom.ast.cpp.ICPPBinding; -import org.eclipse.cdt.core.index.IIndex; -import org.eclipse.cdt.core.index.IndexFilter; -import org.eclipse.cdt.core.model.CoreModel; -import org.eclipse.cdt.ui.browser.typeinfo.TypeSelectionDialog; - -import org.eclipse.cdt.internal.core.browser.util.IndexModelUtil; /** - * A dialog to select a type from a list of types. The selected type will be - * opened in the editor. + * A dialog to select a type from a list of types. + * + * @deprecated Use {@link ElementSelectionDialog} instead. */ -public class OpenTypeDialog extends TypeSelectionDialog { - - private static final String DIALOG_SETTINGS= OpenTypeDialog.class.getName(); +public class OpenTypeDialog extends ElementSelectionDialog { /** * Constructs an instance of OpenTypeDialog. @@ -50,83 +29,5 @@ public class OpenTypeDialog extends TypeSelectionDialog { */ public OpenTypeDialog(Shell parent) { super(parent); - setTitle(OpenTypeMessages.getString("OpenTypeDialog.title")); //$NON-NLS-1$ - setMessage(OpenTypeMessages.getString("OpenTypeDialog.message")); //$NON-NLS-1$ - setDialogSettings(DIALOG_SETTINGS); - - } - - - char[] toPrefix(String userFilter) { - userFilter= userFilter.trim().replaceAll("^(\\*)*", ""); //$NON-NLS-1$//$NON-NLS-2$ - int asterix= userFilter.indexOf("*"); //$NON-NLS-1$ - return (asterix==-1 ? userFilter : userFilter.substring(0, asterix)).toCharArray(); - } - - /** - * Update the list of elements in AbstractElementListSelectionDialog - * - * Filtering on wildcards and types is done by the superclass - we just provide - * a good starting point - * @param userFilter - */ - public void update(String userFilter) { - char[] prefix = toPrefix(userFilter); - List types = new ArrayList(); - if(prefix.length>0) - try { - IIndex index = CCorePlugin.getIndexManager().getIndex(CoreModel.getDefault().getCModel().getCProjects()); - try { - index.acquireReadLock(); - IBinding[] bindings= index.findBindingsForPrefix(prefix, false, IndexFilter.ALL); - for(int i=0; i 0) buf.append(name); } else if (isSet(SHOW_ENCLOSING_TYPE_ONLY)) { @@ -74,25 +84,68 @@ public class TypeInfoLabelProvider extends LabelProvider { if (parentName != null) { buf.append(parentName.getFullyQualifiedName()); } else { - buf.append(TypeInfoMessages.getString("TypeInfoLabelProvider.globalScope")); //$NON-NLS-1$ + buf.append(TypeInfoMessages.TypeInfoLabelProvider_globalScope); } } else if (isSet(SHOW_FULLY_QUALIFIED)) { + if (qualifiedName.isGlobal()) { + buf.append(TypeInfoMessages.TypeInfoLabelProvider_globalScope); + buf.append(' '); + } buf.append(qualifiedName.getFullyQualifiedName()); } - + if (isSet(SHOW_PARAMETERS) && typeInfo.getCElementType() == ICElement.C_FUNCTION) { + if (typeInfo instanceof IFunctionInfo) { + IFunctionInfo functionInfo= (IFunctionInfo)typeInfo; + String[] params= functionInfo.getParameters(); + if (params != null) { + buf.append(FunctionDeclaration.getParameterClause(params)); + } + } + } + if (isSet(SHOW_RETURN_TYPE)) { + switch(typeInfo.getCElementType()) { + case ICElement.C_FUNCTION: + if (typeInfo instanceof IFunctionInfo) { + IFunctionInfo functionInfo= (IFunctionInfo)typeInfo; + String returnType= functionInfo.getReturnType(); + if (returnType != null && returnType.length() > 0) { + buf.append(TypeInfoMessages.TypeInfoLabelProvider_colon); + buf.append(returnType); + } + } + case ICElement.C_VARIABLE: + ITypeReference ref= typeInfo.getResolvedReference(); + if (ref != null) { + ICElement[] cElements= ref.getCElements(); + if (cElements != null && cElements.length > 0) { + String returnType= null; + if (cElements[0] instanceof IVariableDeclaration) { + try { + returnType= ((IVariableDeclaration)cElements[0]).getTypeName(); + } catch (CModelException exc) { + } + } + if (returnType != null && returnType.length() > 0) { + buf.append(TypeInfoMessages.TypeInfoLabelProvider_colon); + buf.append(returnType); + } + } + } + } + } if (isSet(SHOW_PATH)) { IPath path = null; - ITypeReference ref = typeRef.getResolvedReference(); + ITypeReference ref = typeInfo.getResolvedReference(); if (ref != null) { path = ref.getPath(); } else { - ICProject project = typeRef.getEnclosingProject(); + ICProject project = typeInfo.getEnclosingProject(); if (project != null) { path = project.getProject().getFullPath(); } } if (path != null) { - buf.append(TypeInfoMessages.getString("TypeInfoLabelProvider.dash"));//$NON-NLS-1$ + buf.append(TypeInfoMessages.TypeInfoLabelProvider_dash); buf.append(path.toString()); } } @@ -156,6 +209,12 @@ public class TypeInfoLabelProvider extends LabelProvider { case ICElement.C_TYPEDEF: return TYPEDEF_ICON; + case ICElement.C_FUNCTION: + return FUNCTION_ICON; + + case ICElement.C_VARIABLE: + return VARIABLE_ICON; + default: return UNKNOWN_TYPE_ICON; } diff --git a/core/org.eclipse.cdt.ui/browser/org/eclipse/cdt/ui/browser/typeinfo/TypeInfoMessages.java b/core/org.eclipse.cdt.ui/browser/org/eclipse/cdt/ui/browser/typeinfo/TypeInfoMessages.java index 37fc639bdd8..0d98ec049aa 100644 --- a/core/org.eclipse.cdt.ui/browser/org/eclipse/cdt/ui/browser/typeinfo/TypeInfoMessages.java +++ b/core/org.eclipse.cdt.ui/browser/org/eclipse/cdt/ui/browser/typeinfo/TypeInfoMessages.java @@ -1,5 +1,5 @@ /******************************************************************************* - * Copyright (c) 2004, 2006 QNX Software Systems and others. + * Copyright (c) 2004, 2007 QNX Software Systems and others. * All rights reserved. This program and the accompanying materials * are made available under the terms of the Eclipse Public License v1.0 * which accompanies this distribution, and is available at @@ -7,44 +7,40 @@ * * Contributors: * QNX Software Systems - initial API and implementation + * Anton Leherbauer (Wind River Systems) *******************************************************************************/ package org.eclipse.cdt.ui.browser.typeinfo; -import java.text.MessageFormat; -import java.util.MissingResourceException; -import java.util.ResourceBundle; +import org.eclipse.osgi.util.NLS; -public class TypeInfoMessages { +public final class TypeInfoMessages extends NLS { - private static final String RESOURCE_BUNDLE= TypeInfoMessages.class.getName(); - - private static ResourceBundle fgResourceBundle; - static { - try { - fgResourceBundle = ResourceBundle.getBundle(RESOURCE_BUNDLE); - } catch (MissingResourceException x) { - fgResourceBundle = null; - } - } + private static final String BUNDLE_NAME = "org.eclipse.cdt.ui.browser.typeinfo.TypeInfoMessages";//$NON-NLS-1$ private TypeInfoMessages() { + // Do not instantiate } - public static String getString(String key) { - try { - return fgResourceBundle.getString(key); - } catch (MissingResourceException e) { - return '!' + key + '!'; - } catch (NullPointerException e) { - return "#" + key + "#"; //$NON-NLS-1$ //$NON-NLS-2$ - } + public static String OpenSymbolDialog_UpdateSymbolsJob_name; + public static String OpenSymbolDialog_UpdateSymbolsJob_inProgress; + public static String TypeSelectionDialog_lowerLabel; + public static String TypeSelectionDialog_upperLabel; + public static String TypeSelectionDialog_filterLabel; + public static String TypeSelectionDialog_filterNamespaces; + public static String TypeSelectionDialog_filterClasses; + public static String TypeSelectionDialog_filterStructs; + public static String TypeSelectionDialog_filterTypedefs; + public static String TypeSelectionDialog_filterEnums; + public static String TypeSelectionDialog_filterUnions; + public static String TypeSelectionDialog_filterFunctions; + public static String TypeSelectionDialog_filterVariables; + public static String TypeSelectionDialog_filterLowLevelTypes; + public static String TypeInfoLabelProvider_default_filename; + public static String TypeInfoLabelProvider_globalScope; + public static String TypeInfoLabelProvider_dash; + public static String TypeInfoLabelProvider_colon; + + static { + NLS.initializeMessages(BUNDLE_NAME, TypeInfoMessages.class); } - - public static String getFormattedString(String key, String arg) { - return getFormattedString(key, new String[] { arg }); - } - - public static String getFormattedString(String key, String[] args) { - return MessageFormat.format(getString(key), args); - } -} +} \ No newline at end of file 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 a8bb0323434..2dfc305a34f 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 @@ -7,19 +7,26 @@ # # Contributors: # QNX Software Systems - Initial API and implementation +# Anton Leherbauer (Wind River Systems) ############################################################################### -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 +TypeSelectionDialog_lowerLabel=&Qualified name and location: +TypeSelectionDialog_upperLabel=&Matching elements: +TypeSelectionDialog_filterLabel=Visible element types: +TypeSelectionDialog_filterNamespaces=&Namespace +TypeSelectionDialog_filterClasses=&Class +TypeSelectionDialog_filterStructs=&Struct +TypeSelectionDialog_filterTypedefs=&Typedef +TypeSelectionDialog_filterEnums=&Enumeration +TypeSelectionDialog_filterUnions=&Union +TypeSelectionDialog_filterFunctions=&Function +TypeSelectionDialog_filterVariables=&Variable +TypeSelectionDialog_filterLowLevelTypes=Show &low-level elements (names beginning with '_') -TypeInfoLabelProvider.default_filename=default -TypeInfoLabelProvider.globalScope=(global) -TypeInfoLabelProvider.dash=\ - +TypeInfoLabelProvider_default_filename=default +TypeInfoLabelProvider_globalScope=(global) +TypeInfoLabelProvider_dash=\ -\ +TypeInfoLabelProvider_colon=:\ + +OpenSymbolDialog_UpdateSymbolsJob_name=Updating Element List +OpenSymbolDialog_UpdateSymbolsJob_inProgress=Updating Element List... \ No newline at end of file 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 765161e6029..58c5096b56a 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 @@ -9,6 +9,7 @@ * IBM Corporation - initial API and implementation * QNX Software Systems - adapted for use in CDT * Markus Schorn (Wind River Systems) + * Anton Leherbauer (Wind River Systems) *******************************************************************************/ package org.eclipse.cdt.ui.browser.typeinfo; @@ -202,20 +203,26 @@ public class TypeSelectionDialog extends TwoPaneElementSelector { 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_FUNCTIONS = "show_functions"; //$NON-NLS-1$ + private static final String SETTINGS_SHOW_VARIABLES = "show_variables"; //$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_ENCLOSING_TYPE_ONLY + TypeInfoLabelProvider.SHOW_PATH); + private static final TypeInfoLabelProvider fElementRenderer = new TypeInfoLabelProvider( + TypeInfoLabelProvider.SHOW_NAME_ONLY); + private static final TypeInfoLabelProvider fQualifierRenderer = new TypeInfoLabelProvider( + TypeInfoLabelProvider.SHOW_FULLY_QUALIFIED | + TypeInfoLabelProvider.SHOW_PARAMETERS | + TypeInfoLabelProvider.SHOW_PATH); private static final StringComparator fStringComparator = new StringComparator(); - private static final int[] fAllTypes = { ICElement.C_NAMESPACE, ICElement.C_CLASS, + private static final int[] ALL_TYPES = { ICElement.C_NAMESPACE, ICElement.C_CLASS, ICElement.C_STRUCT, ICElement.C_TYPEDEF, ICElement.C_ENUMERATION, - ICElement.C_UNION }; + ICElement.C_UNION, ICElement.C_FUNCTION, ICElement.C_VARIABLE }; // the filter matcher contains state information, must not be static private final TypeFilterMatcher fFilterMatcher = new TypeFilterMatcher(); - private Set fKnownTypes = new HashSet(fAllTypes.length); + private Set fKnownTypes = new HashSet(ALL_TYPES.length); private Text fTextWidget; private boolean fSelectFilterText = false; private FilteredList fNewFilteredList; @@ -230,9 +237,9 @@ public class TypeSelectionDialog extends TwoPaneElementSelector { public TypeSelectionDialog(Shell parent) { super(parent, fElementRenderer, fQualifierRenderer); setMatchEmptyString(false); - setUpperListLabel(TypeInfoMessages.getString("TypeSelectionDialog.upperLabel")); //$NON-NLS-1$ - setLowerListLabel(TypeInfoMessages.getString("TypeSelectionDialog.lowerLabel")); //$NON-NLS-1$ - setVisibleTypes(fAllTypes); + setUpperListLabel(TypeInfoMessages.TypeSelectionDialog_upperLabel); + setLowerListLabel(TypeInfoMessages.TypeSelectionDialog_lowerLabel); + setVisibleTypes(ALL_TYPES); setDialogSettings(DIALOG_SETTINGS); } @@ -259,6 +266,18 @@ public class TypeSelectionDialog extends TwoPaneElementSelector { } } + /** + * Answer whether the given type is visible in the dialog. + * + * @param type + * the type constant, see {@link ICElement} + * @return true if the given type is visible, + * false otherwise + */ + protected boolean isVisibleType(int type) { + return fKnownTypes.contains(new Integer(type)); + } + /** * Sets section name to use when storing the dialog settings. * @@ -295,8 +314,8 @@ public class TypeSelectionDialog extends TwoPaneElementSelector { */ public void create() { super.create(); - if (!fSelectFilterText) - fTextWidget.setSelection(0,0); + if (fSelectFilterText) + fTextWidget.selectAll(); } /* @@ -323,22 +342,28 @@ public class TypeSelectionDialog extends TwoPaneElementSelector { int type = typeObject.intValue(); switch (type) { case ICElement.C_NAMESPACE: - name = TypeInfoMessages.getString("TypeSelectionDialog.filterNamespaces"); //$NON-NLS-1$ + name = TypeInfoMessages.TypeSelectionDialog_filterNamespaces; break; case ICElement.C_CLASS: - name = TypeInfoMessages.getString("TypeSelectionDialog.filterClasses"); //$NON-NLS-1$ + name = TypeInfoMessages.TypeSelectionDialog_filterClasses; break; case ICElement.C_STRUCT: - name = TypeInfoMessages.getString("TypeSelectionDialog.filterStructs"); //$NON-NLS-1$ + name = TypeInfoMessages.TypeSelectionDialog_filterStructs; break; case ICElement.C_TYPEDEF: - name = TypeInfoMessages.getString("TypeSelectionDialog.filterTypedefs"); //$NON-NLS-1$ + name = TypeInfoMessages.TypeSelectionDialog_filterTypedefs; break; case ICElement.C_ENUMERATION: - name = TypeInfoMessages.getString("TypeSelectionDialog.filterEnums"); //$NON-NLS-1$ + name = TypeInfoMessages.TypeSelectionDialog_filterEnums; break; case ICElement.C_UNION: - name = TypeInfoMessages.getString("TypeSelectionDialog.filterUnions"); //$NON-NLS-1$ + name = TypeInfoMessages.TypeSelectionDialog_filterUnions; + break; + case ICElement.C_FUNCTION: + name = TypeInfoMessages.TypeSelectionDialog_filterFunctions; + break; + case ICElement.C_VARIABLE: + name = TypeInfoMessages.TypeSelectionDialog_filterVariables; break; default: return; @@ -379,10 +404,11 @@ public class TypeSelectionDialog extends TwoPaneElementSelector { * @param parent area to create controls in */ private void createTypeFilterArea(Composite parent) { - createLabel(parent, TypeInfoMessages.getString("TypeSelectionDialog.filterLabel")); //$NON-NLS-1$ + createLabel(parent, TypeInfoMessages.TypeSelectionDialog_filterLabel); Composite upperRow = new Composite(parent, SWT.NONE); - GridLayout upperLayout = new GridLayout(3, true); + int columns= fKnownTypes.size() > 6 ? 4 : 3; + GridLayout upperLayout = new GridLayout(columns, true); upperLayout.verticalSpacing = 2; upperLayout.marginHeight = 0; upperLayout.marginWidth = 0; @@ -390,39 +416,41 @@ public class TypeSelectionDialog extends TwoPaneElementSelector { // 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]); + for (int i = 0; i < ALL_TYPES.length; ++i) { + Integer typeObject = new Integer(ALL_TYPES[i]); if (fKnownTypes.contains(typeObject)) createTypeCheckbox(upperRow, typeObject); } - Composite lowerRow = new Composite(parent, SWT.NONE); - GridLayout lowerLayout = new GridLayout(1, true); - lowerLayout.verticalSpacing = 2; - lowerLayout.marginHeight = 0; - upperLayout.marginWidth = 0; - lowerRow.setLayout(lowerLayout); + if (showLowLevelFilter()) { + Composite lowerRow = new Composite(parent, SWT.NONE); + GridLayout lowerLayout = new GridLayout(1, true); + lowerLayout.verticalSpacing = 2; + lowerLayout.marginHeight = 0; + upperLayout.marginWidth = 0; + lowerRow.setLayout(lowerLayout); - Composite composite = new Composite(lowerRow, SWT.NONE); - GridLayout layout= new GridLayout(2, false); - layout.marginHeight = 0; - layout.marginWidth = 0; - composite.setLayout(layout); + Composite composite = new Composite(lowerRow, SWT.NONE); + GridLayout layout= new GridLayout(2, false); + layout.marginHeight = 0; + layout.marginWidth = 0; + composite.setLayout(layout); - String name = TypeInfoMessages.getString("TypeSelectionDialog.filterLowLevelTypes"); //$NON-NLS-1$ - Button checkbox = new Button(composite, SWT.CHECK); - checkbox.setFont(composite.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(); + String name = TypeInfoMessages.TypeSelectionDialog_filterLowLevelTypes; + Button checkbox = new Button(composite, SWT.CHECK); + checkbox.setFont(composite.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(); + } } - } - }); + }); + } } /** @@ -466,6 +494,8 @@ public class TypeSelectionDialog extends TwoPaneElementSelector { 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_FUNCTIONS, fFilterMatcher.getVisibleTypes().contains(new Integer(ICElement.C_FUNCTION))); + section.put(SETTINGS_SHOW_VARIABLES, fFilterMatcher.getVisibleTypes().contains(new Integer(ICElement.C_VARIABLE))); section.put(SETTINGS_SHOW_LOWLEVEL, fFilterMatcher.getShowLowLevelTypes()); } @@ -479,6 +509,8 @@ public class TypeSelectionDialog extends TwoPaneElementSelector { section.put(SETTINGS_SHOW_TYPEDEFS, true); section.put(SETTINGS_SHOW_ENUMS, true); section.put(SETTINGS_SHOW_UNIONS, true); + section.put(SETTINGS_SHOW_FUNCTIONS, true); + section.put(SETTINGS_SHOW_VARIABLES, true); section.put(SETTINGS_SHOW_LOWLEVEL, false); } @@ -529,9 +561,30 @@ public class TypeSelectionDialog extends TwoPaneElementSelector { if (fKnownTypes.contains(typeObject)) fFilterMatcher.getVisibleTypes().add(typeObject); } - fFilterMatcher.setShowLowLevelTypes(section.getBoolean(SETTINGS_SHOW_LOWLEVEL)); + if (section.getBoolean(SETTINGS_SHOW_FUNCTIONS)) { + Integer typeObject = new Integer(ICElement.C_FUNCTION); + if (fKnownTypes.contains(typeObject)) + fFilterMatcher.getVisibleTypes().add(typeObject); + } + if (section.getBoolean(SETTINGS_SHOW_VARIABLES)) { + Integer typeObject = new Integer(ICElement.C_VARIABLE); + if (fKnownTypes.contains(typeObject)) + fFilterMatcher.getVisibleTypes().add(typeObject); + } + if (showLowLevelFilter()) { + fFilterMatcher.setShowLowLevelTypes(section.getBoolean(SETTINGS_SHOW_LOWLEVEL)); + } else { + fFilterMatcher.setShowLowLevelTypes(true); + } } + /** + * @return whether the low level filter checkbox should be shown + */ + protected boolean showLowLevelFilter() { + return true; + } + /* (non-Cdoc) * @see org.eclipse.jface.window.Window#getInitialSize() */ diff --git a/core/org.eclipse.cdt.ui/plugin.properties b/core/org.eclipse.cdt.ui/plugin.properties index b6e62b746bd..18654b14486 100644 --- a/core/org.eclipse.cdt.ui/plugin.properties +++ b/core/org.eclipse.cdt.ui/plugin.properties @@ -8,6 +8,7 @@ # Contributors: # IBM Corporation - initial API and implementation # Markus Schorn (Wind River Systems) +# Anton Leherbauer (Wind River Systems) ############################################################################### pluginName=C/C++ Development Tools UI providerName=Eclipse.org @@ -192,11 +193,11 @@ CEditorPresentationActionSet.description=Actions to customize the C/C++ editor p searchMenu.label= Se&arch refactoringMenu.label= Re&factor -# Open Type -OpenTypeAction.label= Open &Type... -OpenTypeAction.tooltip= Open Type -ActionDefinition.openType.name= Open Type -ActionDefinition.openType.description= Open a type in a C editor +# Open Element +OpenTypeAction.label= Open &Element... +OpenTypeAction.tooltip= Open Element +ActionDefinition.openType.name= Open Element +ActionDefinition.openType.description= Open an element in an Editor #Add include ActionDefinition.addInclude.name= Add Include diff --git a/core/org.eclipse.cdt.ui/src/org/eclipse/cdt/internal/ui/editor/AddIncludeOnSelectionAction.java b/core/org.eclipse.cdt.ui/src/org/eclipse/cdt/internal/ui/editor/AddIncludeOnSelectionAction.java index e87c6cbf7e0..f39048871d6 100644 --- a/core/org.eclipse.cdt.ui/src/org/eclipse/cdt/internal/ui/editor/AddIncludeOnSelectionAction.java +++ b/core/org.eclipse.cdt.ui/src/org/eclipse/cdt/internal/ui/editor/AddIncludeOnSelectionAction.java @@ -1,5 +1,5 @@ /******************************************************************************* - * Copyright (c) 2000, 2006 IBM Corporation and others. + * Copyright (c) 2000, 2007 IBM Corporation and others. * All rights reserved. This program and the accompanying materials * are made available under the terms of the Eclipse Public License v1.0 * which accompanies this distribution, and is available at @@ -273,7 +273,7 @@ public class AddIncludeOnSelectionAction extends Action implements IUpdate { if (pdomNames.size() > 1) { - ElementListSelectionDialog dialog= new ElementListSelectionDialog(getShell(), new TypeInfoLabelProvider(TypeInfoLabelProvider.SHOW_TYPE_ONLY)); + ElementListSelectionDialog dialog= new ElementListSelectionDialog(getShell(), new TypeInfoLabelProvider(TypeInfoLabelProvider.SHOW_NAME_ONLY)); dialog.setElements(pdomNames.toArray()); dialog.setTitle(CEditorMessages.getString("AddIncludeOnSelection.label")); //$NON-NLS-1$ dialog.setMessage(CEditorMessages.getString("AddIncludeOnSelection.description")); //$NON-NLS-1$