mirror of
https://github.com/eclipse-cdt/cdt
synced 2025-06-07 17:56:01 +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
|
* All rights reserved. This program and the accompanying materials
|
||||||
* are made available under the terms of the Eclipse Public License v1.0
|
* are made available under the terms of the Eclipse Public License v1.0
|
||||||
* which accompanies this distribution, and is available at
|
* which accompanies this distribution, and is available at
|
||||||
|
@ -7,11 +7,14 @@
|
||||||
*
|
*
|
||||||
* Contributors:
|
* Contributors:
|
||||||
* QNX Software Systems - initial API and implementation
|
* QNX Software Systems - initial API and implementation
|
||||||
|
* Markus Schorn (Wind River Systems)
|
||||||
*******************************************************************************/
|
*******************************************************************************/
|
||||||
package org.eclipse.cdt.core.browser;
|
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.CModelException;
|
||||||
import org.eclipse.cdt.core.model.CoreModel;
|
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.ICElement;
|
||||||
import org.eclipse.cdt.core.model.ICProject;
|
import org.eclipse.cdt.core.model.ICProject;
|
||||||
import org.eclipse.cdt.core.model.ITranslationUnit;
|
import org.eclipse.cdt.core.model.ITranslationUnit;
|
||||||
|
@ -135,24 +138,22 @@ public class TypeReference implements ITypeReference {
|
||||||
ICElement elem = CoreModel.getDefault().create(path);
|
ICElement elem = CoreModel.getDefault().create(path);
|
||||||
if (elem instanceof ITranslationUnit)
|
if (elem instanceof ITranslationUnit)
|
||||||
unit = (ITranslationUnit) elem;
|
unit = (ITranslationUnit) elem;
|
||||||
}
|
else {
|
||||||
|
try {
|
||||||
if (unit == null) {
|
unit= CoreModelUtil.findTranslationUnitForLocation(path, findCProject(getProject()));
|
||||||
IProject project = getProject();
|
} catch (CModelException e) {
|
||||||
if (project != null) {
|
CCorePlugin.log(e);
|
||||||
ICProject cProject = findCProject(project);
|
|
||||||
if (cProject != null) {
|
|
||||||
IPath path = getLocation();
|
|
||||||
ICElement elem = CoreModel.getDefault().createTranslationUnitFrom(cProject, path);
|
|
||||||
if (elem instanceof ITranslationUnit)
|
|
||||||
unit = (ITranslationUnit) elem;
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
return unit;
|
return unit;
|
||||||
}
|
}
|
||||||
|
|
||||||
private ICProject findCProject(IProject project) {
|
private ICProject findCProject(IProject project) {
|
||||||
|
if (project == null) {
|
||||||
|
return null;
|
||||||
|
}
|
||||||
try {
|
try {
|
||||||
ICProject[] cProjects = CoreModel.getDefault().getCModel().getCProjects();
|
ICProject[] cProjects = CoreModel.getDefault().getCModel().getCProjects();
|
||||||
if (cProjects != null) {
|
if (cProjects != null) {
|
||||||
|
|
|
@ -942,15 +942,14 @@
|
||||||
description="%CNavigationActionSet.description"
|
description="%CNavigationActionSet.description"
|
||||||
visible="false"
|
visible="false"
|
||||||
id="org.eclipse.cdt.ui.NavigationActionSet">
|
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"
|
id="org.eclipse.cdt.ui.actions.openElementInCallHierarchy"
|
||||||
class="org.eclipse.cdt.internal.ui.callhierarchy.OpenElementInCallHierarchyAction"
|
class="org.eclipse.cdt.internal.ui.callhierarchy.OpenElementInCallHierarchyAction"
|
||||||
definitionId="org.eclipse.cdt.ui.navigate.open.element.in.call.hierarchy"
|
definitionId="org.eclipse.cdt.ui.navigate.open.element.in.call.hierarchy"
|
||||||
label="%OpenElementInCallHierarchyAction.label"
|
label="%OpenElementInCallHierarchyAction.label"
|
||||||
menubarPath="navigate/open.ext2"
|
menubarPath="navigate/open.ext2"
|
||||||
tooltip="%OpenElementInCallHierarchyAction.tooltip">
|
tooltip="%OpenElementInCallHierarchyAction.tooltip">
|
||||||
</action-->
|
</action>
|
||||||
<action
|
<action
|
||||||
id="org.eclipse.cdt.ui.actions.openTypeInHierarchy"
|
id="org.eclipse.cdt.ui.actions.openTypeInHierarchy"
|
||||||
class="org.eclipse.cdt.internal.ui.typehierarchy.OpenTypeInHierarchyAction"
|
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
|
* All rights reserved. This program and the accompanying materials
|
||||||
* are made available under the terms of the Eclipse Public License v1.0
|
* are made available under the terms of the Eclipse Public License v1.0
|
||||||
* which accompanies this distribution, and is available at
|
* 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.index.IndexLocationFactory;
|
||||||
import org.eclipse.cdt.core.model.CModelException;
|
import org.eclipse.cdt.core.model.CModelException;
|
||||||
import org.eclipse.cdt.core.model.CoreModel;
|
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.ICContainer;
|
||||||
import org.eclipse.cdt.core.model.ICElement;
|
import org.eclipse.cdt.core.model.ICElement;
|
||||||
import org.eclipse.cdt.core.model.ICProject;
|
import org.eclipse.cdt.core.model.ICProject;
|
||||||
|
@ -149,34 +150,7 @@ public class CModelUtil {
|
||||||
* @throws CModelException
|
* @throws CModelException
|
||||||
*/
|
*/
|
||||||
public static ITranslationUnit findTranslationUnitForLocation(IPath location, ICProject preferredProject) throws CModelException {
|
public static ITranslationUnit findTranslationUnitForLocation(IPath location, ICProject preferredProject) throws CModelException {
|
||||||
IFile[] files= ResourcesPlugin.getWorkspace().getRoot().findFilesForLocation(location);
|
return CoreModelUtil.findTranslationUnitForLocation(location, preferredProject);
|
||||||
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;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
|
|
@ -48,7 +48,7 @@ BinaryParserBlock.desc=Set required binary parser for this project
|
||||||
|
|
||||||
BaseIndexerBlock.label=C/C++ Indexer
|
BaseIndexerBlock.label=C/C++ Indexer
|
||||||
BaseIndexerBlock.desc=C/C++ Indexer setting for this project.
|
BaseIndexerBlock.desc=C/C++ Indexer setting for this project.
|
||||||
BaseIndexerBlock.comboLabel=Select Indexer
|
BaseIndexerBlock.comboLabel=Select indexer
|
||||||
|
|
||||||
ReferenceBlock.label= Projects
|
ReferenceBlock.label= Projects
|
||||||
ReferenceBlock.desc= Referenced C/C++ 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.browser.ITypeReference;
|
||||||
import org.eclipse.cdt.core.model.ICElement;
|
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 {
|
public class OpenElementInCallHierarchyAction implements IWorkbenchWindowActionDelegate {
|
||||||
|
|
||||||
|
@ -42,7 +42,7 @@ public class OpenElementInCallHierarchyAction implements IWorkbenchWindowActionD
|
||||||
}
|
}
|
||||||
|
|
||||||
public void run(IAction action) {
|
public void run(IAction action) {
|
||||||
OpenTypeDialog dialog = new OpenTypeDialog(getShell());
|
ElementSelectionDialog dialog = new ElementSelectionDialog(getShell());
|
||||||
configureDialog(dialog);
|
configureDialog(dialog);
|
||||||
int result = dialog.open();
|
int result = dialog.open();
|
||||||
if (result != IDialogConstants.OK_ID)
|
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.setDialogSettings(getClass().getName());
|
||||||
dialog.setVisibleTypes(VISIBLE_TYPES);
|
dialog.setVisibleTypes(VISIBLE_TYPES);
|
||||||
dialog.setTitle(CHMessages.OpenElementInCallHierarchyAction_title);
|
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.CacheSizeBlock;
|
||||||
import org.eclipse.cdt.ui.dialogs.ICOptionContainer;
|
import org.eclipse.cdt.ui.dialogs.ICOptionContainer;
|
||||||
import org.eclipse.cdt.ui.dialogs.IndexerBlock;
|
import org.eclipse.cdt.ui.dialogs.IndexerBlock;
|
||||||
|
import org.eclipse.cdt.ui.dialogs.IndexerStrategyBlock;
|
||||||
|
|
||||||
public class IndexerPreferencePage extends PreferencePage implements
|
public class IndexerPreferencePage extends PreferencePage implements
|
||||||
IWorkbenchPreferencePage, ICOptionContainer {
|
IWorkbenchPreferencePage, ICOptionContainer {
|
||||||
|
|
||||||
private IndexerBlock fOptionBlock;
|
private IndexerBlock fOptionBlock;
|
||||||
private CacheSizeBlock fCacheBlock;
|
private CacheSizeBlock fCacheBlock;
|
||||||
|
private IndexerStrategyBlock fStrategyBlock;
|
||||||
|
|
||||||
public IndexerPreferencePage(){
|
public IndexerPreferencePage(){
|
||||||
fOptionBlock = new IndexerBlock();
|
fOptionBlock = new IndexerBlock();
|
||||||
|
fStrategyBlock= new IndexerStrategyBlock(this);
|
||||||
fCacheBlock= new CacheSizeBlock(this);
|
fCacheBlock= new CacheSizeBlock(this);
|
||||||
}
|
}
|
||||||
|
|
||||||
protected Control createContents(Composite parent) {
|
protected Control createContents(Composite parent) {
|
||||||
|
GridLayout gl;
|
||||||
Composite composite = new Composite(parent, SWT.NONE);
|
Composite composite = new Composite(parent, SWT.NONE);
|
||||||
composite.setLayout(new GridLayout());
|
composite.setLayout(gl= new GridLayout());
|
||||||
GridData gd= new GridData();
|
composite.setLayoutData(new GridData());
|
||||||
composite.setLayoutData(gd);
|
gl.verticalSpacing= 0;
|
||||||
|
|
||||||
fOptionBlock.createControl(composite);
|
fOptionBlock.createControl(composite);
|
||||||
|
fStrategyBlock.createControl(composite);
|
||||||
fCacheBlock.createControl(composite);
|
fCacheBlock.createControl(composite);
|
||||||
|
|
||||||
return composite;
|
return composite;
|
||||||
|
@ -59,6 +64,10 @@ public class IndexerPreferencePage extends PreferencePage implements
|
||||||
setErrorMessage(fOptionBlock.getErrorMessage());
|
setErrorMessage(fOptionBlock.getErrorMessage());
|
||||||
setValid(false);
|
setValid(false);
|
||||||
}
|
}
|
||||||
|
else if (!fStrategyBlock.isValid()) {
|
||||||
|
setErrorMessage(fStrategyBlock.getErrorMessage());
|
||||||
|
setValid(false);
|
||||||
|
}
|
||||||
else if (!fCacheBlock.isValid()) {
|
else if (!fCacheBlock.isValid()) {
|
||||||
setErrorMessage(fCacheBlock.getErrorMessage());
|
setErrorMessage(fCacheBlock.getErrorMessage());
|
||||||
setValid(false);
|
setValid(false);
|
||||||
|
@ -80,6 +89,7 @@ public class IndexerPreferencePage extends PreferencePage implements
|
||||||
public boolean performOk() {
|
public boolean performOk() {
|
||||||
try {
|
try {
|
||||||
fOptionBlock.performApply(new NullProgressMonitor());
|
fOptionBlock.performApply(new NullProgressMonitor());
|
||||||
|
fStrategyBlock.performApply(new NullProgressMonitor());
|
||||||
fCacheBlock.performApply(new NullProgressMonitor());
|
fCacheBlock.performApply(new NullProgressMonitor());
|
||||||
} catch (CoreException e) {}
|
} catch (CoreException e) {}
|
||||||
return true;
|
return true;
|
||||||
|
@ -87,6 +97,8 @@ public class IndexerPreferencePage extends PreferencePage implements
|
||||||
|
|
||||||
public void performDefaults() {
|
public void performDefaults() {
|
||||||
fOptionBlock.performDefaults();
|
fOptionBlock.performDefaults();
|
||||||
|
fStrategyBlock.performDefaults();
|
||||||
fCacheBlock.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.browser.ITypeReference;
|
||||||
import org.eclipse.cdt.core.model.ICElement;
|
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 {
|
public class OpenTypeInHierarchyAction implements IWorkbenchWindowActionDelegate {
|
||||||
|
|
||||||
|
@ -42,7 +42,7 @@ public class OpenTypeInHierarchyAction implements IWorkbenchWindowActionDelegate
|
||||||
}
|
}
|
||||||
|
|
||||||
public void run(IAction action) {
|
public void run(IAction action) {
|
||||||
OpenTypeDialog dialog = new OpenTypeDialog(getShell());
|
ElementSelectionDialog dialog = new ElementSelectionDialog(getShell());
|
||||||
configureDialog(dialog);
|
configureDialog(dialog);
|
||||||
int result = dialog.open();
|
int result = dialog.open();
|
||||||
if (result != IDialogConstants.OK_ID)
|
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.setDialogSettings(getClass().getName());
|
||||||
dialog.setVisibleTypes(VISIBLE_TYPES);
|
dialog.setVisibleTypes(VISIBLE_TYPES);
|
||||||
dialog.setTitle(Messages.OpenTypeInHierarchyAction_title);
|
dialog.setTitle(Messages.OpenTypeInHierarchyAction_title);
|
||||||
|
|
Loading…
Add table
Reference in a new issue