1
0
Fork 0
mirror of https://github.com/eclipse-cdt/cdt synced 2025-07-23 17:05:26 +02:00

Define the open declaration action properly

This commit is contained in:
Alain Magloire 2004-09-07 19:29:33 +00:00
parent 373ace7ff4
commit 482188a798
5 changed files with 75 additions and 3 deletions

View file

@ -45,6 +45,9 @@ ViewMake.name=Make Targets
ActionSetMake.label=Make Actions
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.description= Makefile Source Actions
@ -54,6 +57,9 @@ ActionDefinition.comment.description= Turn the selected lines into # style comme
ActionDefinition.uncomment.name= Uncomment
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

View file

@ -225,7 +225,13 @@
</objectContribution>
</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
name="%CommandTargetBuild.name"
description="%CommandTargetBuild.description"
@ -268,6 +274,19 @@
command="org.eclipse.cdt.make.ui.edit.text.makefile.uncomment"
configuration="org.eclipse.ui.defaultAcceleratorConfiguration">
</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
point="org.eclipse.ui.preferencePages">

View file

@ -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 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$
}

View file

@ -25,7 +25,9 @@ import org.eclipse.jface.text.FindReplaceDocumentAdapter;
import org.eclipse.jface.text.IDocument;
import org.eclipse.jface.text.IRegion;
import org.eclipse.jface.text.ITextOperationTarget;
import org.eclipse.jface.text.ITextViewerExtension;
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.IVerticalRuler;
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() {
SourceViewerConfiguration configuration = getSourceViewerConfiguration();
if (configuration instanceof MakefileSourceConfiguration) {
@ -159,7 +188,7 @@ public class MakefileEditor extends TextEditor implements ISelectionChangedListe
}
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.
getSourceViewerDecorationSupport(viewer);

View file

@ -10,18 +10,22 @@
*******************************************************************************/
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.IMakefile;
import org.eclipse.cdt.make.internal.ui.MakeUIPlugin;
import org.eclipse.cdt.make.internal.ui.text.WordPartDetector;
import org.eclipse.cdt.make.ui.IWorkingCopyManager;
import org.eclipse.core.resources.IFile;
import org.eclipse.core.resources.IStorage;
import org.eclipse.core.runtime.IPath;
import org.eclipse.core.runtime.Path;
import org.eclipse.jface.text.IDocument;
import org.eclipse.jface.text.ITextSelection;
import org.eclipse.jface.viewers.ISelectionProvider;
import org.eclipse.ui.IEditorPart;
import org.eclipse.ui.IStorageEditorInput;
import org.eclipse.ui.IWorkbenchPage;
import org.eclipse.ui.PartInitException;
import org.eclipse.ui.ide.IDE;
@ -94,6 +98,20 @@ public class OpenDeclarationAction extends TextEditorAction {
}
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;
}