1
0
Fork 0
mirror of https://github.com/eclipse-cdt/cdt synced 2025-04-22 22:22:11 +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) {
boolean sameType= IndexModelUtil.bindingHasCElementType(binding, new int[]{elementType});
if (sameType && binding instanceof IFunction && params != null) {
String[] otherParams;
try {
otherParams= IndexModelUtil.extractParameterTypes((IFunction)binding);
String[]otherParams= IndexModelUtil.extractParameterTypes((IFunction)binding);
return Arrays.equals(params, otherParams);
} catch (DOMException exc) {
CCorePlugin.log(exc);
@ -164,27 +163,29 @@ public class IndexTypeInfo implements ITypeInfo, IFunctionInfo {
}, new NullProgressMonitor());
if(ibs.length>0) {
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);
} else {
names= index.findNames(ibs[0], IIndex.FIND_DEFINITIONS);
}
if(names.length>0) {
IIndexFileLocation ifl = names[0].getFile().getLocation();
for (int i = 0; i < names.length; i++) {
IIndexName indexName = names[i];
IIndexFileLocation ifl = indexName.getFile().getLocation();
String fullPath = ifl.getFullPath();
if(fullPath!=null) {
if (fullPath != null) {
IFile file = ResourcesPlugin.getWorkspace().getRoot().getFile(new Path(fullPath));
if(file!=null) {
reference = new IndexTypeReference(
ibs[0], file, file.getProject(), names[0].getNodeOffset(), names[0].getNodeLength()
);
}
break;
} else {
IPath path = URIUtil.toPath(ifl.getURI());
if(path!=null) {
reference = new IndexTypeReference(
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.widgets.Composite;
import org.eclipse.swt.widgets.Event;
import org.eclipse.swt.widgets.Label;
import org.eclipse.swt.widgets.Listener;
import org.eclipse.swt.widgets.Shell;
import org.eclipse.swt.widgets.Table;
import org.eclipse.swt.widgets.Text;
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.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.
* A dialog to select an element from a filterable list of elements.
*
* @since 4.0
*/
@ -70,7 +71,7 @@ public class ElementSelectionDialog extends TypeSelectionDialog {
}
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);
if (elements != null && !monitor.isCanceled()) {
final Shell shell= getShell();
@ -126,7 +127,7 @@ public class ElementSelectionDialog extends TypeSelectionDialog {
Runnable update= new Runnable() {
public void run() {
if (!shell.isDisposed() && !fDone) {
fMonitor.beginTask(TypeInfoMessages.OpenSymbolDialog_UpdateSymbolsJob_inProgress, IProgressMonitor.UNKNOWN);
fMonitor.beginTask(OpenTypeMessages.ElementSelectionDialog_UpdateElementsJob_inProgress, IProgressMonitor.UNKNOWN);
}
}};
shell.getDisplay().asyncExec(update);
@ -153,7 +154,7 @@ public class ElementSelectionDialog extends TypeSelectionDialog {
*/
public ElementSelectionDialog(Shell parent) {
super(parent);
fUpdateJob= new UpdateElementsJob(TypeInfoMessages.OpenSymbolDialog_UpdateSymbolsJob_name);
fUpdateJob= new UpdateElementsJob(OpenTypeMessages.ElementSelectionDialog_UpdateElementsJob_name);
fUpdateJob.setRule(SINGLE_INSTANCE_RULE);
}
@ -194,18 +195,19 @@ public class ElementSelectionDialog extends TypeSelectionDialog {
* @see org.eclipse.cdt.ui.browser.typeinfo.TypeSelectionDialog#showLowLevelFilter()
*/
protected boolean showLowLevelFilter() {
// the low-level filter is useless for us
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) {
FilteredList list= super.createFilteredList(parent);
protected Table createLowerList(Composite parent) {
Table table= super.createLowerList(parent);
createProgressMonitorPart(parent);
return list;
return table;
}
/**
* Create the control for progress reporting.
* @param parent
@ -216,7 +218,11 @@ public class ElementSelectionDialog extends TypeSelectionDialog {
gridData.horizontalIndent= 0;
gridData.verticalAlignment= GridData.BEGINNING;
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];
try {
String[] fqn;
if(binding instanceof ICPPBinding) {
fqn= ((ICPPBinding)binding).getQualifiedName();
} else {
fqn = new String[] {binding.getName()};
}
final int elementType = IndexModelUtil.getElementType(binding);
if (isVisibleType(elementType)) {
String[] fqn;
if(binding instanceof ICPPBinding) {
fqn= ((ICPPBinding)binding).getQualifiedName();
} else {
fqn = new String[] {binding.getName()};
}
if (binding instanceof IFunction) {
final IFunction function = (IFunction)binding;
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.ITextSelection;
import org.eclipse.jface.viewers.ISelection;
import org.eclipse.osgi.util.NLS;
import org.eclipse.swt.widgets.Shell;
import org.eclipse.ui.IEditorPart;
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.ITypeReference;
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.internal.ui.util.EditorUtility;
@ -62,20 +64,20 @@ public class OpenTypeAction implements IWorkbenchWindowActionDelegate {
ITypeReference location = info.getResolvedReference();
if (location == null) {
// could not resolve location
String title = OpenTypeMessages.getString("OpenTypeAction.errorTitle"); //$NON-NLS-1$
String message = OpenTypeMessages.getFormattedString("OpenTypeAction.errorTypeNotFound", info.getQualifiedTypeName().toString()); //$NON-NLS-1$
String title = OpenTypeMessages.OpenTypeAction_errorTitle;
String message = NLS.bind(OpenTypeMessages.OpenTypeAction_errorTypeNotFound, info.getQualifiedTypeName().toString());
MessageDialog.openError(getShell(), title, message);
} else if (!openTypeInEditor(location)) {
// error opening editor
String title = OpenTypeMessages.getString("OpenTypeAction.errorTitle"); //$NON-NLS-1$
String message = OpenTypeMessages.getFormattedString("OpenTypeAction.errorOpenEditor", location.getPath().toString()); //$NON-NLS-1$
String title = OpenTypeMessages.OpenTypeAction_errorTitle;
String message = NLS.bind(OpenTypeMessages.OpenTypeAction_errorOpenEditor, location.getPath().toString());
MessageDialog.openError(getShell(), title, message);
}
}
private void configureDialog(ElementSelectionDialog dialog) {
dialog.setTitle(OpenTypeMessages.getString("OpenTypeDialog.title")); //$NON-NLS-1$
dialog.setMessage(OpenTypeMessages.getString("OpenTypeDialog.message")); //$NON-NLS-1$
dialog.setTitle(OpenTypeMessages.OpenTypeDialog_title);
dialog.setMessage(OpenTypeMessages.OpenTypeDialog_message);
dialog.setDialogSettings(getClass().getName());
if (fWorkbenchWindow != null) {
IWorkbenchPage page= fWorkbenchWindow.getActivePage();
@ -105,10 +107,16 @@ public class OpenTypeAction implements IWorkbenchWindowActionDelegate {
* @return true if succesfully displayed.
*/
private boolean openTypeInEditor(ITypeReference location) {
ITranslationUnit unit = location.getTranslationUnit();
IEditorPart editorPart = null;
ICElement[] cElements= location.getCElements();
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)
editorPart = EditorUtility.openInEditor(unit);
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
* are made available under the terms of the Eclipse Public License v1.0
* which accompanies this distribution, and is available at
@ -7,48 +7,37 @@
*
* Contributors:
* QNX Software Systems - initial API and implementation
* Anton Leherbauer (Wind River Systems)
*******************************************************************************/
package org.eclipse.cdt.internal.ui.browser.opentype;
import java.text.MessageFormat;
import java.util.MissingResourceException;
import java.util.ResourceBundle;
import org.eclipse.osgi.util.NLS;
/**
* OpenTypeMessages
*/
public class OpenTypeMessages {
public final class OpenTypeMessages extends NLS {
private static final String RESOURCE_BUNDLE= OpenTypeMessages.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.internal.ui.browser.opentype.OpenTypeMessages";//$NON-NLS-1$
private OpenTypeMessages() {
// 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 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);
}
public static String OpenTypeAction_exception_title;
public static String OpenTypeAction_exception_message;
public static String OpenTypeAction_notypes_title;
public static String OpenTypeAction_notypes_message;
public static String OpenTypeAction_description;
public static String OpenTypeAction_tooltip;
public static String OpenTypeAction_label;
public static String OpenTypeAction_errorTitle;
public static String OpenTypeAction_errorOpenEditor;
public static String OpenTypeAction_errorTypeNotFound;
public static String OpenTypeDialog_title;
public static String OpenTypeDialog_message;
public static String OpenTypeDialog_filter;
public static String ElementSelectionDialog_UpdateElementsJob_name;
public static String ElementSelectionDialog_UpdateElementsJob_inProgress;
}
static {
NLS.initializeMessages(BUNDLE_NAME, OpenTypeMessages.class);
}
}

View file

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

View file

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