mirror of
https://github.com/eclipse-cdt/cdt
synced 2025-07-28 11:25:35 +02:00
Support for OpenDeclaration action on the MakefileEditor.
This commit is contained in:
parent
2a28b0cfa7
commit
fbb3c4c84d
17 changed files with 278 additions and 58 deletions
|
@ -36,5 +36,12 @@ public interface IDirective {
|
|||
*/
|
||||
int getEndLine();
|
||||
|
||||
/**
|
||||
* Returns the filename where the directive was found.
|
||||
*
|
||||
* @return String - filename
|
||||
*/
|
||||
String getFileName();
|
||||
|
||||
String toString();
|
||||
}
|
||||
|
|
|
@ -40,12 +40,27 @@ public interface IMakefile extends IParent {
|
|||
*/
|
||||
IRule[] getRules();
|
||||
|
||||
/**
|
||||
* Returns the IRule for target.
|
||||
*
|
||||
* @param target
|
||||
* @return
|
||||
*/
|
||||
IRule[] getRules(String target);
|
||||
|
||||
/**
|
||||
* Returns IInferenceRule
|
||||
* @return
|
||||
*/
|
||||
IInferenceRule[] getInferenceRules();
|
||||
|
||||
/**
|
||||
* Returns the IInferenceRules for target.
|
||||
* @param target
|
||||
* @return
|
||||
*/
|
||||
IInferenceRule[] getInferenceRules(String target);
|
||||
|
||||
/**
|
||||
* Returns ITargetRule
|
||||
* @return
|
||||
|
@ -53,11 +68,27 @@ public interface IMakefile extends IParent {
|
|||
ITargetRule[] getTargetRules();
|
||||
|
||||
/**
|
||||
* Return IMacroDefintion
|
||||
* Returns the ITargetRules for name.
|
||||
*
|
||||
* @param target
|
||||
* @return
|
||||
*/
|
||||
ITargetRule[] getTargetRules(String target);
|
||||
|
||||
/**
|
||||
* Return IMacroDefinition
|
||||
* @return
|
||||
*/
|
||||
IMacroDefinition[] getMacroDefinitions();
|
||||
|
||||
/**
|
||||
* Returns the IMacroDefinitions for name.
|
||||
*
|
||||
* @param name
|
||||
* @return
|
||||
*/
|
||||
IMacroDefinition[] getMacroDefinitions(String name);
|
||||
|
||||
/**
|
||||
* Return all the builtin directives.
|
||||
* @return
|
||||
|
@ -70,6 +101,14 @@ public interface IMakefile extends IParent {
|
|||
*/
|
||||
IMacroDefinition[] getBuiltinMacroDefinitions();
|
||||
|
||||
/**
|
||||
* Returns the Builtin macro definition for name.
|
||||
*
|
||||
* @param name
|
||||
* @return
|
||||
*/
|
||||
IMacroDefinition[] getBuiltinMacroDefinitions(String name);
|
||||
|
||||
/**
|
||||
* Returning after expanding any macros.
|
||||
* @return String - expanded line
|
||||
|
@ -86,8 +125,11 @@ public interface IMakefile extends IParent {
|
|||
|
||||
/**
|
||||
* Clear the all statements and (re)parse the Makefile
|
||||
*
|
||||
* @param name
|
||||
* @param makefile
|
||||
* @throws IOException
|
||||
*/
|
||||
void parse(Reader makefile) throws IOException;
|
||||
void parse(String name, Reader makefile) throws IOException;
|
||||
|
||||
}
|
||||
|
|
|
@ -55,7 +55,7 @@ public abstract class AbstractMakefile extends Parent implements IMakefile {
|
|||
return (IRule[]) array.toArray(new IRule[0]);
|
||||
}
|
||||
|
||||
public IRule[] getRule(String target) {
|
||||
public IRule[] getRules(String target) {
|
||||
IRule[] rules = getRules();
|
||||
List array = new ArrayList(rules.length);
|
||||
for (int i = 0; i < rules.length; i++) {
|
||||
|
@ -77,7 +77,7 @@ public abstract class AbstractMakefile extends Parent implements IMakefile {
|
|||
return (IInferenceRule[]) array.toArray(new IInferenceRule[0]);
|
||||
}
|
||||
|
||||
public IInferenceRule[] getInferenceRule(String target) {
|
||||
public IInferenceRule[] getInferenceRules(String target) {
|
||||
IInferenceRule[] irules = getInferenceRules();
|
||||
List array = new ArrayList(irules.length);
|
||||
for (int i = 0; i < irules.length; i++) {
|
||||
|
@ -99,7 +99,7 @@ public abstract class AbstractMakefile extends Parent implements IMakefile {
|
|||
return (ITargetRule[]) array.toArray(new ITargetRule[0]);
|
||||
}
|
||||
|
||||
public ITargetRule[] getTargetRule(String target) {
|
||||
public ITargetRule[] getTargetRules(String target) {
|
||||
ITargetRule[] trules = getTargetRules();
|
||||
List array = new ArrayList(trules.length);
|
||||
for (int i = 0; i < trules.length; i++) {
|
||||
|
@ -121,7 +121,7 @@ public abstract class AbstractMakefile extends Parent implements IMakefile {
|
|||
return (IMacroDefinition[]) array.toArray(new IMacroDefinition[0]);
|
||||
}
|
||||
|
||||
public IMacroDefinition[] getMacroDefinition(String name) {
|
||||
public IMacroDefinition[] getMacroDefinitions(String name) {
|
||||
IMacroDefinition[] variables = getMacroDefinitions();
|
||||
List array = new ArrayList(variables.length);
|
||||
for (int i = 0; i < variables.length; i++) {
|
||||
|
@ -143,7 +143,7 @@ public abstract class AbstractMakefile extends Parent implements IMakefile {
|
|||
return (IMacroDefinition[]) array.toArray(new IMacroDefinition[0]);
|
||||
}
|
||||
|
||||
public IMacroDefinition[] getBuiltinMacroDefinition(String name) {
|
||||
public IMacroDefinition[] getBuiltinMacroDefinitions(String name) {
|
||||
IMacroDefinition[] variables = getBuiltinMacroDefinitions();
|
||||
List array = new ArrayList(variables.length);
|
||||
for (int i = 0; i < variables.length; i++) {
|
||||
|
@ -165,7 +165,7 @@ public abstract class AbstractMakefile extends Parent implements IMakefile {
|
|||
return (IInferenceRule[]) array.toArray(new IInferenceRule[0]);
|
||||
}
|
||||
|
||||
public IInferenceRule[] getBuiltinInferenceRule(String target) {
|
||||
public IInferenceRule[] getBuiltinInferenceRules(String target) {
|
||||
IInferenceRule[] irules = getBuiltinInferenceRules();
|
||||
List array = new ArrayList(irules.length);
|
||||
for (int i = 0; i < irules.length; i++) {
|
||||
|
@ -211,9 +211,9 @@ public abstract class AbstractMakefile extends Parent implements IMakefile {
|
|||
if (inMacro) {
|
||||
String name = macroName.toString();
|
||||
if (name.length() > 0) {
|
||||
IMacroDefinition[] defs = getMacroDefinition(name);
|
||||
IMacroDefinition[] defs = getMacroDefinitions(name);
|
||||
if (defs.length == 0) {
|
||||
defs = getBuiltinMacroDefinition(name);
|
||||
defs = getBuiltinMacroDefinitions(name);
|
||||
}
|
||||
if (defs.length > 0) {
|
||||
String result = defs[0].getValue().toString();
|
||||
|
@ -236,9 +236,9 @@ public abstract class AbstractMakefile extends Parent implements IMakefile {
|
|||
macroName.append(c);
|
||||
} else if (foundDollar) {
|
||||
String name = String.valueOf(c);
|
||||
IMacroDefinition[] defs = getMacroDefinition(name);
|
||||
IMacroDefinition[] defs = getMacroDefinitions(name);
|
||||
if (defs.length == 0) {
|
||||
defs = getBuiltinMacroDefinition(name);
|
||||
defs = getBuiltinMacroDefinitions(name);
|
||||
}
|
||||
if (defs.length > 0) {
|
||||
String result = defs[0].getValue().toString();
|
||||
|
|
|
@ -16,6 +16,7 @@ public abstract class Directive implements IDirective {
|
|||
|
||||
int endLine;
|
||||
int startLine;
|
||||
String filename;
|
||||
Directive parent;
|
||||
|
||||
public Directive(Directive owner) {
|
||||
|
@ -49,6 +50,18 @@ public abstract class Directive implements IDirective {
|
|||
return parent;
|
||||
}
|
||||
|
||||
/* (non-Javadoc)
|
||||
* @see org.eclipse.cdt.make.core.makefile.IDirective#getFileName()
|
||||
*/
|
||||
public String getFileName() {
|
||||
if (filename == null) {
|
||||
if (parent != null) {
|
||||
filename = parent.getFileName();
|
||||
}
|
||||
}
|
||||
return filename;
|
||||
}
|
||||
|
||||
public void setParent(Directive owner) {
|
||||
parent = owner;
|
||||
}
|
||||
|
@ -66,4 +79,8 @@ public abstract class Directive implements IDirective {
|
|||
setEndLine(end);
|
||||
}
|
||||
|
||||
public void setFilename(String name) {
|
||||
filename = name;
|
||||
}
|
||||
|
||||
}
|
||||
|
|
|
@ -33,18 +33,18 @@ import org.eclipse.cdt.make.core.makefile.IDirective;
|
|||
|
||||
public class NullMakefile extends AbstractMakefile {
|
||||
|
||||
public static IDirective[] empty = new IDirective[0];
|
||||
public final static IDirective[] EMPTY_DIRECTIVES = new IDirective[0];
|
||||
|
||||
public NullMakefile() {
|
||||
super(null);
|
||||
}
|
||||
|
||||
public IDirective[] getDirectives() {
|
||||
return empty;
|
||||
return EMPTY_DIRECTIVES;
|
||||
}
|
||||
|
||||
public IDirective[] getBuiltins() {
|
||||
return empty;
|
||||
return EMPTY_DIRECTIVES;
|
||||
}
|
||||
|
||||
public void addDirective(IDirective directive) {
|
||||
|
@ -57,7 +57,7 @@ public class NullMakefile extends AbstractMakefile {
|
|||
/* (non-Javadoc)
|
||||
* @see org.eclipse.cdt.make.core.makefile.IMakefile#parse(java.io.Reader)
|
||||
*/
|
||||
public void parse(Reader makefile) throws IOException {
|
||||
public void parse(String name, Reader makefile) throws IOException {
|
||||
}
|
||||
|
||||
}
|
||||
|
|
|
@ -78,7 +78,7 @@ public class GNUMakefile extends AbstractMakefile implements IGNUMakefile {
|
|||
|
||||
public void parse(String name) throws IOException {
|
||||
FileReader stream = new FileReader(name);
|
||||
parse(stream);
|
||||
parse(name, stream);
|
||||
if (stream != null) {
|
||||
try {
|
||||
stream.close();
|
||||
|
@ -87,11 +87,11 @@ public class GNUMakefile extends AbstractMakefile implements IGNUMakefile {
|
|||
}
|
||||
}
|
||||
|
||||
public void parse(Reader reader) throws IOException {
|
||||
parse(new MakefileReader(reader));
|
||||
public void parse(String name, Reader reader) throws IOException {
|
||||
parse(name, new MakefileReader(reader));
|
||||
}
|
||||
|
||||
protected void parse(MakefileReader reader) throws IOException {
|
||||
protected void parse(String name, MakefileReader reader) throws IOException {
|
||||
String line;
|
||||
Rule[] rules = null;
|
||||
Stack conditions = new Stack();
|
||||
|
@ -102,6 +102,8 @@ public class GNUMakefile extends AbstractMakefile implements IGNUMakefile {
|
|||
// Clear any old directives.
|
||||
clearDirectives();
|
||||
|
||||
setFilename(name);
|
||||
|
||||
while ((line = reader.readLine()) != null) {
|
||||
startLine = endLine + 1;
|
||||
endLine = reader.getLineNumber();
|
||||
|
@ -767,7 +769,7 @@ public class GNUMakefile extends AbstractMakefile implements IGNUMakefile {
|
|||
try {
|
||||
InputStream stream = MakeCorePlugin.getDefault().openStream(new Path(location));
|
||||
GNUMakefile gnu = new GNUMakefile();
|
||||
gnu.parse(new InputStreamReader(stream));
|
||||
gnu.parse(location, new InputStreamReader(stream));
|
||||
builtins = gnu.getDirectives();
|
||||
for (int i = 0; i < builtins.length; i++) {
|
||||
if (builtins[i] instanceof MacroDefinition) {
|
||||
|
|
|
@ -91,7 +91,7 @@ public class GNUMakefileValidator implements IMakefileValidator {
|
|||
try {
|
||||
stream = file.getContents();
|
||||
Reader source = new InputStreamReader(stream);
|
||||
gnu.parse(source);
|
||||
gnu.parse(file.getFullPath().toString(), source);
|
||||
validateDirectives(file, gnu.getDirectives());
|
||||
} catch (CoreException e) {
|
||||
} catch (IOException e) {
|
||||
|
|
|
@ -70,7 +70,7 @@ public class PosixMakefile extends AbstractMakefile {
|
|||
|
||||
public void parse(String name) throws IOException {
|
||||
FileReader stream = new FileReader(name);
|
||||
parse(stream);
|
||||
parse(name, stream);
|
||||
if (stream != null) {
|
||||
try {
|
||||
stream.close();
|
||||
|
@ -79,15 +79,21 @@ public class PosixMakefile extends AbstractMakefile {
|
|||
}
|
||||
}
|
||||
|
||||
public void parse(Reader reader) throws IOException {
|
||||
parse(new MakefileReader(reader));
|
||||
public void parse(String name, Reader reader) throws IOException {
|
||||
parse(name, new MakefileReader(reader));
|
||||
}
|
||||
|
||||
protected void parse(MakefileReader reader) throws IOException {
|
||||
protected void parse(String name, MakefileReader reader) throws IOException {
|
||||
String line;
|
||||
Rule[] rules = null;
|
||||
int startLine = 0;
|
||||
int endLine = 0;
|
||||
|
||||
// Clear any old directives.
|
||||
clearDirectives();
|
||||
|
||||
setFilename(name);
|
||||
|
||||
while ((line = reader.readLine()) != null) {
|
||||
startLine = endLine + 1;
|
||||
endLine = reader.getLineNumber();
|
||||
|
@ -204,7 +210,7 @@ public class PosixMakefile extends AbstractMakefile {
|
|||
try {
|
||||
InputStream stream = MakeCorePlugin.getDefault().openStream(new Path(location));
|
||||
PosixMakefile gnu = new PosixMakefile();
|
||||
gnu.parse(new InputStreamReader(stream));
|
||||
gnu.parse(location, new InputStreamReader(stream));
|
||||
builtins = gnu.getDirectives();
|
||||
for (int i = 0; i < builtins.length; i++) {
|
||||
if (builtins[i] instanceof MacroDefinition) {
|
||||
|
|
|
@ -156,7 +156,7 @@ MakePreferencePage.description=Make Project Preferences
|
|||
MakeProjectPropertyPage.closedproject=Project Closed
|
||||
MakeProjectPropertyPage.internalError=An Internal error has occur please check error log.
|
||||
|
||||
# Makefile Editor messages
|
||||
#-------------- Makefile Editor messages
|
||||
ContentAssistProposal.label=Content Assist@Ctrl+SPACE
|
||||
ContentAssistProposal.tooltip=Content Assist
|
||||
ContentAssistProposal.image=
|
||||
|
@ -179,6 +179,10 @@ Uncomment.label=Uncommen&t
|
|||
Uncomment.tooltip=Uncomment the Selected # comment Lines
|
||||
Uncomment.description=Uncomment the selected # comment lines
|
||||
|
||||
OpenDeclarationAction.label=&Open Declaration@F3
|
||||
OpenDeclarationAction.description=Open an editor on the referenced element
|
||||
OpenDeclarationAction.tooltip=Open an editor on the referenced element
|
||||
|
||||
# ------- LexicalSortingAction------------
|
||||
|
||||
LexicalSortingAction.label=Sort
|
||||
|
|
|
@ -17,8 +17,10 @@ import org.eclipse.ui.texteditor.ITextEditorActionDefinitionIds;
|
|||
*/
|
||||
public interface IMakefileEditorActionDefinitionIds extends ITextEditorActionDefinitionIds {
|
||||
|
||||
String UNCOMMENT = "org.eclipse.cdt.make.ui.edit.text.makefile.comment"; //$NON-NLS-1$
|
||||
final String UNCOMMENT = "org.eclipse.cdt.make.ui.edit.text.makefile.comment"; //$NON-NLS-1$
|
||||
|
||||
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$
|
||||
|
||||
}
|
||||
|
|
|
@ -144,7 +144,7 @@ public class MakefileDocumentProvider extends FileDocumentProvider implements IM
|
|||
String content = document.get();
|
||||
StringReader reader = new StringReader(content);
|
||||
try {
|
||||
info.fCopy.parse(reader);
|
||||
info.fCopy.parse(info.fCopy.getFileName(), reader);
|
||||
} catch (IOException e) {
|
||||
}
|
||||
}
|
||||
|
|
|
@ -31,10 +31,13 @@ import org.eclipse.jface.viewers.ISelection;
|
|||
import org.eclipse.jface.viewers.ISelectionChangedListener;
|
||||
import org.eclipse.jface.viewers.IStructuredSelection;
|
||||
import org.eclipse.jface.viewers.SelectionChangedEvent;
|
||||
import org.eclipse.ui.IEditorInput;
|
||||
import org.eclipse.ui.IEditorSite;
|
||||
import org.eclipse.ui.IPartService;
|
||||
import org.eclipse.ui.IWorkbenchPart;
|
||||
import org.eclipse.ui.IWorkbenchWindow;
|
||||
import org.eclipse.ui.editors.text.TextEditor;
|
||||
import org.eclipse.ui.texteditor.AbstractTextEditor;
|
||||
import org.eclipse.ui.texteditor.DefaultRangeIndicator;
|
||||
import org.eclipse.ui.texteditor.ITextEditorActionConstants;
|
||||
import org.eclipse.ui.texteditor.ITextEditorActionDefinitionIds;
|
||||
|
@ -125,6 +128,11 @@ public class MakefileEditor extends TextEditor implements ISelectionChangedListe
|
|||
setAction("Uncomment", a); //$NON-NLS-1$
|
||||
markAsStateDependentAction("Uncomment", true); //$NON-NLS-1$
|
||||
|
||||
a = new OpenDeclarationAction(this);
|
||||
a.setActionDefinitionId(IMakefileEditorActionDefinitionIds.OPEN_DECLARATION);
|
||||
setAction("OpenDeclarationAction", a); //$NON-NLS-1$
|
||||
markAsStateDependentAction("OpenDeclarationAction", true); //$NON-NLS-1$
|
||||
|
||||
}
|
||||
|
||||
/* (non-Javadoc)
|
||||
|
@ -169,7 +177,7 @@ public class MakefileEditor extends TextEditor implements ISelectionChangedListe
|
|||
return fFindReplaceDocumentAdapter;
|
||||
}
|
||||
|
||||
private void setSelection(IDirective directive, boolean moveCursor) {
|
||||
public void setSelection(IDirective directive, boolean moveCursor) {
|
||||
int startLine = directive.getStartLine() - 1;
|
||||
int endLine = directive.getEndLine() - 1;
|
||||
try {
|
||||
|
@ -217,7 +225,7 @@ public class MakefileEditor extends TextEditor implements ISelectionChangedListe
|
|||
super.editorContextMenuAboutToShow(menu);
|
||||
addAction(menu, ITextEditorActionConstants.GROUP_EDIT, "Comment"); //$NON-NLS-1$
|
||||
addAction(menu, ITextEditorActionConstants.GROUP_EDIT, "Uncomment"); //$NON-NLS-1$
|
||||
|
||||
//addAction(menu, ITextEditorActionConstants.GROUP_EDIT, "OpenDeclarationAction"); //$NON-NLS-1$
|
||||
}
|
||||
|
||||
}
|
||||
|
|
|
@ -10,6 +10,8 @@
|
|||
***********************************************************************/
|
||||
package org.eclipse.cdt.make.internal.ui.editor;
|
||||
|
||||
import java.util.ResourceBundle;
|
||||
|
||||
import org.eclipse.cdt.make.internal.ui.MakeUIPlugin;
|
||||
import org.eclipse.jface.action.IMenuManager;
|
||||
import org.eclipse.jface.action.IToolBarManager;
|
||||
|
@ -27,6 +29,7 @@ import org.eclipse.ui.texteditor.RetargetTextEditorAction;
|
|||
public class MakefileEditorActionContributor extends BasicTextEditorActionContributor {
|
||||
|
||||
private MakefileEditorTogglePresentationAction fTogglePresentation;
|
||||
private OpenDeclarationAction fOpenDeclarationAction;
|
||||
protected RetargetTextEditorAction fContentAssistProposal;
|
||||
protected RetargetTextEditorAction fContentAssistTip;
|
||||
|
||||
|
@ -35,11 +38,14 @@ public class MakefileEditorActionContributor extends BasicTextEditorActionContri
|
|||
*/
|
||||
public MakefileEditorActionContributor() {
|
||||
super();
|
||||
fContentAssistProposal = new RetargetTextEditorAction(MakeUIPlugin.getDefault().getResourceBundle(), "ContentAssistProposal."); //$NON-NLS-1$
|
||||
ResourceBundle bundle = MakeUIPlugin.getDefault().getResourceBundle();
|
||||
fContentAssistProposal = new RetargetTextEditorAction(bundle, "ContentAssistProposal."); //$NON-NLS-1$
|
||||
fContentAssistProposal.setActionDefinitionId(ITextEditorActionDefinitionIds.CONTENT_ASSIST_PROPOSALS);
|
||||
fContentAssistTip = new RetargetTextEditorAction(MakeUIPlugin.getDefault().getResourceBundle(), "ContentAssistTip."); //$NON-NLS-1$
|
||||
fContentAssistTip = new RetargetTextEditorAction(bundle, "ContentAssistTip."); //$NON-NLS-1$
|
||||
fContentAssistTip.setActionDefinitionId(ITextEditorActionDefinitionIds.CONTENT_ASSIST_CONTEXT_INFORMATION);
|
||||
fTogglePresentation = new MakefileEditorTogglePresentationAction();
|
||||
fOpenDeclarationAction = new OpenDeclarationAction();
|
||||
|
||||
}
|
||||
|
||||
/**
|
||||
|
@ -63,6 +69,9 @@ public class MakefileEditorActionContributor extends BasicTextEditorActionContri
|
|||
|
||||
fTogglePresentation.setEditor(editor);
|
||||
fTogglePresentation.update();
|
||||
|
||||
fOpenDeclarationAction.setEditor(editor);
|
||||
fOpenDeclarationAction.update();
|
||||
}
|
||||
|
||||
/*
|
||||
|
@ -84,6 +93,7 @@ public class MakefileEditorActionContributor extends BasicTextEditorActionContri
|
|||
editMenu.add(new Separator());
|
||||
editMenu.add(fContentAssistProposal);
|
||||
editMenu.add(fContentAssistTip);
|
||||
editMenu.add(fOpenDeclarationAction);
|
||||
}
|
||||
|
||||
IToolBarManager toolBarManager = bars.getToolBarManager();
|
||||
|
|
|
@ -0,0 +1,112 @@
|
|||
/*******************************************************************************
|
||||
* Copyright (c) 2000, 2004 IBM Corporation and others.
|
||||
* All rights reserved. This program and the accompanying materials
|
||||
* are made available under the terms of the Common Public License v1.0
|
||||
* which accompanies this distribution, and is available at
|
||||
* http://www.eclipse.org/legal/cpl-v10.html
|
||||
*
|
||||
* Contributors:
|
||||
* IBM Corporation - initial API and implementation
|
||||
*******************************************************************************/
|
||||
package org.eclipse.cdt.make.internal.ui.editor;
|
||||
|
||||
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.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.jface.viewers.IStructuredSelection;
|
||||
import org.eclipse.jface.viewers.StructuredSelection;
|
||||
import org.eclipse.ui.IEditorPart;
|
||||
import org.eclipse.ui.IWorkbenchPage;
|
||||
import org.eclipse.ui.PartInitException;
|
||||
import org.eclipse.ui.ide.IDE;
|
||||
import org.eclipse.ui.texteditor.IDocumentProvider;
|
||||
import org.eclipse.ui.texteditor.ITextEditor;
|
||||
import org.eclipse.ui.texteditor.TextEditorAction;
|
||||
|
||||
public class OpenDeclarationAction extends TextEditorAction {
|
||||
|
||||
public OpenDeclarationAction() {
|
||||
this(null);
|
||||
}
|
||||
|
||||
public OpenDeclarationAction(ITextEditor editor) {
|
||||
super(MakeUIPlugin.getDefault().getResourceBundle(), "OpenDeclarationAction.", editor); //$NON-NLS-1$
|
||||
}
|
||||
|
||||
/*
|
||||
* (non-Javadoc)
|
||||
*
|
||||
* @see org.eclipse.jface.action.IAction#run()
|
||||
*/
|
||||
public void run() {
|
||||
ITextEditor editor = getTextEditor();
|
||||
if (editor == null) {
|
||||
return;
|
||||
}
|
||||
ISelectionProvider provider = editor.getSelectionProvider();
|
||||
if (provider == null) {
|
||||
return;
|
||||
}
|
||||
IDirective[] directives = null;
|
||||
IWorkingCopyManager fManager = MakeUIPlugin.getDefault().getWorkingCopyManager();
|
||||
IMakefile makefile = fManager.getWorkingCopy(editor.getEditorInput());
|
||||
if (makefile != null) {
|
||||
IDocumentProvider prov = editor.getDocumentProvider();
|
||||
IDocument doc = prov.getDocument(editor.getEditorInput());
|
||||
try {
|
||||
ITextSelection textSelection = (ITextSelection) provider.getSelection();
|
||||
int offset = textSelection.getOffset();
|
||||
WordPartDetector wordPart = new WordPartDetector(doc, textSelection.getOffset());
|
||||
String name = wordPart.toString();
|
||||
if (WordPartDetector.inMacro(doc, offset)) {
|
||||
directives = makefile.getMacroDefinitions(name);
|
||||
if (directives.length == 0) {
|
||||
directives = makefile.getBuiltinMacroDefinitions(name);
|
||||
}
|
||||
} else {
|
||||
directives = makefile.getTargetRules(name);
|
||||
}
|
||||
if (directives != null && directives.length > 0) {
|
||||
openInEditor(directives[0]);
|
||||
}
|
||||
} catch (Exception x) {
|
||||
//
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
private static IEditorPart openInEditor(IDirective directive) throws PartInitException {
|
||||
String filename = directive.getFileName();
|
||||
IPath path = new Path(filename);
|
||||
IFile file = MakeUIPlugin.getWorkspace().getRoot().getFileForLocation(path);
|
||||
if (file != null) {
|
||||
IWorkbenchPage p = MakeUIPlugin.getActivePage();
|
||||
if (p != null) {
|
||||
IEditorPart editorPart = IDE.openEditor(p, file, true);
|
||||
if (editorPart instanceof MakefileEditor) {
|
||||
IStructuredSelection selection = new StructuredSelection(directive);
|
||||
((MakefileEditor)editorPart).setSelection(directive, true);
|
||||
}
|
||||
return editorPart;
|
||||
}
|
||||
}
|
||||
return null;
|
||||
}
|
||||
|
||||
/*
|
||||
* (non-Javadoc)
|
||||
*
|
||||
* @see org.eclipse.jdt.ui.actions.SelectionDispatchAction#selectionChanged(org.eclipse.jface.text.ITextSelection)
|
||||
*/
|
||||
//public void selectionChanged(ITextSelection selection) {
|
||||
//setEnabled(fEditor != null);
|
||||
//}
|
||||
}
|
|
@ -24,17 +24,23 @@ public class WordPartDetector {
|
|||
int offset;
|
||||
|
||||
/**
|
||||
* Method WordPartDetector.
|
||||
* WordPartDetector.
|
||||
* @param viewer is a text viewer
|
||||
* @param documentOffset into the SQL document
|
||||
*/
|
||||
public WordPartDetector(ITextViewer viewer, int documentOffset) {
|
||||
this(viewer.getDocument(), documentOffset);
|
||||
}
|
||||
|
||||
/**
|
||||
*
|
||||
* @param doc
|
||||
* @param documentOffset
|
||||
*/
|
||||
public WordPartDetector(IDocument doc, int documentOffset) {
|
||||
offset = documentOffset - 1;
|
||||
int endOffset = documentOffset;
|
||||
try {
|
||||
IDocument doc = viewer.getDocument();
|
||||
//int bottom = viewer.getBottomIndexEndOffset();
|
||||
//int top = viewer.getTopIndexStartOffset();
|
||||
IRegion region = doc.getLineInformationOfOffset(documentOffset);
|
||||
int top = region.getOffset();
|
||||
int bottom = region.getLength() + top;
|
||||
|
@ -46,15 +52,18 @@ public class WordPartDetector {
|
|||
}
|
||||
//we've been one step too far : increase the offset
|
||||
offset++;
|
||||
wordPart = viewer.getDocument().get(offset, endOffset - offset);
|
||||
wordPart = doc.get(offset, endOffset - offset);
|
||||
} catch (BadLocationException e) {
|
||||
// do nothing
|
||||
}
|
||||
}
|
||||
|
||||
public static boolean inMacro(ITextViewer viewer, int offset) {
|
||||
return inMacro(viewer.getDocument(), offset);
|
||||
}
|
||||
|
||||
public static boolean inMacro(IDocument document, int offset) {
|
||||
boolean isMacro = false;
|
||||
IDocument document = viewer.getDocument();
|
||||
// Try to figure out if we are in a Macro.
|
||||
try {
|
||||
for (int index = offset - 1; index >= 0; index--) {
|
||||
|
|
|
@ -80,7 +80,7 @@ public class MakefileReconcilingStrategy implements IReconcilingStrategy {
|
|||
String content = fDocumentProvider.getDocument(fEditor.getEditorInput()).get();
|
||||
StringReader reader = new StringReader(content);
|
||||
try {
|
||||
makefile.parse(reader);
|
||||
makefile.parse(makefile.getFileName(), reader);
|
||||
} catch (IOException e) {
|
||||
}
|
||||
|
||||
|
|
|
@ -54,28 +54,29 @@ public class MakefileTextHover implements ITextHover {
|
|||
if (fEditor != null && len > -1) {
|
||||
IWorkingCopyManager fManager = MakeUIPlugin.getDefault().getWorkingCopyManager();
|
||||
IMakefile makefile = fManager.getWorkingCopy(fEditor.getEditorInput());
|
||||
IMacroDefinition[] statements;
|
||||
WordPartDetector wordPart = new WordPartDetector(textViewer, offset);
|
||||
String name = wordPart.toString();
|
||||
IMacroDefinition[] statements = null;
|
||||
if (WordPartDetector.inMacro(textViewer, offset)) {
|
||||
IMacroDefinition[] m1 = makefile.getMacroDefinitions();
|
||||
IMacroDefinition[] m2 = makefile.getBuiltinMacroDefinitions();
|
||||
statements = new IMacroDefinition[m1.length + m2.length];
|
||||
System.arraycopy(m1, 0, statements, 0, m1.length);
|
||||
System.arraycopy(m2, 0, statements, m1.length, m2.length);
|
||||
} else {
|
||||
statements = makefile.getMacroDefinitions(name);
|
||||
if (statements == null || statements.length == 0) {
|
||||
statements = makefile.getBuiltinMacroDefinitions(name);
|
||||
}
|
||||
}
|
||||
|
||||
if (statements == null) {
|
||||
statements = new IMacroDefinition[0];
|
||||
}
|
||||
// iterate over all the different categories
|
||||
WordPartDetector wordPart = new WordPartDetector(textViewer, offset);
|
||||
StringBuffer buffer = new StringBuffer();
|
||||
for (int i = 0; i < statements.length; i++) {
|
||||
String name = statements[i].getName();
|
||||
if (i > 0) {
|
||||
buffer.append("\n"); //$NON-NLS-1$
|
||||
}
|
||||
String infoString = statements[i].getValue().toString();
|
||||
if (name != null && name.equals(wordPart.toString())) {
|
||||
buffer.append(name);
|
||||
buffer.append(" - "); //$NON-NLS-1$
|
||||
buffer.append(infoString);
|
||||
break;
|
||||
}
|
||||
}
|
||||
return buffer.toString();
|
||||
}
|
||||
|
|
Loading…
Add table
Reference in a new issue