mirror of
https://github.com/eclipse-cdt/cdt
synced 2025-04-29 19:45:01 +02:00
Fix for 186995, action to open include browser.
This commit is contained in:
parent
1cc80334d3
commit
086a2e9463
11 changed files with 302 additions and 7 deletions
|
@ -309,6 +309,8 @@ ActionDefinition.openTypeHierarchy.name= Open Type Hierarchy
|
||||||
ActionDefinition.openTypeHierarchy.description= Open a type hierarchy on the selected element
|
ActionDefinition.openTypeHierarchy.description= Open a type hierarchy on the selected element
|
||||||
ActionDefinition.openElementInCallHierarchy.name= Open Element in Call Hierarchy
|
ActionDefinition.openElementInCallHierarchy.name= Open Element in Call Hierarchy
|
||||||
ActionDefinition.openElementInCallHierarchy.description= Open an element in the call hierarchy view
|
ActionDefinition.openElementInCallHierarchy.description= Open an element in the call hierarchy view
|
||||||
|
ActionDefinition.openIncludeBrowser.name= Open Include Browser
|
||||||
|
ActionDefinition.openIncludeBrowser.description= Open an include browser on the selected element
|
||||||
OpenTypeHierarchyAction.label=Open Type Hie&rarchy
|
OpenTypeHierarchyAction.label=Open Type Hie&rarchy
|
||||||
OpenTypeHierarchyAction.tooltip=Opens a Type Hierarchy for the Selected Element
|
OpenTypeHierarchyAction.tooltip=Opens a Type Hierarchy for the Selected Element
|
||||||
ViewCommand.typeHierarchy.name= C Type Hierarchy
|
ViewCommand.typeHierarchy.name= C Type Hierarchy
|
||||||
|
@ -383,9 +385,12 @@ Dummy.label = dummy
|
||||||
# Common Navigator
|
# Common Navigator
|
||||||
navigatorContent.name = CDT Elements
|
navigatorContent.name = CDT Elements
|
||||||
|
|
||||||
OpenCallHierarchy.label = Open Call Hierarchy
|
OpenCallHierarchy.label = Open Call H&ierarchy
|
||||||
OpenCallHierarchy.tooltip = Open Call Hierarchy
|
OpenCallHierarchy.tooltip = Open Call Hierarchy
|
||||||
|
|
||||||
|
OpenIncludeBrowser.label = Open Inc&lude Browser
|
||||||
|
OpenIncludeBrowser.tooltip = Open Include Browser
|
||||||
|
|
||||||
ParserProposalCategory=Parsing-based Proposals
|
ParserProposalCategory=Parsing-based Proposals
|
||||||
DefaultProposalCategory= &Basic Proposals
|
DefaultProposalCategory= &Basic Proposals
|
||||||
TemplateProposalCategory= Te&mplate Proposals
|
TemplateProposalCategory= Te&mplate Proposals
|
||||||
|
|
|
@ -1027,6 +1027,14 @@
|
||||||
description="%COpenActionSet.description"
|
description="%COpenActionSet.description"
|
||||||
visible="false"
|
visible="false"
|
||||||
id="org.eclipse.cdt.ui.OpenActionSet">
|
id="org.eclipse.cdt.ui.OpenActionSet">
|
||||||
|
<action
|
||||||
|
definitionId="org.eclipse.cdt.ui.edit.open.include.browser"
|
||||||
|
id="org.eclipse.cdt.ui.actions.OpenIncludeBrowser"
|
||||||
|
label="%OpenIncludeBrowser.label"
|
||||||
|
menubarPath="navigate/open.ext"
|
||||||
|
retarget="true"
|
||||||
|
tooltip="%OpenIncludeBrowser.tooltip">
|
||||||
|
</action>
|
||||||
<action
|
<action
|
||||||
definitionId="org.eclipse.cdt.ui.edit.open.call.hierarchy"
|
definitionId="org.eclipse.cdt.ui.edit.open.call.hierarchy"
|
||||||
id="org.eclipse.cdt.ui.actions.OpenCallHierarchy"
|
id="org.eclipse.cdt.ui.actions.OpenCallHierarchy"
|
||||||
|
@ -1219,6 +1227,16 @@
|
||||||
contextId="org.eclipse.cdt.ui.cViewScope"
|
contextId="org.eclipse.cdt.ui.cViewScope"
|
||||||
commandId="org.eclipse.cdt.ui.edit.open.call.hierarchy"
|
commandId="org.eclipse.cdt.ui.edit.open.call.hierarchy"
|
||||||
schemeId="org.eclipse.ui.defaultAcceleratorConfiguration"/>
|
schemeId="org.eclipse.ui.defaultAcceleratorConfiguration"/>
|
||||||
|
<key
|
||||||
|
sequence="M1+M3+I"
|
||||||
|
contextId="org.eclipse.cdt.ui.cEditorScope"
|
||||||
|
commandId="org.eclipse.cdt.ui.edit.open.include.browser"
|
||||||
|
schemeId="org.eclipse.ui.defaultAcceleratorConfiguration"/>
|
||||||
|
<key
|
||||||
|
sequence="M1+M3+I"
|
||||||
|
contextId="org.eclipse.cdt.ui.cViewScope"
|
||||||
|
commandId="org.eclipse.cdt.ui.edit.open.include.browser"
|
||||||
|
schemeId="org.eclipse.ui.defaultAcceleratorConfiguration"/>
|
||||||
<!--removed, see bug 167162
|
<!--removed, see bug 167162
|
||||||
<key
|
<key
|
||||||
sequence="M1+F3"
|
sequence="M1+F3"
|
||||||
|
@ -1403,6 +1421,12 @@
|
||||||
categoryId="org.eclipse.ui.category.navigate"
|
categoryId="org.eclipse.ui.category.navigate"
|
||||||
id="org.eclipse.cdt.ui.edit.open.type.hierarchy">
|
id="org.eclipse.cdt.ui.edit.open.type.hierarchy">
|
||||||
</command>
|
</command>
|
||||||
|
<command
|
||||||
|
categoryId="org.eclipse.ui.category.navigate"
|
||||||
|
description="%ActionDefinition.openIncludeBrowser.description"
|
||||||
|
name="%ActionDefinition.openIncludeBrowser.name"
|
||||||
|
id="org.eclipse.cdt.ui.edit.open.include.browser">
|
||||||
|
</command>
|
||||||
<command
|
<command
|
||||||
name="%ActionDefinition.openTypeInHierarchy.name"
|
name="%ActionDefinition.openTypeInHierarchy.name"
|
||||||
description="%ActionDefinition.openTypeInHierarchy.description"
|
description="%ActionDefinition.openTypeInHierarchy.description"
|
||||||
|
|
|
@ -97,7 +97,7 @@ public class CContentOutlinePage extends Page implements IContentOutlinePage, IS
|
||||||
private MemberFilterActionGroup fMemberFilterActionGroup;
|
private MemberFilterActionGroup fMemberFilterActionGroup;
|
||||||
|
|
||||||
private ActionGroup fSelectionSearchGroup;
|
private ActionGroup fSelectionSearchGroup;
|
||||||
private ActionGroup fOpenViewActionGroup;
|
private OpenViewActionGroup fOpenViewActionGroup;
|
||||||
private ActionGroup fRefactoringActionGroup;
|
private ActionGroup fRefactoringActionGroup;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
@ -343,6 +343,7 @@ public class CContentOutlinePage extends Page implements IContentOutlinePage, IS
|
||||||
|
|
||||||
fSelectionSearchGroup = new SelectionSearchGroup(this);
|
fSelectionSearchGroup = new SelectionSearchGroup(this);
|
||||||
fOpenViewActionGroup = new OpenViewActionGroup(this);
|
fOpenViewActionGroup = new OpenViewActionGroup(this);
|
||||||
|
fOpenViewActionGroup.setEnableIncludeBrowser(true);
|
||||||
fRefactoringActionGroup= new CRefactoringActionGroup(this);
|
fRefactoringActionGroup= new CRefactoringActionGroup(this);
|
||||||
// Custom filter group
|
// Custom filter group
|
||||||
fCustomFiltersActionGroup= new CustomFiltersActionGroup("org.eclipse.cdt.ui.COutlinePage", getTreeViewer()); //$NON-NLS-1$
|
fCustomFiltersActionGroup= new CustomFiltersActionGroup("org.eclipse.cdt.ui.COutlinePage", getTreeViewer()); //$NON-NLS-1$
|
||||||
|
|
|
@ -152,6 +152,12 @@ public interface ICEditorActionDefinitionIds extends ITextEditorActionDefinition
|
||||||
*/
|
*/
|
||||||
public static final String OPEN_CALL_HIERARCHY= "org.eclipse.cdt.ui.edit.open.call.hierarchy"; //$NON-NLS-1$
|
public static final String OPEN_CALL_HIERARCHY= "org.eclipse.cdt.ui.edit.open.call.hierarchy"; //$NON-NLS-1$
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Action definition ID for opening the include browser.
|
||||||
|
* (value <code>"org.eclipse.cdt.ui.edit.open.include.browser"</code>).
|
||||||
|
*/
|
||||||
|
public static final String OPEN_INCLUDE_BROWSER= "org.eclipse.cdt.ui.edit.open.include.browser"; //$NON-NLS-1$
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Action definition ID for go to next c member.
|
* Action definition ID for go to next c member.
|
||||||
* (value <code>"org.eclipse.cdt.ui.edit.text.c.goto.next.memeber"</code>)
|
* (value <code>"org.eclipse.cdt.ui.edit.text.c.goto.next.memeber"</code>)
|
||||||
|
|
|
@ -50,6 +50,10 @@ public class IBMessages extends NLS {
|
||||||
public static String IBViewPart_waitingOnIndexerMessage;
|
public static String IBViewPart_waitingOnIndexerMessage;
|
||||||
public static String IBViewPart_workspaceScope;
|
public static String IBViewPart_workspaceScope;
|
||||||
|
|
||||||
|
public static String OpenIncludeBrowserAction_label;
|
||||||
|
|
||||||
|
public static String OpenIncludeBrowserAction_tooltip;
|
||||||
|
|
||||||
static {
|
static {
|
||||||
// initialize resource bundle
|
// initialize resource bundle
|
||||||
NLS.initializeMessages(BUNDLE_NAME, IBMessages.class);
|
NLS.initializeMessages(BUNDLE_NAME, IBMessages.class);
|
||||||
|
|
|
@ -41,3 +41,5 @@ IBHistoryListAction_Remove_label=Remove
|
||||||
IBHistoryDropDownAction_tooltip=Show History List
|
IBHistoryDropDownAction_tooltip=Show History List
|
||||||
IBHistoryListAction_HistoryList_label=Select a file to show in the Include Browser:
|
IBHistoryListAction_HistoryList_label=Select a file to show in the Include Browser:
|
||||||
IBHistoryListAction_label=Open History...
|
IBHistoryListAction_label=Open History...
|
||||||
|
OpenIncludeBrowserAction_label=Open Inc&lude Browser
|
||||||
|
OpenIncludeBrowserAction_tooltip=Open Include Browser
|
||||||
|
|
|
@ -0,0 +1,90 @@
|
||||||
|
/*******************************************************************************
|
||||||
|
* Copyright (c) 2007 Wind River Systems, Inc. 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
|
||||||
|
* http://www.eclipse.org/legal/epl-v10.html
|
||||||
|
*
|
||||||
|
* Contributors:
|
||||||
|
* Markus Schorn - initial API and implementation
|
||||||
|
*******************************************************************************/
|
||||||
|
|
||||||
|
package org.eclipse.cdt.internal.ui.includebrowser;
|
||||||
|
|
||||||
|
import org.eclipse.core.runtime.CoreException;
|
||||||
|
import org.eclipse.jface.text.ITextSelection;
|
||||||
|
import org.eclipse.ui.IWorkbenchPage;
|
||||||
|
import org.eclipse.ui.IWorkbenchWindow;
|
||||||
|
import org.eclipse.ui.texteditor.ITextEditor;
|
||||||
|
|
||||||
|
import org.eclipse.cdt.core.CCorePlugin;
|
||||||
|
import org.eclipse.cdt.core.index.IIndex;
|
||||||
|
import org.eclipse.cdt.core.index.IIndexFileLocation;
|
||||||
|
import org.eclipse.cdt.core.index.IIndexInclude;
|
||||||
|
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.IInclude;
|
||||||
|
import org.eclipse.cdt.core.model.ISourceReference;
|
||||||
|
import org.eclipse.cdt.core.model.ITranslationUnit;
|
||||||
|
import org.eclipse.cdt.ui.CUIPlugin;
|
||||||
|
|
||||||
|
import org.eclipse.cdt.internal.ui.util.ExceptionHandler;
|
||||||
|
import org.eclipse.cdt.internal.ui.viewsupport.IndexUI;
|
||||||
|
|
||||||
|
public class IncludeBrowserUI {
|
||||||
|
|
||||||
|
public static void open(final IWorkbenchWindow window, final ICElement input) {
|
||||||
|
try {
|
||||||
|
ITranslationUnit tu= convertToTranslationUnit(input);
|
||||||
|
if (tu != null) {
|
||||||
|
IWorkbenchPage page= window.getActivePage();
|
||||||
|
IBViewPart result= (IBViewPart)page.showView(CUIPlugin.ID_INCLUDE_BROWSER);
|
||||||
|
result.setInput(tu);
|
||||||
|
}
|
||||||
|
} catch (CoreException e) {
|
||||||
|
ExceptionHandler.handle(e, window.getShell(), IBMessages.OpenIncludeBrowserAction_label, null);
|
||||||
|
} catch (InterruptedException e) {
|
||||||
|
Thread.currentThread().interrupt();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
public static void open(final ITextEditor editor, final ITextSelection sel) {
|
||||||
|
if (editor != null) {
|
||||||
|
ICElement inputCElement = CUIPlugin.getDefault().getWorkingCopyManager().getWorkingCopy(editor.getEditorInput());
|
||||||
|
open (editor.getSite().getWorkbenchWindow(), inputCElement);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
private static ITranslationUnit convertToTranslationUnit(ICElement input) throws CoreException, InterruptedException {
|
||||||
|
ITranslationUnit result= null;
|
||||||
|
if (input instanceof IInclude) {
|
||||||
|
result= findTargetTranslationUnit((IInclude) input);
|
||||||
|
}
|
||||||
|
if (result == null && input instanceof ISourceReference) {
|
||||||
|
result= ((ISourceReference) input).getTranslationUnit();
|
||||||
|
}
|
||||||
|
return result;
|
||||||
|
}
|
||||||
|
|
||||||
|
private static ITranslationUnit findTargetTranslationUnit(IInclude input) throws CoreException, InterruptedException {
|
||||||
|
ICProject project= input.getCProject();
|
||||||
|
if (project != null) {
|
||||||
|
IIndex index= CCorePlugin.getIndexManager().getIndex(project);
|
||||||
|
index.acquireReadLock();
|
||||||
|
try {
|
||||||
|
IIndexInclude include= IndexUI.elementToInclude(index, input);
|
||||||
|
if (include != null) {
|
||||||
|
IIndexFileLocation loc= include.getIncludesLocation();
|
||||||
|
if (loc != null) {
|
||||||
|
return CoreModelUtil.findTranslationUnitForLocation(loc, project);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
finally {
|
||||||
|
index.releaseReadLock();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
}
|
|
@ -0,0 +1,92 @@
|
||||||
|
/*******************************************************************************
|
||||||
|
* Copyright (c) 2007 Wind River Systems, Inc. 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
|
||||||
|
* http://www.eclipse.org/legal/epl-v10.html
|
||||||
|
*
|
||||||
|
* Contributors:
|
||||||
|
* Markus Schorn - initial API and implementation
|
||||||
|
*******************************************************************************/
|
||||||
|
|
||||||
|
package org.eclipse.cdt.internal.ui.includebrowser;
|
||||||
|
|
||||||
|
import org.eclipse.core.runtime.IAdaptable;
|
||||||
|
import org.eclipse.jface.text.ITextSelection;
|
||||||
|
import org.eclipse.jface.viewers.IStructuredSelection;
|
||||||
|
import org.eclipse.ui.IWorkbenchSite;
|
||||||
|
import org.eclipse.ui.texteditor.ITextEditor;
|
||||||
|
|
||||||
|
import org.eclipse.cdt.core.model.ICElement;
|
||||||
|
import org.eclipse.cdt.core.model.ISourceReference;
|
||||||
|
import org.eclipse.cdt.ui.CUIPlugin;
|
||||||
|
import org.eclipse.cdt.ui.actions.SelectionDispatchAction;
|
||||||
|
|
||||||
|
|
||||||
|
public class OpenIncludeBrowserAction extends SelectionDispatchAction {
|
||||||
|
|
||||||
|
private ITextEditor fEditor;
|
||||||
|
|
||||||
|
public OpenIncludeBrowserAction(IWorkbenchSite site) {
|
||||||
|
super(site);
|
||||||
|
setText(IBMessages.OpenIncludeBrowserAction_label);
|
||||||
|
setToolTipText(IBMessages.OpenIncludeBrowserAction_tooltip);
|
||||||
|
}
|
||||||
|
|
||||||
|
public OpenIncludeBrowserAction(ITextEditor editor) {
|
||||||
|
this(editor.getSite());
|
||||||
|
fEditor= editor;
|
||||||
|
setEnabled(fEditor != null && CUIPlugin.getDefault().getWorkingCopyManager().getWorkingCopy(editor.getEditorInput()) != null);
|
||||||
|
}
|
||||||
|
|
||||||
|
public void run(ITextSelection sel) {
|
||||||
|
IncludeBrowserUI.open(fEditor, sel);
|
||||||
|
}
|
||||||
|
|
||||||
|
public void run(IStructuredSelection selection) {
|
||||||
|
if (!selection.isEmpty()) {
|
||||||
|
Object selectedObject= selection.getFirstElement();
|
||||||
|
ICElement elem= (ICElement) getAdapter(selectedObject, ICElement.class);
|
||||||
|
if (elem != null) {
|
||||||
|
IncludeBrowserUI.open(getSite().getWorkbenchWindow(), elem);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
public void selectionChanged(ITextSelection sel) {
|
||||||
|
}
|
||||||
|
|
||||||
|
public void selectionChanged(IStructuredSelection selection) {
|
||||||
|
if (selection.isEmpty()) {
|
||||||
|
setEnabled(false);
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
Object selectedObject= selection.getFirstElement();
|
||||||
|
ICElement elem= (ICElement) getAdapter(selectedObject, ICElement.class);
|
||||||
|
if (elem != null) {
|
||||||
|
setEnabled(isValidElement(elem));
|
||||||
|
}
|
||||||
|
else {
|
||||||
|
setEnabled(false);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
private boolean isValidElement(ICElement elem) {
|
||||||
|
if (elem instanceof ISourceReference) {
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
|
private Object getAdapter(Object object, Class desiredClass) {
|
||||||
|
if (desiredClass.isInstance(object)) {
|
||||||
|
return object;
|
||||||
|
}
|
||||||
|
if (object instanceof IAdaptable) {
|
||||||
|
IAdaptable adaptable= (IAdaptable) object;
|
||||||
|
return adaptable.getAdapter(desiredClass);
|
||||||
|
}
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
}
|
|
@ -51,6 +51,7 @@ import org.eclipse.cdt.core.index.IIndex;
|
||||||
import org.eclipse.cdt.core.index.IIndexBinding;
|
import org.eclipse.cdt.core.index.IIndexBinding;
|
||||||
import org.eclipse.cdt.core.index.IIndexFile;
|
import org.eclipse.cdt.core.index.IIndexFile;
|
||||||
import org.eclipse.cdt.core.index.IIndexFileLocation;
|
import org.eclipse.cdt.core.index.IIndexFileLocation;
|
||||||
|
import org.eclipse.cdt.core.index.IIndexInclude;
|
||||||
import org.eclipse.cdt.core.index.IIndexName;
|
import org.eclipse.cdt.core.index.IIndexName;
|
||||||
import org.eclipse.cdt.core.index.IndexFilter;
|
import org.eclipse.cdt.core.index.IndexFilter;
|
||||||
import org.eclipse.cdt.core.index.IndexLocationFactory;
|
import org.eclipse.cdt.core.index.IndexLocationFactory;
|
||||||
|
@ -58,6 +59,7 @@ import org.eclipse.cdt.core.model.CModelException;
|
||||||
import org.eclipse.cdt.core.model.CoreModelUtil;
|
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.IInclude;
|
||||||
import org.eclipse.cdt.core.model.ILanguage;
|
import org.eclipse.cdt.core.model.ILanguage;
|
||||||
import org.eclipse.cdt.core.model.ISourceRange;
|
import org.eclipse.cdt.core.model.ISourceRange;
|
||||||
import org.eclipse.cdt.core.model.ISourceReference;
|
import org.eclipse.cdt.core.model.ISourceReference;
|
||||||
|
@ -167,11 +169,7 @@ public class IndexUI {
|
||||||
String elementName= element.getElementName();
|
String elementName= element.getElementName();
|
||||||
int idx= elementName.lastIndexOf(":")+1; //$NON-NLS-1$
|
int idx= elementName.lastIndexOf(":")+1; //$NON-NLS-1$
|
||||||
ISourceRange pos= sf.getSourceRange();
|
ISourceRange pos= sf.getSourceRange();
|
||||||
IRegion region= new Region(pos.getIdStartPos()+idx, pos.getIdLength()-idx);
|
IRegion region = getConvertedRegion(tu, file, pos.getIdStartPos()+idx, pos.getIdLength()-idx);
|
||||||
IPositionConverter converter= CCorePlugin.getPositionTrackerManager().findPositionConverter(tu, file.getTimestamp());
|
|
||||||
if (converter != null) {
|
|
||||||
region= converter.actualToHistoric(region);
|
|
||||||
}
|
|
||||||
IIndexName[] names= file.findNames(region.getOffset(), region.getLength());
|
IIndexName[] names= file.findNames(region.getOffset(), region.getLength());
|
||||||
for (int i = 0; i < names.length; i++) {
|
for (int i = 0; i < names.length; i++) {
|
||||||
IIndexName name = names[i];
|
IIndexName name = names[i];
|
||||||
|
@ -186,6 +184,51 @@ public class IndexUI {
|
||||||
return null;
|
return null;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
private static IRegion getConvertedRegion(ITranslationUnit tu, IIndexFile file, int pos, int length) throws CoreException {
|
||||||
|
IRegion region= new Region(pos, length);
|
||||||
|
IPositionConverter converter= CCorePlugin.getPositionTrackerManager().findPositionConverter(tu, file.getTimestamp());
|
||||||
|
if (converter != null) {
|
||||||
|
region= converter.actualToHistoric(region);
|
||||||
|
}
|
||||||
|
return region;
|
||||||
|
}
|
||||||
|
|
||||||
|
public static IIndexInclude elementToInclude(IIndex index, IInclude include) throws CoreException {
|
||||||
|
if (include != null) {
|
||||||
|
ITranslationUnit tu= include.getTranslationUnit();
|
||||||
|
if (tu != null) {
|
||||||
|
IIndexFileLocation location= IndexLocationFactory.getIFL(tu);
|
||||||
|
if (location != null) {
|
||||||
|
IIndexFile file= index.getFile(location);
|
||||||
|
if (file != null) {
|
||||||
|
String elementName= include.getElementName();
|
||||||
|
elementName= elementName.substring(elementName.lastIndexOf('/')+1);
|
||||||
|
ISourceRange pos= include.getSourceRange();
|
||||||
|
IRegion region= getConvertedRegion(tu, file, pos.getIdStartPos(), pos.getIdLength());
|
||||||
|
|
||||||
|
IIndexInclude[] includes= index.findIncludes(file);
|
||||||
|
int bestDiff= Integer.MAX_VALUE;
|
||||||
|
IIndexInclude best= null;
|
||||||
|
for (int i = 0; i < includes.length; i++) {
|
||||||
|
IIndexInclude candidate = includes[i];
|
||||||
|
int diff= Math.abs(candidate.getNameOffset()- region.getOffset());
|
||||||
|
if (diff > bestDiff) {
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
if (candidate.getName().endsWith(elementName)) {
|
||||||
|
bestDiff= diff;
|
||||||
|
best= candidate;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return best;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
public static ICElementHandle[] findRepresentative(IIndex index, IBinding binding) throws CoreException {
|
public static ICElementHandle[] findRepresentative(IIndex index, IBinding binding) throws CoreException {
|
||||||
ICElementHandle[] defs = IndexUI.findAllDefinitions(index, binding);
|
ICElementHandle[] defs = IndexUI.findAllDefinitions(index, binding);
|
||||||
if (defs.length == 0) {
|
if (defs.length == 0) {
|
||||||
|
|
|
@ -49,6 +49,13 @@ public class CdtActionConstants {
|
||||||
*/
|
*/
|
||||||
public static final String OPEN_CALL_HIERARCHY= "org.eclipse.cdt.ui.actions.OpenCallHierarchy"; //$NON-NLS-1$
|
public static final String OPEN_CALL_HIERARCHY= "org.eclipse.cdt.ui.actions.OpenCallHierarchy"; //$NON-NLS-1$
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Navigate menu: name of standard Open Include Browser global action
|
||||||
|
* (value <code>"org.eclipse.cdt.ui.actions.OpenIncludeBrowser"</code>).
|
||||||
|
* @since 4.0
|
||||||
|
*/
|
||||||
|
public static final String OPEN_INCLUDE_BROWSER= "org.eclipse.cdt.ui.actions.OpenIncludeBrowser"; //$NON-NLS-1$
|
||||||
|
|
||||||
// Edit menu
|
// Edit menu
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
|
|
@ -32,6 +32,7 @@ import org.eclipse.cdt.core.model.ICElement;
|
||||||
import org.eclipse.cdt.internal.ui.IContextMenuConstants;
|
import org.eclipse.cdt.internal.ui.IContextMenuConstants;
|
||||||
import org.eclipse.cdt.internal.ui.callhierarchy.OpenCallHierarchyAction;
|
import org.eclipse.cdt.internal.ui.callhierarchy.OpenCallHierarchyAction;
|
||||||
import org.eclipse.cdt.internal.ui.editor.ICEditorActionDefinitionIds;
|
import org.eclipse.cdt.internal.ui.editor.ICEditorActionDefinitionIds;
|
||||||
|
import org.eclipse.cdt.internal.ui.includebrowser.OpenIncludeBrowserAction;
|
||||||
import org.eclipse.cdt.internal.ui.typehierarchy.OpenTypeHierarchyAction;
|
import org.eclipse.cdt.internal.ui.typehierarchy.OpenTypeHierarchyAction;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
@ -50,6 +51,7 @@ public class OpenViewActionGroup extends ActionGroup {
|
||||||
private boolean fSuppressTypeHierarchy;
|
private boolean fSuppressTypeHierarchy;
|
||||||
private boolean fSuppressCallHierarchy;
|
private boolean fSuppressCallHierarchy;
|
||||||
private boolean fSuppressProperties;
|
private boolean fSuppressProperties;
|
||||||
|
private boolean fEnableIncludeBrowser;
|
||||||
private IWorkbenchSite fSite;
|
private IWorkbenchSite fSite;
|
||||||
private String fGroupName= IContextMenuConstants.GROUP_OPEN;
|
private String fGroupName= IContextMenuConstants.GROUP_OPEN;
|
||||||
|
|
||||||
|
@ -58,6 +60,7 @@ public class OpenViewActionGroup extends ActionGroup {
|
||||||
private OpenTypeHierarchyAction fOpenTypeHierarchy;
|
private OpenTypeHierarchyAction fOpenTypeHierarchy;
|
||||||
private PropertyDialogAction fOpenPropertiesDialog;
|
private PropertyDialogAction fOpenPropertiesDialog;
|
||||||
private OpenCallHierarchyAction fOpenCallHierarchy;
|
private OpenCallHierarchyAction fOpenCallHierarchy;
|
||||||
|
private OpenIncludeBrowserAction fOpenIncludeBrowser;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Creates a new <code>OpenActionGroup</code>. The group requires
|
* Creates a new <code>OpenActionGroup</code>. The group requires
|
||||||
|
@ -103,6 +106,10 @@ public class OpenViewActionGroup extends ActionGroup {
|
||||||
fOpenCallHierarchy.setActionDefinitionId(ICEditorActionDefinitionIds.OPEN_CALL_HIERARCHY);
|
fOpenCallHierarchy.setActionDefinitionId(ICEditorActionDefinitionIds.OPEN_CALL_HIERARCHY);
|
||||||
part.setAction("OpenCallHierarchy", fOpenCallHierarchy); //$NON-NLS-1$
|
part.setAction("OpenCallHierarchy", fOpenCallHierarchy); //$NON-NLS-1$
|
||||||
|
|
||||||
|
fOpenIncludeBrowser= new OpenIncludeBrowserAction(part);
|
||||||
|
fOpenIncludeBrowser.setActionDefinitionId(ICEditorActionDefinitionIds.OPEN_INCLUDE_BROWSER);
|
||||||
|
part.setAction("OpenIncludeBrowser", fOpenIncludeBrowser); //$NON-NLS-1$
|
||||||
|
|
||||||
initialize(part.getEditorSite());
|
initialize(part.getEditorSite());
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -119,6 +126,9 @@ public class OpenViewActionGroup extends ActionGroup {
|
||||||
fOpenCallHierarchy= new OpenCallHierarchyAction(site);
|
fOpenCallHierarchy= new OpenCallHierarchyAction(site);
|
||||||
fOpenCallHierarchy.setActionDefinitionId(ICEditorActionDefinitionIds.OPEN_CALL_HIERARCHY);
|
fOpenCallHierarchy.setActionDefinitionId(ICEditorActionDefinitionIds.OPEN_CALL_HIERARCHY);
|
||||||
|
|
||||||
|
fOpenIncludeBrowser= new OpenIncludeBrowserAction(site);
|
||||||
|
fOpenIncludeBrowser.setActionDefinitionId(ICEditorActionDefinitionIds.OPEN_INCLUDE_BROWSER);
|
||||||
|
|
||||||
fOpenPropertiesDialog= new PropertyDialogAction(site, site.getSelectionProvider());
|
fOpenPropertiesDialog= new PropertyDialogAction(site, site.getSelectionProvider());
|
||||||
fOpenPropertiesDialog.setActionDefinitionId("org.eclipse.ui.file.properties"); //$NON-NLS-1$
|
fOpenPropertiesDialog.setActionDefinitionId("org.eclipse.ui.file.properties"); //$NON-NLS-1$
|
||||||
|
|
||||||
|
@ -133,6 +143,7 @@ public class OpenViewActionGroup extends ActionGroup {
|
||||||
// fOpenExternalJavadoc.update(selection);
|
// fOpenExternalJavadoc.update(selection);
|
||||||
fOpenTypeHierarchy.update(selection);
|
fOpenTypeHierarchy.update(selection);
|
||||||
fOpenCallHierarchy.update(selection);
|
fOpenCallHierarchy.update(selection);
|
||||||
|
fOpenIncludeBrowser.update(selection);
|
||||||
if (!fEditorIsOwner) {
|
if (!fEditorIsOwner) {
|
||||||
if (selection instanceof IStructuredSelection) {
|
if (selection instanceof IStructuredSelection) {
|
||||||
IStructuredSelection ss= (IStructuredSelection)selection;
|
IStructuredSelection ss= (IStructuredSelection)selection;
|
||||||
|
@ -144,6 +155,7 @@ public class OpenViewActionGroup extends ActionGroup {
|
||||||
// provider.addSelectionChangedListener(fOpenExternalJavadoc);
|
// provider.addSelectionChangedListener(fOpenExternalJavadoc);
|
||||||
provider.addSelectionChangedListener(fOpenTypeHierarchy);
|
provider.addSelectionChangedListener(fOpenTypeHierarchy);
|
||||||
provider.addSelectionChangedListener(fOpenCallHierarchy);
|
provider.addSelectionChangedListener(fOpenCallHierarchy);
|
||||||
|
provider.addSelectionChangedListener(fOpenIncludeBrowser);
|
||||||
// no need to register the open properties dialog action since it registers itself
|
// no need to register the open properties dialog action since it registers itself
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -168,6 +180,9 @@ public class OpenViewActionGroup extends ActionGroup {
|
||||||
if (!fSuppressCallHierarchy && fOpenCallHierarchy.isEnabled()) {
|
if (!fSuppressCallHierarchy && fOpenCallHierarchy.isEnabled()) {
|
||||||
menu.appendToGroup(fGroupName, fOpenCallHierarchy);
|
menu.appendToGroup(fGroupName, fOpenCallHierarchy);
|
||||||
}
|
}
|
||||||
|
if (fEnableIncludeBrowser && fOpenIncludeBrowser.isEnabled()) {
|
||||||
|
menu.appendToGroup(fGroupName, fOpenIncludeBrowser);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
// appendToGroup(menu, fOpenSuperImplementation);
|
// appendToGroup(menu, fOpenSuperImplementation);
|
||||||
IStructuredSelection selection= getStructuredSelection();
|
IStructuredSelection selection= getStructuredSelection();
|
||||||
|
@ -187,6 +202,7 @@ public class OpenViewActionGroup extends ActionGroup {
|
||||||
// provider.removeSelectionChangedListener(fOpenExternalJavadoc);
|
// provider.removeSelectionChangedListener(fOpenExternalJavadoc);
|
||||||
provider.removeSelectionChangedListener(fOpenTypeHierarchy);
|
provider.removeSelectionChangedListener(fOpenTypeHierarchy);
|
||||||
provider.removeSelectionChangedListener(fOpenCallHierarchy);
|
provider.removeSelectionChangedListener(fOpenCallHierarchy);
|
||||||
|
provider.removeSelectionChangedListener(fOpenIncludeBrowser);
|
||||||
if (fOpenPropertiesDialog != null) {
|
if (fOpenPropertiesDialog != null) {
|
||||||
fOpenPropertiesDialog.dispose();
|
fOpenPropertiesDialog.dispose();
|
||||||
}
|
}
|
||||||
|
@ -198,6 +214,7 @@ public class OpenViewActionGroup extends ActionGroup {
|
||||||
// actionBars.setGlobalActionHandler(JdtActionConstants.OPEN_EXTERNAL_JAVA_DOC, fOpenExternalJavadoc);
|
// actionBars.setGlobalActionHandler(JdtActionConstants.OPEN_EXTERNAL_JAVA_DOC, fOpenExternalJavadoc);
|
||||||
actionBars.setGlobalActionHandler(CdtActionConstants.OPEN_TYPE_HIERARCHY, fOpenTypeHierarchy);
|
actionBars.setGlobalActionHandler(CdtActionConstants.OPEN_TYPE_HIERARCHY, fOpenTypeHierarchy);
|
||||||
actionBars.setGlobalActionHandler(CdtActionConstants.OPEN_CALL_HIERARCHY, fOpenCallHierarchy);
|
actionBars.setGlobalActionHandler(CdtActionConstants.OPEN_CALL_HIERARCHY, fOpenCallHierarchy);
|
||||||
|
actionBars.setGlobalActionHandler(CdtActionConstants.OPEN_INCLUDE_BROWSER, fOpenIncludeBrowser);
|
||||||
if (fOpenPropertiesDialog != null) {
|
if (fOpenPropertiesDialog != null) {
|
||||||
actionBars.setGlobalActionHandler(ActionFactory.PROPERTIES.getId(), fOpenPropertiesDialog);
|
actionBars.setGlobalActionHandler(ActionFactory.PROPERTIES.getId(), fOpenPropertiesDialog);
|
||||||
}
|
}
|
||||||
|
@ -249,4 +266,8 @@ public class OpenViewActionGroup extends ActionGroup {
|
||||||
public void setSuppressProperties(boolean suppressProperties) {
|
public void setSuppressProperties(boolean suppressProperties) {
|
||||||
fSuppressProperties = suppressProperties;
|
fSuppressProperties = suppressProperties;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public void setEnableIncludeBrowser(boolean enableIncludeBrowser) {
|
||||||
|
fEnableIncludeBrowser= enableIncludeBrowser;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
Loading…
Add table
Reference in a new issue