mirror of
https://github.com/eclipse-cdt/cdt
synced 2025-06-07 17:56:01 +02:00
Patch from Chris Wiebe
to deal with includes outside the workspace.
This commit is contained in:
parent
1f042fb9a2
commit
9e531f825a
6 changed files with 123 additions and 43 deletions
|
@ -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
|
2004-02-03 Alain Magloire
|
||||||
PR 51121
|
PR 51121
|
||||||
From Chris Wiebe:
|
From Chris Wiebe:
|
||||||
|
|
|
@ -12,14 +12,18 @@ package org.eclipse.cdt.internal.ui.opentype;
|
||||||
|
|
||||||
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.ICElement;
|
||||||
|
import org.eclipse.cdt.core.resources.FileStorage;
|
||||||
import org.eclipse.cdt.core.search.SearchEngine;
|
import org.eclipse.cdt.core.search.SearchEngine;
|
||||||
import org.eclipse.cdt.internal.ui.editor.CEditor;
|
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.internal.ui.util.EditorUtility;
|
||||||
import org.eclipse.cdt.ui.CUIPlugin;
|
import org.eclipse.cdt.ui.CUIPlugin;
|
||||||
import org.eclipse.core.resources.IResource;
|
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.action.IAction;
|
||||||
import org.eclipse.jface.dialogs.IDialogConstants;
|
import org.eclipse.jface.dialogs.IDialogConstants;
|
||||||
|
import org.eclipse.jface.dialogs.MessageDialog;
|
||||||
import org.eclipse.jface.dialogs.ProgressMonitorDialog;
|
import org.eclipse.jface.dialogs.ProgressMonitorDialog;
|
||||||
import org.eclipse.jface.viewers.ISelection;
|
import org.eclipse.jface.viewers.ISelection;
|
||||||
import org.eclipse.swt.widgets.Shell;
|
import org.eclipse.swt.widgets.Shell;
|
||||||
|
@ -69,7 +73,14 @@ public class OpenTypeAction implements IWorkbenchWindowActionDelegate {
|
||||||
if (result != IDialogConstants.OK_ID)
|
if (result != IDialogConstants.OK_ID)
|
||||||
return;
|
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) {
|
if (celement != null) {
|
||||||
try {
|
try {
|
||||||
IResource res= celement.getUnderlyingResource();
|
IResource res= celement.getUnderlyingResource();
|
||||||
|
@ -77,6 +88,7 @@ public class OpenTypeAction implements IWorkbenchWindowActionDelegate {
|
||||||
if (part instanceof CEditor) {
|
if (part instanceof CEditor) {
|
||||||
CEditor ed= (CEditor)part;
|
CEditor ed= (CEditor)part;
|
||||||
ed.setSelection(celement);
|
ed.setSelection(celement);
|
||||||
|
revealed = true;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
catch (CModelException ex){
|
catch (CModelException ex){
|
||||||
|
@ -86,6 +98,36 @@ public class OpenTypeAction implements IWorkbenchWindowActionDelegate {
|
||||||
ex.printStackTrace();
|
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)
|
/* (non-Javadoc)
|
||||||
|
|
|
@ -17,6 +17,7 @@ import org.eclipse.cdt.core.search.BasicSearchMatch;
|
||||||
import org.eclipse.core.resources.IFile;
|
import org.eclipse.core.resources.IFile;
|
||||||
import org.eclipse.core.resources.IResource;
|
import org.eclipse.core.resources.IResource;
|
||||||
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* To change the template for this generated type comment go to
|
* To change the template for this generated type comment go to
|
||||||
* Window>Preferences>Java>Code Generation>Code and Comments
|
* Window>Preferences>Java>Code Generation>Code and Comments
|
||||||
|
@ -30,42 +31,57 @@ public class TypeSearchMatch extends BasicSearchMatch
|
||||||
public String getFileName() {
|
public String getFileName() {
|
||||||
if (resource != null)
|
if (resource != null)
|
||||||
return resource.getName();
|
return resource.getName();
|
||||||
return "";
|
else if (path != null)
|
||||||
|
return path.lastSegment();
|
||||||
|
else
|
||||||
|
return null;
|
||||||
}
|
}
|
||||||
|
|
||||||
public String getFilePath() {
|
public String getFilePath() {
|
||||||
if (resource != null)
|
if (resource != null)
|
||||||
return resource.getFullPath().toString();
|
return resource.getFullPath().toString();
|
||||||
return "";
|
else if (path != null)
|
||||||
|
return path.toString();
|
||||||
|
else
|
||||||
|
return null;
|
||||||
}
|
}
|
||||||
|
|
||||||
public String getFileExtension() {
|
public String getFileExtension() {
|
||||||
if (resource != null)
|
if (resource != null)
|
||||||
return resource.getFileExtension();
|
return resource.getFileExtension();
|
||||||
return "";
|
else if (path != null)
|
||||||
|
return path.getFileExtension();
|
||||||
|
else
|
||||||
|
return null;
|
||||||
}
|
}
|
||||||
|
|
||||||
public String getQualifiedParentName() {
|
public String getQualifiedParentName() {
|
||||||
StringBuffer buf= new StringBuffer();
|
StringBuffer buf= new StringBuffer();
|
||||||
if (getFileName().length() > 0)
|
String fileName = getFileName();
|
||||||
buf.append(getFileName());
|
if (fileName != null && fileName.length() > 0)
|
||||||
if (getParentName().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(OpenTypeMessages.getString("TypeInfoLabelProvider.colon")); //$NON-NLS-1$
|
||||||
buf.append(getParentName());
|
buf.append(parentName);
|
||||||
}
|
}
|
||||||
return buf.toString();
|
return buf.toString();
|
||||||
}
|
}
|
||||||
|
|
||||||
public String getFullyQualifiedName() {
|
public String getFullyQualifiedName() {
|
||||||
StringBuffer buf= new StringBuffer();
|
StringBuffer buf= new StringBuffer();
|
||||||
if (getFilePath().length() > 0)
|
String filePath = getFilePath();
|
||||||
buf.append(getFilePath());
|
if (filePath != null && filePath.length() > 0)
|
||||||
if (getParentName().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(OpenTypeMessages.getString("TypeInfoLabelProvider.colon")); //$NON-NLS-1$
|
||||||
buf.append(getParentName());
|
buf.append(parentName);
|
||||||
buf.append("::");
|
buf.append("::");
|
||||||
}
|
}
|
||||||
buf.append(getName());
|
String name = getName();
|
||||||
|
if (name != null && name.length() > 0)
|
||||||
|
buf.append(name);
|
||||||
return buf.toString();
|
return buf.toString();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -18,6 +18,7 @@ import org.eclipse.jface.viewers.LabelProvider;
|
||||||
import org.eclipse.swt.graphics.Image;
|
import org.eclipse.swt.graphics.Image;
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
public class TypeSearchMatchLabelProvider extends LabelProvider {
|
public class TypeSearchMatchLabelProvider extends LabelProvider {
|
||||||
|
|
||||||
public static final int SHOW_FULLYQUALIFIED= 0x01;
|
public static final int SHOW_FULLYQUALIFIED= 0x01;
|
||||||
|
@ -58,26 +59,44 @@ public class TypeSearchMatchLabelProvider extends LabelProvider {
|
||||||
|
|
||||||
StringBuffer buf= new StringBuffer();
|
StringBuffer buf= new StringBuffer();
|
||||||
if (isSet(SHOW_TYPE_ONLY)) {
|
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)) {
|
} 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)) {
|
} else if (isSet(SHOW_FILENAME_ONLY)) {
|
||||||
buf.append(typeRef.getFileName());
|
String name= typeRef.getFileName();
|
||||||
|
if (name != null && name.length() > 0)
|
||||||
|
buf.append(name);
|
||||||
} else {
|
} else {
|
||||||
if (isSet(SHOW_FULLYQUALIFIED))
|
if (isSet(SHOW_FULLYQUALIFIED)) {
|
||||||
buf.append(typeRef.getFullyQualifiedName());
|
String name= typeRef.getFullyQualifiedName();
|
||||||
else
|
if (name != null && name.length() > 0)
|
||||||
buf.append(typeRef.getParentName());
|
buf.append(name);
|
||||||
|
}
|
||||||
|
else {
|
||||||
|
String name= typeRef.getParentName();
|
||||||
|
if (name != null && name.length() > 0)
|
||||||
|
buf.append(name);
|
||||||
|
}
|
||||||
|
|
||||||
if (isSet(SHOW_FILENAME_POSTFIX)) {
|
if (isSet(SHOW_FILENAME_POSTFIX)) {
|
||||||
buf.append(OpenTypeMessages.getString("TypeInfoLabelProvider.dash")); //$NON-NLS-1$
|
String name= typeRef.getFileName();
|
||||||
buf.append(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)) {
|
if (isSet(SHOW_ROOT_POSTFIX)) {
|
||||||
buf.append(OpenTypeMessages.getString("TypeInfoLabelProvider.dash"));//$NON-NLS-1$
|
String path= typeRef.getFilePath();
|
||||||
buf.append(typeRef.getFilePath());
|
if (path != null && path.length() > 0) {
|
||||||
|
buf.append(OpenTypeMessages.getString("TypeInfoLabelProvider.dash"));//$NON-NLS-1$
|
||||||
|
buf.append(path);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
return buf.toString();
|
return buf.toString();
|
||||||
}
|
}
|
||||||
|
|
|
@ -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
|
* All rights reserved. This program and the accompanying materials
|
||||||
* are made available under the terms of the Common Public License v1.0
|
* are made available under the terms of the Common Public License v1.0
|
||||||
* which accompanies this distribution, and is available at
|
* which accompanies this distribution, and is available at
|
||||||
|
|
|
@ -16,12 +16,11 @@ import java.util.ArrayList;
|
||||||
import java.util.Comparator;
|
import java.util.Comparator;
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
|
|
||||||
import org.eclipse.cdt.core.model.ICElement;
|
|
||||||
import org.eclipse.cdt.core.search.ICSearchScope;
|
import org.eclipse.cdt.core.search.ICSearchScope;
|
||||||
import org.eclipse.cdt.core.search.SearchEngine;
|
import org.eclipse.cdt.core.search.SearchEngine;
|
||||||
import org.eclipse.cdt.internal.ui.opentype.OpenTypeMessages;
|
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.TypeSearchMatch;
|
||||||
|
import org.eclipse.cdt.internal.ui.opentype.TypeSearchMatchLabelProvider;
|
||||||
import org.eclipse.cdt.internal.ui.opentype.TypeSearchOperation;
|
import org.eclipse.cdt.internal.ui.opentype.TypeSearchOperation;
|
||||||
import org.eclipse.cdt.internal.ui.util.StringMatcher;
|
import org.eclipse.cdt.internal.ui.util.StringMatcher;
|
||||||
import org.eclipse.cdt.internal.ui.util.ExceptionHandler;
|
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.FilteredList;
|
||||||
import org.eclipse.ui.dialogs.TwoPaneElementSelector;
|
import org.eclipse.ui.dialogs.TwoPaneElementSelector;
|
||||||
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* A dialog to select a type from a list of types.
|
* A dialog to select a type from a list of types.
|
||||||
*/
|
*/
|
||||||
|
@ -199,20 +199,9 @@ public class TypeSelectionDialog extends TwoPaneElementSelector {
|
||||||
TypeSearchMatch selection= (TypeSearchMatch) getLowerSelectedElement();
|
TypeSearchMatch selection= (TypeSearchMatch) getLowerSelectedElement();
|
||||||
if (selection == null)
|
if (selection == null)
|
||||||
return;
|
return;
|
||||||
|
|
||||||
// get the corresponding CElement
|
List result= new ArrayList(1);
|
||||||
ICElement celement= selection.getCElement();
|
result.add(selection);
|
||||||
if (celement != null) {
|
setResult(result);
|
||||||
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);
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
Loading…
Add table
Reference in a new issue