mirror of
https://github.com/eclipse-cdt/cdt
synced 2025-06-09 10:46:02 +02:00
Call Hierarchy: Fix view description; remove 'Open Call Hierarchy' action from toolbar; limit drag'n'drop to functions and variables.
This commit is contained in:
parent
5e5664eae5
commit
ee979cebbc
8 changed files with 88 additions and 113 deletions
|
@ -1130,7 +1130,6 @@
|
||||||
label="%OpenCallHierarchy.label"
|
label="%OpenCallHierarchy.label"
|
||||||
menubarPath="navigate/open.ext"
|
menubarPath="navigate/open.ext"
|
||||||
retarget="true"
|
retarget="true"
|
||||||
toolbarPath="org.eclipse.search.searchActionSet/Search"
|
|
||||||
tooltip="%OpenCallHierarchy.tooltip">
|
tooltip="%OpenCallHierarchy.tooltip">
|
||||||
</action>
|
</action>
|
||||||
<!--action
|
<!--action
|
||||||
|
|
|
@ -98,6 +98,15 @@ public class CHContentProvider extends AsyncTreeContentProvider {
|
||||||
CHNode node = (CHNode) parentElement;
|
CHNode node = (CHNode) parentElement;
|
||||||
ICElement elem= node.getRepresentedDeclaration();
|
ICElement elem= node.getRepresentedDeclaration();
|
||||||
if (elem != null) {
|
if (elem != null) {
|
||||||
|
// mstodo !! for demo only !!
|
||||||
|
if (elem.getElementName().equals("slow")) { //$NON-NLS-1$
|
||||||
|
try {
|
||||||
|
Thread.sleep(3000);
|
||||||
|
} catch (InterruptedException e) {
|
||||||
|
e.printStackTrace();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
// mstodo !! for demo only !!
|
||||||
if (fComputeReferencedBy) {
|
if (fComputeReferencedBy) {
|
||||||
return asyncronouslyComputeReferencedBy(node, elem);
|
return asyncronouslyComputeReferencedBy(node, elem);
|
||||||
}
|
}
|
||||||
|
|
|
@ -24,6 +24,8 @@ import org.eclipse.swt.widgets.Display;
|
||||||
|
|
||||||
import org.eclipse.cdt.core.model.ICElement;
|
import org.eclipse.cdt.core.model.ICElement;
|
||||||
|
|
||||||
|
import org.eclipse.cdt.internal.ui.missingapi.CIndexQueries;
|
||||||
|
|
||||||
public class CHDropTargetListener implements DropTargetListener {
|
public class CHDropTargetListener implements DropTargetListener {
|
||||||
|
|
||||||
private CHViewPart fCallHierarchy;
|
private CHViewPart fCallHierarchy;
|
||||||
|
@ -44,8 +46,9 @@ public class CHDropTargetListener implements DropTargetListener {
|
||||||
if (event.detail != DND.DROP_NONE) {
|
if (event.detail != DND.DROP_NONE) {
|
||||||
if (LocalSelectionTransfer.getTransfer().isSupportedType(event.currentDataType)) {
|
if (LocalSelectionTransfer.getTransfer().isSupportedType(event.currentDataType)) {
|
||||||
fInput= checkLocalSelection();
|
fInput= checkLocalSelection();
|
||||||
if (fInput == null) {
|
if (!CIndexQueries.isRelevantForCallHierarchy(fInput)) {
|
||||||
event.detail= DND.DROP_NONE;
|
event.detail= DND.DROP_NONE;
|
||||||
|
fInput= null;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -20,7 +20,7 @@ CHViewPart_Refresh_label=Refresh
|
||||||
CHViewPart_Refresh_tooltip=Refresh View Content
|
CHViewPart_Refresh_tooltip=Refresh View Content
|
||||||
CHViewPart_WorkspaceScope=workspace
|
CHViewPart_WorkspaceScope=workspace
|
||||||
CHViewPart_Title_callers=Callers of {0} - in {1}
|
CHViewPart_Title_callers=Callers of {0} - in {1}
|
||||||
CHViewPart_Title_callees=Calls made by {0} - in {1}
|
CHViewPart_Title_callees=Calls from {0} - in {1}
|
||||||
CHViewPart_FocusOn_label=Focus On ''{0}''
|
CHViewPart_FocusOn_label=Focus On ''{0}''
|
||||||
CHViewPart_Open_label=Open
|
CHViewPart_Open_label=Open
|
||||||
CHViewPart_Open_tooltip=Open
|
CHViewPart_Open_tooltip=Open
|
||||||
|
|
|
@ -15,7 +15,6 @@ import java.util.ArrayList;
|
||||||
import java.util.Arrays;
|
import java.util.Arrays;
|
||||||
import java.util.Iterator;
|
import java.util.Iterator;
|
||||||
|
|
||||||
import org.eclipse.core.runtime.IPath;
|
|
||||||
import org.eclipse.jface.action.Action;
|
import org.eclipse.jface.action.Action;
|
||||||
import org.eclipse.jface.action.IAction;
|
import org.eclipse.jface.action.IAction;
|
||||||
import org.eclipse.jface.action.IMenuListener;
|
import org.eclipse.jface.action.IMenuListener;
|
||||||
|
@ -51,6 +50,7 @@ import org.eclipse.ui.IMemento;
|
||||||
import org.eclipse.ui.IViewSite;
|
import org.eclipse.ui.IViewSite;
|
||||||
import org.eclipse.ui.IWorkbenchPage;
|
import org.eclipse.ui.IWorkbenchPage;
|
||||||
import org.eclipse.ui.IWorkbenchPartSite;
|
import org.eclipse.ui.IWorkbenchPartSite;
|
||||||
|
import org.eclipse.ui.IWorkingSet;
|
||||||
import org.eclipse.ui.PartInitException;
|
import org.eclipse.ui.PartInitException;
|
||||||
import org.eclipse.ui.actions.ActionFactory;
|
import org.eclipse.ui.actions.ActionFactory;
|
||||||
import org.eclipse.ui.part.PageBook;
|
import org.eclipse.ui.part.PageBook;
|
||||||
|
@ -106,11 +106,11 @@ public class CHViewPart extends ViewPart {
|
||||||
private ExtendedTreeViewer fTreeViewer;
|
private ExtendedTreeViewer fTreeViewer;
|
||||||
|
|
||||||
// filters, sorter
|
// filters, sorter
|
||||||
private CHWorkingSetFilter fWorkingSetFilter;
|
|
||||||
private ViewerFilter fVariableFilter;
|
private ViewerFilter fVariableFilter;
|
||||||
private ViewerFilter fMacroFilter;
|
private ViewerFilter fMacroFilter;
|
||||||
private ViewerComparator fSorterAlphaNumeric;
|
private ViewerComparator fSorterAlphaNumeric;
|
||||||
private ViewerComparator fSorterReferencePosition;
|
private ViewerComparator fSorterReferencePosition;
|
||||||
|
private WorkingSetFilterUI fWorkingSetFilterUI;
|
||||||
|
|
||||||
// actions
|
// actions
|
||||||
private Action fReferencedByAction;
|
private Action fReferencedByAction;
|
||||||
|
@ -129,7 +129,6 @@ public class CHViewPart extends ViewPart {
|
||||||
private OpenViewActionGroup fOpenViewActionGroup;
|
private OpenViewActionGroup fOpenViewActionGroup;
|
||||||
private SelectionSearchGroup fSelectionSearchGroup;
|
private SelectionSearchGroup fSelectionSearchGroup;
|
||||||
private CRefactoringActionGroup fRefactoringActionGroup;
|
private CRefactoringActionGroup fRefactoringActionGroup;
|
||||||
private WorkingSetFilterUI fFilterUI;
|
|
||||||
|
|
||||||
|
|
||||||
public void setFocus() {
|
public void setFocus() {
|
||||||
|
@ -205,9 +204,9 @@ public class CHViewPart extends ViewPart {
|
||||||
fRefactoringActionGroup.dispose();
|
fRefactoringActionGroup.dispose();
|
||||||
fRefactoringActionGroup= null;
|
fRefactoringActionGroup= null;
|
||||||
}
|
}
|
||||||
if (fFilterUI != null) {
|
if (fWorkingSetFilterUI != null) {
|
||||||
fFilterUI.dispose();
|
fWorkingSetFilterUI.dispose();
|
||||||
fFilterUI= null;
|
fWorkingSetFilterUI= null;
|
||||||
}
|
}
|
||||||
super.dispose();
|
super.dispose();
|
||||||
}
|
}
|
||||||
|
@ -245,8 +244,8 @@ public class CHViewPart extends ViewPart {
|
||||||
|
|
||||||
|
|
||||||
public void saveState(IMemento memento) {
|
public void saveState(IMemento memento) {
|
||||||
if (fWorkingSetFilter != null) {
|
if (fWorkingSetFilterUI != null) {
|
||||||
fWorkingSetFilter.getUI().saveState(memento, KEY_WORKING_SET_FILTER);
|
fWorkingSetFilterUI.saveState(memento, KEY_WORKING_SET_FILTER);
|
||||||
}
|
}
|
||||||
memento.putString(KEY_FILTER_MACROS, String.valueOf(fFilterMacrosAction.isChecked()));
|
memento.putString(KEY_FILTER_MACROS, String.valueOf(fFilterMacrosAction.isChecked()));
|
||||||
memento.putString(KEY_FILTER_VARIABLES, String.valueOf(fFilterVariablesAction.isChecked()));
|
memento.putString(KEY_FILTER_VARIABLES, String.valueOf(fFilterVariablesAction.isChecked()));
|
||||||
|
@ -313,7 +312,7 @@ public class CHViewPart extends ViewPart {
|
||||||
fSelectionSearchGroup= new SelectionSearchGroup(getSite());
|
fSelectionSearchGroup= new SelectionSearchGroup(getSite());
|
||||||
fRefactoringActionGroup= new CRefactoringActionGroup(this);
|
fRefactoringActionGroup= new CRefactoringActionGroup(this);
|
||||||
|
|
||||||
fFilterUI= new WorkingSetFilterUI(this, fMemento, KEY_WORKING_SET_FILTER) {
|
fWorkingSetFilterUI= new WorkingSetFilterUI(this, fMemento, KEY_WORKING_SET_FILTER) {
|
||||||
protected void onWorkingSetChange() {
|
protected void onWorkingSetChange() {
|
||||||
updateWorkingSetFilter(this);
|
updateWorkingSetFilter(this);
|
||||||
}
|
}
|
||||||
|
@ -490,7 +489,7 @@ public class CHViewPart extends ViewPart {
|
||||||
// tm.add(fNext);
|
// tm.add(fNext);
|
||||||
// tm.add(fPrevious);
|
// tm.add(fPrevious);
|
||||||
// tm.add(new Separator());
|
// tm.add(new Separator());
|
||||||
fFilterUI.fillActionBars(actionBars);
|
fWorkingSetFilterUI.fillActionBars(actionBars);
|
||||||
mm.add(fReferencedByAction);
|
mm.add(fReferencedByAction);
|
||||||
mm.add(fMakesReferenceToAction);
|
mm.add(fMakesReferenceToAction);
|
||||||
mm.add(new Separator());
|
mm.add(new Separator());
|
||||||
|
@ -602,28 +601,32 @@ public class CHViewPart extends ViewPart {
|
||||||
private void updateDescription() {
|
private void updateDescription() {
|
||||||
String message= ""; //$NON-NLS-1$
|
String message= ""; //$NON-NLS-1$
|
||||||
if (!fShowsMessage) {
|
if (!fShowsMessage) {
|
||||||
ITranslationUnit tu= getInput();
|
ICElement elem= getInput();
|
||||||
if (tu != null) {
|
if (elem != null) {
|
||||||
IPath path= tu.getPath();
|
String format, scope, label;
|
||||||
if (path != null) {
|
|
||||||
String format, file, scope;
|
// label
|
||||||
|
label= CElementLabels.getElementLabel(elem, CHHistoryAction.LABEL_OPTIONS);
|
||||||
file= path.lastSegment() + "(" + path.removeLastSegments(1) + ")"; //$NON-NLS-1$//$NON-NLS-2$
|
|
||||||
if (fWorkingSetFilter == null) {
|
// scope
|
||||||
scope= CHMessages.CHViewPart_WorkspaceScope;
|
IWorkingSet workingSet= fWorkingSetFilterUI.getWorkingSet();
|
||||||
}
|
if (workingSet == null) {
|
||||||
else {
|
scope= CHMessages.CHViewPart_WorkspaceScope;
|
||||||
scope= fWorkingSetFilter.getLabel();
|
}
|
||||||
}
|
else {
|
||||||
|
scope= workingSet.getLabel();
|
||||||
if (fReferencedByAction.isChecked()) {
|
}
|
||||||
format= CHMessages.CHViewPart_Title_callers;
|
|
||||||
}
|
// format
|
||||||
else {
|
if (fReferencedByAction.isChecked()) {
|
||||||
format= CHMessages.CHViewPart_Title_callees;
|
format= CHMessages.CHViewPart_Title_callers;
|
||||||
}
|
}
|
||||||
message= Messages.format(format, file, scope);
|
else {
|
||||||
}
|
format= CHMessages.CHViewPart_Title_callees;
|
||||||
|
}
|
||||||
|
|
||||||
|
// message
|
||||||
|
message= Messages.format(format, label, scope);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
message= "The Call Hierarchy is work in progress! - " + message; //$NON-NLS-1$
|
message= "The Call Hierarchy is work in progress! - " + message; //$NON-NLS-1$
|
||||||
|
@ -767,10 +770,10 @@ public class CHViewPart extends ViewPart {
|
||||||
fHistoryEntries.addAll(Arrays.asList(remaining));
|
fHistoryEntries.addAll(Arrays.asList(remaining));
|
||||||
}
|
}
|
||||||
|
|
||||||
public ITranslationUnit getInput() {
|
public ICElement getInput() {
|
||||||
Object input= fTreeViewer.getInput();
|
Object input= fTreeViewer.getInput();
|
||||||
if (input instanceof ITranslationUnit) {
|
if (input instanceof ICElement) {
|
||||||
return (ITranslationUnit) input;
|
return (ICElement) input;
|
||||||
}
|
}
|
||||||
return null;
|
return null;
|
||||||
}
|
}
|
||||||
|
|
|
@ -1,64 +0,0 @@
|
||||||
/*******************************************************************************
|
|
||||||
* Copyright (c) 2006 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.callhierarchy;
|
|
||||||
|
|
||||||
import org.eclipse.jface.viewers.Viewer;
|
|
||||||
import org.eclipse.jface.viewers.ViewerFilter;
|
|
||||||
import org.eclipse.ui.IWorkingSet;
|
|
||||||
|
|
||||||
import org.eclipse.cdt.core.model.ICElement;
|
|
||||||
|
|
||||||
import org.eclipse.cdt.internal.ui.viewsupport.WorkingSetFilterUI;
|
|
||||||
|
|
||||||
public class CHWorkingSetFilter extends ViewerFilter {
|
|
||||||
|
|
||||||
private WorkingSetFilterUI fWorkingSetFilter;
|
|
||||||
|
|
||||||
public CHWorkingSetFilter(WorkingSetFilterUI wsFilter) {
|
|
||||||
fWorkingSetFilter= wsFilter;
|
|
||||||
}
|
|
||||||
|
|
||||||
public boolean select(Viewer viewer, Object parentElement, Object element) {
|
|
||||||
if (parentElement instanceof CHNode) {
|
|
||||||
if (element instanceof CHMultiDefNode) {
|
|
||||||
CHNode[] children= ((CHMultiDefNode) element).getChildNodes();
|
|
||||||
for (int i = 0; i < children.length; i++) {
|
|
||||||
CHNode node = children[i];
|
|
||||||
if (fWorkingSetFilter.isPartOfWorkingSet(node.getRepresentedDeclaration())) {
|
|
||||||
return true;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
return false;
|
|
||||||
}
|
|
||||||
else if (element instanceof CHNode) {
|
|
||||||
CHNode node= (CHNode) element;
|
|
||||||
ICElement decl= node.getRepresentedDeclaration();
|
|
||||||
if (decl != null) {
|
|
||||||
return fWorkingSetFilter.isPartOfWorkingSet(decl);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
return true;
|
|
||||||
}
|
|
||||||
|
|
||||||
public WorkingSetFilterUI getUI() {
|
|
||||||
return fWorkingSetFilter;
|
|
||||||
}
|
|
||||||
|
|
||||||
public String getLabel() {
|
|
||||||
IWorkingSet ws= fWorkingSetFilter.getWorkingSet();
|
|
||||||
if (ws != null) {
|
|
||||||
return ws.getLabel();
|
|
||||||
}
|
|
||||||
return CHMessages.CHViewPart_WorkspaceScope;
|
|
||||||
}
|
|
||||||
}
|
|
|
@ -145,7 +145,7 @@ public class CallHierarchyUI {
|
||||||
IASTName name= getSelectedName(editorInput, sel);
|
IASTName name= getSelectedName(editorInput, sel);
|
||||||
if (name != null) {
|
if (name != null) {
|
||||||
IBinding binding= name.resolveBinding();
|
IBinding binding= name.resolveBinding();
|
||||||
if (index.isRelevantForCallHierarchy(binding)) {
|
if (CIndexQueries.isRelevantForCallHierarchy(binding)) {
|
||||||
if (name.isDefinition()) {
|
if (name.isDefinition()) {
|
||||||
ICElement elem= index.findDefinition(project, name);
|
ICElement elem= index.findDefinition(project, name);
|
||||||
if (elem != null) {
|
if (elem != null) {
|
||||||
|
|
|
@ -67,6 +67,41 @@ public class CIndexQueries {
|
||||||
return sInstance;
|
return sInstance;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public static boolean isRelevantForCallHierarchy(IBinding binding) {
|
||||||
|
if (binding instanceof ICExternalBinding ||
|
||||||
|
binding instanceof IEnumerator ||
|
||||||
|
binding instanceof IFunction ||
|
||||||
|
binding instanceof IVariable) {
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
|
public static boolean isRelevantForCallHierarchy(ICElement elem) {
|
||||||
|
if (elem == null) {
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
switch (elem.getElementType()) {
|
||||||
|
case ICElement.C_CLASS_CTOR:
|
||||||
|
case ICElement.C_CLASS_DTOR:
|
||||||
|
case ICElement.C_ENUMERATOR:
|
||||||
|
case ICElement.C_FIELD:
|
||||||
|
case ICElement.C_FUNCTION:
|
||||||
|
case ICElement.C_FUNCTION_DECLARATION:
|
||||||
|
case ICElement.C_METHOD:
|
||||||
|
case ICElement.C_METHOD_DECLARATION:
|
||||||
|
case ICElement.C_TEMPLATE_FUNCTION:
|
||||||
|
case ICElement.C_TEMPLATE_FUNCTION_DECLARATION:
|
||||||
|
case ICElement.C_TEMPLATE_METHOD:
|
||||||
|
case ICElement.C_TEMPLATE_METHOD_DECLARATION:
|
||||||
|
case ICElement.C_TEMPLATE_VARIABLE:
|
||||||
|
case ICElement.C_VARIABLE:
|
||||||
|
case ICElement.C_VARIABLE_DECLARATION:
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Searches for all include-relations that include the given translation unit.
|
* Searches for all include-relations that include the given translation unit.
|
||||||
* @param scope the projects to be searched.
|
* @param scope the projects to be searched.
|
||||||
|
@ -404,16 +439,6 @@ public class CIndexQueries {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
public boolean isRelevantForCallHierarchy(IBinding binding) {
|
|
||||||
if (binding instanceof ICExternalBinding ||
|
|
||||||
binding instanceof IEnumerator ||
|
|
||||||
binding instanceof IFunction ||
|
|
||||||
binding instanceof IVariable) {
|
|
||||||
return true;
|
|
||||||
}
|
|
||||||
return false;
|
|
||||||
}
|
|
||||||
|
|
||||||
public ICElement[] findAllDefinitions(ICProject[] projectsToSearch, IASTName name) {
|
public ICElement[] findAllDefinitions(ICProject[] projectsToSearch, IASTName name) {
|
||||||
ArrayList result= new ArrayList();
|
ArrayList result= new ArrayList();
|
||||||
for (int i = 0; i < projectsToSearch.length; i++) {
|
for (int i = 0; i < projectsToSearch.length; i++) {
|
||||||
|
|
Loading…
Add table
Reference in a new issue