1
0
Fork 0
mirror of https://github.com/eclipse-cdt/cdt synced 2025-06-06 17:26:01 +02:00

Fix Open Element in case of modified editor, misc. improvements for ElemementSelectionDialog

This commit is contained in:
Anton Leherbauer 2007-04-19 15:34:40 +00:00
parent 3a04ca57ba
commit eda6e679cf
7 changed files with 91 additions and 89 deletions

View file

@ -151,9 +151,8 @@ public class IndexTypeInfo implements ITypeInfo, IFunctionInfo {
public boolean acceptBinding(IBinding binding) { public boolean acceptBinding(IBinding binding) {
boolean sameType= IndexModelUtil.bindingHasCElementType(binding, new int[]{elementType}); boolean sameType= IndexModelUtil.bindingHasCElementType(binding, new int[]{elementType});
if (sameType && binding instanceof IFunction && params != null) { if (sameType && binding instanceof IFunction && params != null) {
String[] otherParams;
try { try {
otherParams= IndexModelUtil.extractParameterTypes((IFunction)binding); String[]otherParams= IndexModelUtil.extractParameterTypes((IFunction)binding);
return Arrays.equals(params, otherParams); return Arrays.equals(params, otherParams);
} catch (DOMException exc) { } catch (DOMException exc) {
CCorePlugin.log(exc); CCorePlugin.log(exc);
@ -164,27 +163,29 @@ public class IndexTypeInfo implements ITypeInfo, IFunctionInfo {
}, new NullProgressMonitor()); }, new NullProgressMonitor());
if(ibs.length>0) { if(ibs.length>0) {
IIndexName[] names; IIndexName[] names;
if (elementType == ICElement.C_TYPEDEF) { names= index.findNames(ibs[0], IIndex.FIND_DEFINITIONS);
if (names.length == 0 && elementType == ICElement.C_VARIABLE || elementType == ICElement.C_FUNCTION) {
names= index.findNames(ibs[0], IIndex.FIND_DECLARATIONS); names= index.findNames(ibs[0], IIndex.FIND_DECLARATIONS);
} else {
names= index.findNames(ibs[0], IIndex.FIND_DEFINITIONS);
} }
if(names.length>0) { for (int i = 0; i < names.length; i++) {
IIndexFileLocation ifl = names[0].getFile().getLocation(); IIndexName indexName = names[i];
IIndexFileLocation ifl = indexName.getFile().getLocation();
String fullPath = ifl.getFullPath(); String fullPath = ifl.getFullPath();
if(fullPath!=null) { if (fullPath != null) {
IFile file = ResourcesPlugin.getWorkspace().getRoot().getFile(new Path(fullPath)); IFile file = ResourcesPlugin.getWorkspace().getRoot().getFile(new Path(fullPath));
if(file!=null) { if(file!=null) {
reference = new IndexTypeReference( reference = new IndexTypeReference(
ibs[0], file, file.getProject(), names[0].getNodeOffset(), names[0].getNodeLength() ibs[0], file, file.getProject(), names[0].getNodeOffset(), names[0].getNodeLength()
); );
} }
break;
} else { } else {
IPath path = URIUtil.toPath(ifl.getURI()); IPath path = URIUtil.toPath(ifl.getURI());
if(path!=null) { if(path!=null) {
reference = new IndexTypeReference( reference = new IndexTypeReference(
ibs[0], path, null, names[0].getNodeOffset(), names[0].getNodeLength() ibs[0], path, null, names[0].getNodeOffset(), names[0].getNodeLength()
); );
break;
} }
} }
} }

View file

@ -29,8 +29,10 @@ import org.eclipse.swt.layout.GridData;
import org.eclipse.swt.layout.GridLayout; import org.eclipse.swt.layout.GridLayout;
import org.eclipse.swt.widgets.Composite; import org.eclipse.swt.widgets.Composite;
import org.eclipse.swt.widgets.Event; import org.eclipse.swt.widgets.Event;
import org.eclipse.swt.widgets.Label;
import org.eclipse.swt.widgets.Listener; import org.eclipse.swt.widgets.Listener;
import org.eclipse.swt.widgets.Shell; import org.eclipse.swt.widgets.Shell;
import org.eclipse.swt.widgets.Table;
import org.eclipse.swt.widgets.Text; import org.eclipse.swt.widgets.Text;
import org.eclipse.ui.dialogs.FilteredList; import org.eclipse.ui.dialogs.FilteredList;
@ -45,13 +47,12 @@ import org.eclipse.cdt.core.dom.ast.cpp.ICPPBinding;
import org.eclipse.cdt.core.index.IIndex; import org.eclipse.cdt.core.index.IIndex;
import org.eclipse.cdt.core.index.IndexFilter; import org.eclipse.cdt.core.index.IndexFilter;
import org.eclipse.cdt.core.model.CoreModel; 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.ui.browser.typeinfo.TypeSelectionDialog;
import org.eclipse.cdt.internal.core.browser.util.IndexModelUtil; import org.eclipse.cdt.internal.core.browser.util.IndexModelUtil;
/** /**
* A dialog to select a element from a filterable list of elements. * A dialog to select an element from a filterable list of elements.
* *
* @since 4.0 * @since 4.0
*/ */
@ -70,7 +71,7 @@ public class ElementSelectionDialog extends TypeSelectionDialog {
} }
public IStatus run(final IProgressMonitor monitor) { public IStatus run(final IProgressMonitor monitor) {
monitor.beginTask(TypeInfoMessages.OpenSymbolDialog_UpdateSymbolsJob_inProgress, IProgressMonitor.UNKNOWN); monitor.beginTask(OpenTypeMessages.ElementSelectionDialog_UpdateElementsJob_inProgress, IProgressMonitor.UNKNOWN);
final ITypeInfo[] elements= getElementsByPrefix(fCurrentPrefix, monitor); final ITypeInfo[] elements= getElementsByPrefix(fCurrentPrefix, monitor);
if (elements != null && !monitor.isCanceled()) { if (elements != null && !monitor.isCanceled()) {
final Shell shell= getShell(); final Shell shell= getShell();
@ -126,7 +127,7 @@ public class ElementSelectionDialog extends TypeSelectionDialog {
Runnable update= new Runnable() { Runnable update= new Runnable() {
public void run() { public void run() {
if (!shell.isDisposed() && !fDone) { if (!shell.isDisposed() && !fDone) {
fMonitor.beginTask(TypeInfoMessages.OpenSymbolDialog_UpdateSymbolsJob_inProgress, IProgressMonitor.UNKNOWN); fMonitor.beginTask(OpenTypeMessages.ElementSelectionDialog_UpdateElementsJob_inProgress, IProgressMonitor.UNKNOWN);
} }
}}; }};
shell.getDisplay().asyncExec(update); shell.getDisplay().asyncExec(update);
@ -153,7 +154,7 @@ public class ElementSelectionDialog extends TypeSelectionDialog {
*/ */
public ElementSelectionDialog(Shell parent) { public ElementSelectionDialog(Shell parent) {
super(parent); super(parent);
fUpdateJob= new UpdateElementsJob(TypeInfoMessages.OpenSymbolDialog_UpdateSymbolsJob_name); fUpdateJob= new UpdateElementsJob(OpenTypeMessages.ElementSelectionDialog_UpdateElementsJob_name);
fUpdateJob.setRule(SINGLE_INSTANCE_RULE); fUpdateJob.setRule(SINGLE_INSTANCE_RULE);
} }
@ -194,18 +195,19 @@ public class ElementSelectionDialog extends TypeSelectionDialog {
* @see org.eclipse.cdt.ui.browser.typeinfo.TypeSelectionDialog#showLowLevelFilter() * @see org.eclipse.cdt.ui.browser.typeinfo.TypeSelectionDialog#showLowLevelFilter()
*/ */
protected boolean showLowLevelFilter() { protected boolean showLowLevelFilter() {
// the low-level filter is useless for us
return false; return false;
} }
/* /*
* @see org.eclipse.cdt.ui.browser.typeinfo.TypeSelectionDialog#createFilteredList(org.eclipse.swt.widgets.Composite) * @see org.eclipse.ui.dialogs.TwoPaneElementSelector#createLowerList(org.eclipse.swt.widgets.Composite)
*/ */
protected FilteredList createFilteredList(Composite parent) { protected Table createLowerList(Composite parent) {
FilteredList list= super.createFilteredList(parent); Table table= super.createLowerList(parent);
createProgressMonitorPart(parent); createProgressMonitorPart(parent);
return list; return table;
} }
/** /**
* Create the control for progress reporting. * Create the control for progress reporting.
* @param parent * @param parent
@ -216,7 +218,11 @@ public class ElementSelectionDialog extends TypeSelectionDialog {
gridData.horizontalIndent= 0; gridData.horizontalIndent= 0;
gridData.verticalAlignment= GridData.BEGINNING; gridData.verticalAlignment= GridData.BEGINNING;
fProgressMonitorPart.setLayoutData(gridData); fProgressMonitorPart.setLayoutData(gridData);
fUpdateJob.addJobChangeListener(new UpdateJobListener(fProgressMonitorPart));
Label separator= new Label(parent.getParent(), SWT.SEPARATOR | SWT.HORIZONTAL);
separator.setLayoutData(new GridData(GridData.FILL_HORIZONTAL));
fUpdateJob.addJobChangeListener(new UpdateJobListener(fProgressMonitorPart));
} }
/** /**
@ -243,15 +249,15 @@ public class ElementSelectionDialog extends TypeSelectionDialog {
} }
IBinding binding = bindings[i]; IBinding binding = bindings[i];
try { try {
String[] fqn;
if(binding instanceof ICPPBinding) {
fqn= ((ICPPBinding)binding).getQualifiedName();
} else {
fqn = new String[] {binding.getName()};
}
final int elementType = IndexModelUtil.getElementType(binding); final int elementType = IndexModelUtil.getElementType(binding);
if (isVisibleType(elementType)) { if (isVisibleType(elementType)) {
String[] fqn;
if(binding instanceof ICPPBinding) {
fqn= ((ICPPBinding)binding).getQualifiedName();
} else {
fqn = new String[] {binding.getName()};
}
if (binding instanceof IFunction) { if (binding instanceof IFunction) {
final IFunction function = (IFunction)binding; final IFunction function = (IFunction)binding;
final String[] paramTypes = IndexModelUtil.extractParameterTypes(function); final String[] paramTypes = IndexModelUtil.extractParameterTypes(function);

View file

@ -19,6 +19,7 @@ import org.eclipse.jface.text.BadLocationException;
import org.eclipse.jface.text.IDocument; import org.eclipse.jface.text.IDocument;
import org.eclipse.jface.text.ITextSelection; import org.eclipse.jface.text.ITextSelection;
import org.eclipse.jface.viewers.ISelection; import org.eclipse.jface.viewers.ISelection;
import org.eclipse.osgi.util.NLS;
import org.eclipse.swt.widgets.Shell; import org.eclipse.swt.widgets.Shell;
import org.eclipse.ui.IEditorPart; import org.eclipse.ui.IEditorPart;
import org.eclipse.ui.IWorkbenchPage; import org.eclipse.ui.IWorkbenchPage;
@ -31,6 +32,7 @@ import org.eclipse.ui.texteditor.ITextEditor;
import org.eclipse.cdt.core.browser.ITypeInfo; import org.eclipse.cdt.core.browser.ITypeInfo;
import org.eclipse.cdt.core.browser.ITypeReference; import org.eclipse.cdt.core.browser.ITypeReference;
import org.eclipse.cdt.core.model.CModelException; import org.eclipse.cdt.core.model.CModelException;
import org.eclipse.cdt.core.model.ICElement;
import org.eclipse.cdt.core.model.ITranslationUnit; import org.eclipse.cdt.core.model.ITranslationUnit;
import org.eclipse.cdt.internal.ui.util.EditorUtility; import org.eclipse.cdt.internal.ui.util.EditorUtility;
@ -62,20 +64,20 @@ public class OpenTypeAction implements IWorkbenchWindowActionDelegate {
ITypeReference location = info.getResolvedReference(); ITypeReference location = info.getResolvedReference();
if (location == null) { if (location == null) {
// could not resolve location // could not resolve location
String title = OpenTypeMessages.getString("OpenTypeAction.errorTitle"); //$NON-NLS-1$ String title = OpenTypeMessages.OpenTypeAction_errorTitle;
String message = OpenTypeMessages.getFormattedString("OpenTypeAction.errorTypeNotFound", info.getQualifiedTypeName().toString()); //$NON-NLS-1$ String message = NLS.bind(OpenTypeMessages.OpenTypeAction_errorTypeNotFound, info.getQualifiedTypeName().toString());
MessageDialog.openError(getShell(), title, message); MessageDialog.openError(getShell(), title, message);
} else if (!openTypeInEditor(location)) { } else if (!openTypeInEditor(location)) {
// error opening editor // error opening editor
String title = OpenTypeMessages.getString("OpenTypeAction.errorTitle"); //$NON-NLS-1$ String title = OpenTypeMessages.OpenTypeAction_errorTitle;
String message = OpenTypeMessages.getFormattedString("OpenTypeAction.errorOpenEditor", location.getPath().toString()); //$NON-NLS-1$ String message = NLS.bind(OpenTypeMessages.OpenTypeAction_errorOpenEditor, location.getPath().toString());
MessageDialog.openError(getShell(), title, message); MessageDialog.openError(getShell(), title, message);
} }
} }
private void configureDialog(ElementSelectionDialog dialog) { private void configureDialog(ElementSelectionDialog dialog) {
dialog.setTitle(OpenTypeMessages.getString("OpenTypeDialog.title")); //$NON-NLS-1$ dialog.setTitle(OpenTypeMessages.OpenTypeDialog_title);
dialog.setMessage(OpenTypeMessages.getString("OpenTypeDialog.message")); //$NON-NLS-1$ dialog.setMessage(OpenTypeMessages.OpenTypeDialog_message);
dialog.setDialogSettings(getClass().getName()); dialog.setDialogSettings(getClass().getName());
if (fWorkbenchWindow != null) { if (fWorkbenchWindow != null) {
IWorkbenchPage page= fWorkbenchWindow.getActivePage(); IWorkbenchPage page= fWorkbenchWindow.getActivePage();
@ -105,10 +107,16 @@ public class OpenTypeAction implements IWorkbenchWindowActionDelegate {
* @return true if succesfully displayed. * @return true if succesfully displayed.
*/ */
private boolean openTypeInEditor(ITypeReference location) { private boolean openTypeInEditor(ITypeReference location) {
ITranslationUnit unit = location.getTranslationUnit(); ICElement[] cElements= location.getCElements();
IEditorPart editorPart = null;
try { try {
if (cElements.length > 0) {
IEditorPart editor= EditorUtility.openInEditor(cElements[0]);
EditorUtility.revealInEditor(editor, cElements[0]);
return true;
}
ITranslationUnit unit = location.getTranslationUnit();
IEditorPart editorPart = null;
if (unit != null) if (unit != null)
editorPart = EditorUtility.openInEditor(unit); editorPart = EditorUtility.openInEditor(unit);
if (editorPart == null) { if (editorPart == null) {

View file

@ -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 * All rights reserved. This program and the accompanying materials
* are made available under the terms of the Eclipse Public License v1.0 * are made available under the terms of the Eclipse Public License v1.0
* which accompanies this distribution, and is available at * which accompanies this distribution, and is available at
@ -7,48 +7,37 @@
* *
* Contributors: * Contributors:
* QNX Software Systems - initial API and implementation * QNX Software Systems - initial API and implementation
* Anton Leherbauer (Wind River Systems)
*******************************************************************************/ *******************************************************************************/
package org.eclipse.cdt.internal.ui.browser.opentype; package org.eclipse.cdt.internal.ui.browser.opentype;
import java.text.MessageFormat; import org.eclipse.osgi.util.NLS;
import java.util.MissingResourceException;
import java.util.ResourceBundle;
/** public final class OpenTypeMessages extends NLS {
* OpenTypeMessages
*/
public class OpenTypeMessages {
private static final String RESOURCE_BUNDLE= OpenTypeMessages.class.getName(); private static final String BUNDLE_NAME = "org.eclipse.cdt.internal.ui.browser.opentype.OpenTypeMessages";//$NON-NLS-1$
private static ResourceBundle fgResourceBundle;
static {
try {
fgResourceBundle = ResourceBundle.getBundle(RESOURCE_BUNDLE);
} catch (MissingResourceException x) {
fgResourceBundle = null;
}
}
private OpenTypeMessages() { private OpenTypeMessages() {
// Do not instantiate
} }
public static String getString(String key) { public static String OpenTypeAction_exception_title;
try { public static String OpenTypeAction_exception_message;
return fgResourceBundle.getString(key); public static String OpenTypeAction_notypes_title;
} catch (MissingResourceException e) { public static String OpenTypeAction_notypes_message;
return '!' + key + '!'; public static String OpenTypeAction_description;
} catch (NullPointerException e) { public static String OpenTypeAction_tooltip;
return "#" + key + "#"; //$NON-NLS-1$ //$NON-NLS-2$ public static String OpenTypeAction_label;
} public static String OpenTypeAction_errorTitle;
} public static String OpenTypeAction_errorOpenEditor;
public static String OpenTypeAction_errorTypeNotFound;
public static String getFormattedString(String key, String arg) { public static String OpenTypeDialog_title;
return getFormattedString(key, new String[] { arg }); public static String OpenTypeDialog_message;
} public static String OpenTypeDialog_filter;
public static String ElementSelectionDialog_UpdateElementsJob_name;
public static String getFormattedString(String key, String[] args) { public static String ElementSelectionDialog_UpdateElementsJob_inProgress;
return MessageFormat.format(getString(key), args);
}
} static {
NLS.initializeMessages(BUNDLE_NAME, OpenTypeMessages.class);
}
}

View file

@ -10,17 +10,20 @@
# Anton Leherbauer (Wind River Systems) # Anton Leherbauer (Wind River Systems)
############################################################################### ###############################################################################
OpenTypeAction.exception.title=Exception OpenTypeAction_exception_title=Exception
OpenTypeAction.exception.message=Unexpected exception. See log for details. OpenTypeAction_exception_message=Unexpected exception. See log for details.
OpenTypeAction.notypes.title=Element Selection OpenTypeAction_notypes_title=Element Selection
OpenTypeAction.notypes.message=No elements available. OpenTypeAction_notypes_message=No elements available.
OpenTypeAction.description=Open an element in an Editor OpenTypeAction_description=Open an element in an Editor
OpenTypeAction.tooltip=Open an Element OpenTypeAction_tooltip=Open an Element
OpenTypeAction.label=Open Element... OpenTypeAction_label=Open Element...
OpenTypeAction.errorTitle=Open Element OpenTypeAction_errorTitle=Open Element
OpenTypeAction.errorOpenEditor=Error opening editor for file \"{0}\" OpenTypeAction_errorOpenEditor=Error opening editor for file \"{0}\"
OpenTypeAction.errorTypeNotFound=Could not locate definition of element \"{0}\" OpenTypeAction_errorTypeNotFound=Could not locate definition of element \"{0}\"
OpenTypeDialog.title=Open Element OpenTypeDialog_title=Open Element
OpenTypeDialog.message=&Choose an element (? = any character, * = any string): OpenTypeDialog_message=&Choose an element (? = any character, * = any string):
OpenTypeDialog.filter= OpenTypeDialog_filter=
ElementSelectionDialog_UpdateElementsJob_name=Updating element list
ElementSelectionDialog_UpdateElementsJob_inProgress=Updating element list...

View file

@ -21,8 +21,6 @@ public final class TypeInfoMessages extends NLS {
// Do not instantiate // Do not instantiate
} }
public static String OpenSymbolDialog_UpdateSymbolsJob_name;
public static String OpenSymbolDialog_UpdateSymbolsJob_inProgress;
public static String TypeSelectionDialog_lowerLabel; public static String TypeSelectionDialog_lowerLabel;
public static String TypeSelectionDialog_upperLabel; public static String TypeSelectionDialog_upperLabel;
public static String TypeSelectionDialog_filterLabel; public static String TypeSelectionDialog_filterLabel;

View file

@ -27,6 +27,3 @@ TypeInfoLabelProvider_default_filename=default
TypeInfoLabelProvider_globalScope=(global) TypeInfoLabelProvider_globalScope=(global)
TypeInfoLabelProvider_dash=\ -\ TypeInfoLabelProvider_dash=\ -\
TypeInfoLabelProvider_colon=:\ TypeInfoLabelProvider_colon=:\
OpenSymbolDialog_UpdateSymbolsJob_name=Updating Element List
OpenSymbolDialog_UpdateSymbolsJob_inProgress=Updating Element List...