diff --git a/core/org.eclipse.cdt.ui/ChangeLog b/core/org.eclipse.cdt.ui/ChangeLog index 974b8e7485b..5610c8147e8 100644 --- a/core/org.eclipse.cdt.ui/ChangeLog +++ b/core/org.eclipse.cdt.ui/ChangeLog @@ -1,3 +1,17 @@ +2004-02-05 Alain Magloire + + From Chris Wiebe: + This patch fixes a problem in the OpenType dialog where it did not show + types defined in #includes outside the workspace. If a CElement does + not exist for a given type, it tries to open an editor at the file and + line where the match was found. + + * src/org/eclipse/cdt/internal/ui/opentype/OpenTypeAction.java + * src/org/eclipse/cdt/internal/ui/opentype/TypeSearchMatch.java + * src/org/eclipse/cdt/internal/ui/opentype/TypeSearchMatchLabelProvider.java + * src/org/eclpise/cdt/internal/ui/opentype/dialogs/OpenTypeSelectionDialog.java + * src/org/eclpise/cdt/internal/ui/opentype/dialogs/TypeSelectionDialog.java + 2004-02-03 Alain Magloire PR 51121 From Chris Wiebe: diff --git a/core/org.eclipse.cdt.ui/src/org/eclipse/cdt/internal/ui/opentype/OpenTypeAction.java b/core/org.eclipse.cdt.ui/src/org/eclipse/cdt/internal/ui/opentype/OpenTypeAction.java index bf6307a38c1..3155a1c995f 100644 --- a/core/org.eclipse.cdt.ui/src/org/eclipse/cdt/internal/ui/opentype/OpenTypeAction.java +++ b/core/org.eclipse.cdt.ui/src/org/eclipse/cdt/internal/ui/opentype/OpenTypeAction.java @@ -12,14 +12,18 @@ package org.eclipse.cdt.internal.ui.opentype; import org.eclipse.cdt.core.model.CModelException; import org.eclipse.cdt.core.model.ICElement; +import org.eclipse.cdt.core.resources.FileStorage; import org.eclipse.cdt.core.search.SearchEngine; import org.eclipse.cdt.internal.ui.editor.CEditor; -import org.eclipse.cdt.internal.ui.opentype.dialogs.*; +import org.eclipse.cdt.internal.ui.opentype.dialogs.OpenTypeSelectionDialog; import org.eclipse.cdt.internal.ui.util.EditorUtility; import org.eclipse.cdt.ui.CUIPlugin; import org.eclipse.core.resources.IResource; +import org.eclipse.core.resources.IStorage; +import org.eclipse.core.runtime.IPath; import org.eclipse.jface.action.IAction; import org.eclipse.jface.dialogs.IDialogConstants; +import org.eclipse.jface.dialogs.MessageDialog; import org.eclipse.jface.dialogs.ProgressMonitorDialog; import org.eclipse.jface.viewers.ISelection; import org.eclipse.swt.widgets.Shell; @@ -69,7 +73,14 @@ public class OpenTypeAction implements IWorkbenchWindowActionDelegate { if (result != IDialogConstants.OK_ID) return; - ICElement celement= (ICElement)dialog.getFirstResult(); + TypeSearchMatch selection= (TypeSearchMatch)dialog.getFirstResult(); + if (selection == null) + return; + + boolean revealed = false; + + // get the corresponding CElement + ICElement celement= selection.getCElement(); if (celement != null) { try { IResource res= celement.getUnderlyingResource(); @@ -77,6 +88,7 @@ public class OpenTypeAction implements IWorkbenchWindowActionDelegate { if (part instanceof CEditor) { CEditor ed= (CEditor)part; ed.setSelection(celement); + revealed = true; } } catch (CModelException ex){ @@ -86,6 +98,36 @@ public class OpenTypeAction implements IWorkbenchWindowActionDelegate { ex.printStackTrace(); } } + + if (!revealed) { + try { + IPath path = selection.getLocation(); + IStorage storage = new FileStorage(path); + IEditorPart part= EditorUtility.openInEditor(storage); + if (part instanceof CEditor) { + CEditor ed= (CEditor)part; + ed.selectAndReveal(selection.getStartOffset(), selection.getName().length()); + revealed = true; + } + } + catch (CModelException ex){ + ex.printStackTrace(); + } + catch(PartInitException ex) { + ex.printStackTrace(); + } + } + + if (!revealed) + { + // could not find definition + String path= selection.getFilePath(); + if (path == null || path.length() == 0) + path= "Unknown"; + String title= OpenTypeMessages.getString("TypeSelectionDialog.errorTitle"); //$NON-NLS-1$ + String message= OpenTypeMessages.getFormattedString("TypeSelectionDialog.dialogMessage", path); //$NON-NLS-1$ + MessageDialog.openError(parent, title, message); + } } /* (non-Javadoc) diff --git a/core/org.eclipse.cdt.ui/src/org/eclipse/cdt/internal/ui/opentype/TypeSearchMatch.java b/core/org.eclipse.cdt.ui/src/org/eclipse/cdt/internal/ui/opentype/TypeSearchMatch.java index 48aacab4a1c..0e1ff7673b4 100644 --- a/core/org.eclipse.cdt.ui/src/org/eclipse/cdt/internal/ui/opentype/TypeSearchMatch.java +++ b/core/org.eclipse.cdt.ui/src/org/eclipse/cdt/internal/ui/opentype/TypeSearchMatch.java @@ -17,6 +17,7 @@ import org.eclipse.cdt.core.search.BasicSearchMatch; 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 @@ -30,42 +31,57 @@ public class TypeSearchMatch extends BasicSearchMatch public String getFileName() { if (resource != null) return resource.getName(); - return ""; + else if (path != null) + return path.lastSegment(); + else + return null; } public String getFilePath() { if (resource != null) return resource.getFullPath().toString(); - return ""; + else if (path != null) + return path.toString(); + else + return null; } public String getFileExtension() { if (resource != null) return resource.getFileExtension(); - return ""; + else if (path != null) + return path.getFileExtension(); + else + return null; } public String getQualifiedParentName() { StringBuffer buf= new StringBuffer(); - if (getFileName().length() > 0) - buf.append(getFileName()); - if (getParentName().length() > 0) { + String fileName = getFileName(); + if (fileName != null && fileName.length() > 0) + buf.append(fileName); + String parentName = getParentName(); + if (parentName != null && parentName.length() > 0) { buf.append(OpenTypeMessages.getString("TypeInfoLabelProvider.colon")); //$NON-NLS-1$ - buf.append(getParentName()); + buf.append(parentName); } return buf.toString(); } public String getFullyQualifiedName() { StringBuffer buf= new StringBuffer(); - if (getFilePath().length() > 0) - buf.append(getFilePath()); - if (getParentName().length() > 0) { + String filePath = getFilePath(); + if (filePath != null && filePath.length() > 0) + buf.append(filePath); + String parentName = getParentName(); + if (parentName != null && parentName.length() > 0) { buf.append(OpenTypeMessages.getString("TypeInfoLabelProvider.colon")); //$NON-NLS-1$ - buf.append(getParentName()); + buf.append(parentName); buf.append("::"); } - buf.append(getName()); + String name = getName(); + if (name != null && name.length() > 0) + buf.append(name); return buf.toString(); } diff --git a/core/org.eclipse.cdt.ui/src/org/eclipse/cdt/internal/ui/opentype/TypeSearchMatchLabelProvider.java b/core/org.eclipse.cdt.ui/src/org/eclipse/cdt/internal/ui/opentype/TypeSearchMatchLabelProvider.java index 2ba90a81107..8465e13af6a 100644 --- a/core/org.eclipse.cdt.ui/src/org/eclipse/cdt/internal/ui/opentype/TypeSearchMatchLabelProvider.java +++ b/core/org.eclipse.cdt.ui/src/org/eclipse/cdt/internal/ui/opentype/TypeSearchMatchLabelProvider.java @@ -18,6 +18,7 @@ import org.eclipse.jface.viewers.LabelProvider; import org.eclipse.swt.graphics.Image; + public class TypeSearchMatchLabelProvider extends LabelProvider { public static final int SHOW_FULLYQUALIFIED= 0x01; @@ -58,26 +59,44 @@ public class TypeSearchMatchLabelProvider extends LabelProvider { StringBuffer buf= new StringBuffer(); if (isSet(SHOW_TYPE_ONLY)) { - buf.append(typeRef.getName()); + String name= typeRef.getName(); + if (name != null && name.length() > 0) + buf.append(name); } else if (isSet(SHOW_TYPE_CONTAINER_ONLY)) { - buf.append(typeRef.getQualifiedParentName()); + String name= typeRef.getQualifiedParentName(); + if (name != null && name.length() > 0) + buf.append(name); } else if (isSet(SHOW_FILENAME_ONLY)) { - buf.append(typeRef.getFileName()); + String name= typeRef.getFileName(); + if (name != null && name.length() > 0) + buf.append(name); } else { - if (isSet(SHOW_FULLYQUALIFIED)) - buf.append(typeRef.getFullyQualifiedName()); - else - buf.append(typeRef.getParentName()); + if (isSet(SHOW_FULLYQUALIFIED)) { + String name= typeRef.getFullyQualifiedName(); + if (name != null && name.length() > 0) + buf.append(name); + } + else { + String name= typeRef.getParentName(); + if (name != null && name.length() > 0) + buf.append(name); + } if (isSet(SHOW_FILENAME_POSTFIX)) { - buf.append(OpenTypeMessages.getString("TypeInfoLabelProvider.dash")); //$NON-NLS-1$ - buf.append(typeRef.getFileName()); + String name= typeRef.getFileName(); + if (name != null && name.length() > 0) { + buf.append(OpenTypeMessages.getString("TypeInfoLabelProvider.dash")); //$NON-NLS-1$ + buf.append(name); + } } } if (isSet(SHOW_ROOT_POSTFIX)) { - buf.append(OpenTypeMessages.getString("TypeInfoLabelProvider.dash"));//$NON-NLS-1$ - buf.append(typeRef.getFilePath()); + String path= typeRef.getFilePath(); + if (path != null && path.length() > 0) { + buf.append(OpenTypeMessages.getString("TypeInfoLabelProvider.dash"));//$NON-NLS-1$ + buf.append(path); + } } return buf.toString(); } diff --git a/core/org.eclipse.cdt.ui/src/org/eclipse/cdt/internal/ui/opentype/dialogs/OpenTypeSelectionDialog.java b/core/org.eclipse.cdt.ui/src/org/eclipse/cdt/internal/ui/opentype/dialogs/OpenTypeSelectionDialog.java index 6a73fbed665..1ae25873b3f 100644 --- a/core/org.eclipse.cdt.ui/src/org/eclipse/cdt/internal/ui/opentype/dialogs/OpenTypeSelectionDialog.java +++ b/core/org.eclipse.cdt.ui/src/org/eclipse/cdt/internal/ui/opentype/dialogs/OpenTypeSelectionDialog.java @@ -1,5 +1,5 @@ /******************************************************************************* - * Copyright (c) 2000, 2003 IBM Corporation and others. + * Copyright (c) 2000,2003,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 diff --git a/core/org.eclipse.cdt.ui/src/org/eclipse/cdt/internal/ui/opentype/dialogs/TypeSelectionDialog.java b/core/org.eclipse.cdt.ui/src/org/eclipse/cdt/internal/ui/opentype/dialogs/TypeSelectionDialog.java index 8754c32b5c6..760f86ec060 100644 --- a/core/org.eclipse.cdt.ui/src/org/eclipse/cdt/internal/ui/opentype/dialogs/TypeSelectionDialog.java +++ b/core/org.eclipse.cdt.ui/src/org/eclipse/cdt/internal/ui/opentype/dialogs/TypeSelectionDialog.java @@ -16,12 +16,11 @@ import java.util.ArrayList; import java.util.Comparator; import java.util.List; -import org.eclipse.cdt.core.model.ICElement; import org.eclipse.cdt.core.search.ICSearchScope; import org.eclipse.cdt.core.search.SearchEngine; import org.eclipse.cdt.internal.ui.opentype.OpenTypeMessages; -import org.eclipse.cdt.internal.ui.opentype.TypeSearchMatchLabelProvider; import org.eclipse.cdt.internal.ui.opentype.TypeSearchMatch; +import org.eclipse.cdt.internal.ui.opentype.TypeSearchMatchLabelProvider; import org.eclipse.cdt.internal.ui.opentype.TypeSearchOperation; import org.eclipse.cdt.internal.ui.util.StringMatcher; import org.eclipse.cdt.internal.ui.util.ExceptionHandler; @@ -35,6 +34,7 @@ import org.eclipse.swt.widgets.Shell; import org.eclipse.ui.dialogs.FilteredList; import org.eclipse.ui.dialogs.TwoPaneElementSelector; + /** * A dialog to select a type from a list of types. */ @@ -199,20 +199,9 @@ public class TypeSelectionDialog extends TwoPaneElementSelector { TypeSearchMatch selection= (TypeSearchMatch) getLowerSelectedElement(); if (selection == null) return; - - // get the corresponding CElement - ICElement celement= selection.getCElement(); - if (celement != null) { - List result= new ArrayList(1); - result.add(celement); - setResult(result); - } - else { - // could not find definition - String title= OpenTypeMessages.getString("TypeSelectionDialog.errorTitle"); //$NON-NLS-1$ - String message= OpenTypeMessages.getFormattedString("TypeSelectionDialog.dialogMessage", selection.getFilePath()); //$NON-NLS-1$ - MessageDialog.openError(getShell(), title, message); - setResult(null); - } + + List result= new ArrayList(1); + result.add(selection); + setResult(result); } }