mirror of
https://github.com/eclipse-cdt/cdt
synced 2025-04-23 06:32:10 +02:00
Fix for 182312, adds 'Open Element in Call Hierarchy' action.
This commit is contained in:
parent
78a7a6be39
commit
38b2d76e76
7 changed files with 40 additions and 54 deletions
|
@ -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,11 +7,14 @@
|
|||
*
|
||||
* Contributors:
|
||||
* QNX Software Systems - initial API and implementation
|
||||
* Markus Schorn (Wind River Systems)
|
||||
*******************************************************************************/
|
||||
package org.eclipse.cdt.core.browser;
|
||||
|
||||
import org.eclipse.cdt.core.CCorePlugin;
|
||||
import org.eclipse.cdt.core.model.CModelException;
|
||||
import org.eclipse.cdt.core.model.CoreModel;
|
||||
import org.eclipse.cdt.core.model.CoreModelUtil;
|
||||
import org.eclipse.cdt.core.model.ICElement;
|
||||
import org.eclipse.cdt.core.model.ICProject;
|
||||
import org.eclipse.cdt.core.model.ITranslationUnit;
|
||||
|
@ -135,24 +138,22 @@ public class TypeReference implements ITypeReference {
|
|||
ICElement elem = CoreModel.getDefault().create(path);
|
||||
if (elem instanceof ITranslationUnit)
|
||||
unit = (ITranslationUnit) elem;
|
||||
}
|
||||
|
||||
if (unit == null) {
|
||||
IProject project = getProject();
|
||||
if (project != null) {
|
||||
ICProject cProject = findCProject(project);
|
||||
if (cProject != null) {
|
||||
IPath path = getLocation();
|
||||
ICElement elem = CoreModel.getDefault().createTranslationUnitFrom(cProject, path);
|
||||
if (elem instanceof ITranslationUnit)
|
||||
unit = (ITranslationUnit) elem;
|
||||
else {
|
||||
try {
|
||||
unit= CoreModelUtil.findTranslationUnitForLocation(path, findCProject(getProject()));
|
||||
} catch (CModelException e) {
|
||||
CCorePlugin.log(e);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
return unit;
|
||||
}
|
||||
|
||||
private ICProject findCProject(IProject project) {
|
||||
if (project == null) {
|
||||
return null;
|
||||
}
|
||||
try {
|
||||
ICProject[] cProjects = CoreModel.getDefault().getCModel().getCProjects();
|
||||
if (cProjects != null) {
|
||||
|
|
|
@ -942,15 +942,14 @@
|
|||
description="%CNavigationActionSet.description"
|
||||
visible="false"
|
||||
id="org.eclipse.cdt.ui.NavigationActionSet">
|
||||
<!-- enable only after the open symbol dialog can handle functions
|
||||
action
|
||||
<action
|
||||
id="org.eclipse.cdt.ui.actions.openElementInCallHierarchy"
|
||||
class="org.eclipse.cdt.internal.ui.callhierarchy.OpenElementInCallHierarchyAction"
|
||||
definitionId="org.eclipse.cdt.ui.navigate.open.element.in.call.hierarchy"
|
||||
label="%OpenElementInCallHierarchyAction.label"
|
||||
menubarPath="navigate/open.ext2"
|
||||
tooltip="%OpenElementInCallHierarchyAction.tooltip">
|
||||
</action-->
|
||||
</action>
|
||||
<action
|
||||
id="org.eclipse.cdt.ui.actions.openTypeInHierarchy"
|
||||
class="org.eclipse.cdt.internal.ui.typehierarchy.OpenTypeInHierarchyAction"
|
||||
|
|
|
@ -1,5 +1,5 @@
|
|||
/*******************************************************************************
|
||||
* Copyright (c) 2004, 2006 IBM Corporation and others.
|
||||
* Copyright (c) 2004, 2007 IBM Corporation 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
|
||||
|
@ -21,6 +21,7 @@ import org.eclipse.cdt.core.index.IIndexFileLocation;
|
|||
import org.eclipse.cdt.core.index.IndexLocationFactory;
|
||||
import org.eclipse.cdt.core.model.CModelException;
|
||||
import org.eclipse.cdt.core.model.CoreModel;
|
||||
import org.eclipse.cdt.core.model.CoreModelUtil;
|
||||
import org.eclipse.cdt.core.model.ICContainer;
|
||||
import org.eclipse.cdt.core.model.ICElement;
|
||||
import org.eclipse.cdt.core.model.ICProject;
|
||||
|
@ -149,34 +150,7 @@ public class CModelUtil {
|
|||
* @throws CModelException
|
||||
*/
|
||||
public static ITranslationUnit findTranslationUnitForLocation(IPath location, ICProject preferredProject) throws CModelException {
|
||||
IFile[] files= ResourcesPlugin.getWorkspace().getRoot().findFilesForLocation(location);
|
||||
if (files.length > 0) {
|
||||
for (int i = 0; i < files.length; i++) {
|
||||
IFile file = files[i];
|
||||
ITranslationUnit tu= findTranslationUnit(file);
|
||||
if (tu != null) {
|
||||
return tu;
|
||||
}
|
||||
}
|
||||
}
|
||||
else {
|
||||
CoreModel coreModel = CoreModel.getDefault();
|
||||
ITranslationUnit tu= null;
|
||||
if (preferredProject != null) {
|
||||
tu= coreModel.createTranslationUnitFrom(preferredProject, location);
|
||||
}
|
||||
if (tu == null) {
|
||||
ICProject[] projects= coreModel.getCModel().getCProjects();
|
||||
for (int i = 0; i < projects.length && tu == null; i++) {
|
||||
ICProject project = projects[i];
|
||||
if (!project.equals(preferredProject)) {
|
||||
tu= coreModel.createTranslationUnitFrom(project, location);
|
||||
}
|
||||
}
|
||||
}
|
||||
return tu;
|
||||
}
|
||||
return null;
|
||||
return CoreModelUtil.findTranslationUnitForLocation(location, preferredProject);
|
||||
}
|
||||
|
||||
/**
|
||||
|
|
|
@ -48,7 +48,7 @@ BinaryParserBlock.desc=Set required binary parser for this project
|
|||
|
||||
BaseIndexerBlock.label=C/C++ Indexer
|
||||
BaseIndexerBlock.desc=C/C++ Indexer setting for this project.
|
||||
BaseIndexerBlock.comboLabel=Select Indexer
|
||||
BaseIndexerBlock.comboLabel=Select indexer
|
||||
|
||||
ReferenceBlock.label= Projects
|
||||
ReferenceBlock.desc= Referenced C/C++ Projects
|
||||
|
|
|
@ -28,7 +28,7 @@ import org.eclipse.cdt.core.browser.ITypeInfo;
|
|||
import org.eclipse.cdt.core.browser.ITypeReference;
|
||||
import org.eclipse.cdt.core.model.ICElement;
|
||||
|
||||
import org.eclipse.cdt.internal.ui.browser.opentype.OpenTypeDialog;
|
||||
import org.eclipse.cdt.internal.ui.browser.opentype.ElementSelectionDialog;
|
||||
|
||||
public class OpenElementInCallHierarchyAction implements IWorkbenchWindowActionDelegate {
|
||||
|
||||
|
@ -42,7 +42,7 @@ public class OpenElementInCallHierarchyAction implements IWorkbenchWindowActionD
|
|||
}
|
||||
|
||||
public void run(IAction action) {
|
||||
OpenTypeDialog dialog = new OpenTypeDialog(getShell());
|
||||
ElementSelectionDialog dialog = new ElementSelectionDialog(getShell());
|
||||
configureDialog(dialog);
|
||||
int result = dialog.open();
|
||||
if (result != IDialogConstants.OK_ID)
|
||||
|
@ -67,7 +67,7 @@ public class OpenElementInCallHierarchyAction implements IWorkbenchWindowActionD
|
|||
}
|
||||
}
|
||||
|
||||
private void configureDialog(OpenTypeDialog dialog) {
|
||||
private void configureDialog(ElementSelectionDialog dialog) {
|
||||
dialog.setDialogSettings(getClass().getName());
|
||||
dialog.setVisibleTypes(VISIBLE_TYPES);
|
||||
dialog.setTitle(CHMessages.OpenElementInCallHierarchyAction_title);
|
||||
|
|
|
@ -27,25 +27,30 @@ import org.eclipse.ui.IWorkbenchPreferencePage;
|
|||
import org.eclipse.cdt.ui.dialogs.CacheSizeBlock;
|
||||
import org.eclipse.cdt.ui.dialogs.ICOptionContainer;
|
||||
import org.eclipse.cdt.ui.dialogs.IndexerBlock;
|
||||
import org.eclipse.cdt.ui.dialogs.IndexerStrategyBlock;
|
||||
|
||||
public class IndexerPreferencePage extends PreferencePage implements
|
||||
IWorkbenchPreferencePage, ICOptionContainer {
|
||||
|
||||
private IndexerBlock fOptionBlock;
|
||||
private CacheSizeBlock fCacheBlock;
|
||||
private IndexerStrategyBlock fStrategyBlock;
|
||||
|
||||
public IndexerPreferencePage(){
|
||||
fOptionBlock = new IndexerBlock();
|
||||
fStrategyBlock= new IndexerStrategyBlock(this);
|
||||
fCacheBlock= new CacheSizeBlock(this);
|
||||
}
|
||||
|
||||
protected Control createContents(Composite parent) {
|
||||
GridLayout gl;
|
||||
Composite composite = new Composite(parent, SWT.NONE);
|
||||
composite.setLayout(new GridLayout());
|
||||
GridData gd= new GridData();
|
||||
composite.setLayoutData(gd);
|
||||
composite.setLayout(gl= new GridLayout());
|
||||
composite.setLayoutData(new GridData());
|
||||
gl.verticalSpacing= 0;
|
||||
|
||||
fOptionBlock.createControl(composite);
|
||||
fStrategyBlock.createControl(composite);
|
||||
fCacheBlock.createControl(composite);
|
||||
|
||||
return composite;
|
||||
|
@ -59,6 +64,10 @@ public class IndexerPreferencePage extends PreferencePage implements
|
|||
setErrorMessage(fOptionBlock.getErrorMessage());
|
||||
setValid(false);
|
||||
}
|
||||
else if (!fStrategyBlock.isValid()) {
|
||||
setErrorMessage(fStrategyBlock.getErrorMessage());
|
||||
setValid(false);
|
||||
}
|
||||
else if (!fCacheBlock.isValid()) {
|
||||
setErrorMessage(fCacheBlock.getErrorMessage());
|
||||
setValid(false);
|
||||
|
@ -80,6 +89,7 @@ public class IndexerPreferencePage extends PreferencePage implements
|
|||
public boolean performOk() {
|
||||
try {
|
||||
fOptionBlock.performApply(new NullProgressMonitor());
|
||||
fStrategyBlock.performApply(new NullProgressMonitor());
|
||||
fCacheBlock.performApply(new NullProgressMonitor());
|
||||
} catch (CoreException e) {}
|
||||
return true;
|
||||
|
@ -87,6 +97,8 @@ public class IndexerPreferencePage extends PreferencePage implements
|
|||
|
||||
public void performDefaults() {
|
||||
fOptionBlock.performDefaults();
|
||||
fStrategyBlock.performDefaults();
|
||||
fCacheBlock.performDefaults();
|
||||
updateContainer();
|
||||
}
|
||||
}
|
||||
|
|
|
@ -28,7 +28,7 @@ import org.eclipse.cdt.core.browser.ITypeInfo;
|
|||
import org.eclipse.cdt.core.browser.ITypeReference;
|
||||
import org.eclipse.cdt.core.model.ICElement;
|
||||
|
||||
import org.eclipse.cdt.internal.ui.browser.opentype.OpenTypeDialog;
|
||||
import org.eclipse.cdt.internal.ui.browser.opentype.ElementSelectionDialog;
|
||||
|
||||
public class OpenTypeInHierarchyAction implements IWorkbenchWindowActionDelegate {
|
||||
|
||||
|
@ -42,7 +42,7 @@ public class OpenTypeInHierarchyAction implements IWorkbenchWindowActionDelegate
|
|||
}
|
||||
|
||||
public void run(IAction action) {
|
||||
OpenTypeDialog dialog = new OpenTypeDialog(getShell());
|
||||
ElementSelectionDialog dialog = new ElementSelectionDialog(getShell());
|
||||
configureDialog(dialog);
|
||||
int result = dialog.open();
|
||||
if (result != IDialogConstants.OK_ID)
|
||||
|
@ -67,7 +67,7 @@ public class OpenTypeInHierarchyAction implements IWorkbenchWindowActionDelegate
|
|||
}
|
||||
}
|
||||
|
||||
private void configureDialog(OpenTypeDialog dialog) {
|
||||
private void configureDialog(ElementSelectionDialog dialog) {
|
||||
dialog.setDialogSettings(getClass().getName());
|
||||
dialog.setVisibleTypes(VISIBLE_TYPES);
|
||||
dialog.setTitle(Messages.OpenTypeInHierarchyAction_title);
|
||||
|
|
Loading…
Add table
Reference in a new issue