mirror of
https://github.com/eclipse-cdt/cdt
synced 2025-07-31 12:55:40 +02:00
Call Hierarchy: Open from CEditor
This commit is contained in:
parent
1ebafa1b12
commit
4924166f87
10 changed files with 213 additions and 24 deletions
|
@ -7,6 +7,7 @@
|
||||||
*
|
*
|
||||||
* Contributors:
|
* Contributors:
|
||||||
* IBM Corporation - initial API and implementation
|
* IBM Corporation - initial API and implementation
|
||||||
|
* Markus Schorn (Wind River Systems)
|
||||||
*******************************************************************************/
|
*******************************************************************************/
|
||||||
package org.eclipse.cdt.internal.ui.actions;
|
package org.eclipse.cdt.internal.ui.actions;
|
||||||
|
|
||||||
|
@ -17,7 +18,12 @@ 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.model.ISourceReference;
|
import org.eclipse.cdt.core.model.ISourceReference;
|
||||||
import org.eclipse.cdt.internal.ui.util.EditorUtility;
|
import org.eclipse.cdt.internal.ui.util.EditorUtility;
|
||||||
|
import org.eclipse.cdt.internal.ui.viewsupport.CElementLabels;
|
||||||
|
import org.eclipse.cdt.internal.ui.viewsupport.CUILabelProvider;
|
||||||
|
|
||||||
import org.eclipse.cdt.ui.CElementLabelProvider;
|
import org.eclipse.cdt.ui.CElementLabelProvider;
|
||||||
|
|
||||||
|
import org.eclipse.jface.viewers.ILabelProvider;
|
||||||
import org.eclipse.jface.window.Window;
|
import org.eclipse.jface.window.Window;
|
||||||
import org.eclipse.swt.widgets.Shell;
|
import org.eclipse.swt.widgets.Shell;
|
||||||
import org.eclipse.ui.IEditorPart;
|
import org.eclipse.ui.IEditorPart;
|
||||||
|
@ -65,7 +71,22 @@ public class OpenActionUtil {
|
||||||
* Utility method that can be called by subclassers.
|
* Utility method that can be called by subclassers.
|
||||||
*/
|
*/
|
||||||
public static ICElement selectCElement(ICElement[] elements, Shell shell, String title, String message) {
|
public static ICElement selectCElement(ICElement[] elements, Shell shell, String title, String message) {
|
||||||
|
return selectCElement(elements, shell, title, message, 0, 0);
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Shows a dialog for resolving an ambigous C element.
|
||||||
|
* @see CElementLabels
|
||||||
|
* @param elements an array of ambigous elements.
|
||||||
|
* @param shell parent shell for showing the dialog
|
||||||
|
* @param title title of the dialog
|
||||||
|
* @param message message to be shown in the dialog
|
||||||
|
* @param textFlags text flags to change the label provider
|
||||||
|
* @param imageFlags image flags to change the label provider
|
||||||
|
* @return the selected element or <code>null</code>
|
||||||
|
* @since 4.0
|
||||||
|
*/
|
||||||
|
public static ICElement selectCElement(ICElement[] elements, Shell shell, String title, String message, int textFlags, int imageFlags) {
|
||||||
int nResults= elements.length;
|
int nResults= elements.length;
|
||||||
|
|
||||||
if (nResults == 0)
|
if (nResults == 0)
|
||||||
|
@ -74,11 +95,15 @@ public class OpenActionUtil {
|
||||||
if (nResults == 1)
|
if (nResults == 1)
|
||||||
return elements[0];
|
return elements[0];
|
||||||
|
|
||||||
int flags= CElementLabelProvider.SHOW_DEFAULT
|
ILabelProvider labelProvider;
|
||||||
| CElementLabelProvider.SHOW_QUALIFIED;
|
if (textFlags == 0 && imageFlags == 0) {
|
||||||
// | CElementLabelProvider.SHOW_ROOT;
|
labelProvider= new CElementLabelProvider(CElementLabelProvider.SHOW_DEFAULT | CElementLabelProvider.SHOW_QUALIFIED);
|
||||||
|
}
|
||||||
|
else {
|
||||||
|
labelProvider= new CUILabelProvider(textFlags, imageFlags);
|
||||||
|
}
|
||||||
|
|
||||||
ElementListSelectionDialog dialog= new ElementListSelectionDialog(shell, new CElementLabelProvider(flags));
|
ElementListSelectionDialog dialog= new ElementListSelectionDialog(shell, labelProvider);
|
||||||
dialog.setTitle(title);
|
dialog.setTitle(title);
|
||||||
dialog.setMessage(message);
|
dialog.setMessage(message);
|
||||||
dialog.setElements(elements);
|
dialog.setElements(elements);
|
||||||
|
|
|
@ -15,6 +15,8 @@ import org.eclipse.osgi.util.NLS;
|
||||||
|
|
||||||
public class CHMessages extends NLS {
|
public class CHMessages extends NLS {
|
||||||
private static final String BUNDLE_NAME = "org.eclipse.cdt.internal.ui.callhierarchy.CHMessages"; //$NON-NLS-1$
|
private static final String BUNDLE_NAME = "org.eclipse.cdt.internal.ui.callhierarchy.CHMessages"; //$NON-NLS-1$
|
||||||
|
public static String CallHierarchyUI_label;
|
||||||
|
public static String CallHierarchyUI_selectMessage;
|
||||||
public static String CHHistoryListAction_HistoryDialog_title;
|
public static String CHHistoryListAction_HistoryDialog_title;
|
||||||
public static String CHHistoryListAction_HistoryList_label;
|
public static String CHHistoryListAction_HistoryList_label;
|
||||||
public static String CHHistoryListAction_OpenHistory_label;
|
public static String CHHistoryListAction_OpenHistory_label;
|
||||||
|
|
|
@ -32,3 +32,5 @@ CHHistoryListAction_OpenHistory_label=Open History...
|
||||||
CHHistoryDropDownAction_ShowHistoryList_tooltip=Show History List
|
CHHistoryDropDownAction_ShowHistoryList_tooltip=Show History List
|
||||||
OpenCallHierarchyAction_label=Open Call H&ierarchy (work in progress)
|
OpenCallHierarchyAction_label=Open Call H&ierarchy (work in progress)
|
||||||
OpenCallHierarchyAction_tooltip=Open Call Hierarchy (work in progress)
|
OpenCallHierarchyAction_tooltip=Open Call Hierarchy (work in progress)
|
||||||
|
CallHierarchyUI_label=Open Call Hierarchy
|
||||||
|
CallHierarchyUI_selectMessage=Select one element from the list
|
||||||
|
|
|
@ -122,12 +122,12 @@ public class CHViewPart extends ViewPart {
|
||||||
private Action fRefreshAction;
|
private Action fRefreshAction;
|
||||||
private Action fHistoryAction;
|
private Action fHistoryAction;
|
||||||
private Action fShowReference;
|
private Action fShowReference;
|
||||||
|
private Action fOpenElement;
|
||||||
|
|
||||||
// action groups
|
// action groups
|
||||||
private OpenViewActionGroup fOpenViewActionGroup;
|
private OpenViewActionGroup fOpenViewActionGroup;
|
||||||
private SelectionSearchGroup fSelectionSearchGroup;
|
private SelectionSearchGroup fSelectionSearchGroup;
|
||||||
private CRefactoringActionGroup fRefactoringActionGroup;
|
private CRefactoringActionGroup fRefactoringActionGroup;
|
||||||
private Action fOpenElement;
|
|
||||||
private WorkingSetFilterUI fFilterUI;
|
private WorkingSetFilterUI fFilterUI;
|
||||||
|
|
||||||
|
|
||||||
|
@ -461,6 +461,10 @@ public class CHViewPart extends ViewPart {
|
||||||
// setup action bar
|
// setup action bar
|
||||||
// global action hooks
|
// global action hooks
|
||||||
IActionBars actionBars = getViewSite().getActionBars();
|
IActionBars actionBars = getViewSite().getActionBars();
|
||||||
|
fRefactoringActionGroup.fillActionBars(actionBars);
|
||||||
|
fOpenViewActionGroup.fillActionBars(actionBars);
|
||||||
|
fSelectionSearchGroup.fillActionBars(actionBars);
|
||||||
|
|
||||||
actionBars.setGlobalActionHandler(ActionFactory.NEXT.getId(), fNextAction);
|
actionBars.setGlobalActionHandler(ActionFactory.NEXT.getId(), fNextAction);
|
||||||
actionBars.setGlobalActionHandler(ActionFactory.PREVIOUS.getId(), fPreviousAction);
|
actionBars.setGlobalActionHandler(ActionFactory.PREVIOUS.getId(), fPreviousAction);
|
||||||
actionBars.setGlobalActionHandler(ActionFactory.REFRESH.getId(), fRefreshAction);
|
actionBars.setGlobalActionHandler(ActionFactory.REFRESH.getId(), fRefreshAction);
|
||||||
|
|
|
@ -12,13 +12,30 @@
|
||||||
package org.eclipse.cdt.internal.ui.callhierarchy;
|
package org.eclipse.cdt.internal.ui.callhierarchy;
|
||||||
|
|
||||||
import org.eclipse.core.runtime.CoreException;
|
import org.eclipse.core.runtime.CoreException;
|
||||||
|
import org.eclipse.core.runtime.IProgressMonitor;
|
||||||
|
import org.eclipse.core.runtime.IStatus;
|
||||||
|
import org.eclipse.core.runtime.Status;
|
||||||
|
import org.eclipse.core.runtime.jobs.Job;
|
||||||
|
import org.eclipse.jface.text.ITextSelection;
|
||||||
|
import org.eclipse.swt.widgets.Display;
|
||||||
|
import org.eclipse.ui.IEditorInput;
|
||||||
import org.eclipse.ui.IWorkbenchPage;
|
import org.eclipse.ui.IWorkbenchPage;
|
||||||
import org.eclipse.ui.IWorkbenchWindow;
|
import org.eclipse.ui.IWorkbenchWindow;
|
||||||
|
|
||||||
|
import org.eclipse.cdt.core.dom.ast.IASTName;
|
||||||
|
import org.eclipse.cdt.core.dom.ast.IASTTranslationUnit;
|
||||||
|
import org.eclipse.cdt.core.model.CoreModel;
|
||||||
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.ILanguage;
|
||||||
|
import org.eclipse.cdt.core.model.IWorkingCopy;
|
||||||
import org.eclipse.cdt.ui.CUIPlugin;
|
import org.eclipse.cdt.ui.CUIPlugin;
|
||||||
|
|
||||||
|
import org.eclipse.cdt.internal.ui.actions.OpenActionUtil;
|
||||||
|
import org.eclipse.cdt.internal.ui.editor.CEditor;
|
||||||
|
import org.eclipse.cdt.internal.ui.missingapi.CIndexQueries;
|
||||||
import org.eclipse.cdt.internal.ui.util.ExceptionHandler;
|
import org.eclipse.cdt.internal.ui.util.ExceptionHandler;
|
||||||
|
import org.eclipse.cdt.internal.ui.viewsupport.CElementLabels;
|
||||||
|
|
||||||
public class CallHierarchyUI {
|
public class CallHierarchyUI {
|
||||||
|
|
||||||
|
@ -41,4 +58,91 @@ public class CallHierarchyUI {
|
||||||
return null;
|
return null;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
private static CHViewPart openInViewPart(IWorkbenchWindow window, ICElement[] input) {
|
||||||
|
ICElement elem = null;
|
||||||
|
switch (input.length) {
|
||||||
|
case 0:
|
||||||
|
break;
|
||||||
|
case 1:
|
||||||
|
elem = input[0];
|
||||||
|
break;
|
||||||
|
default:
|
||||||
|
elem = OpenActionUtil.selectCElement(input, window.getShell(),
|
||||||
|
CHMessages.CallHierarchyUI_label, CHMessages.CallHierarchyUI_selectMessage,
|
||||||
|
CElementLabels.ALL_DEFAULT | CElementLabels.MF_POST_FILE_QUALIFIED, 0);
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
if (elem != null) {
|
||||||
|
return openInViewPart(window, elem);
|
||||||
|
}
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
|
||||||
|
public static void open(final CEditor editor, final ITextSelection sel) {
|
||||||
|
if (editor != null) {
|
||||||
|
final ICProject project= editor.getInputCElement().getCProject();
|
||||||
|
final IEditorInput editorInput = editor.getEditorInput();
|
||||||
|
final Display display= Display.getCurrent();
|
||||||
|
|
||||||
|
Job job= new Job(CHMessages.CallHierarchyUI_label) {
|
||||||
|
protected IStatus run(IProgressMonitor monitor) {
|
||||||
|
try {
|
||||||
|
final ICElement[] elems= findDefinitions();
|
||||||
|
if (elems != null && elems.length > 0) {
|
||||||
|
display.asyncExec(new Runnable() {
|
||||||
|
public void run() {
|
||||||
|
openInViewPart(editor.getSite().getWorkbenchWindow(), elems);
|
||||||
|
}});
|
||||||
|
}
|
||||||
|
return Status.OK_STATUS;
|
||||||
|
}
|
||||||
|
catch (CoreException e) {
|
||||||
|
return e.getStatus();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
private ICElement[] findDefinitions() throws CoreException {
|
||||||
|
CIndexQueries index= CIndexQueries.getInstance();
|
||||||
|
IASTName name= getSelectedName(editorInput, sel);
|
||||||
|
if (name != null) {
|
||||||
|
if (name.isDefinition()) {
|
||||||
|
ICElement elem= index.findDefinition(project, name);
|
||||||
|
if (elem != null) {
|
||||||
|
return new ICElement[]{elem};
|
||||||
|
}
|
||||||
|
}
|
||||||
|
else {
|
||||||
|
ICElement[] elems= index.findAllDefinitions(project, name);
|
||||||
|
if (elems.length == 0) {
|
||||||
|
ICProject[] allProjects= CoreModel.getDefault().getCModel().getCProjects();
|
||||||
|
elems= index.findAllDefinitions(allProjects, name);
|
||||||
|
}
|
||||||
|
return elems;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
};
|
||||||
|
job.setUser(true);
|
||||||
|
job.schedule();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
private static IASTName getSelectedName(IEditorInput editorInput, ITextSelection selection) throws CoreException {
|
||||||
|
int selectionStart = selection.getOffset();
|
||||||
|
int selectionLength = selection.getLength();
|
||||||
|
|
||||||
|
IWorkingCopy workingCopy = CUIPlugin.getDefault().getWorkingCopyManager().getWorkingCopy(editorInput);
|
||||||
|
if (workingCopy == null)
|
||||||
|
return null;
|
||||||
|
|
||||||
|
int options= ILanguage.AST_SKIP_ALL_HEADERS | ILanguage.AST_USE_INDEX;
|
||||||
|
IASTTranslationUnit ast = workingCopy.getLanguage().getASTTranslationUnit(workingCopy, options);
|
||||||
|
IASTName[] selectedNames = workingCopy.getLanguage().getSelectedNames(ast, selectionStart, selectionLength);
|
||||||
|
|
||||||
|
if (selectedNames.length > 0 && selectedNames[0] != null) { // just right, only one name selected
|
||||||
|
return selectedNames[0];
|
||||||
|
}
|
||||||
|
return null;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -21,17 +21,27 @@ import org.eclipse.cdt.core.model.IFunctionDeclaration;
|
||||||
import org.eclipse.cdt.core.model.IVariableDeclaration;
|
import org.eclipse.cdt.core.model.IVariableDeclaration;
|
||||||
import org.eclipse.cdt.ui.actions.SelectionDispatchAction;
|
import org.eclipse.cdt.ui.actions.SelectionDispatchAction;
|
||||||
|
|
||||||
|
import org.eclipse.cdt.internal.ui.editor.CEditor;
|
||||||
|
|
||||||
|
|
||||||
public class OpenCallHierarchyAction extends SelectionDispatchAction {
|
public class OpenCallHierarchyAction extends SelectionDispatchAction {
|
||||||
|
|
||||||
|
private CEditor fEditor;
|
||||||
|
|
||||||
public OpenCallHierarchyAction(IWorkbenchSite site) {
|
public OpenCallHierarchyAction(IWorkbenchSite site) {
|
||||||
super(site);
|
super(site);
|
||||||
setText(CHMessages.OpenCallHierarchyAction_label);
|
setText(CHMessages.OpenCallHierarchyAction_label);
|
||||||
setToolTipText(CHMessages.OpenCallHierarchyAction_tooltip);
|
setToolTipText(CHMessages.OpenCallHierarchyAction_tooltip);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public OpenCallHierarchyAction(CEditor editor) {
|
||||||
|
this(editor.getSite());
|
||||||
|
fEditor= editor;
|
||||||
|
setEnabled(true);
|
||||||
|
}
|
||||||
|
|
||||||
public void run(ITextSelection sel) {
|
public void run(ITextSelection sel) {
|
||||||
// mstodo run open call tree on editor.
|
CallHierarchyUI.open(fEditor, sel);
|
||||||
}
|
}
|
||||||
|
|
||||||
public void run(IStructuredSelection selection) {
|
public void run(IStructuredSelection selection) {
|
||||||
|
@ -46,7 +56,7 @@ public class OpenCallHierarchyAction extends SelectionDispatchAction {
|
||||||
|
|
||||||
public void selectionChanged(ITextSelection sel) {
|
public void selectionChanged(ITextSelection sel) {
|
||||||
}
|
}
|
||||||
|
|
||||||
public void selectionChanged(IStructuredSelection selection) {
|
public void selectionChanged(IStructuredSelection selection) {
|
||||||
if (selection.isEmpty()) {
|
if (selection.isEmpty()) {
|
||||||
setEnabled(false);
|
setEnabled(false);
|
||||||
|
|
|
@ -89,6 +89,7 @@ import org.eclipse.swt.graphics.Point;
|
||||||
import org.eclipse.swt.widgets.Composite;
|
import org.eclipse.swt.widgets.Composite;
|
||||||
import org.eclipse.swt.widgets.Control;
|
import org.eclipse.swt.widgets.Control;
|
||||||
import org.eclipse.swt.widgets.Shell;
|
import org.eclipse.swt.widgets.Shell;
|
||||||
|
import org.eclipse.ui.IActionBars;
|
||||||
import org.eclipse.ui.IEditorActionBarContributor;
|
import org.eclipse.ui.IEditorActionBarContributor;
|
||||||
import org.eclipse.ui.IEditorInput;
|
import org.eclipse.ui.IEditorInput;
|
||||||
import org.eclipse.ui.IFileEditorInput;
|
import org.eclipse.ui.IFileEditorInput;
|
||||||
|
@ -132,6 +133,7 @@ import org.eclipse.cdt.refactoring.actions.CRefactoringActionGroup;
|
||||||
import org.eclipse.cdt.ui.CUIPlugin;
|
import org.eclipse.cdt.ui.CUIPlugin;
|
||||||
import org.eclipse.cdt.ui.IWorkingCopyManager;
|
import org.eclipse.cdt.ui.IWorkingCopyManager;
|
||||||
import org.eclipse.cdt.ui.PreferenceConstants;
|
import org.eclipse.cdt.ui.PreferenceConstants;
|
||||||
|
import org.eclipse.cdt.ui.actions.OpenViewActionGroup;
|
||||||
import org.eclipse.cdt.ui.actions.ShowInCViewAction;
|
import org.eclipse.cdt.ui.actions.ShowInCViewAction;
|
||||||
import org.eclipse.cdt.ui.text.ICPartitions;
|
import org.eclipse.cdt.ui.text.ICPartitions;
|
||||||
import org.eclipse.cdt.ui.text.folding.ICFoldingStructureProvider;
|
import org.eclipse.cdt.ui.text.folding.ICFoldingStructureProvider;
|
||||||
|
@ -510,6 +512,7 @@ public class CEditor extends TextEditor implements ISelectionChangedListener, IS
|
||||||
private ActionGroup fSelectionSearchGroup;
|
private ActionGroup fSelectionSearchGroup;
|
||||||
private ActionGroup fTextSearchGroup;
|
private ActionGroup fTextSearchGroup;
|
||||||
private CRefactoringActionGroup fRefactoringActionGroup;
|
private CRefactoringActionGroup fRefactoringActionGroup;
|
||||||
|
private ActionGroup fOpenInViewGroup;
|
||||||
|
|
||||||
/** Action which shows selected element in CView. */
|
/** Action which shows selected element in CView. */
|
||||||
private ShowInCViewAction fShowInCViewAction;
|
private ShowInCViewAction fShowInCViewAction;
|
||||||
|
@ -985,6 +988,11 @@ public class CEditor extends TextEditor implements ISelectionChangedListener, IS
|
||||||
fRefactoringActionGroup = null;
|
fRefactoringActionGroup = null;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if (fOpenInViewGroup != null) {
|
||||||
|
fOpenInViewGroup.dispose();
|
||||||
|
fOpenInViewGroup = null;
|
||||||
|
}
|
||||||
|
|
||||||
if (fEditorSelectionChangedListener != null) {
|
if (fEditorSelectionChangedListener != null) {
|
||||||
fEditorSelectionChangedListener.uninstall(getSelectionProvider());
|
fEditorSelectionChangedListener.uninstall(getSelectionProvider());
|
||||||
fEditorSelectionChangedListener= null;
|
fEditorSelectionChangedListener= null;
|
||||||
|
@ -1124,6 +1132,7 @@ public class CEditor extends TextEditor implements ISelectionChangedListener, IS
|
||||||
fSelectionSearchGroup = new SelectionSearchGroup(this);
|
fSelectionSearchGroup = new SelectionSearchGroup(this);
|
||||||
fTextSearchGroup= new TextSearchGroup(this);
|
fTextSearchGroup= new TextSearchGroup(this);
|
||||||
fRefactoringActionGroup= new CRefactoringActionGroup(this);
|
fRefactoringActionGroup= new CRefactoringActionGroup(this);
|
||||||
|
fOpenInViewGroup= new OpenViewActionGroup(this);
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
@ -1157,6 +1166,7 @@ public class CEditor extends TextEditor implements ISelectionChangedListener, IS
|
||||||
fSelectionSearchGroup.fillContextMenu(menu);
|
fSelectionSearchGroup.fillContextMenu(menu);
|
||||||
fTextSearchGroup.fillContextMenu(menu);
|
fTextSearchGroup.fillContextMenu(menu);
|
||||||
fRefactoringActionGroup.fillContextMenu(menu);
|
fRefactoringActionGroup.fillContextMenu(menu);
|
||||||
|
fOpenInViewGroup.fillContextMenu(menu);
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
@ -2242,4 +2252,12 @@ public class CEditor extends TextEditor implements ISelectionChangedListener, IS
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Called whenever the editor is activated and allows for registering
|
||||||
|
* action handlers.
|
||||||
|
*/
|
||||||
|
public void fillActionBars(IActionBars actionBars) {
|
||||||
|
fOpenInViewGroup.fillActionBars(actionBars);
|
||||||
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
|
@ -8,6 +8,7 @@
|
||||||
* Contributors:
|
* Contributors:
|
||||||
* IBM Corporation - initial API and implementation
|
* IBM Corporation - initial API and implementation
|
||||||
* QNX Software System
|
* QNX Software System
|
||||||
|
* Markus Schorn (Wind River Systems)
|
||||||
*******************************************************************************/
|
*******************************************************************************/
|
||||||
package org.eclipse.cdt.internal.ui.editor;
|
package org.eclipse.cdt.internal.ui.editor;
|
||||||
|
|
||||||
|
@ -200,6 +201,12 @@ public class CEditorActionContributor extends TextEditorActionContributor {
|
||||||
fAddInclude.setAction(getAction(textEditor, "AddIncludeOnSelection")); //$NON-NLS-1$
|
fAddInclude.setAction(getAction(textEditor, "AddIncludeOnSelection")); //$NON-NLS-1$
|
||||||
fOpenOnSelection.setAction(getAction(textEditor, "OpenOnSelection")); //$NON-NLS-1$
|
fOpenOnSelection.setAction(getAction(textEditor, "OpenOnSelection")); //$NON-NLS-1$
|
||||||
fFormatter.setAction(getAction(textEditor, "Format")); //$NON-NLS-1$
|
fFormatter.setAction(getAction(textEditor, "Format")); //$NON-NLS-1$
|
||||||
|
|
||||||
|
if (part instanceof CEditor) {
|
||||||
|
CEditor cEditor= (CEditor) part;
|
||||||
|
cEditor.fillActionBars(getActionBars());
|
||||||
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/*
|
/*
|
||||||
|
|
|
@ -393,7 +393,7 @@ public class CIndexQueries {
|
||||||
ArrayList result= new ArrayList(defs.length);
|
ArrayList result= new ArrayList(defs.length);
|
||||||
for (int i = 0; i < defs.length; i++) {
|
for (int i = 0; i < defs.length; i++) {
|
||||||
IASTName defName = defs[i];
|
IASTName defName = defs[i];
|
||||||
ICElement elem= findEnclosingElement(project, (PDOMName) defName);
|
ICElement elem= findEnclosingElement(project, defName);
|
||||||
if (elem != null) {
|
if (elem != null) {
|
||||||
result.add(elem);
|
result.add(elem);
|
||||||
}
|
}
|
||||||
|
@ -403,16 +403,23 @@ public class CIndexQueries {
|
||||||
return EMPTY_ELEMENTS;
|
return EMPTY_ELEMENTS;
|
||||||
}
|
}
|
||||||
|
|
||||||
private ICElement findEnclosingElement(ICProject project, PDOMName declName) {
|
private ICElement findEnclosingElement(ICProject project, IASTName declName) {
|
||||||
ITranslationUnit tu= toTranslationUnit(project, declName);
|
ITranslationUnit tu= toTranslationUnit(project, declName);
|
||||||
if (tu != null) {
|
if (tu != null) {
|
||||||
// mstodo use correct timestamp
|
int offset= 0;
|
||||||
// PDOMFile file= declName.getFile();
|
if (declName instanceof PDOMName) {
|
||||||
long timestamp= tu.getPath().toFile().lastModified();
|
PDOMName pname= (PDOMName) declName;
|
||||||
IPositionConverter pc= CCorePlugin.getPositionTrackerManager().findPositionConverter(tu.getPath(), timestamp);
|
offset= pname.getNodeOffset();
|
||||||
int offset= declName.getNodeOffset();
|
// mstodo use correct timestamp
|
||||||
if (pc != null) {
|
// PDOMFile file= pname.getFile();
|
||||||
offset= pc.historicToActual(new Region(offset, 0)).getOffset();
|
long timestamp= tu.getPath().toFile().lastModified();
|
||||||
|
IPositionConverter pc= CCorePlugin.getPositionTrackerManager().findPositionConverter(tu.getPath(), timestamp);
|
||||||
|
if (pc != null) {
|
||||||
|
offset= pc.historicToActual(new Region(offset, 0)).getOffset();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
else {
|
||||||
|
offset= declName.getFileLocation().getNodeOffset();
|
||||||
}
|
}
|
||||||
return findElement(tu, offset, true);
|
return findElement(tu, offset, true);
|
||||||
}
|
}
|
||||||
|
@ -433,6 +440,10 @@ public class CIndexQueries {
|
||||||
}
|
}
|
||||||
|
|
||||||
public ICElement findDefinition(ICProject project, IASTName name) {
|
public ICElement findDefinition(ICProject project, IASTName name) {
|
||||||
|
if (name.isDefinition()) {
|
||||||
|
return findEnclosingElement(project, name);
|
||||||
|
}
|
||||||
|
|
||||||
PDOM pdom;
|
PDOM pdom;
|
||||||
try {
|
try {
|
||||||
pdom = (PDOM) CCorePlugin.getPDOMManager().getPDOM(project);
|
pdom = (PDOM) CCorePlugin.getPDOMManager().getPDOM(project);
|
||||||
|
@ -463,7 +474,7 @@ public class CIndexQueries {
|
||||||
if (defs != null) {
|
if (defs != null) {
|
||||||
for (int i = 0; i < defs.length; i++) {
|
for (int i = 0; i < defs.length; i++) {
|
||||||
IASTName defName = defs[i];
|
IASTName defName = defs[i];
|
||||||
ICElement elem= findEnclosingElement(project, (PDOMName) defName);
|
ICElement elem= findEnclosingElement(project, defName);
|
||||||
if (elem != null) {
|
if (elem != null) {
|
||||||
return elem;
|
return elem;
|
||||||
}
|
}
|
||||||
|
|
|
@ -100,8 +100,9 @@ public class OpenViewActionGroup extends ActionGroup {
|
||||||
// fOpenTypeHierarchy.setActionDefinitionId(ICEditorActionDefinitionIds.OPEN_TYPE_HIERARCHY);
|
// fOpenTypeHierarchy.setActionDefinitionId(ICEditorActionDefinitionIds.OPEN_TYPE_HIERARCHY);
|
||||||
// part.setAction("OpenTypeHierarchy", fOpenTypeHierarchy); //$NON-NLS-1$
|
// part.setAction("OpenTypeHierarchy", fOpenTypeHierarchy); //$NON-NLS-1$
|
||||||
|
|
||||||
fOpenCallHierarchy= new OpenCallHierarchyAction(part.getSite());
|
fOpenCallHierarchy= new OpenCallHierarchyAction(part);
|
||||||
fOpenCallHierarchy.setActionDefinitionId(ICEditorActionDefinitionIds.OPEN_CALL_HIERARCHY);
|
fOpenCallHierarchy.setActionDefinitionId(ICEditorActionDefinitionIds.OPEN_CALL_HIERARCHY);
|
||||||
|
part.setAction("OpenCallHierarchy", fOpenCallHierarchy); //$NON-NLS-1$
|
||||||
|
|
||||||
initialize(part.getEditorSite());
|
initialize(part.getEditorSite());
|
||||||
}
|
}
|
||||||
|
@ -168,8 +169,9 @@ public class OpenViewActionGroup extends ActionGroup {
|
||||||
}
|
}
|
||||||
// appendToGroup(menu, fOpenSuperImplementation);
|
// appendToGroup(menu, fOpenSuperImplementation);
|
||||||
IStructuredSelection selection= getStructuredSelection();
|
IStructuredSelection selection= getStructuredSelection();
|
||||||
if (fOpenPropertiesDialog != null && fOpenPropertiesDialog.isEnabled() && selection != null &&fOpenPropertiesDialog.isApplicableForSelection(selection))
|
if (fOpenPropertiesDialog != null && fOpenPropertiesDialog.isEnabled() && selection != null &&fOpenPropertiesDialog.isApplicableForSelection(selection)) {
|
||||||
menu.appendToGroup(IContextMenuConstants.GROUP_PROPERTIES, fOpenPropertiesDialog);
|
menu.appendToGroup(IContextMenuConstants.GROUP_PROPERTIES, fOpenPropertiesDialog);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
/*
|
/*
|
||||||
|
@ -181,7 +183,9 @@ public class OpenViewActionGroup extends ActionGroup {
|
||||||
// provider.removeSelectionChangedListener(fOpenExternalJavadoc);
|
// provider.removeSelectionChangedListener(fOpenExternalJavadoc);
|
||||||
// provider.removeSelectionChangedListener(fOpenTypeHierarchy);
|
// provider.removeSelectionChangedListener(fOpenTypeHierarchy);
|
||||||
provider.removeSelectionChangedListener(fOpenCallHierarchy);
|
provider.removeSelectionChangedListener(fOpenCallHierarchy);
|
||||||
fOpenPropertiesDialog.dispose();
|
if (fOpenPropertiesDialog != null) {
|
||||||
|
fOpenPropertiesDialog.dispose();
|
||||||
|
}
|
||||||
super.dispose();
|
super.dispose();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -190,7 +194,9 @@ 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(ActionFactory.PROPERTIES.getId(), fOpenPropertiesDialog);
|
if (fOpenPropertiesDialog != null) {
|
||||||
|
actionBars.setGlobalActionHandler(ActionFactory.PROPERTIES.getId(), fOpenPropertiesDialog);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
private IStructuredSelection getStructuredSelection() {
|
private IStructuredSelection getStructuredSelection() {
|
||||||
|
@ -204,8 +210,8 @@ public class OpenViewActionGroup extends ActionGroup {
|
||||||
}
|
}
|
||||||
|
|
||||||
public static boolean canActionBeAdded(ISelection selection) {
|
public static boolean canActionBeAdded(ISelection selection) {
|
||||||
if(selection instanceof ITextSelection) {
|
if (selection instanceof ITextSelection) {
|
||||||
return (((ITextSelection)selection).getLength() > 0);
|
return true;
|
||||||
}
|
}
|
||||||
return getElement(selection) != null;
|
return getElement(selection) != null;
|
||||||
}
|
}
|
||||||
|
|
Loading…
Add table
Reference in a new issue