mirror of
https://github.com/eclipse-cdt/cdt
synced 2025-06-09 18:56:02 +02:00
Fix for 235065: [Outline] show in outline view does not select correct element
This commit is contained in:
parent
0a836d8009
commit
604b8366ec
1 changed files with 78 additions and 1 deletions
|
@ -13,6 +13,7 @@
|
|||
*******************************************************************************/
|
||||
package org.eclipse.cdt.internal.ui.editor;
|
||||
|
||||
import org.eclipse.core.runtime.IAdaptable;
|
||||
import org.eclipse.core.runtime.ListenerList;
|
||||
import org.eclipse.jface.action.Action;
|
||||
import org.eclipse.jface.action.IMenuListener;
|
||||
|
@ -43,8 +44,13 @@ import org.eclipse.ui.IWorkbenchPart;
|
|||
import org.eclipse.ui.PlatformUI;
|
||||
import org.eclipse.ui.actions.ActionContext;
|
||||
import org.eclipse.ui.actions.ActionGroup;
|
||||
import org.eclipse.ui.navigator.resources.ProjectExplorer;
|
||||
import org.eclipse.ui.part.IPageSite;
|
||||
import org.eclipse.ui.part.IShowInSource;
|
||||
import org.eclipse.ui.part.IShowInTarget;
|
||||
import org.eclipse.ui.part.IShowInTargetList;
|
||||
import org.eclipse.ui.part.Page;
|
||||
import org.eclipse.ui.part.ShowInContext;
|
||||
import org.eclipse.ui.texteditor.ITextEditor;
|
||||
import org.eclipse.ui.texteditor.ITextEditorActionDefinitionIds;
|
||||
import org.eclipse.ui.views.contentoutline.IContentOutlinePage;
|
||||
|
@ -80,7 +86,7 @@ import org.eclipse.cdt.internal.ui.viewsupport.DecoratingCLabelProvider;
|
|||
*
|
||||
* @since 5.0
|
||||
*/
|
||||
public abstract class AbstractCModelOutlinePage extends Page implements IContentOutlinePage, ISelectionChangedListener {
|
||||
public abstract class AbstractCModelOutlinePage extends Page implements IContentOutlinePage, ISelectionChangedListener, IAdaptable {
|
||||
|
||||
/**
|
||||
* A specialized tree viewer for outline content.
|
||||
|
@ -226,6 +232,77 @@ public abstract class AbstractCModelOutlinePage extends Page implements IContent
|
|||
fOpenIncludeAction= new OpenIncludeAction(this);
|
||||
}
|
||||
|
||||
/*
|
||||
* @see org.eclipse.core.runtime.IAdaptable#getAdapter(java.lang.Class)
|
||||
*/
|
||||
@SuppressWarnings("unchecked")
|
||||
public Object getAdapter(Class key) {
|
||||
if (key == IShowInSource.class) {
|
||||
return getShowInSource();
|
||||
}
|
||||
if (key == IShowInTargetList.class) {
|
||||
return new IShowInTargetList() {
|
||||
public String[] getShowInTargetIds() {
|
||||
return new String[] { ProjectExplorer.VIEW_ID };
|
||||
}
|
||||
};
|
||||
}
|
||||
if (key == IShowInTarget.class) {
|
||||
return getShowInTarget();
|
||||
}
|
||||
return null;
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns the <code>IShowInSource</code> for this view.
|
||||
*
|
||||
* @return the {@link IShowInSource}
|
||||
*/
|
||||
protected IShowInSource getShowInSource() {
|
||||
return new IShowInSource() {
|
||||
public ShowInContext getShowInContext() {
|
||||
return new ShowInContext(
|
||||
null,
|
||||
getSite().getSelectionProvider().getSelection());
|
||||
}
|
||||
};
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns the <code>IShowInTarget</code> for this view.
|
||||
*
|
||||
* @return the {@link IShowInTarget}
|
||||
*/
|
||||
protected IShowInTarget getShowInTarget() {
|
||||
return new IShowInTarget() {
|
||||
public boolean show(ShowInContext context) {
|
||||
ISelection sel= context.getSelection();
|
||||
if (sel instanceof ITextSelection) {
|
||||
ITextSelection tsel= (ITextSelection) sel;
|
||||
int offset= tsel.getOffset();
|
||||
ICElement element= null;
|
||||
if (fEditor instanceof CEditor) {
|
||||
element= ((CEditor)fEditor).getElementAt(offset, false);
|
||||
} else if (fInput != null) {
|
||||
try {
|
||||
element= fInput.getElementAtOffset(offset);
|
||||
} catch (CModelException exc) {
|
||||
CUIPlugin.log(exc);
|
||||
}
|
||||
}
|
||||
if (element != null) {
|
||||
setSelection(new StructuredSelection(element));
|
||||
return true;
|
||||
}
|
||||
} else if (sel instanceof IStructuredSelection) {
|
||||
setSelection(sel);
|
||||
return true;
|
||||
}
|
||||
return false;
|
||||
}
|
||||
};
|
||||
}
|
||||
|
||||
public boolean isLinkingEnabled() {
|
||||
return PreferenceConstants.getPreferenceStore().getBoolean(PreferenceConstants.OUTLINE_LINK_TO_EDITOR);
|
||||
}
|
||||
|
|
Loading…
Add table
Reference in a new issue