mirror of
https://github.com/eclipse-cdt/cdt
synced 2025-08-11 18:25:40 +02:00
Work on code completion and hover.
This commit is contained in:
parent
b618113882
commit
e6e17610e5
16 changed files with 449 additions and 71 deletions
|
@ -67,3 +67,19 @@ BuildPropertyCommon.label.addVar=Add
|
||||||
BuildPropertyCommon.label.message=Value:
|
BuildPropertyCommon.label.message=Value:
|
||||||
BuildPropertyCommon.label.browse=Browse...
|
BuildPropertyCommon.label.browse=Browse...
|
||||||
BuildPropertyCommon.label.configs=Defined configurations:
|
BuildPropertyCommon.label.configs=Defined configurations:
|
||||||
|
|
||||||
|
# Makefile Editor messages
|
||||||
|
ContentAssistProposal.label=Content Assist@Ctrl+SPACE
|
||||||
|
ContentAssistProposal.tooltip=Content Assist
|
||||||
|
ContentAssistProposal.image=
|
||||||
|
ContentAssistProposal.description=Content Assist
|
||||||
|
|
||||||
|
ContentAssistTip.label=Content Tip@Ctrl+SHIFT+SPACE
|
||||||
|
ContentAssistTip.tooltip=Content Tip
|
||||||
|
ContentAssistTip.image=
|
||||||
|
ContentAssistTip.description=Content Tip
|
||||||
|
|
||||||
|
TogglePresentation.label=Change Presentation
|
||||||
|
TogglePresentation.tooltip=Enable/Disable Segmented Source Viewer
|
||||||
|
TogglePresentation.description=Enable/Disable Segmented Source Viewer
|
||||||
|
|
||||||
|
|
|
@ -10,9 +10,6 @@
|
||||||
***********************************************************************/
|
***********************************************************************/
|
||||||
package org.eclipse.cdt.make.internal.ui.editor;
|
package org.eclipse.cdt.make.internal.ui.editor;
|
||||||
|
|
||||||
import java.io.IOException;
|
|
||||||
import java.io.Reader;
|
|
||||||
import java.io.StringReader;
|
|
||||||
import java.util.ArrayList;
|
import java.util.ArrayList;
|
||||||
import java.util.Arrays;
|
import java.util.Arrays;
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
|
@ -23,7 +20,7 @@ import org.eclipse.cdt.make.core.makefile.IMakefile;
|
||||||
import org.eclipse.cdt.make.core.makefile.IRule;
|
import org.eclipse.cdt.make.core.makefile.IRule;
|
||||||
import org.eclipse.cdt.make.core.makefile.IStatement;
|
import org.eclipse.cdt.make.core.makefile.IStatement;
|
||||||
import org.eclipse.cdt.make.core.makefile.ITargetRule;
|
import org.eclipse.cdt.make.core.makefile.ITargetRule;
|
||||||
import org.eclipse.cdt.make.internal.core.makefile.posix.PosixMakefile;
|
import org.eclipse.cdt.make.internal.core.makefile.NullMakefile;
|
||||||
import org.eclipse.cdt.make.internal.ui.MakeUIImages;
|
import org.eclipse.cdt.make.internal.ui.MakeUIImages;
|
||||||
import org.eclipse.jface.text.BadLocationException;
|
import org.eclipse.jface.text.BadLocationException;
|
||||||
import org.eclipse.jface.text.IDocument;
|
import org.eclipse.jface.text.IDocument;
|
||||||
|
@ -54,6 +51,7 @@ public class MakefileContentOutlinePage extends ContentOutlinePage implements IC
|
||||||
protected boolean showInferenceRule = true;
|
protected boolean showInferenceRule = true;
|
||||||
|
|
||||||
protected IMakefile makefile;
|
protected IMakefile makefile;
|
||||||
|
protected IMakefile nullMakefile = new NullMakefile();
|
||||||
|
|
||||||
/* (non-Javadoc)
|
/* (non-Javadoc)
|
||||||
* @see org.eclipse.jface.viewers.ITreeContentProvider#getChildren(java.lang.Object)
|
* @see org.eclipse.jface.viewers.ITreeContentProvider#getChildren(java.lang.Object)
|
||||||
|
@ -109,21 +107,12 @@ public class MakefileContentOutlinePage extends ContentOutlinePage implements IC
|
||||||
*/
|
*/
|
||||||
public void inputChanged(Viewer viewer, Object oldInput, Object newInput) {
|
public void inputChanged(Viewer viewer, Object oldInput, Object newInput) {
|
||||||
if (oldInput != null) {
|
if (oldInput != null) {
|
||||||
//IDocument document= fDocumentProvider.getDocument(oldInput);
|
makefile = nullMakefile;
|
||||||
//if (document != null) {
|
|
||||||
//}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
if (newInput != null) {
|
if (newInput != null) {
|
||||||
IDocument document= fDocumentProvider.getDocument(newInput);
|
IDocument document= fDocumentProvider.getDocument(newInput);
|
||||||
if (document != null) {
|
makefile = fEditor.getMakefile(document);
|
||||||
try {
|
|
||||||
String content = document.get();
|
|
||||||
Reader r = new StringReader(content);
|
|
||||||
makefile = new PosixMakefile(r);
|
|
||||||
} catch (IOException e) {
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -10,6 +10,7 @@
|
||||||
***********************************************************************/
|
***********************************************************************/
|
||||||
package org.eclipse.cdt.make.internal.ui.editor;
|
package org.eclipse.cdt.make.internal.ui.editor;
|
||||||
|
|
||||||
|
import org.eclipse.cdt.make.internal.ui.text.makefile.MakefilePartitionScanner;
|
||||||
import org.eclipse.core.runtime.CoreException;
|
import org.eclipse.core.runtime.CoreException;
|
||||||
import org.eclipse.jface.text.IDocument;
|
import org.eclipse.jface.text.IDocument;
|
||||||
import org.eclipse.jface.text.IDocumentPartitioner;
|
import org.eclipse.jface.text.IDocumentPartitioner;
|
||||||
|
|
|
@ -10,9 +10,24 @@
|
||||||
***********************************************************************/
|
***********************************************************************/
|
||||||
package org.eclipse.cdt.make.internal.ui.editor;
|
package org.eclipse.cdt.make.internal.ui.editor;
|
||||||
|
|
||||||
|
import java.io.IOException;
|
||||||
|
import java.io.Reader;
|
||||||
|
import java.io.StringReader;
|
||||||
|
import java.util.ResourceBundle;
|
||||||
|
|
||||||
|
import org.eclipse.cdt.make.core.makefile.IMakefile;
|
||||||
|
import org.eclipse.cdt.make.internal.core.makefile.NullMakefile;
|
||||||
|
import org.eclipse.cdt.make.internal.core.makefile.posix.PosixMakefile;
|
||||||
|
import org.eclipse.cdt.make.internal.ui.MakeUIPlugin;
|
||||||
|
import org.eclipse.cdt.make.internal.ui.text.MakefileColorManager;
|
||||||
import org.eclipse.core.runtime.IProgressMonitor;
|
import org.eclipse.core.runtime.IProgressMonitor;
|
||||||
|
import org.eclipse.jface.action.IAction;
|
||||||
|
import org.eclipse.jface.text.IDocument;
|
||||||
|
import org.eclipse.jface.text.source.ISourceViewer;
|
||||||
import org.eclipse.ui.editors.text.TextEditor;
|
import org.eclipse.ui.editors.text.TextEditor;
|
||||||
import org.eclipse.ui.texteditor.DefaultRangeIndicator;
|
import org.eclipse.ui.texteditor.DefaultRangeIndicator;
|
||||||
|
import org.eclipse.ui.texteditor.ITextEditorActionDefinitionIds;
|
||||||
|
import org.eclipse.ui.texteditor.TextOperationAction;
|
||||||
import org.eclipse.ui.views.contentoutline.IContentOutlinePage;
|
import org.eclipse.ui.views.contentoutline.IContentOutlinePage;
|
||||||
|
|
||||||
public class MakefileEditor extends TextEditor {
|
public class MakefileEditor extends TextEditor {
|
||||||
|
@ -25,8 +40,35 @@ public class MakefileEditor extends TextEditor {
|
||||||
* The page that shows the outline.
|
* The page that shows the outline.
|
||||||
*/
|
*/
|
||||||
protected MakefileContentOutlinePage page;
|
protected MakefileContentOutlinePage page;
|
||||||
|
protected IMakefile makefile;
|
||||||
|
|
||||||
|
private MakefileContentOutlinePage getOutlinePage() {
|
||||||
|
if (page == null) {
|
||||||
|
page = new MakefileContentOutlinePage(getDocumentProvider(), this);
|
||||||
|
page.setInput(getEditorInput());
|
||||||
|
}
|
||||||
|
return page;
|
||||||
|
}
|
||||||
|
|
||||||
|
public IMakefile getMakefile() {
|
||||||
|
IDocument document = getDocumentProvider().getDocument(getEditorInput());
|
||||||
|
return getMakefile(document);
|
||||||
|
}
|
||||||
|
|
||||||
|
public IMakefile getMakefile(IDocument document) {
|
||||||
|
if (document != null) {
|
||||||
|
if (makefile == null || isDirty()) {
|
||||||
|
try {
|
||||||
|
String content = document.get();
|
||||||
|
Reader r = new StringReader(content);
|
||||||
|
makefile = new PosixMakefile(r);
|
||||||
|
} catch (IOException e) {
|
||||||
|
makefile = new NullMakefile();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return makefile;
|
||||||
|
}
|
||||||
|
|
||||||
public MakefileEditor() {
|
public MakefileEditor() {
|
||||||
super();
|
super();
|
||||||
|
@ -38,7 +80,7 @@ public class MakefileEditor extends TextEditor {
|
||||||
*/
|
*/
|
||||||
protected void initializeEditor() {
|
protected void initializeEditor() {
|
||||||
|
|
||||||
setSourceViewerConfiguration(new MakefileEditorConfiguration(new MakefileColorManager()));
|
setSourceViewerConfiguration(new MakefileSourceConfiguration(new MakefileColorManager(), this));
|
||||||
setRangeIndicator(new DefaultRangeIndicator());
|
setRangeIndicator(new DefaultRangeIndicator());
|
||||||
setEditorContextMenuId("#MakefileEditorContext"); //$NON-NLS-1$
|
setEditorContextMenuId("#MakefileEditorContext"); //$NON-NLS-1$
|
||||||
setRulerContextMenuId("#MakefileRulerContext"); //$NON-NLS-1$
|
setRulerContextMenuId("#MakefileRulerContext"); //$NON-NLS-1$
|
||||||
|
@ -55,15 +97,6 @@ public class MakefileEditor extends TextEditor {
|
||||||
return super.getAdapter(key);
|
return super.getAdapter(key);
|
||||||
}
|
}
|
||||||
|
|
||||||
private MakefileContentOutlinePage getOutlinePage() {
|
|
||||||
if (page == null) {
|
|
||||||
page= new MakefileContentOutlinePage(getDocumentProvider(), this);
|
|
||||||
//page.addPostSelectionChangedListener(selectionChangedListener);
|
|
||||||
page.setInput(getEditorInput());
|
|
||||||
}
|
|
||||||
return page;
|
|
||||||
}
|
|
||||||
|
|
||||||
/* (non-Javadoc)
|
/* (non-Javadoc)
|
||||||
* @see org.eclipse.ui.ISaveablePart#doSave(org.eclipse.core.runtime.IProgressMonitor)
|
* @see org.eclipse.ui.ISaveablePart#doSave(org.eclipse.core.runtime.IProgressMonitor)
|
||||||
*/
|
*/
|
||||||
|
@ -74,4 +107,24 @@ public class MakefileEditor extends TextEditor {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Method to install the editor actions.
|
||||||
|
*
|
||||||
|
* @see org.eclipse.ui.texteditor.AbstractTextEditor#createActions()
|
||||||
|
*/
|
||||||
|
protected void createActions() {
|
||||||
|
super.createActions();
|
||||||
|
|
||||||
|
ResourceBundle bundle = MakeUIPlugin.getDefault().getResourceBundle();
|
||||||
|
|
||||||
|
IAction a = new TextOperationAction(bundle, "ContentAssistProposal.", this, ISourceViewer.CONTENTASSIST_PROPOSALS); //$NON-NLS-1$
|
||||||
|
a.setActionDefinitionId(ITextEditorActionDefinitionIds.CONTENT_ASSIST_PROPOSALS);
|
||||||
|
setAction("ContentAssistProposal", a); //$NON-NLS-1$
|
||||||
|
|
||||||
|
a = new TextOperationAction(bundle, "ContentAssistTip.", this, ISourceViewer.CONTENTASSIST_CONTEXT_INFORMATION); //$NON-NLS-1$
|
||||||
|
a.setActionDefinitionId(ITextEditorActionDefinitionIds.CONTENT_ASSIST_CONTEXT_INFORMATION);
|
||||||
|
setAction("ContentAssistTip", a); //$NON-NLS-1$
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
|
@ -10,24 +10,36 @@
|
||||||
***********************************************************************/
|
***********************************************************************/
|
||||||
package org.eclipse.cdt.make.internal.ui.editor;
|
package org.eclipse.cdt.make.internal.ui.editor;
|
||||||
|
|
||||||
|
import org.eclipse.cdt.make.internal.ui.MakeUIPlugin;
|
||||||
|
import org.eclipse.jface.action.IMenuManager;
|
||||||
import org.eclipse.jface.action.IToolBarManager;
|
import org.eclipse.jface.action.IToolBarManager;
|
||||||
|
import org.eclipse.jface.action.Separator;
|
||||||
import org.eclipse.ui.IActionBars;
|
import org.eclipse.ui.IActionBars;
|
||||||
import org.eclipse.ui.IEditorPart;
|
import org.eclipse.ui.IEditorPart;
|
||||||
|
import org.eclipse.ui.IWorkbenchActionConstants;
|
||||||
import org.eclipse.ui.texteditor.BasicTextEditorActionContributor;
|
import org.eclipse.ui.texteditor.BasicTextEditorActionContributor;
|
||||||
import org.eclipse.ui.texteditor.ITextEditor;
|
import org.eclipse.ui.texteditor.ITextEditor;
|
||||||
|
import org.eclipse.ui.texteditor.ITextEditorActionDefinitionIds;
|
||||||
|
import org.eclipse.ui.texteditor.RetargetTextEditorAction;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
*/
|
*/
|
||||||
public class MakefileEditorActionContributor extends BasicTextEditorActionContributor {
|
public class MakefileEditorActionContributor extends BasicTextEditorActionContributor {
|
||||||
private MakefileEditorTogglePresentationAction togglePresentationAction;
|
|
||||||
private static final String TOGGLE_PRESENTATION = "makefile_toggle_presentation"; //$NON-NLS-1$
|
private MakefileEditorTogglePresentationAction fTogglePresentation;
|
||||||
|
protected RetargetTextEditorAction fContentAssistProposal;
|
||||||
|
protected RetargetTextEditorAction fContentAssistTip;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Constructor for MakefileEditorActionContributor.
|
* Constructor for MakefileEditorActionContributor.
|
||||||
*/
|
*/
|
||||||
public MakefileEditorActionContributor() {
|
public MakefileEditorActionContributor() {
|
||||||
super();
|
super();
|
||||||
togglePresentationAction = new MakefileEditorTogglePresentationAction();
|
fContentAssistProposal = new RetargetTextEditorAction(MakeUIPlugin.getDefault().getResourceBundle(), "ContentAssistProposal."); //$NON-NLS-1$
|
||||||
|
fContentAssistProposal.setActionDefinitionId(ITextEditorActionDefinitionIds.CONTENT_ASSIST_PROPOSALS);
|
||||||
|
fContentAssistTip = new RetargetTextEditorAction(MakeUIPlugin.getDefault().getResourceBundle(), "ContentAssistTip."); //$NON-NLS-1$
|
||||||
|
fContentAssistTip.setActionDefinitionId(ITextEditorActionDefinitionIds.CONTENT_ASSIST_CONTEXT_INFORMATION);
|
||||||
|
fTogglePresentation = new MakefileEditorTogglePresentationAction();
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
@ -35,11 +47,30 @@ public class MakefileEditorActionContributor extends BasicTextEditorActionContri
|
||||||
*/
|
*/
|
||||||
public void setActiveEditor(IEditorPart targetEditor) {
|
public void setActiveEditor(IEditorPart targetEditor) {
|
||||||
super.setActiveEditor(targetEditor);
|
super.setActiveEditor(targetEditor);
|
||||||
ITextEditor textEditor = null;
|
doSetActiveEditor(targetEditor);
|
||||||
if (targetEditor instanceof ITextEditor)
|
}
|
||||||
textEditor = (ITextEditor) targetEditor;
|
|
||||||
|
|
||||||
togglePresentationAction.setEditor(textEditor);
|
private void doSetActiveEditor(IEditorPart part) {
|
||||||
|
super.setActiveEditor(part);
|
||||||
|
|
||||||
|
ITextEditor editor = null;
|
||||||
|
if (part instanceof ITextEditor) {
|
||||||
|
editor = (ITextEditor) part;
|
||||||
|
}
|
||||||
|
|
||||||
|
fContentAssistProposal.setAction(getAction(editor, "ContentAssistProposal")); //$NON-NLS-1$
|
||||||
|
fContentAssistTip.setAction(getAction(editor, "ContentAssistTip")); //$NON-NLS-1$
|
||||||
|
|
||||||
|
fTogglePresentation.setEditor(editor);
|
||||||
|
fTogglePresentation.update();
|
||||||
|
}
|
||||||
|
|
||||||
|
/*
|
||||||
|
* @see IEditorActionBarContributor#dispose()
|
||||||
|
*/
|
||||||
|
public void dispose() {
|
||||||
|
doSetActiveEditor(null);
|
||||||
|
super.dispose();
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
@ -47,15 +78,19 @@ public class MakefileEditorActionContributor extends BasicTextEditorActionContri
|
||||||
*/
|
*/
|
||||||
public void init(IActionBars bars) {
|
public void init(IActionBars bars) {
|
||||||
super.init(bars);
|
super.init(bars);
|
||||||
bars.setGlobalActionHandler(TOGGLE_PRESENTATION, togglePresentationAction);
|
IMenuManager menuManager = bars.getMenuManager();
|
||||||
|
IMenuManager editMenu = menuManager.findMenuUsingPath(IWorkbenchActionConstants.M_EDIT);
|
||||||
|
if (editMenu != null) {
|
||||||
|
editMenu.add(new Separator());
|
||||||
|
editMenu.add(fContentAssistProposal);
|
||||||
|
editMenu.add(fContentAssistTip);
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
IToolBarManager toolBarManager = bars.getToolBarManager();
|
||||||
* @see org.eclipse.ui.part.EditorActionBarContributor#contributeToToolBar(IToolBarManager)
|
if (toolBarManager != null) {
|
||||||
*/
|
toolBarManager.add(new Separator());
|
||||||
public void contributeToToolBar(IToolBarManager toolBarManager) {
|
toolBarManager.add(fTogglePresentation);
|
||||||
super.contributeToToolBar(toolBarManager);
|
}
|
||||||
toolBarManager.add(togglePresentationAction);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
|
@ -19,18 +19,11 @@ import org.eclipse.ui.texteditor.TextEditorAction;
|
||||||
*/
|
*/
|
||||||
public class MakefileEditorTogglePresentationAction extends TextEditorAction {
|
public class MakefileEditorTogglePresentationAction extends TextEditorAction {
|
||||||
|
|
||||||
private final static String ACTION_ID = "org.eclipse.cdt.make.ui.MakefileEditorTogglePresentationAction"; //$NON-NLS-1$
|
|
||||||
/**
|
/**
|
||||||
* Constructor for MakefileEditorTogglePresentationAction.
|
* Constructor for MakefileEditorTogglePresentationAction.
|
||||||
* @param bundle
|
|
||||||
* @param prefix
|
|
||||||
* @param editor
|
|
||||||
*/
|
*/
|
||||||
public MakefileEditorTogglePresentationAction() {
|
public MakefileEditorTogglePresentationAction() {
|
||||||
super(MakeUIPlugin.getDefault().getResourceBundle(), "MakefileEditorTogglePresentationAction.", null); //$NON-NLS-1$
|
super(MakeUIPlugin.getDefault().getResourceBundle(), "MakefileEditorTogglePresentation.", null); //$NON-NLS-1$
|
||||||
|
|
||||||
setToolTipText("MakefileEditorTogglePresentationAction.tooltip"); //$NON-NLS-1$
|
|
||||||
setActionDefinitionId(ACTION_ID);
|
|
||||||
MakeUIImages.setImageDescriptors(this, MakeUIImages.T_TOOL, MakeUIImages.IMG_TOOLS_MAKEFILE_SEGMENT_EDIT);
|
MakeUIImages.setImageDescriptors(this, MakeUIImages.T_TOOL, MakeUIImages.IMG_TOOLS_MAKEFILE_SEGMENT_EDIT);
|
||||||
update();
|
update();
|
||||||
}
|
}
|
||||||
|
@ -50,16 +43,8 @@ public class MakefileEditorTogglePresentationAction extends TextEditorAction {
|
||||||
* @see org.eclipse.ui.texteditor.IUpdate#update()
|
* @see org.eclipse.ui.texteditor.IUpdate#update()
|
||||||
*/
|
*/
|
||||||
public void update() {
|
public void update() {
|
||||||
setChecked(isChecked());
|
setChecked(getTextEditor() != null && getTextEditor().showsHighlightRangeOnly());
|
||||||
setEnabled(isEnabled());
|
setEnabled(true);
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* @see org.eclipse.ui.texteditor.TextEditorAction#setEditor(ITextEditor)
|
|
||||||
*/
|
|
||||||
public void setEditor(ITextEditor editor) {
|
|
||||||
super.setEditor(editor);
|
|
||||||
update();
|
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
|
@ -10,8 +10,15 @@
|
||||||
***********************************************************************/
|
***********************************************************************/
|
||||||
package org.eclipse.cdt.make.internal.ui.editor;
|
package org.eclipse.cdt.make.internal.ui.editor;
|
||||||
|
|
||||||
|
import org.eclipse.cdt.make.internal.ui.text.IMakefileColorManager;
|
||||||
|
import org.eclipse.cdt.make.internal.ui.text.MakefileColorManager;
|
||||||
|
import org.eclipse.cdt.make.internal.ui.text.makefile.MakefileCodeScanner;
|
||||||
|
import org.eclipse.cdt.make.internal.ui.text.makefile.MakefileCompletionProcessor;
|
||||||
|
import org.eclipse.cdt.make.internal.ui.text.makefile.MakefilePartitionScanner;
|
||||||
import org.eclipse.jface.text.IDocument;
|
import org.eclipse.jface.text.IDocument;
|
||||||
import org.eclipse.jface.text.TextAttribute;
|
import org.eclipse.jface.text.TextAttribute;
|
||||||
|
import org.eclipse.jface.text.contentassist.ContentAssistant;
|
||||||
|
import org.eclipse.jface.text.contentassist.IContentAssistant;
|
||||||
import org.eclipse.jface.text.presentation.IPresentationReconciler;
|
import org.eclipse.jface.text.presentation.IPresentationReconciler;
|
||||||
import org.eclipse.jface.text.presentation.PresentationReconciler;
|
import org.eclipse.jface.text.presentation.PresentationReconciler;
|
||||||
import org.eclipse.jface.text.rules.BufferedRuleBasedScanner;
|
import org.eclipse.jface.text.rules.BufferedRuleBasedScanner;
|
||||||
|
@ -19,11 +26,13 @@ import org.eclipse.jface.text.rules.DefaultDamagerRepairer;
|
||||||
import org.eclipse.jface.text.rules.Token;
|
import org.eclipse.jface.text.rules.Token;
|
||||||
import org.eclipse.jface.text.source.ISourceViewer;
|
import org.eclipse.jface.text.source.ISourceViewer;
|
||||||
import org.eclipse.jface.text.source.SourceViewerConfiguration;
|
import org.eclipse.jface.text.source.SourceViewerConfiguration;
|
||||||
|
import org.eclipse.swt.graphics.RGB;
|
||||||
|
|
||||||
public class MakefileEditorConfiguration extends SourceViewerConfiguration {
|
public class MakefileSourceConfiguration extends SourceViewerConfiguration {
|
||||||
|
|
||||||
private IMakefileColorManager colorManager = null;
|
private IMakefileColorManager colorManager;
|
||||||
private MakefileCodeScanner codeScanner = null;
|
private MakefileCodeScanner codeScanner;
|
||||||
|
private MakefileEditor fEditor;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Single token scanner.
|
* Single token scanner.
|
||||||
|
@ -37,8 +46,9 @@ public class MakefileEditorConfiguration extends SourceViewerConfiguration {
|
||||||
/**
|
/**
|
||||||
* Constructor for MakeConfiguration
|
* Constructor for MakeConfiguration
|
||||||
*/
|
*/
|
||||||
public MakefileEditorConfiguration(IMakefileColorManager colorManager) {
|
public MakefileSourceConfiguration(IMakefileColorManager colorManager, MakefileEditor editor) {
|
||||||
super();
|
super();
|
||||||
|
fEditor = editor;
|
||||||
this.colorManager = colorManager;
|
this.colorManager = colorManager;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -51,10 +61,29 @@ public class MakefileEditorConfiguration extends SourceViewerConfiguration {
|
||||||
MakefileEditor.MAKE_COMMENT,
|
MakefileEditor.MAKE_COMMENT,
|
||||||
MakefileEditor.MAKE_KEYWORD,
|
MakefileEditor.MAKE_KEYWORD,
|
||||||
MakefileEditor.MAKE_MACRO_VAR,
|
MakefileEditor.MAKE_MACRO_VAR,
|
||||||
MakefileEditor.MAKE_META_DATA };
|
MakefileEditor.MAKE_META_DATA
|
||||||
|
};
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @see org.eclipse.jface.text.source.SourceViewerConfiguration#getContentAssistant(ISourceViewer)
|
||||||
|
*/
|
||||||
|
public IContentAssistant getContentAssistant(ISourceViewer sourceViewer) {
|
||||||
|
ContentAssistant assistant = new ContentAssistant();
|
||||||
|
assistant.setContentAssistProcessor(new MakefileCompletionProcessor(fEditor), IDocument.DEFAULT_CONTENT_TYPE);
|
||||||
|
assistant.setContentAssistProcessor(new MakefileCompletionProcessor(fEditor), MakefileEditor.MAKE_MACRO_VAR);
|
||||||
|
assistant.enableAutoActivation(true);
|
||||||
|
assistant.setAutoActivationDelay(500);
|
||||||
|
assistant.setProposalPopupOrientation(IContentAssistant.CONTEXT_INFO_BELOW);
|
||||||
|
assistant.setContextInformationPopupOrientation(IContentAssistant.CONTEXT_INFO_BELOW);
|
||||||
|
//Set to Carolina blue
|
||||||
|
assistant.setContextInformationPopupBackground(getColorManager().getColor(new RGB(0, 191, 255)));
|
||||||
|
|
||||||
|
return assistant;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
protected IMakefileColorManager getColorManager() {
|
protected IMakefileColorManager getColorManager() {
|
||||||
if (null == colorManager)
|
if (null == colorManager)
|
||||||
colorManager = new MakefileColorManager();
|
colorManager = new MakefileColorManager();
|
|
@ -8,7 +8,7 @@
|
||||||
* Contributors:
|
* Contributors:
|
||||||
* QNX Software Systems - Initial API and implementation
|
* QNX Software Systems - Initial API and implementation
|
||||||
***********************************************************************/
|
***********************************************************************/
|
||||||
package org.eclipse.cdt.make.internal.ui.editor;
|
package org.eclipse.cdt.make.internal.ui.text;
|
||||||
|
|
||||||
import org.eclipse.swt.SWT;
|
import org.eclipse.swt.SWT;
|
||||||
import org.eclipse.swt.graphics.Color;
|
import org.eclipse.swt.graphics.Color;
|
|
@ -8,7 +8,7 @@
|
||||||
* Contributors:
|
* Contributors:
|
||||||
* QNX Software Systems - Initial API and implementation
|
* QNX Software Systems - Initial API and implementation
|
||||||
***********************************************************************/
|
***********************************************************************/
|
||||||
package org.eclipse.cdt.make.internal.ui.editor;
|
package org.eclipse.cdt.make.internal.ui.text;
|
||||||
|
|
||||||
import java.util.HashMap;
|
import java.util.HashMap;
|
||||||
import java.util.Iterator;
|
import java.util.Iterator;
|
|
@ -0,0 +1,61 @@
|
||||||
|
/*
|
||||||
|
* "The Java Developer's Guide to Eclipse"
|
||||||
|
* by Shavor, D'Anjou, Fairbrother, Kehn, Kellerman, McCarthy
|
||||||
|
*
|
||||||
|
* (C) Copyright International Business Machines Corporation, 2003.
|
||||||
|
* All Rights Reserved.
|
||||||
|
*
|
||||||
|
* Code or samples provided herein are provided without warranty of any kind.
|
||||||
|
*/
|
||||||
|
package org.eclipse.cdt.make.internal.ui.text;
|
||||||
|
|
||||||
|
import org.eclipse.jface.text.BadLocationException;
|
||||||
|
import org.eclipse.jface.text.IDocument;
|
||||||
|
import org.eclipse.jface.text.ITextViewer;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Used to scan and detect for SQL keywords
|
||||||
|
*/
|
||||||
|
public class WordPartDetector {
|
||||||
|
String wordPart = "";
|
||||||
|
int offset;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Method WordPartDetector.
|
||||||
|
* @param viewer is a text viewer
|
||||||
|
* @param documentOffset into the SQL document
|
||||||
|
*/
|
||||||
|
public WordPartDetector(ITextViewer viewer, int documentOffset) {
|
||||||
|
offset = documentOffset - 1;
|
||||||
|
int endOffset = documentOffset;
|
||||||
|
try {
|
||||||
|
IDocument doc = viewer.getDocument();
|
||||||
|
int bottom = viewer.getBottomIndexEndOffset();
|
||||||
|
int top = viewer.getTopIndexStartOffset();
|
||||||
|
while (offset >= top && Character.isLetterOrDigit(doc.getChar(offset))) {
|
||||||
|
offset--;
|
||||||
|
}
|
||||||
|
while (endOffset < bottom && Character.isLetterOrDigit(doc.getChar(endOffset))) {
|
||||||
|
endOffset++;
|
||||||
|
}
|
||||||
|
//we've been one step too far : increase the offset
|
||||||
|
offset++;
|
||||||
|
wordPart = viewer.getDocument().get(offset, endOffset - offset);
|
||||||
|
} catch (BadLocationException e) {
|
||||||
|
// do nothing
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Method getString.
|
||||||
|
* @return String
|
||||||
|
*/
|
||||||
|
public String getString() {
|
||||||
|
return wordPart;
|
||||||
|
}
|
||||||
|
|
||||||
|
public int getOffset() {
|
||||||
|
return offset;
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
|
@ -8,11 +8,12 @@
|
||||||
* Contributors:
|
* Contributors:
|
||||||
* QNX Software Systems - Initial API and implementation
|
* QNX Software Systems - Initial API and implementation
|
||||||
***********************************************************************/
|
***********************************************************************/
|
||||||
package org.eclipse.cdt.make.internal.ui.editor;
|
package org.eclipse.cdt.make.internal.ui.text.makefile;
|
||||||
|
|
||||||
import java.util.ArrayList;
|
import java.util.ArrayList;
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
|
|
||||||
|
import org.eclipse.cdt.make.internal.ui.text.IMakefileColorManager;
|
||||||
import org.eclipse.jface.text.TextAttribute;
|
import org.eclipse.jface.text.TextAttribute;
|
||||||
import org.eclipse.jface.text.rules.EndOfLineRule;
|
import org.eclipse.jface.text.rules.EndOfLineRule;
|
||||||
import org.eclipse.jface.text.rules.ICharacterScanner;
|
import org.eclipse.jface.text.rules.ICharacterScanner;
|
||||||
|
@ -158,6 +159,7 @@ public class MakefileCodeScanner extends RuleBasedScanner {
|
||||||
|
|
||||||
return Token.UNDEFINED;
|
return Token.UNDEFINED;
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Returns the characters in the buffer to the scanner.
|
* Returns the characters in the buffer to the scanner.
|
||||||
*
|
*
|
|
@ -0,0 +1,207 @@
|
||||||
|
/**********************************************************************
|
||||||
|
* Copyright (c) 2002,2003 QNX Software Systems 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:
|
||||||
|
* QNX Software Systems - Initial API and implementation
|
||||||
|
***********************************************************************/
|
||||||
|
package org.eclipse.cdt.make.internal.ui.text.makefile;
|
||||||
|
|
||||||
|
import java.util.ArrayList;
|
||||||
|
|
||||||
|
import org.eclipse.cdt.make.core.makefile.IMacroDefinition;
|
||||||
|
import org.eclipse.cdt.make.core.makefile.IMakefile;
|
||||||
|
import org.eclipse.cdt.make.core.makefile.IRule;
|
||||||
|
import org.eclipse.cdt.make.core.makefile.IStatement;
|
||||||
|
import org.eclipse.cdt.make.internal.ui.MakeUIImages;
|
||||||
|
import org.eclipse.cdt.make.internal.ui.editor.MakefileEditor;
|
||||||
|
import org.eclipse.cdt.make.internal.ui.text.WordPartDetector;
|
||||||
|
import org.eclipse.jface.text.BadLocationException;
|
||||||
|
import org.eclipse.jface.text.IDocument;
|
||||||
|
import org.eclipse.jface.text.ITextViewer;
|
||||||
|
import org.eclipse.jface.text.TextPresentation;
|
||||||
|
import org.eclipse.jface.text.contentassist.CompletionProposal;
|
||||||
|
import org.eclipse.jface.text.contentassist.ContextInformation;
|
||||||
|
import org.eclipse.jface.text.contentassist.ICompletionProposal;
|
||||||
|
import org.eclipse.jface.text.contentassist.IContentAssistProcessor;
|
||||||
|
import org.eclipse.jface.text.contentassist.IContextInformation;
|
||||||
|
import org.eclipse.jface.text.contentassist.IContextInformationPresenter;
|
||||||
|
import org.eclipse.jface.text.contentassist.IContextInformationValidator;
|
||||||
|
import org.eclipse.swt.graphics.Image;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* MakefileCompletionProcessor
|
||||||
|
*/
|
||||||
|
public class MakefileCompletionProcessor implements IContentAssistProcessor {
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Simple content assist tip closer. The tip is valid in a range
|
||||||
|
* of 5 characters around its popup location.
|
||||||
|
*/
|
||||||
|
protected static class Validator implements IContextInformationValidator, IContextInformationPresenter {
|
||||||
|
|
||||||
|
protected int fInstallOffset;
|
||||||
|
|
||||||
|
/*
|
||||||
|
* @see IContextInformationValidator#isContextInformationValid(int)
|
||||||
|
*/
|
||||||
|
public boolean isContextInformationValid(int offset) {
|
||||||
|
return Math.abs(fInstallOffset - offset) < 5;
|
||||||
|
}
|
||||||
|
|
||||||
|
/*
|
||||||
|
* @see IContextInformationValidator#install(IContextInformation, ITextViewer, int)
|
||||||
|
*/
|
||||||
|
public void install(IContextInformation info, ITextViewer viewer, int offset) {
|
||||||
|
fInstallOffset = offset;
|
||||||
|
}
|
||||||
|
|
||||||
|
/*
|
||||||
|
* @see org.eclipse.jface.text.contentassist.IContextInformationPresenter#updatePresentation(int, TextPresentation)
|
||||||
|
*/
|
||||||
|
public boolean updatePresentation(int documentPosition, TextPresentation presentation) {
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
protected IContextInformationValidator fValidator = new Validator();
|
||||||
|
protected Image imageMacro = MakeUIImages.getImage(MakeUIImages.IMG_OBJS_MAKEFILE_MACRO);
|
||||||
|
protected Image imageTarget = MakeUIImages.getImage(MakeUIImages.IMG_OBJS_MAKEFILE_TARGET_RULE);
|
||||||
|
protected MakefileEditor fEditor;
|
||||||
|
|
||||||
|
public MakefileCompletionProcessor(MakefileEditor editor) {
|
||||||
|
fEditor = editor;
|
||||||
|
}
|
||||||
|
|
||||||
|
/* (non-Javadoc)
|
||||||
|
* @see org.eclipse.jface.text.contentassist.IContentAssistProcessor#computeCompletionProposals(org.eclipse.jface.text.ITextViewer, int)
|
||||||
|
*/
|
||||||
|
public ICompletionProposal[] computeCompletionProposals(ITextViewer viewer, int documentOffset) {
|
||||||
|
boolean macro = inMacro(viewer, documentOffset);
|
||||||
|
IMakefile makefile = fEditor.getMakefile(viewer.getDocument());
|
||||||
|
IStatement[] statements = null;
|
||||||
|
if (macro) {
|
||||||
|
statements = makefile.getMacroDefinitions();
|
||||||
|
} else {
|
||||||
|
statements = makefile.getTargetRules();
|
||||||
|
}
|
||||||
|
|
||||||
|
ArrayList proposalList = new ArrayList(statements.length);
|
||||||
|
WordPartDetector wordPart = new WordPartDetector(viewer, documentOffset);
|
||||||
|
|
||||||
|
// iterate over all the different categories
|
||||||
|
for (int i = 0; i < statements.length; i++) {
|
||||||
|
String name = null;
|
||||||
|
Image image = null;
|
||||||
|
String infoString = "";//getContentInfoString(name);
|
||||||
|
if (statements[i] instanceof IMacroDefinition) {
|
||||||
|
name = ((IMacroDefinition) statements[i]).getName();
|
||||||
|
image = imageMacro;
|
||||||
|
infoString = ((IMacroDefinition)statements[i]).getValue();
|
||||||
|
} else if (statements[i] instanceof IRule) {
|
||||||
|
name = ((IRule) statements[i]).getTarget().toString();
|
||||||
|
image = imageTarget;
|
||||||
|
infoString = name;
|
||||||
|
}
|
||||||
|
if (name != null && name.startsWith(wordPart.getString())) {
|
||||||
|
IContextInformation info = new ContextInformation(name, infoString);
|
||||||
|
ICompletionProposal result =
|
||||||
|
new CompletionProposal(
|
||||||
|
name,
|
||||||
|
wordPart.getOffset(),
|
||||||
|
wordPart.getString().length(),
|
||||||
|
name.length(),
|
||||||
|
image,
|
||||||
|
name,
|
||||||
|
info,
|
||||||
|
infoString);
|
||||||
|
proposalList.add(result);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return (ICompletionProposal[]) proposalList.toArray(new ICompletionProposal[0]);
|
||||||
|
}
|
||||||
|
|
||||||
|
/* (non-Javadoc)
|
||||||
|
* @see org.eclipse.jface.text.contentassist.IContentAssistProcessor#computeContextInformation(org.eclipse.jface.text.ITextViewer, int)
|
||||||
|
*/
|
||||||
|
public IContextInformation[] computeContextInformation(ITextViewer viewer, int documentOffset) {
|
||||||
|
WordPartDetector wordPart = new WordPartDetector(viewer, documentOffset);
|
||||||
|
boolean macro = inMacro(viewer, documentOffset);
|
||||||
|
IMakefile makefile = fEditor.getMakefile(viewer.getDocument());
|
||||||
|
ArrayList contextList = new ArrayList();
|
||||||
|
if (macro) {
|
||||||
|
IStatement[] statements = makefile.getMacroDefinitions();
|
||||||
|
for (int i = 0; i < statements.length; i++) {
|
||||||
|
if (statements[i] instanceof IMacroDefinition) {
|
||||||
|
String name = ((IMacroDefinition) statements[i]).getName();
|
||||||
|
if (name != null && name.equals(wordPart.getString())) {
|
||||||
|
String value = ((IMacroDefinition) statements[i]).getValue();
|
||||||
|
if (value != null && value.length() > 0) {
|
||||||
|
contextList.add(value);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
IContextInformation[] result = new IContextInformation[contextList.size()];
|
||||||
|
for (int i = 0; i < result.length; i++) {
|
||||||
|
String context = (String)contextList.get(i);
|
||||||
|
result[i] = new ContextInformation(imageMacro, wordPart.getString(), context);
|
||||||
|
}
|
||||||
|
return result;
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
/* (non-Javadoc)
|
||||||
|
* @see org.eclipse.jface.text.contentassist.IContentAssistProcessor#getCompletionProposalAutoActivationCharacters()
|
||||||
|
*/
|
||||||
|
public char[] getCompletionProposalAutoActivationCharacters() {
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
|
||||||
|
/* (non-Javadoc)
|
||||||
|
* @see org.eclipse.jface.text.contentassist.IContentAssistProcessor#getContextInformationAutoActivationCharacters()
|
||||||
|
*/
|
||||||
|
public char[] getContextInformationAutoActivationCharacters() {
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
|
||||||
|
/* (non-Javadoc)
|
||||||
|
* @see org.eclipse.jface.text.contentassist.IContentAssistProcessor#getErrorMessage()
|
||||||
|
*/
|
||||||
|
public String getErrorMessage() {
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
|
||||||
|
/* (non-Javadoc)
|
||||||
|
* @see org.eclipse.jface.text.contentassist.IContentAssistProcessor#getContextInformationValidator()
|
||||||
|
*/
|
||||||
|
public IContextInformationValidator getContextInformationValidator() {
|
||||||
|
return fValidator;
|
||||||
|
}
|
||||||
|
|
||||||
|
private boolean inMacro(ITextViewer viewer, 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--) {
|
||||||
|
char c;
|
||||||
|
c = document.getChar(index);
|
||||||
|
if (c == '$') {
|
||||||
|
isMacro = true;
|
||||||
|
break;
|
||||||
|
} else if (Character.isWhitespace(c)) {
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
} catch (BadLocationException e) {
|
||||||
|
}
|
||||||
|
return isMacro;
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
|
@ -8,7 +8,7 @@
|
||||||
* Contributors:
|
* Contributors:
|
||||||
* QNX Software Systems - Initial API and implementation
|
* QNX Software Systems - Initial API and implementation
|
||||||
***********************************************************************/
|
***********************************************************************/
|
||||||
package org.eclipse.cdt.make.internal.ui.editor;
|
package org.eclipse.cdt.make.internal.ui.text.makefile;
|
||||||
|
|
||||||
import java.util.ArrayList;
|
import java.util.ArrayList;
|
||||||
import java.util.List;
|
import java.util.List;
|
|
@ -8,7 +8,7 @@
|
||||||
* Contributors:
|
* Contributors:
|
||||||
* QNX Software Systems - Initial API and implementation
|
* QNX Software Systems - Initial API and implementation
|
||||||
***********************************************************************/
|
***********************************************************************/
|
||||||
package org.eclipse.cdt.make.internal.ui.editor;
|
package org.eclipse.cdt.make.internal.ui.text.makefile;
|
||||||
|
|
||||||
import java.util.ArrayList;
|
import java.util.ArrayList;
|
||||||
import java.util.List;
|
import java.util.List;
|
|
@ -8,7 +8,7 @@
|
||||||
* Contributors:
|
* Contributors:
|
||||||
* QNX Software Systems - Initial API and implementation
|
* QNX Software Systems - Initial API and implementation
|
||||||
***********************************************************************/
|
***********************************************************************/
|
||||||
package org.eclipse.cdt.make.internal.ui.editor;
|
package org.eclipse.cdt.make.internal.ui.text.makefile;
|
||||||
|
|
||||||
import org.eclipse.jface.text.rules.ICharacterScanner;
|
import org.eclipse.jface.text.rules.ICharacterScanner;
|
||||||
import org.eclipse.jface.text.rules.IToken;
|
import org.eclipse.jface.text.rules.IToken;
|
|
@ -8,7 +8,7 @@
|
||||||
* Contributors:
|
* Contributors:
|
||||||
* QNX Software Systems - Initial API and implementation
|
* QNX Software Systems - Initial API and implementation
|
||||||
***********************************************************************/
|
***********************************************************************/
|
||||||
package org.eclipse.cdt.make.internal.ui.editor;
|
package org.eclipse.cdt.make.internal.ui.text.makefile;
|
||||||
|
|
||||||
import org.eclipse.jface.text.rules.IWordDetector;
|
import org.eclipse.jface.text.rules.IWordDetector;
|
||||||
|
|
Loading…
Add table
Reference in a new issue