1
0
Fork 0
mirror of https://github.com/eclipse-cdt/cdt synced 2025-06-07 09:46:02 +02:00

Implements 48213, Quick Type Hierarchy.

This commit is contained in:
Markus Schorn 2007-01-30 15:00:23 +00:00
parent 2ebf9e97c2
commit b1f86f0374
20 changed files with 463 additions and 71 deletions

View file

@ -191,6 +191,9 @@ ActionDefinition.addInclude.description= Create include statement on selection
ActionDefinition.showOutline.name= Show outline ActionDefinition.showOutline.name= Show outline
ActionDefinition.showOutline.description= Shows outline ActionDefinition.showOutline.description= Shows outline
ActionDefinition.showQuickTypeHierarchy.name= Quick Type Hierarchy
ActionDefinition.showQuickTypeHierarchy.description= Shows quick type hierarchy
CElementWorkingSetPage.name = C/C++ CElementWorkingSetPage.name = C/C++
CEditorFontDefinition.description = The C/C++ editor text font is used by C/C++ editors. CEditorFontDefinition.description = The C/C++ editor text font is used by C/C++ editors.

View file

@ -992,6 +992,11 @@
contextId="org.eclipse.cdt.ui.cEditorScope" contextId="org.eclipse.cdt.ui.cEditorScope"
commandId="org.eclipse.cdt.ui.edit.open.outline" commandId="org.eclipse.cdt.ui.edit.open.outline"
schemeId="org.eclipse.ui.defaultAcceleratorConfiguration"/> schemeId="org.eclipse.ui.defaultAcceleratorConfiguration"/>
<key
sequence="M1+T"
contextId="org.eclipse.cdt.ui.cEditorScope"
commandId="org.eclipse.cdt.ui.edit.open.quick.type.hierarchy"
schemeId="org.eclipse.ui.defaultAcceleratorConfiguration"/>
<key <key
sequence="M1+M2+ARROW_DOWN" sequence="M1+M2+ARROW_DOWN"
contextId="org.eclipse.cdt.ui.cEditorScope" contextId="org.eclipse.cdt.ui.cEditorScope"
@ -1126,6 +1131,12 @@
categoryId="org.eclipse.cdt.ui.category.source" categoryId="org.eclipse.cdt.ui.category.source"
id="org.eclipse.cdt.ui.edit.open.outline"> id="org.eclipse.cdt.ui.edit.open.outline">
</command> </command>
<command
name="%ActionDefinition.showQuickTypeHierarchy.name"
description="%ActionDefinition.showQuickTypeHierarchy.description"
categoryId="org.eclipse.cdt.ui.category.source"
id="org.eclipse.cdt.ui.edit.open.quick.type.hierarchy">
</command>
<command <command
name="%ActionDefinition.GotoNextMember.name" name="%ActionDefinition.GotoNextMember.name"
description="%ActionDefinition.GotoNextMember.description" description="%ActionDefinition.GotoNextMember.description"

View file

@ -21,6 +21,7 @@ import org.eclipse.swt.widgets.Display;
import org.eclipse.ui.IEditorInput; 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.ui.texteditor.ITextEditor;
import org.eclipse.cdt.core.CCorePlugin; import org.eclipse.cdt.core.CCorePlugin;
import org.eclipse.cdt.core.dom.ast.DOMException; import org.eclipse.cdt.core.dom.ast.DOMException;
@ -37,7 +38,6 @@ import org.eclipse.cdt.core.model.ICProject;
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.actions.OpenActionUtil;
import org.eclipse.cdt.internal.ui.editor.CEditor;
import org.eclipse.cdt.internal.ui.util.ExceptionHandler; import org.eclipse.cdt.internal.ui.util.ExceptionHandler;
import org.eclipse.cdt.internal.ui.viewsupport.CElementLabels; import org.eclipse.cdt.internal.ui.viewsupport.CElementLabels;
import org.eclipse.cdt.internal.ui.viewsupport.IndexUI; import org.eclipse.cdt.internal.ui.viewsupport.IndexUI;
@ -91,31 +91,34 @@ public class CallHierarchyUI {
return null; return null;
} }
public static void open(final CEditor editor, final ITextSelection sel) { public static void open(final ITextEditor editor, final ITextSelection sel) {
if (editor != null) { if (editor != null) {
final ICProject project= editor.getInputCElement().getCProject(); ICElement inputCElement = CUIPlugin.getDefault().getWorkingCopyManager().getWorkingCopy(editor.getEditorInput());
final IEditorInput editorInput = editor.getEditorInput(); if (inputCElement != null) {
final Display display= Display.getCurrent(); final ICProject project= inputCElement.getCProject();
final IEditorInput editorInput = editor.getEditorInput();
Job job= new Job(CHMessages.CallHierarchyUI_label) { final Display display= Display.getCurrent();
protected IStatus run(IProgressMonitor monitor) {
try { Job job= new Job(CHMessages.CallHierarchyUI_label) {
final ICElement[] elems= findDefinitions(project, editorInput, sel); protected IStatus run(IProgressMonitor monitor) {
if (elems != null && elems.length > 0) { try {
display.asyncExec(new Runnable() { final ICElement[] elems= findDefinitions(project, editorInput, sel);
public void run() { if (elems != null && elems.length > 0) {
openInViewPart(editor.getSite().getWorkbenchWindow(), elems); display.asyncExec(new Runnable() {
}}); public void run() {
openInViewPart(editor.getSite().getWorkbenchWindow(), elems);
}});
}
return Status.OK_STATUS;
}
catch (CoreException e) {
return e.getStatus();
} }
return Status.OK_STATUS;
}
catch (CoreException e) {
return e.getStatus();
} }
} };
}; job.setUser(true);
job.setUser(true); job.schedule();
job.schedule(); }
} }
} }

View file

@ -15,20 +15,20 @@ import org.eclipse.core.runtime.IAdaptable;
import org.eclipse.jface.text.ITextSelection; import org.eclipse.jface.text.ITextSelection;
import org.eclipse.jface.viewers.IStructuredSelection; import org.eclipse.jface.viewers.IStructuredSelection;
import org.eclipse.ui.IWorkbenchSite; import org.eclipse.ui.IWorkbenchSite;
import org.eclipse.ui.texteditor.ITextEditor;
import org.eclipse.cdt.core.model.ICElement; import org.eclipse.cdt.core.model.ICElement;
import org.eclipse.cdt.core.model.IEnumeration; import org.eclipse.cdt.core.model.IEnumeration;
import org.eclipse.cdt.core.model.IEnumerator; import org.eclipse.cdt.core.model.IEnumerator;
import org.eclipse.cdt.core.model.IFunctionDeclaration; 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.CUIPlugin;
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; private ITextEditor fEditor;
public OpenCallHierarchyAction(IWorkbenchSite site) { public OpenCallHierarchyAction(IWorkbenchSite site) {
super(site); super(site);
@ -36,10 +36,10 @@ public class OpenCallHierarchyAction extends SelectionDispatchAction {
setToolTipText(CHMessages.OpenCallHierarchyAction_tooltip); setToolTipText(CHMessages.OpenCallHierarchyAction_tooltip);
} }
public OpenCallHierarchyAction(CEditor editor) { public OpenCallHierarchyAction(ITextEditor editor) {
this(editor.getSite()); this(editor.getSite());
fEditor= editor; fEditor= editor;
setEnabled(fEditor != null && fEditor.getInputCElement() != null); setEnabled(fEditor != null && CUIPlugin.getDefault().getWorkingCopyManager().getWorkingCopy(editor.getEditorInput()) != null);
} }
public void run(ITextSelection sel) { public void run(ITextSelection sel) {

View file

@ -2293,7 +2293,11 @@ public class CEditor extends TextEditor implements ISelectionChangedListener, IR
action = new TextOperationAction(CEditorMessages.getResourceBundle(), "OpenOutline.", this, CSourceViewer.SHOW_OUTLINE, true); //$NON-NLS-1$ action = new TextOperationAction(CEditorMessages.getResourceBundle(), "OpenOutline.", this, CSourceViewer.SHOW_OUTLINE, true); //$NON-NLS-1$
action.setActionDefinitionId(ICEditorActionDefinitionIds.OPEN_OUTLINE); action.setActionDefinitionId(ICEditorActionDefinitionIds.OPEN_OUTLINE);
setAction("OpenOutline", action); //$NON-NLS-1$*/ setAction("OpenOutline", action); //$NON-NLS-1$*/
action = new TextOperationAction(CEditorMessages.getResourceBundle(), "OpenHierarchy.", this, CSourceViewer.SHOW_HIERARCHY, true); //$NON-NLS-1$
action.setActionDefinitionId(ICEditorActionDefinitionIds.OPEN_QUICK_TYPE_HIERARCHY);
setAction("OpenHierarchy", action); //$NON-NLS-1$*/
action = new GoToNextPreviousMemberAction(CEditorMessages.getResourceBundle(), "GotoNextMember.", this, true); //$NON-NLS-1$ action = new GoToNextPreviousMemberAction(CEditorMessages.getResourceBundle(), "GotoNextMember.", this, true); //$NON-NLS-1$
action.setActionDefinitionId(ICEditorActionDefinitionIds.GOTO_NEXT_MEMBER); action.setActionDefinitionId(ICEditorActionDefinitionIds.GOTO_NEXT_MEMBER);
setAction(GoToNextPreviousMemberAction.PREVIOUS_MEMBER, action); setAction(GoToNextPreviousMemberAction.PREVIOUS_MEMBER, action);
@ -2340,6 +2344,7 @@ public class CEditor extends TextEditor implements ISelectionChangedListener, IR
addAction(menu, IContextMenuConstants.GROUP_OPEN, "OpenCallHierarchy"); //$NON-NLS-1$ addAction(menu, IContextMenuConstants.GROUP_OPEN, "OpenCallHierarchy"); //$NON-NLS-1$
addAction(menu, IContextMenuConstants.GROUP_OPEN, "OpenOutline"); //$NON-NLS-1$ addAction(menu, IContextMenuConstants.GROUP_OPEN, "OpenOutline"); //$NON-NLS-1$
addAction(menu, IContextMenuConstants.GROUP_OPEN, "OpenHierarchy"); //$NON-NLS-1$
} }
ActionContext context= new ActionContext(getSelectionProvider().getSelection()); ActionContext context= new ActionContext(getSelectionProvider().getSelection());

View file

@ -41,6 +41,10 @@ OpenOutline.label= Quick Out&line
OpenOutline.tooltip= Shows the Quick Outline of Editor Input OpenOutline.tooltip= Shows the Quick Outline of Editor Input
OpenOutline.description= Shows the quick outline for the editor input OpenOutline.description= Shows the quick outline for the editor input
OpenHierarchy.label= Quick Type Hierarchy
OpenHierarchy.tooltip= Shows the Quick Type Hierarchy of Editor Input
OpenHierarchy.description= Shows the quick type hierarchy for the editor input
TogglePresentation.label=Show Source of Selected Element Only TogglePresentation.label=Show Source of Selected Element Only
TogglePresentation.tooltip=Show Source of Selected Element Only TogglePresentation.tooltip=Show Source of Selected Element Only

View file

@ -52,9 +52,12 @@ public class CSourceViewer extends ProjectionViewer implements IPropertyChangeLi
/** Show outline operation id. */ /** Show outline operation id. */
public static final int SHOW_OUTLINE = 101; public static final int SHOW_OUTLINE = 101;
public static final int SHOW_HIERARCHY = 102;
/** Presents outline. */ /** Presents outline. */
private IInformationPresenter fOutlinePresenter; private IInformationPresenter fOutlinePresenter;
/** Presents type hierarchy. */
private IInformationPresenter fHierarchyPresenter;
private List fTextConverters; private List fTextConverters;
private boolean fIgnoreTextConverters= false; private boolean fIgnoreTextConverters= false;
@ -147,6 +150,9 @@ public class CSourceViewer extends ProjectionViewer implements IPropertyChangeLi
fOutlinePresenter= cConfiguration.getOutlinePresenter(this); fOutlinePresenter= cConfiguration.getOutlinePresenter(this);
if (fOutlinePresenter != null) if (fOutlinePresenter != null)
fOutlinePresenter.install(this); fOutlinePresenter.install(this);
fHierarchyPresenter= cConfiguration.getHierarchyPresenter(this);
if (fHierarchyPresenter != null)
fHierarchyPresenter.install(this);
} }
if (fPreferenceStore != null) { if (fPreferenceStore != null) {
fPreferenceStore.addPropertyChangeListener(this); fPreferenceStore.addPropertyChangeListener(this);
@ -241,6 +247,10 @@ public class CSourceViewer extends ProjectionViewer implements IPropertyChangeLi
if (fOutlinePresenter != null) { if (fOutlinePresenter != null) {
fOutlinePresenter.uninstall(); fOutlinePresenter.uninstall();
fOutlinePresenter= null; fOutlinePresenter= null;
}
if (fHierarchyPresenter != null) {
fHierarchyPresenter.uninstall();
fHierarchyPresenter= null;
} }
if (fForegroundColor != null) { if (fForegroundColor != null) {
fForegroundColor.dispose(); fForegroundColor.dispose();
@ -308,6 +318,9 @@ public class CSourceViewer extends ProjectionViewer implements IPropertyChangeLi
case SHOW_OUTLINE: case SHOW_OUTLINE:
fOutlinePresenter.showInformation(); fOutlinePresenter.showInformation();
return; return;
case SHOW_HIERARCHY:
fHierarchyPresenter.showInformation();
return;
case UNDO: case UNDO:
fIgnoreTextConverters= true; fIgnoreTextConverters= true;
super.doOperation(operation); super.doOperation(operation);
@ -329,6 +342,9 @@ public class CSourceViewer extends ProjectionViewer implements IPropertyChangeLi
if (operation == SHOW_OUTLINE) { if (operation == SHOW_OUTLINE) {
return fOutlinePresenter != null; return fOutlinePresenter != null;
} }
else if (operation == SHOW_HIERARCHY) {
return fHierarchyPresenter != null;
}
return super.canDoOperation(operation); return super.canDoOperation(operation);
} }

View file

@ -127,6 +127,12 @@ public interface ICEditorActionDefinitionIds extends ITextEditorActionDefinition
*/ */
public static final String OPEN_TYPE_HIERARCHY= "org.eclipse.cdt.ui.edit.open.type.hierarchy"; //$NON-NLS-1$ public static final String OPEN_TYPE_HIERARCHY= "org.eclipse.cdt.ui.edit.open.type.hierarchy"; //$NON-NLS-1$
/**
* Action definition ID of the navigate -> open type hierarchy action
* (value <code>"org.eclipse.cdt.ui.edit.text.c.open.quick.type.hierarchy"</code>).
*/
public static final String OPEN_QUICK_TYPE_HIERARCHY= "org.eclipse.cdt.ui.edit.open.quick.type.hierarchy"; //$NON-NLS-1$
/** /**
* Action definition ID of the navigate -> open action * Action definition ID of the navigate -> open action
* (value <code>"org.eclipse.cdt.ui.edit.text.c.open.editor"</code>). * (value <code>"org.eclipse.cdt.ui.edit.text.c.open.editor"</code>).

View file

@ -83,6 +83,8 @@ import org.eclipse.cdt.internal.ui.text.c.hover.CEditorTextHoverDescriptor;
import org.eclipse.cdt.internal.ui.text.c.hover.CEditorTextHoverProxy; import org.eclipse.cdt.internal.ui.text.c.hover.CEditorTextHoverProxy;
import org.eclipse.cdt.internal.ui.text.contentassist.CContentAssistProcessor; import org.eclipse.cdt.internal.ui.text.contentassist.CContentAssistProcessor;
import org.eclipse.cdt.internal.ui.text.contentassist.ContentAssistPreference; import org.eclipse.cdt.internal.ui.text.contentassist.ContentAssistPreference;
import org.eclipse.cdt.internal.ui.typehierarchy.THInformationControl;
import org.eclipse.cdt.internal.ui.typehierarchy.THInformationProvider;
import org.eclipse.cdt.internal.ui.util.ExternalEditorInput; import org.eclipse.cdt.internal.ui.util.ExternalEditorInput;
@ -258,6 +260,26 @@ public class CSourceViewerConfiguration extends TextSourceViewerConfiguration {
return presenter; return presenter;
} }
/**
* Creates outline presenter.
* @return Presenter with outline view.
*/
public IInformationPresenter getHierarchyPresenter(ISourceViewer sourceViewer) {
final IInformationControlCreator hierarchyControlCreator = getHierarchyControlCreator();
final InformationPresenter presenter = new InformationPresenter(hierarchyControlCreator);
presenter.setDocumentPartitioning(getConfiguredDocumentPartitioning(sourceViewer));
presenter.setAnchor(AbstractInformationControlManager.ANCHOR_GLOBAL);
final IInformationProvider provider = new THInformationProvider(getEditor());
presenter.setInformationProvider(provider, IDocument.DEFAULT_CONTENT_TYPE);
presenter.setInformationProvider(provider, ICPartitions.C_MULTI_LINE_COMMENT);
presenter.setInformationProvider(provider, ICPartitions.C_SINGLE_LINE_COMMENT);
presenter.setInformationProvider(provider, ICPartitions.C_STRING);
presenter.setInformationProvider(provider, ICPartitions.C_CHARACTER);
presenter.setInformationProvider(provider, ICPartitions.C_PREPROCESSOR);
presenter.setSizeConstraints(50, 20, true, false);
return presenter;
}
/** /**
* Initializes the scanners. * Initializes the scanners.
*/ */
@ -732,7 +754,25 @@ public class CSourceViewerConfiguration extends TextSourceViewerConfiguration {
}; };
return conrolCreator; return conrolCreator;
} }
/**
* Creates control for outline presentation in editor.
* @return Control.
*/
private IInformationControlCreator getHierarchyControlCreator() {
final IInformationControlCreator conrolCreator = new IInformationControlCreator() {
/**
* @see org.eclipse.jface.text.IInformationControlCreator#createInformationControl(org.eclipse.swt.widgets.Shell)
*/
public IInformationControl createInformationControl(Shell parent) {
int shellStyle= SWT.RESIZE;
int treeStyle= SWT.V_SCROLL | SWT.H_SCROLL;
return new THInformationControl(parent, shellStyle, treeStyle);
}
};
return conrolCreator;
}
protected ILanguage getLanguage() { protected ILanguage getLanguage() {
if (fTextEditor == null) { if (fTextEditor == null) {
return null; return null;

View file

@ -0,0 +1,23 @@
/*******************************************************************************
* 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.typehierarchy;
import org.eclipse.ui.progress.IWorkbenchSiteProgressService;
public interface ITHModelPresenter {
void setMessage(String msg);
void onEvent(int event);
IWorkbenchSiteProgressService getProgressService();
}

View file

@ -26,6 +26,8 @@ public class Messages extends NLS {
public static String THHistoryListAction_HistoryList_title; public static String THHistoryListAction_HistoryList_title;
public static String THHistoryListAction_label; public static String THHistoryListAction_label;
public static String THHistoryListAction_Remove; public static String THHistoryListAction_Remove;
public static String THInformationControl_regularTitle;
public static String THInformationControl_showDefiningTypesTitle;
public static String THViewPart_AutomaticOrientation; public static String THViewPart_AutomaticOrientation;
public static String THViewPart_Cancel; public static String THViewPart_Cancel;
public static String THViewPart_Cancel_tooltip; public static String THViewPart_Cancel_tooltip;

View file

@ -15,16 +15,17 @@ import org.eclipse.core.runtime.IAdaptable;
import org.eclipse.jface.text.ITextSelection; import org.eclipse.jface.text.ITextSelection;
import org.eclipse.jface.viewers.IStructuredSelection; import org.eclipse.jface.viewers.IStructuredSelection;
import org.eclipse.ui.IWorkbenchSite; import org.eclipse.ui.IWorkbenchSite;
import org.eclipse.ui.texteditor.ITextEditor;
import org.eclipse.cdt.core.model.ICElement; import org.eclipse.cdt.core.model.ICElement;
import org.eclipse.cdt.ui.CUIPlugin;
import org.eclipse.cdt.ui.actions.SelectionDispatchAction; import org.eclipse.cdt.ui.actions.SelectionDispatchAction;
import org.eclipse.cdt.internal.ui.editor.CEditor;
public class OpenTypeHierarchyAction extends SelectionDispatchAction { public class OpenTypeHierarchyAction extends SelectionDispatchAction {
private CEditor fEditor; private ITextEditor fEditor;
public OpenTypeHierarchyAction(IWorkbenchSite site) { public OpenTypeHierarchyAction(IWorkbenchSite site) {
super(site); super(site);
@ -32,10 +33,10 @@ public class OpenTypeHierarchyAction extends SelectionDispatchAction {
setToolTipText(Messages.OpenTypeHierarchyAction_tooltip); setToolTipText(Messages.OpenTypeHierarchyAction_tooltip);
} }
public OpenTypeHierarchyAction(CEditor editor) { public OpenTypeHierarchyAction(ITextEditor editor) {
this(editor.getSite()); this(editor.getSite());
fEditor= editor; fEditor= editor;
setEnabled(fEditor != null && fEditor.getInputCElement() != null); setEnabled(fEditor != null && CUIPlugin.getDefault().getWorkingCopyManager().getWorkingCopy(editor.getEditorInput()) != null);
} }
public void run(ITextSelection sel) { public void run(ITextSelection sel) {

View file

@ -70,7 +70,7 @@ class THGraph {
} }
private THGraphEdge addEdge(THGraphNode from, THGraphNode to) { private THGraphEdge addEdge(THGraphNode from, THGraphNode to) {
if (createsLoop(from, to)) { if (createsLoopOrIsDuplicate(from, to)) {
return null; return null;
} }
THGraphEdge edge= new THGraphEdge(from, to); THGraphEdge edge= new THGraphEdge(from, to);
@ -81,7 +81,7 @@ class THGraph {
return edge; return edge;
} }
private boolean createsLoop(THGraphNode from, THGraphNode to) { private boolean createsLoopOrIsDuplicate(THGraphNode from, THGraphNode to) {
if (from == to) { if (from == to) {
return true; return true;
} }
@ -107,6 +107,14 @@ class THGraph {
} }
} }
} }
// check if edge is already there.
List out= from.getOutgoing();
for (Iterator iterator = out.iterator(); iterator.hasNext();) {
THGraphEdge edge = (THGraphEdge) iterator.next();
if (edge.getEndNode() == to) {
return true;
}
}
return false; return false;
} }

View file

@ -68,10 +68,10 @@ class THHierarchyModel {
private Job fJob; private Job fJob;
private Display fDisplay; private Display fDisplay;
private THViewPart fView; private ITHModelPresenter fView;
private WorkingSetFilterUI fFilter; private WorkingSetFilterUI fFilter;
public THHierarchyModel(THViewPart view, Display display) { public THHierarchyModel(ITHModelPresenter view, Display display) {
fDisplay= display; fDisplay= display;
fView= view; fView= view;
} }
@ -127,7 +127,7 @@ class THHierarchyModel {
} }
fJob= new BackgroundJob(); fJob= new BackgroundJob();
fJob.setRule(RULE); fJob.setRule(RULE);
IWorkbenchSiteProgressService ps= (IWorkbenchSiteProgressService) fView.getSite().getAdapter(IWorkbenchSiteProgressService.class); IWorkbenchSiteProgressService ps= fView.getProgressService();
if (ps != null) { if (ps != null) {
ps.schedule(fJob, 0L, true); ps.schedule(fJob, 0L, true);
} }
@ -395,8 +395,7 @@ class THHierarchyModel {
private boolean isImplementor(ICElement element) { private boolean isImplementor(ICElement element) {
if (element == null if (element == null
|| fSelectedMember == null || fMemberSignatureToSelect == null || fSelectedMember == null || fMemberSignatureToSelect == null) {
|| fGraph.isTrivial()) {
return false; return false;
} }
THGraphNode gnode= fGraph.getNode(element); THGraphNode gnode= fGraph.getNode(element);
@ -420,4 +419,11 @@ class THHierarchyModel {
public ICElement getSelectedMember() { public ICElement getSelectedMember() {
return fSelectedMember; return fSelectedMember;
} }
public boolean hasTrivialHierarchy() {
if (fRootNodes == null || fRootNodes.length == 0) {
return true;
}
return fRootNodes.length == 1 && !fRootNodes[0].hasChildren();
}
} }

View file

@ -0,0 +1,183 @@
/*******************************************************************************
* 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.typehierarchy;
import java.util.Iterator;
import org.eclipse.jface.viewers.ISelection;
import org.eclipse.jface.viewers.IStructuredSelection;
import org.eclipse.jface.viewers.StructuredSelection;
import org.eclipse.jface.viewers.TreeViewer;
import org.eclipse.jface.viewers.ViewerSorter;
import org.eclipse.swt.SWT;
import org.eclipse.swt.widgets.Composite;
import org.eclipse.swt.widgets.Display;
import org.eclipse.swt.widgets.Shell;
import org.eclipse.swt.widgets.Tree;
import org.eclipse.swt.widgets.TreeItem;
import org.eclipse.ui.progress.IWorkbenchSiteProgressService;
import com.ibm.icu.text.MessageFormat;
import org.eclipse.cdt.core.model.CModelException;
import org.eclipse.cdt.core.model.ICElement;
import org.eclipse.cdt.ui.CUIPlugin;
import org.eclipse.cdt.internal.ui.editor.ICEditorActionDefinitionIds;
import org.eclipse.cdt.internal.ui.text.AbstractInformationControl;
import org.eclipse.cdt.internal.ui.viewsupport.EditorOpener;
public class THInformationControl extends AbstractInformationControl implements ITHModelPresenter {
private THHierarchyModel fModel;
private THLabelProvider fHierarchyLabelProvider;
private TreeViewer fHierarchyTreeViewer;
public THInformationControl(Shell parent, int shellStyle, int treeStyle) {
super(parent, shellStyle, treeStyle, ICEditorActionDefinitionIds.OPEN_QUICK_TYPE_HIERARCHY, true);
}
protected boolean hasHeader() {
return true;
}
protected TreeViewer createTreeViewer(Composite parent, int style) {
Display display= getShell().getDisplay();
fModel= new THHierarchyModel(this, display);
fHierarchyLabelProvider= new THLabelProvider(display, fModel);
fHierarchyLabelProvider.setMarkImplementers(false);
fHierarchyTreeViewer = new TreeViewer(parent, SWT.H_SCROLL | SWT.V_SCROLL | SWT.BORDER);
fHierarchyTreeViewer.setContentProvider(new THContentProvider());
fHierarchyTreeViewer.setLabelProvider(fHierarchyLabelProvider);
fHierarchyTreeViewer.setSorter(new ViewerSorter());
fHierarchyTreeViewer.setUseHashlookup(true);
return fHierarchyTreeViewer;
}
protected void onOpenElement(ISelection selection) {
ICElement elem= (ICElement) getSelectedElement();
if (elem != null) {
try {
EditorOpener.open(CUIPlugin.getActivePage(), elem);
} catch (CModelException e) {
CUIPlugin.getDefault().log(e);
}
}
}
public void setInput(Object input) {
if (input instanceof ICElement[]) {
ICElement[] splitInput= (ICElement[]) input;
if (TypeHierarchyUI.isValidTypeInput(splitInput[0])) {
fModel.setInput(splitInput[0], splitInput[1]);
fHierarchyLabelProvider.setHideNonImplementers(splitInput[1] != null);
fHierarchyTreeViewer.setInput(fModel);
fModel.computeGraph();
String msgfmt= Messages.THInformationControl_regularTitle;
String obj= splitInput[0].getElementName();
if (splitInput[1] != null) {
msgfmt= Messages.THInformationControl_showDefiningTypesTitle;
obj= splitInput[1].getElementName();
}
String title= MessageFormat.format(msgfmt, new Object[] {obj});
setTitleText(title);
}
}
}
protected String getId() {
return "org.eclipse.cdt.internal.ui.typehierarchy.QuickHierarchy"; //$NON-NLS-1$
}
protected Object getSelectedElement() {
THNode node= selectionToNode(fHierarchyTreeViewer.getSelection());
if (node != null) {
ICElement elem= node.getElement();
if (node.isImplementor()) {
fModel.onHierarchySelectionChanged(node);
ICElement melem= fModel.getSelectedMember();
if (melem != null) {
return melem;
}
}
return elem;
}
return null;
}
private THNode selectionToNode(ISelection selection) {
if (selection instanceof IStructuredSelection) {
IStructuredSelection ss= (IStructuredSelection) selection;
for (Iterator iter = ss.iterator(); iter.hasNext(); ) {
Object cand= iter.next();
if (cand instanceof THNode) {
return (THNode) cand;
}
}
}
return null;
}
public void onEvent(int event) {
switch (event) {
case THHierarchyModel.END_OF_COMPUTATION:
if (fModel.hasTrivialHierarchy()) {
fHierarchyLabelProvider.setHideNonImplementers(false);
}
fHierarchyTreeViewer.refresh();
THNode selection= fModel.getSelectionInHierarchy();
if (selection != null) {
fHierarchyTreeViewer.setSelection(new StructuredSelection(selection));
fHierarchyTreeViewer.expandToLevel(selection, 1);
}
break;
}
}
public void setMessage(String msg) {
}
public IWorkbenchSiteProgressService getProgressService() {
return null;
}
protected void selectFirstMatch() {
Tree tree= fHierarchyTreeViewer.getTree();
Object element= findElement(tree.getItems());
if (element != null)
fHierarchyTreeViewer.setSelection(new StructuredSelection(element), true);
else
fHierarchyTreeViewer.setSelection(StructuredSelection.EMPTY);
}
private THNode findElement(TreeItem[] items) {
for (int i= 0; i < items.length; i++) {
Object item= items[i].getData();
THNode element= null;
if (item instanceof THNode) {
element= (THNode)item;
if (fStringMatcher == null)
return element;
if (element != null) {
String label= fHierarchyLabelProvider.getText(element);
if (fStringMatcher.match(label))
return element;
}
}
element= findElement(items[i].getItems());
if (element != null)
return element;
}
return null;
}
}

View file

@ -0,0 +1,40 @@
/*******************************************************************************
* 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.typehierarchy;
import org.eclipse.jface.text.IRegion;
import org.eclipse.jface.text.ITextViewer;
import org.eclipse.jface.text.Region;
import org.eclipse.jface.text.information.IInformationProvider;
import org.eclipse.jface.text.information.IInformationProviderExtension;
import org.eclipse.ui.texteditor.ITextEditor;
public class THInformationProvider implements IInformationProviderExtension, IInformationProvider {
private ITextEditor fEditor;
public THInformationProvider(ITextEditor editor) {
fEditor= editor;
}
public Object getInformation2(ITextViewer textViewer, IRegion subject) {
return fEditor == null ? null : TypeHierarchyUI.getInput(fEditor, subject);
}
public String getInformation(ITextViewer textViewer, IRegion subject) {
return null;
}
public IRegion getSubject(ITextViewer textViewer, int offset) {
return new Region(offset, 0);
}
}

View file

@ -39,6 +39,8 @@ public class THLabelProvider extends LabelProvider implements IColorProvider {
private THHierarchyModel fModel; private THHierarchyModel fModel;
private HashMap fCachedImages= new HashMap(); private HashMap fCachedImages= new HashMap();
private Color fColorInactive; private Color fColorInactive;
private boolean fMarkImplementers= true;
private boolean fHideNonImplementers= false;
public THLabelProvider(Display display, THHierarchyModel model) { public THLabelProvider(Display display, THHierarchyModel model) {
fColorInactive= display.getSystemColor(SWT.COLOR_DARK_GRAY); fColorInactive= display.getSystemColor(SWT.COLOR_DARK_GRAY);
@ -50,7 +52,8 @@ public class THLabelProvider extends LabelProvider implements IColorProvider {
THNode node= (THNode) element; THNode node= (THNode) element;
ICElement decl= node.getElement(); ICElement decl= node.getElement();
if (decl != null) { if (decl != null) {
if (node.isFiltered()) { if (node.isFiltered() ||
(fHideNonImplementers && !node.isImplementor())) {
fCLabelProvider.setImageFlags(CElementImageProvider.LIGHT_TYPE_ICONS); fCLabelProvider.setImageFlags(CElementImageProvider.LIGHT_TYPE_ICONS);
} }
Image image= fCLabelProvider.getImage(decl); Image image= fCLabelProvider.getImage(decl);
@ -98,7 +101,7 @@ public class THLabelProvider extends LabelProvider implements IColorProvider {
flags |= CElementImageDescriptor.REFERENCED_BY; flags |= CElementImageDescriptor.REFERENCED_BY;
} }
} }
if (node.isImplementor()) { if (fMarkImplementers && node.isImplementor()) {
flags |= CElementImageDescriptor.DEFINES; flags |= CElementImageDescriptor.DEFINES;
} }
@ -130,4 +133,12 @@ public class THLabelProvider extends LabelProvider implements IColorProvider {
public void setShowFiles(boolean show) { public void setShowFiles(boolean show) {
fCLabelProvider.setTextFlags(show ? LABEL_OPTIONS_SHOW_FILES : LABEL_OPTIONS_SIMPLE); fCLabelProvider.setTextFlags(show ? LABEL_OPTIONS_SHOW_FILES : LABEL_OPTIONS_SIMPLE);
} }
public void setMarkImplementers(boolean val) {
fMarkImplementers= val;
}
public void setHideNonImplementers(boolean val) {
fHideNonImplementers= val;
}
} }

View file

@ -67,6 +67,7 @@ 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;
import org.eclipse.ui.part.ViewPart; import org.eclipse.ui.part.ViewPart;
import org.eclipse.ui.progress.IWorkbenchSiteProgressService;
import com.ibm.icu.text.MessageFormat; import com.ibm.icu.text.MessageFormat;
@ -94,7 +95,7 @@ import org.eclipse.cdt.internal.ui.viewsupport.WorkingSetFilterUI;
/** /**
* The view part for the include browser. * The view part for the include browser.
*/ */
public class THViewPart extends ViewPart { public class THViewPart extends ViewPart implements ITHModelPresenter {
private static final int MAX_HISTORY_SIZE = 10; private static final int MAX_HISTORY_SIZE = 10;
private static final String TRUE = String.valueOf(true); private static final String TRUE = String.valueOf(true);
private static final String KEY_WORKING_SET_FILTER = "workingSetFilter"; //$NON-NLS-1$ private static final String KEY_WORKING_SET_FILTER = "workingSetFilter"; //$NON-NLS-1$
@ -868,6 +869,7 @@ public class THViewPart extends ViewPart {
if (!fShowsMessage) { if (!fShowsMessage) {
fIgnoreSelectionChanges++; fIgnoreSelectionChanges++;
try { try {
fHierarchyLabelProvider.setMarkImplementers(!fModel.hasTrivialHierarchy());
fHierarchyTreeViewer.refresh(); fHierarchyTreeViewer.refresh();
fMemberViewer.refresh(); fMemberViewer.refresh();
setSelections(); setSelections();
@ -1051,4 +1053,8 @@ public class THViewPart extends ViewPart {
break; break;
} }
} }
public IWorkbenchSiteProgressService getProgressService() {
return (IWorkbenchSiteProgressService) getSite().getAdapter(IWorkbenchSiteProgressService.class);
}
} }

View file

@ -16,11 +16,14 @@ import org.eclipse.core.runtime.IProgressMonitor;
import org.eclipse.core.runtime.IStatus; import org.eclipse.core.runtime.IStatus;
import org.eclipse.core.runtime.Status; import org.eclipse.core.runtime.Status;
import org.eclipse.core.runtime.jobs.Job; import org.eclipse.core.runtime.jobs.Job;
import org.eclipse.jface.text.IRegion;
import org.eclipse.jface.text.ITextSelection; import org.eclipse.jface.text.ITextSelection;
import org.eclipse.jface.text.Region;
import org.eclipse.swt.widgets.Display; import org.eclipse.swt.widgets.Display;
import org.eclipse.ui.IEditorInput; 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.ui.texteditor.ITextEditor;
import org.eclipse.cdt.core.CCorePlugin; import org.eclipse.cdt.core.CCorePlugin;
import org.eclipse.cdt.core.dom.ast.DOMException; import org.eclipse.cdt.core.dom.ast.DOMException;
@ -44,7 +47,6 @@ import org.eclipse.cdt.core.model.ITranslationUnit;
import org.eclipse.cdt.core.model.IWorkingCopy; 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.editor.CEditor;
import org.eclipse.cdt.internal.ui.util.ExceptionHandler; import org.eclipse.cdt.internal.ui.util.ExceptionHandler;
import org.eclipse.cdt.internal.ui.viewsupport.FindNameForSelectionVisitor; import org.eclipse.cdt.internal.ui.viewsupport.FindNameForSelectionVisitor;
import org.eclipse.cdt.internal.ui.viewsupport.IndexUI; import org.eclipse.cdt.internal.ui.viewsupport.IndexUI;
@ -85,35 +87,55 @@ public class TypeHierarchyUI {
return null; return null;
} }
public static void open(final CEditor editor, final ITextSelection sel) { public static ICElement[] getInput(final ITextEditor editor, IRegion region) {
if (editor != null) { if (editor != null) {
final ICProject project= editor.getInputCElement().getCProject();
final IEditorInput editorInput = editor.getEditorInput(); final IEditorInput editorInput = editor.getEditorInput();
final Display display= Display.getCurrent(); ICElement inputCElement = CUIPlugin.getDefault().getWorkingCopyManager().getWorkingCopy(editorInput);
if (inputCElement != null) {
Job job= new Job(Messages.TypeHierarchyUI_OpenTypeHierarchy) { final ICProject project= inputCElement.getCProject();
protected IStatus run(IProgressMonitor monitor) { try {
try { return findInput(project, editorInput, region);
final ICElement[] elems= findInput(project, editorInput, sel); } catch (CoreException e) {
if (elems != null && elems.length == 2) { CUIPlugin.getDefault().log(e);
display.asyncExec(new Runnable() {
public void run() {
openInViewPart(editor.getSite().getWorkbenchWindow(), elems[0], elems[1]);
}});
}
return Status.OK_STATUS;
}
catch (CoreException e) {
return e.getStatus();
}
} }
}; }
job.setUser(true); }
job.schedule(); return null;
}
public static void open(final ITextEditor editor, final ITextSelection sel) {
if (editor != null) {
ICElement inputCElement = CUIPlugin.getDefault().getWorkingCopyManager().getWorkingCopy(editor.getEditorInput());
if (inputCElement != null) {
final ICProject project= inputCElement.getCProject();
final IEditorInput editorInput = editor.getEditorInput();
final Display display= Display.getCurrent();
Job job= new Job(Messages.TypeHierarchyUI_OpenTypeHierarchy) {
protected IStatus run(IProgressMonitor monitor) {
try {
IRegion reg= new Region(sel.getOffset(), sel.getLength());
final ICElement[] elems= findInput(project, editorInput, reg);
if (elems != null && elems.length == 2) {
display.asyncExec(new Runnable() {
public void run() {
openInViewPart(editor.getSite().getWorkbenchWindow(), elems[0], elems[1]);
}});
}
return Status.OK_STATUS;
}
catch (CoreException e) {
return e.getStatus();
}
}
};
job.setUser(true);
job.schedule();
}
} }
} }
private static ICElement[] findInput(ICProject project, IEditorInput editorInput, ITextSelection sel) throws CoreException { private static ICElement[] findInput(ICProject project, IEditorInput editorInput, IRegion sel) throws CoreException {
try { try {
IIndex index= CCorePlugin.getIndexManager().getIndex(project, IIndexManager.ADD_DEPENDENCIES | IIndexManager.ADD_DEPENDENT); IIndex index= CCorePlugin.getIndexManager().getIndex(project, IIndexManager.ADD_DEPENDENCIES | IIndexManager.ADD_DEPENDENT);
@ -231,9 +253,9 @@ public class TypeHierarchyUI {
return IndexUI.findAnyDeclaration(index, project, binding); return IndexUI.findAnyDeclaration(index, project, binding);
} }
private static IASTName getSelectedName(IIndex index, IEditorInput editorInput, ITextSelection selection) throws CoreException { private static IASTName getSelectedName(IIndex index, IEditorInput editorInput, IRegion sel) throws CoreException {
int selectionStart = selection.getOffset(); int selectionStart = sel.getOffset();
int selectionLength = selection.getLength(); int selectionLength = sel.getLength();
IWorkingCopy workingCopy = CUIPlugin.getDefault().getWorkingCopyManager().getWorkingCopy(editorInput); IWorkingCopy workingCopy = CUIPlugin.getDefault().getWorkingCopyManager().getWorkingCopy(editorInput);
if (workingCopy == null) if (workingCopy == null)

View file

@ -51,3 +51,5 @@ TypeHierarchyUI_OpenTypeHierarchy=Open Type Hierarchy
TypeHierarchyUI_SelectFromList=Select one element from the list TypeHierarchyUI_SelectFromList=Select one element from the list
OpenTypeHierarchyAction_label=Open Type Hierarchy OpenTypeHierarchyAction_label=Open Type Hierarchy
OpenTypeHierarchyAction_tooltip=Open Type Hierarchy OpenTypeHierarchyAction_tooltip=Open Type Hierarchy
THInformationControl_regularTitle=Type Hierarchy of {0}
THInformationControl_showDefiningTypesTitle=Types defining or implementing {0}