mirror of
https://github.com/eclipse-cdt/cdt
synced 2025-08-10 17:55:39 +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>
|
</extension>
|
||||||
|
|
||||||
<!--- Common Navigator extensions -->
|
<!--- Common Navigator extensions -->
|
||||||
<extension
|
<extension
|
||||||
point="org.eclipse.ui.navigator.navigatorContent">
|
point="org.eclipse.ui.navigator.navigatorContent">
|
||||||
<navigatorContent
|
<navigatorContent
|
||||||
activeByDefault="true"
|
activeByDefault="true"
|
||||||
|
@ -1887,6 +1887,13 @@
|
||||||
<instanceof value="org.eclipse.cdt.core.model.ICContainer"/>
|
<instanceof value="org.eclipse.cdt.core.model.ICContainer"/>
|
||||||
<instanceof value="org.eclipse.cdt.core.model.ICElement"/>
|
<instanceof value="org.eclipse.cdt.core.model.ICElement"/>
|
||||||
<instanceof value="org.eclipse.cdt.ui.CElementGrouping"/>
|
<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>
|
</or>
|
||||||
</possibleChildren>
|
</possibleChildren>
|
||||||
<override
|
<override
|
||||||
|
@ -2100,21 +2107,41 @@
|
||||||
description="%HideNonCElements.description"
|
description="%HideNonCElements.description"
|
||||||
id="org.eclipse.cdt.ui.navigator.filters.NonCElementFilter"
|
id="org.eclipse.cdt.ui.navigator.filters.NonCElementFilter"
|
||||||
name="%HideNonCElements.label"/>
|
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">
|
point="org.eclipse.ui.navigator.viewer">
|
||||||
<viewerContentBinding viewerId="org.eclipse.ui.navigator.ProjectExplorer">
|
<viewerContentBinding viewerId="org.eclipse.ui.navigator.ProjectExplorer">
|
||||||
<includes>
|
<includes>
|
||||||
<contentExtension pattern="org.eclipse.cdt.ui.navigator.content"/>
|
<contentExtension pattern="org.eclipse.cdt.ui.navigator.content"/>
|
||||||
<contentExtension pattern="org.eclipse.cdt.ui.navigator.filters.*"/>
|
<contentExtension pattern="org.eclipse.cdt.ui.navigator.filters.*"/>
|
||||||
<contentExtension pattern="org.eclipse.cdt.ui.wizards.*"/>
|
<contentExtension pattern="org.eclipse.cdt.ui.wizards.*"/>
|
||||||
|
<contentExtension pattern="org.eclipse.cdt.ui.navigator.linkHelper"/>
|
||||||
</includes>
|
</includes>
|
||||||
</viewerContentBinding>
|
</viewerContentBinding>
|
||||||
<dragAssistant
|
<dragAssistant
|
||||||
class="org.eclipse.cdt.internal.ui.navigator.CNavigatorDragAdapterAssistant"
|
class="org.eclipse.cdt.internal.ui.navigator.CNavigatorDragAdapterAssistant"
|
||||||
viewerId="org.eclipse.ui.navigator.ProjectExplorer"/>
|
viewerId="org.eclipse.ui.navigator.ProjectExplorer"/>
|
||||||
</extension>
|
</extension>
|
||||||
|
|
||||||
<extension
|
<extension
|
||||||
point="org.eclipse.core.expressions.propertyTesters">
|
point="org.eclipse.core.expressions.propertyTesters">
|
||||||
<propertyTester
|
<propertyTester
|
||||||
|
@ -2182,5 +2209,4 @@
|
||||||
name="%Template.Wizard">
|
name="%Template.Wizard">
|
||||||
</wizard>
|
</wizard>
|
||||||
</extension>
|
</extension>
|
||||||
|
|
||||||
</plugin>
|
</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