mirror of
https://github.com/eclipse-cdt/cdt
synced 2025-08-01 13:25:45 +02:00
Define the open declaration action properly
This commit is contained in:
parent
373ace7ff4
commit
482188a798
5 changed files with 75 additions and 3 deletions
|
@ -45,6 +45,9 @@ ViewMake.name=Make Targets
|
||||||
ActionSetMake.label=Make Actions
|
ActionSetMake.label=Make Actions
|
||||||
ActionSetUpdateMake.label=Update Make Projects
|
ActionSetUpdateMake.label=Update Make Projects
|
||||||
|
|
||||||
|
# Scope and Key Commands
|
||||||
|
scope.makefileEditor.name=Makefile Editor
|
||||||
|
makefileEditor.description=Editor for makefiles
|
||||||
|
|
||||||
category.source.name=Makefile Source
|
category.source.name=Makefile Source
|
||||||
category.source.description= Makefile Source Actions
|
category.source.description= Makefile Source Actions
|
||||||
|
@ -54,6 +57,9 @@ ActionDefinition.comment.description= Turn the selected lines into # style comme
|
||||||
|
|
||||||
ActionDefinition.uncomment.name= Uncomment
|
ActionDefinition.uncomment.name= Uncomment
|
||||||
ActionDefinition.uncomment.description= Uncomment the selected # style comment lines
|
ActionDefinition.uncomment.description= Uncomment the selected # style comment lines
|
||||||
|
|
||||||
|
ActionDefinition.opendecl.name= Open declation
|
||||||
|
ActionDefinition.opendecl.description=Follow to the directive definition
|
||||||
|
|
||||||
MakefileEditor.name=Makefile Editor
|
MakefileEditor.name=Makefile Editor
|
||||||
|
|
||||||
|
|
|
@ -225,7 +225,13 @@
|
||||||
</objectContribution>
|
</objectContribution>
|
||||||
</extension>
|
</extension>
|
||||||
<extension
|
<extension
|
||||||
point="org.eclipse.ui.commands">
|
point="org.eclipse.ui.commands">
|
||||||
|
<scope
|
||||||
|
name="%scope.makefileEditor.name"
|
||||||
|
parent="org.eclipse.ui.textEditorScope"
|
||||||
|
description="%makefileEditor.description"
|
||||||
|
id="org.eclipse.cdt.make.ui.makefileEditorScope">
|
||||||
|
</scope>
|
||||||
<command
|
<command
|
||||||
name="%CommandTargetBuild.name"
|
name="%CommandTargetBuild.name"
|
||||||
description="%CommandTargetBuild.description"
|
description="%CommandTargetBuild.description"
|
||||||
|
@ -268,6 +274,19 @@
|
||||||
command="org.eclipse.cdt.make.ui.edit.text.makefile.uncomment"
|
command="org.eclipse.cdt.make.ui.edit.text.makefile.uncomment"
|
||||||
configuration="org.eclipse.ui.defaultAcceleratorConfiguration">
|
configuration="org.eclipse.ui.defaultAcceleratorConfiguration">
|
||||||
</keyBinding>
|
</keyBinding>
|
||||||
|
<command
|
||||||
|
name="%ActionDefinition.opendecl.name"
|
||||||
|
category="org.eclipse.cdt.make.ui.category.source"
|
||||||
|
description="%ActionDefinition.opendecl.description"
|
||||||
|
id="org.eclipse.cdt.make.ui.edit.text.makefile.opendecl">
|
||||||
|
</command>
|
||||||
|
<keyBinding
|
||||||
|
string="F3"
|
||||||
|
scope="org.eclipse.cdt.make.ui.makefileEditorScope"
|
||||||
|
command="org.eclipse.cdt.make.ui.edit.text.makefile.opendecl"
|
||||||
|
configuration="org.eclipse.ui.defaultAcceleratorConfiguration">
|
||||||
|
</keyBinding>
|
||||||
|
|
||||||
</extension>
|
</extension>
|
||||||
<extension
|
<extension
|
||||||
point="org.eclipse.ui.preferencePages">
|
point="org.eclipse.ui.preferencePages">
|
||||||
|
|
|
@ -21,6 +21,6 @@ public interface IMakefileEditorActionDefinitionIds extends ITextEditorActionDef
|
||||||
|
|
||||||
final String COMMENT = "org.eclipse.cdt.make.ui.edit.text.makefile.uncomment"; //$NON-NLS-1$
|
final String COMMENT = "org.eclipse.cdt.make.ui.edit.text.makefile.uncomment"; //$NON-NLS-1$
|
||||||
|
|
||||||
final String OPEN_DECLARATION = "org.eclipse.cdt.make.ui.edit.text.makefile.open_declaration"; //$NON-NLS-1$
|
final String OPEN_DECLARATION = "org.eclipse.cdt.make.ui.edit.text.makefile.opendcl"; //$NON-NLS-1$
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
|
@ -25,7 +25,9 @@ import org.eclipse.jface.text.FindReplaceDocumentAdapter;
|
||||||
import org.eclipse.jface.text.IDocument;
|
import org.eclipse.jface.text.IDocument;
|
||||||
import org.eclipse.jface.text.IRegion;
|
import org.eclipse.jface.text.IRegion;
|
||||||
import org.eclipse.jface.text.ITextOperationTarget;
|
import org.eclipse.jface.text.ITextOperationTarget;
|
||||||
|
import org.eclipse.jface.text.ITextViewerExtension;
|
||||||
import org.eclipse.jface.text.rules.IWordDetector;
|
import org.eclipse.jface.text.rules.IWordDetector;
|
||||||
|
import org.eclipse.jface.text.source.IOverviewRuler;
|
||||||
import org.eclipse.jface.text.source.ISourceViewer;
|
import org.eclipse.jface.text.source.ISourceViewer;
|
||||||
import org.eclipse.jface.text.source.IVerticalRuler;
|
import org.eclipse.jface.text.source.IVerticalRuler;
|
||||||
import org.eclipse.jface.text.source.SourceViewerConfiguration;
|
import org.eclipse.jface.text.source.SourceViewerConfiguration;
|
||||||
|
@ -78,6 +80,33 @@ public class MakefileEditor extends TextEditor implements ISelectionChangedListe
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Adapted source viewer for CEditor
|
||||||
|
*/
|
||||||
|
|
||||||
|
public class AdaptedSourceViewer extends ProjectionViewer implements ITextViewerExtension {
|
||||||
|
|
||||||
|
|
||||||
|
public AdaptedSourceViewer(Composite parent, IVerticalRuler ruler,
|
||||||
|
IOverviewRuler overviewRuler, boolean showsAnnotation, int styles) {
|
||||||
|
super(parent, ruler, overviewRuler, showsAnnotation, styles);
|
||||||
|
}
|
||||||
|
|
||||||
|
/* (non-Javadoc)
|
||||||
|
* @see org.eclipse.jface.text.source.ISourceViewer#setRangeIndication(int, int, boolean)
|
||||||
|
*/
|
||||||
|
public void setRangeIndication(int offset, int length, boolean moveCursor) {
|
||||||
|
// Fixin a bug in the ProjectViewer implemenation
|
||||||
|
// PR: https://bugs.eclipse.org/bugs/show_bug.cgi?id=72914
|
||||||
|
if (isProjectionMode()) {
|
||||||
|
super.setRangeIndication(offset, length, moveCursor);
|
||||||
|
} else {
|
||||||
|
super.setRangeIndication(offset, length, false);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
MakefileSourceConfiguration getMakefileSourceConfiguration() {
|
MakefileSourceConfiguration getMakefileSourceConfiguration() {
|
||||||
SourceViewerConfiguration configuration = getSourceViewerConfiguration();
|
SourceViewerConfiguration configuration = getSourceViewerConfiguration();
|
||||||
if (configuration instanceof MakefileSourceConfiguration) {
|
if (configuration instanceof MakefileSourceConfiguration) {
|
||||||
|
@ -159,7 +188,7 @@ public class MakefileEditor extends TextEditor implements ISelectionChangedListe
|
||||||
}
|
}
|
||||||
|
|
||||||
protected ISourceViewer createSourceViewer(Composite parent, IVerticalRuler ruler, int styles) {
|
protected ISourceViewer createSourceViewer(Composite parent, IVerticalRuler ruler, int styles) {
|
||||||
ISourceViewer viewer = new ProjectionViewer(parent, ruler, getOverviewRuler(), isOverviewRulerVisible(), styles);
|
ISourceViewer viewer = new AdaptedSourceViewer(parent, ruler, getOverviewRuler(), isOverviewRulerVisible(), styles);
|
||||||
|
|
||||||
// ensure decoration support has been created and configured.
|
// ensure decoration support has been created and configured.
|
||||||
getSourceViewerDecorationSupport(viewer);
|
getSourceViewerDecorationSupport(viewer);
|
||||||
|
|
|
@ -10,18 +10,22 @@
|
||||||
*******************************************************************************/
|
*******************************************************************************/
|
||||||
package org.eclipse.cdt.make.internal.ui.editor;
|
package org.eclipse.cdt.make.internal.ui.editor;
|
||||||
|
|
||||||
|
import org.eclipse.cdt.core.resources.FileStorage;
|
||||||
|
import org.eclipse.cdt.internal.ui.util.ExternalEditorInput;
|
||||||
import org.eclipse.cdt.make.core.makefile.IDirective;
|
import org.eclipse.cdt.make.core.makefile.IDirective;
|
||||||
import org.eclipse.cdt.make.core.makefile.IMakefile;
|
import org.eclipse.cdt.make.core.makefile.IMakefile;
|
||||||
import org.eclipse.cdt.make.internal.ui.MakeUIPlugin;
|
import org.eclipse.cdt.make.internal.ui.MakeUIPlugin;
|
||||||
import org.eclipse.cdt.make.internal.ui.text.WordPartDetector;
|
import org.eclipse.cdt.make.internal.ui.text.WordPartDetector;
|
||||||
import org.eclipse.cdt.make.ui.IWorkingCopyManager;
|
import org.eclipse.cdt.make.ui.IWorkingCopyManager;
|
||||||
import org.eclipse.core.resources.IFile;
|
import org.eclipse.core.resources.IFile;
|
||||||
|
import org.eclipse.core.resources.IStorage;
|
||||||
import org.eclipse.core.runtime.IPath;
|
import org.eclipse.core.runtime.IPath;
|
||||||
import org.eclipse.core.runtime.Path;
|
import org.eclipse.core.runtime.Path;
|
||||||
import org.eclipse.jface.text.IDocument;
|
import org.eclipse.jface.text.IDocument;
|
||||||
import org.eclipse.jface.text.ITextSelection;
|
import org.eclipse.jface.text.ITextSelection;
|
||||||
import org.eclipse.jface.viewers.ISelectionProvider;
|
import org.eclipse.jface.viewers.ISelectionProvider;
|
||||||
import org.eclipse.ui.IEditorPart;
|
import org.eclipse.ui.IEditorPart;
|
||||||
|
import org.eclipse.ui.IStorageEditorInput;
|
||||||
import org.eclipse.ui.IWorkbenchPage;
|
import org.eclipse.ui.IWorkbenchPage;
|
||||||
import org.eclipse.ui.PartInitException;
|
import org.eclipse.ui.PartInitException;
|
||||||
import org.eclipse.ui.ide.IDE;
|
import org.eclipse.ui.ide.IDE;
|
||||||
|
@ -94,6 +98,20 @@ public class OpenDeclarationAction extends TextEditorAction {
|
||||||
}
|
}
|
||||||
return editorPart;
|
return editorPart;
|
||||||
}
|
}
|
||||||
|
} else {
|
||||||
|
// External file
|
||||||
|
IStorage storage = new FileStorage(path);
|
||||||
|
IStorageEditorInput input = new ExternalEditorInput(storage);
|
||||||
|
IWorkbenchPage p = MakeUIPlugin.getActivePage();
|
||||||
|
if (p != null) {
|
||||||
|
String editorID = "org.eclipse.cdt.make.editor"; //$NON-NLS-1$
|
||||||
|
IEditorPart editorPart = IDE.openEditor(p, input, editorID, true);
|
||||||
|
if (editorPart instanceof MakefileEditor) {
|
||||||
|
((MakefileEditor)editorPart).setSelection(directive, true);
|
||||||
|
}
|
||||||
|
return editorPart;
|
||||||
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
return null;
|
return null;
|
||||||
}
|
}
|
||||||
|
|
Loading…
Add table
Reference in a new issue