mirror of
https://github.com/eclipse-cdt/cdt
synced 2025-08-09 17:25:38 +02:00
Fix for 185975: Link view selection to active editor does not work
This commit is contained in:
parent
7e12b44725
commit
1a052de39a
2 changed files with 101 additions and 6 deletions
|
@ -1850,7 +1850,7 @@
|
|||
</extension>
|
||||
|
||||
<!--- Common Navigator extensions -->
|
||||
<extension
|
||||
<extension
|
||||
point="org.eclipse.ui.navigator.navigatorContent">
|
||||
<navigatorContent
|
||||
activeByDefault="true"
|
||||
|
@ -1887,6 +1887,13 @@
|
|||
<instanceof value="org.eclipse.cdt.core.model.ICContainer"/>
|
||||
<instanceof value="org.eclipse.cdt.core.model.ICElement"/>
|
||||
<instanceof value="org.eclipse.cdt.ui.CElementGrouping"/>
|
||||
<adapt
|
||||
type="org.eclipse.core.resources.IProject">
|
||||
<test
|
||||
property="org.eclipse.core.resources.projectNature"
|
||||
value="org.eclipse.cdt.core.cnature">
|
||||
</test>
|
||||
</adapt>
|
||||
</or>
|
||||
</possibleChildren>
|
||||
<override
|
||||
|
@ -2100,21 +2107,41 @@
|
|||
description="%HideNonCElements.description"
|
||||
id="org.eclipse.cdt.ui.navigator.filters.NonCElementFilter"
|
||||
name="%HideNonCElements.label"/>
|
||||
</extension>
|
||||
<extension
|
||||
</extension>
|
||||
<extension
|
||||
point="org.eclipse.ui.navigator.linkHelper">
|
||||
<linkHelper
|
||||
class="org.eclipse.cdt.internal.ui.navigator.CNavigatorLinkHelper"
|
||||
id="org.eclipse.cdt.ui.navigator.linkHelper">
|
||||
<editorInputEnablement>
|
||||
<or>
|
||||
<instanceof value="org.eclipse.ui.IFileEditorInput"/>
|
||||
<instanceof value="org.eclipse.cdt.internal.ui.editor.ITranslationUnitEditorInput"/>
|
||||
</or>
|
||||
</editorInputEnablement>
|
||||
<selectionEnablement>
|
||||
<or>
|
||||
<instanceof value="org.eclipse.core.resources.IResource" />
|
||||
<instanceof value="org.eclipse.cdt.core.model.ICElement"/>
|
||||
</or>
|
||||
</selectionEnablement>
|
||||
</linkHelper>
|
||||
</extension>
|
||||
|
||||
<extension
|
||||
point="org.eclipse.ui.navigator.viewer">
|
||||
<viewerContentBinding viewerId="org.eclipse.ui.navigator.ProjectExplorer">
|
||||
<includes>
|
||||
<contentExtension pattern="org.eclipse.cdt.ui.navigator.content"/>
|
||||
<contentExtension pattern="org.eclipse.cdt.ui.navigator.filters.*"/>
|
||||
<contentExtension pattern="org.eclipse.cdt.ui.wizards.*"/>
|
||||
<contentExtension pattern="org.eclipse.cdt.ui.navigator.linkHelper"/>
|
||||
</includes>
|
||||
</viewerContentBinding>
|
||||
<dragAssistant
|
||||
class="org.eclipse.cdt.internal.ui.navigator.CNavigatorDragAdapterAssistant"
|
||||
viewerId="org.eclipse.ui.navigator.ProjectExplorer"/>
|
||||
</extension>
|
||||
|
||||
</extension>
|
||||
<extension
|
||||
point="org.eclipse.core.expressions.propertyTesters">
|
||||
<propertyTester
|
||||
|
@ -2182,5 +2209,4 @@
|
|||
name="%Template.Wizard">
|
||||
</wizard>
|
||||
</extension>
|
||||
|
||||
</plugin>
|
||||
|
|
|
@ -0,0 +1,69 @@
|
|||
/*******************************************************************************
|
||||
* 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:
|
||||
* Anton Leherbauer (Wind River Systems) - initial API and implementation
|
||||
*******************************************************************************/
|
||||
package org.eclipse.cdt.internal.ui.navigator;
|
||||
|
||||
import org.eclipse.core.resources.IFile;
|
||||
import org.eclipse.jface.viewers.IStructuredSelection;
|
||||
import org.eclipse.jface.viewers.StructuredSelection;
|
||||
import org.eclipse.ui.IEditorInput;
|
||||
import org.eclipse.ui.IEditorPart;
|
||||
import org.eclipse.ui.IWorkbenchPage;
|
||||
import org.eclipse.ui.ide.ResourceUtil;
|
||||
import org.eclipse.ui.navigator.ILinkHelper;
|
||||
|
||||
import org.eclipse.cdt.core.model.CoreModel;
|
||||
import org.eclipse.cdt.core.model.ICElement;
|
||||
import org.eclipse.cdt.core.model.ITranslationUnit;
|
||||
import org.eclipse.cdt.ui.CUIPlugin;
|
||||
import org.eclipse.cdt.ui.IWorkingCopyManager;
|
||||
|
||||
import org.eclipse.cdt.internal.ui.util.EditorUtility;
|
||||
|
||||
/**
|
||||
* Provide support for linking view selection with active editor.
|
||||
*
|
||||
* @since 4.0
|
||||
*/
|
||||
public class CNavigatorLinkHelper implements ILinkHelper {
|
||||
|
||||
/*
|
||||
* @see org.eclipse.ui.navigator.ILinkHelper#activateEditor(org.eclipse.ui.IWorkbenchPage, org.eclipse.jface.viewers.IStructuredSelection)
|
||||
*/
|
||||
public void activateEditor(IWorkbenchPage page, IStructuredSelection selection) {
|
||||
if (selection == null || selection.isEmpty())
|
||||
return;
|
||||
Object element= selection.getFirstElement();
|
||||
IEditorPart part= EditorUtility.isOpenInEditor(element);
|
||||
if (part != null) {
|
||||
page.bringToTop(part);
|
||||
if (element instanceof ICElement && !(element instanceof ITranslationUnit)) {
|
||||
EditorUtility.revealInEditor(part, (ICElement) element);
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
/*
|
||||
* @see org.eclipse.ui.navigator.ILinkHelper#findSelection(org.eclipse.ui.IEditorInput)
|
||||
*/
|
||||
public IStructuredSelection findSelection(IEditorInput input) {
|
||||
IWorkingCopyManager mgr= CUIPlugin.getDefault().getWorkingCopyManager();
|
||||
ICElement element= mgr.getWorkingCopy(input);
|
||||
if (element == null) {
|
||||
IFile file = ResourceUtil.getFile(input);
|
||||
if (file != null && CoreModel.hasCNature(file.getProject())) {
|
||||
element= CoreModel.getDefault().create(file);
|
||||
}
|
||||
}
|
||||
return (element != null) ? new StructuredSelection(element) : StructuredSelection.EMPTY;
|
||||
}
|
||||
|
||||
}
|
Loading…
Add table
Reference in a new issue