1
0
Fork 0
mirror of https://github.com/eclipse-cdt/cdt synced 2025-04-23 14:42:11 +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:
Markus Schorn 2006-09-13 11:00:02 +00:00
parent 5e5664eae5
commit ee979cebbc
8 changed files with 88 additions and 113 deletions

View file

@ -1130,7 +1130,6 @@
label="%OpenCallHierarchy.label"
menubarPath="navigate/open.ext"
retarget="true"
toolbarPath="org.eclipse.search.searchActionSet/Search"
tooltip="%OpenCallHierarchy.tooltip">
</action>
<!--action

View file

@ -98,6 +98,15 @@ public class CHContentProvider extends AsyncTreeContentProvider {
CHNode node = (CHNode) parentElement;
ICElement elem= node.getRepresentedDeclaration();
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) {
return asyncronouslyComputeReferencedBy(node, elem);
}

View file

@ -24,6 +24,8 @@ import org.eclipse.swt.widgets.Display;
import org.eclipse.cdt.core.model.ICElement;
import org.eclipse.cdt.internal.ui.missingapi.CIndexQueries;
public class CHDropTargetListener implements DropTargetListener {
private CHViewPart fCallHierarchy;
@ -44,8 +46,9 @@ public class CHDropTargetListener implements DropTargetListener {
if (event.detail != DND.DROP_NONE) {
if (LocalSelectionTransfer.getTransfer().isSupportedType(event.currentDataType)) {
fInput= checkLocalSelection();
if (fInput == null) {
if (!CIndexQueries.isRelevantForCallHierarchy(fInput)) {
event.detail= DND.DROP_NONE;
fInput= null;
}
}
}

View file

@ -20,7 +20,7 @@ CHViewPart_Refresh_label=Refresh
CHViewPart_Refresh_tooltip=Refresh View Content
CHViewPart_WorkspaceScope=workspace
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_Open_label=Open
CHViewPart_Open_tooltip=Open

View file

@ -15,7 +15,6 @@ import java.util.ArrayList;
import java.util.Arrays;
import java.util.Iterator;
import org.eclipse.core.runtime.IPath;
import org.eclipse.jface.action.Action;
import org.eclipse.jface.action.IAction;
import org.eclipse.jface.action.IMenuListener;
@ -51,6 +50,7 @@ import org.eclipse.ui.IMemento;
import org.eclipse.ui.IViewSite;
import org.eclipse.ui.IWorkbenchPage;
import org.eclipse.ui.IWorkbenchPartSite;
import org.eclipse.ui.IWorkingSet;
import org.eclipse.ui.PartInitException;
import org.eclipse.ui.actions.ActionFactory;
import org.eclipse.ui.part.PageBook;
@ -106,11 +106,11 @@ public class CHViewPart extends ViewPart {
private ExtendedTreeViewer fTreeViewer;
// filters, sorter
private CHWorkingSetFilter fWorkingSetFilter;
private ViewerFilter fVariableFilter;
private ViewerFilter fMacroFilter;
private ViewerComparator fSorterAlphaNumeric;
private ViewerComparator fSorterReferencePosition;
private WorkingSetFilterUI fWorkingSetFilterUI;
// actions
private Action fReferencedByAction;
@ -129,7 +129,6 @@ public class CHViewPart extends ViewPart {
private OpenViewActionGroup fOpenViewActionGroup;
private SelectionSearchGroup fSelectionSearchGroup;
private CRefactoringActionGroup fRefactoringActionGroup;
private WorkingSetFilterUI fFilterUI;
public void setFocus() {
@ -205,9 +204,9 @@ public class CHViewPart extends ViewPart {
fRefactoringActionGroup.dispose();
fRefactoringActionGroup= null;
}
if (fFilterUI != null) {
fFilterUI.dispose();
fFilterUI= null;
if (fWorkingSetFilterUI != null) {
fWorkingSetFilterUI.dispose();
fWorkingSetFilterUI= null;
}
super.dispose();
}
@ -245,8 +244,8 @@ public class CHViewPart extends ViewPart {
public void saveState(IMemento memento) {
if (fWorkingSetFilter != null) {
fWorkingSetFilter.getUI().saveState(memento, KEY_WORKING_SET_FILTER);
if (fWorkingSetFilterUI != null) {
fWorkingSetFilterUI.saveState(memento, KEY_WORKING_SET_FILTER);
}
memento.putString(KEY_FILTER_MACROS, String.valueOf(fFilterMacrosAction.isChecked()));
memento.putString(KEY_FILTER_VARIABLES, String.valueOf(fFilterVariablesAction.isChecked()));
@ -313,7 +312,7 @@ public class CHViewPart extends ViewPart {
fSelectionSearchGroup= new SelectionSearchGroup(getSite());
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() {
updateWorkingSetFilter(this);
}
@ -490,7 +489,7 @@ public class CHViewPart extends ViewPart {
// tm.add(fNext);
// tm.add(fPrevious);
// tm.add(new Separator());
fFilterUI.fillActionBars(actionBars);
fWorkingSetFilterUI.fillActionBars(actionBars);
mm.add(fReferencedByAction);
mm.add(fMakesReferenceToAction);
mm.add(new Separator());
@ -602,28 +601,32 @@ public class CHViewPart extends ViewPart {
private void updateDescription() {
String message= ""; //$NON-NLS-1$
if (!fShowsMessage) {
ITranslationUnit tu= getInput();
if (tu != null) {
IPath path= tu.getPath();
if (path != null) {
String format, file, scope;
file= path.lastSegment() + "(" + path.removeLastSegments(1) + ")"; //$NON-NLS-1$//$NON-NLS-2$
if (fWorkingSetFilter == null) {
scope= CHMessages.CHViewPart_WorkspaceScope;
}
else {
scope= fWorkingSetFilter.getLabel();
}
if (fReferencedByAction.isChecked()) {
format= CHMessages.CHViewPart_Title_callers;
}
else {
format= CHMessages.CHViewPart_Title_callees;
}
message= Messages.format(format, file, scope);
}
ICElement elem= getInput();
if (elem != null) {
String format, scope, label;
// label
label= CElementLabels.getElementLabel(elem, CHHistoryAction.LABEL_OPTIONS);
// scope
IWorkingSet workingSet= fWorkingSetFilterUI.getWorkingSet();
if (workingSet == null) {
scope= CHMessages.CHViewPart_WorkspaceScope;
}
else {
scope= workingSet.getLabel();
}
// format
if (fReferencedByAction.isChecked()) {
format= CHMessages.CHViewPart_Title_callers;
}
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$
@ -767,10 +770,10 @@ public class CHViewPart extends ViewPart {
fHistoryEntries.addAll(Arrays.asList(remaining));
}
public ITranslationUnit getInput() {
public ICElement getInput() {
Object input= fTreeViewer.getInput();
if (input instanceof ITranslationUnit) {
return (ITranslationUnit) input;
if (input instanceof ICElement) {
return (ICElement) input;
}
return null;
}

View file

@ -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;
}
}

View file

@ -145,7 +145,7 @@ public class CallHierarchyUI {
IASTName name= getSelectedName(editorInput, sel);
if (name != null) {
IBinding binding= name.resolveBinding();
if (index.isRelevantForCallHierarchy(binding)) {
if (CIndexQueries.isRelevantForCallHierarchy(binding)) {
if (name.isDefinition()) {
ICElement elem= index.findDefinition(project, name);
if (elem != null) {

View file

@ -67,6 +67,41 @@ public class CIndexQueries {
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.
* @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) {
ArrayList result= new ArrayList();
for (int i = 0; i < projectsToSearch.length; i++) {