Skip to main content

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index] [List Home]
Re: [cdt-patch] Open Type dialog

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.

Chris
Index: .project
===================================================================
retrieving revision 1.5
diff -u -r1.5 .project
--- .project	27 Nov 2003 19:52:23 -0000	1.5
+++ .project	4 Feb 2004 23:42:15 -0000
@@ -4,6 +4,7 @@
 	<comment></comment>
 	<projects>
 		<project>org.eclipse.cdt.core</project>
+		<project>org.eclipse.ui</project>
 	</projects>
 	<buildSpec>
 		<buildCommand>
Index: src/org/eclipse/cdt/internal/ui/opentype/OpenTypeAction.java
===================================================================
retrieving revision 1.1
diff -u -r1.1 OpenTypeAction.java
--- src/org/eclipse/cdt/internal/ui/opentype/OpenTypeAction.java	28 Jan 2004 21:23:08 -0000	1.1
+++ src/org/eclipse/cdt/internal/ui/opentype/OpenTypeAction.java	4 Feb 2004 23:42:20 -0000
@@ -12,14 +12,18 @@
 
 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 @@
 		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,26 @@
 				if (part instanceof CEditor) {
 					CEditor ed= (CEditor)part;
 					ed.setSelection(celement);
+					revealed = true;
+				}
+			}
+			catch (CModelException ex){
+				ex.printStackTrace();
+			}
+			catch(PartInitException ex) {
+				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){
@@ -85,6 +116,17 @@
 			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);
 		}
 	}
 
Index: src/org/eclipse/cdt/internal/ui/opentype/TypeSearchMatch.java
===================================================================
retrieving revision 1.1
diff -u -r1.1 TypeSearchMatch.java
--- src/org/eclipse/cdt/internal/ui/opentype/TypeSearchMatch.java	28 Jan 2004 21:23:08 -0000	1.1
+++ src/org/eclipse/cdt/internal/ui/opentype/TypeSearchMatch.java	4 Feb 2004 23:42:20 -0000
@@ -17,6 +17,7 @@
 import org.eclipse.core.resources.IFile;
 import org.eclipse.core.resources.IResource;
 
+
 /**
  * To change the template for this generated type comment go to
  * Window&gt;Preferences&gt;Java&gt;Code Generation&gt;Code and Comments
@@ -30,42 +31,57 @@
 	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();
 	}
 	
Index: src/org/eclipse/cdt/internal/ui/opentype/TypeSearchMatchLabelProvider.java
===================================================================
retrieving revision 1.1
diff -u -r1.1 TypeSearchMatchLabelProvider.java
--- src/org/eclipse/cdt/internal/ui/opentype/TypeSearchMatchLabelProvider.java	28 Jan 2004 21:23:08 -0000	1.1
+++ src/org/eclipse/cdt/internal/ui/opentype/TypeSearchMatchLabelProvider.java	4 Feb 2004 23:42:20 -0000
@@ -18,6 +18,7 @@
 import org.eclipse.swt.graphics.Image;
 
 
+
 public class TypeSearchMatchLabelProvider extends LabelProvider {
 
 	public static final int SHOW_FULLYQUALIFIED=	0x01;
@@ -58,26 +59,44 @@
 		
 		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();				
 	}
Index: src/org/eclipse/cdt/internal/ui/opentype/dialogs/OpenTypeSelectionDialog.java
===================================================================
retrieving revision 1.1
diff -u -r1.1 OpenTypeSelectionDialog.java
--- src/org/eclipse/cdt/internal/ui/opentype/dialogs/OpenTypeSelectionDialog.java	28 Jan 2004 21:23:08 -0000	1.1
+++ src/org/eclipse/cdt/internal/ui/opentype/dialogs/OpenTypeSelectionDialog.java	4 Feb 2004 23:42:20 -0000
@@ -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
Index: src/org/eclipse/cdt/internal/ui/opentype/dialogs/TypeSelectionDialog.java
===================================================================
retrieving revision 1.1
diff -u -r1.1 TypeSelectionDialog.java
--- src/org/eclipse/cdt/internal/ui/opentype/dialogs/TypeSelectionDialog.java	28 Jan 2004 21:23:08 -0000	1.1
+++ src/org/eclipse/cdt/internal/ui/opentype/dialogs/TypeSelectionDialog.java	4 Feb 2004 23:42:20 -0000
@@ -16,12 +16,11 @@
 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.ui.dialogs.FilteredList;
 import org.eclipse.ui.dialogs.TwoPaneElementSelector;
 
+
 /**
  * A dialog to select a type from a list of types.
  */
@@ -199,20 +199,9 @@
 		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);
 	}
 }

Back to the top