Skip to content

Commit

Permalink
Merge pull request #44 from Krzmbrzl/plugin
Browse files Browse the repository at this point in the history
0.5.0 Update
  • Loading branch information
Krzmbrzl committed Apr 26, 2016
2 parents aa7b4a6 + 92e61a6 commit 3d92df6
Show file tree
Hide file tree
Showing 223 changed files with 74,731 additions and 201 deletions.
2 changes: 1 addition & 1 deletion plugin/Raven.SQDev.Editors/META-INF/MANIFEST.MF
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ Manifest-Version: 1.0
Bundle-ManifestVersion: 2
Bundle-Name: Editors
Bundle-SymbolicName: raven.sqdev.editors;singleton:=true
Bundle-Version: 0.2.0
Bundle-Version: 0.3.0
Bundle-Activator: raven.sqdev.editors.activator.Activator
Require-Bundle: org.eclipse.ui,
org.eclipse.core.runtime,
Expand Down
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Original file line number Diff line number Diff line change
Expand Up @@ -5,12 +5,14 @@
import org.eclipse.jface.text.source.DefaultCharacterPairMatcher;
import org.eclipse.jface.text.source.ICharacterPairMatcher;
import org.eclipse.jface.text.source.ISourceViewer;
import org.eclipse.jface.text.source.ISourceViewerExtension2;
import org.eclipse.jface.text.source.IVerticalRuler;
import org.eclipse.swt.widgets.Composite;
import org.eclipse.ui.editors.text.TextEditor;
import org.eclipse.ui.texteditor.SourceViewerDecorationSupport;

import raven.sqdev.constants.SQDevPreferenceConstants;
import raven.sqdev.misc.CharacterPair;
import raven.sqdev.util.SQDevPreferenceUtil;

/**
Expand Down Expand Up @@ -168,11 +170,18 @@ public void createPartControl(Composite parent) {

/**
* Updates the editor. Needed when some changes are made to the way the
* editor content should be displayed
* editor content should be displayed or when the behaviour of the editor
* should change
*/
public void update() {
if (this.getSourceViewer() != null) {
this.getSourceViewer().invalidateTextPresentation();
if (getSourceViewer() != null) {
getSourceViewer().invalidateTextPresentation();

if (getSourceViewer() instanceof ISourceViewerExtension2) {
// reconfigure the SourceViewer
((ISourceViewerExtension2) getSourceViewer()).unconfigure();
getSourceViewer().configure(getBasicConfiguration());
}
}
}

Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,222 @@
package raven.sqdev.editors;

import org.eclipse.core.runtime.Assert;
import org.eclipse.core.runtime.IProgressMonitor;
import org.eclipse.jface.text.BadLocationException;
import org.eclipse.jface.text.IDocument;
import org.eclipse.jface.text.IInformationControl;
import org.eclipse.jface.text.IInformationControlCreator;
import org.eclipse.jface.text.contentassist.ICompletionProposal;
import org.eclipse.jface.text.contentassist.ICompletionProposalExtension3;
import org.eclipse.jface.text.contentassist.ICompletionProposalExtension5;
import org.eclipse.jface.text.contentassist.ICompletionProposalExtension6;
import org.eclipse.jface.text.contentassist.IContextInformation;
import org.eclipse.jface.viewers.StyledString;
import org.eclipse.swt.SWT;
import org.eclipse.swt.graphics.Image;
import org.eclipse.swt.graphics.ImageData;
import org.eclipse.swt.graphics.Point;
import org.eclipse.swt.graphics.TextStyle;
import org.eclipse.swt.widgets.Shell;
import org.eclipse.ui.PlatformUI;

import raven.sqdev.infoCollection.base.Keyword;
import raven.sqdev.miscellaneous.AdditionalKeywordProposalInformation;
import raven.sqdev.pluginManagement.ResourceManager;

public class BasicCompletionProposal implements ICompletionProposal, ICompletionProposalExtension3,
ICompletionProposalExtension5, ICompletionProposalExtension6 {

/**
* The image for all the SQF commands
*/
private static final Image SQFCOMMAND_IMAGE = new Image(PlatformUI.getWorkbench().getDisplay(),
new ImageData(ResourceManager.getManager()
.getInternalResourceStream(ResourceManager.SQFCOMMAND_ICON)));

/** The string to be displayed in the completion proposal popup. */
private String displayString;
/** The replacement string. */
private String replacementString;
/** The replacement offset. */
private int replacementOffset;
/** The replacement length. */
private int replacementLength;
/** The cursor position after this proposal has been applied. */
private int cursorPosition;
/** The image to be displayed in the completion proposal popup. */
private Image image;
/** The context information of this proposal. */
private IContextInformation contextInformation;
/** The additional info of this proposal. */
private Object additionalProposalInfo;

/**
* Creates a <code>CompletionProposal</code> based on the given
* <code>Keyword</code>
*
* @param keyword
* The respective <code>Keyword</code> this proposal should be
* craeted for
* @param replacementOffset
* The offset of the text to be replaced
* @param replacementLength
* The length of the text to be replaced
*/
public BasicCompletionProposal(Keyword keyword, int replacementOffset, int replacementLength) {
// create instance according to the keyword
this(keyword.getKeyword(), replacementOffset, replacementLength,
keyword.getKeyword().length(), SQFCOMMAND_IMAGE, keyword.getKeyword(), null,
new AdditionalKeywordProposalInformation(keyword));
}

/**
* Creates a new completion proposal based on the provided information. The
* replacement string is considered being the display string too. All
* remaining fields are set to <code>null</code>.
*
* @param replacementString
* the actual string to be inserted into the document
* @param replacementOffset
* the offset of the text to be replaced
* @param replacementLength
* the length of the text to be replaced
* @param cursorPosition
* the position of the cursor following the insert relative to
* replacementOffset
*/
public BasicCompletionProposal(String replacementString, int replacementOffset,
int replacementLength, int cursorPosition) {
this(replacementString, replacementOffset, replacementLength, cursorPosition, null, null,
null, null);
}

/**
* Creates a new completion proposal. All fields are initialized based on
* the provided information.
*
* @param replacementString
* the actual string to be inserted into the document
* @param replacementOffset
* the offset of the text to be replaced
* @param replacementLength
* the length of the text to be replaced
* @param cursorPosition
* the position of the cursor following the insert relative to
* replacementOffset
* @param image
* the image to display for this proposal
* @param displayString
* the string to be displayed for the proposal
* @param contextInformation
* the context information associated with this proposal
* @param additionalProposalInfo
* the additional information associated with this proposal
*/
public BasicCompletionProposal(String replacementString, int replacementOffset,
int replacementLength, int cursorPosition, Image image, String displayString,
IContextInformation contextInformation, Object additionalProposalInfo) {
Assert.isNotNull(replacementString);
Assert.isTrue(replacementOffset >= 0);
Assert.isTrue(replacementLength >= 0);
Assert.isTrue(cursorPosition >= 0);

this.replacementString = replacementString;
this.replacementOffset = replacementOffset;
this.replacementLength = replacementLength;
this.cursorPosition = cursorPosition;
this.image = image;
this.displayString = displayString;
this.contextInformation = contextInformation;
this.additionalProposalInfo = additionalProposalInfo;
}

/*
* @see ICompletionProposal#apply(IDocument)
*/
public void apply(IDocument document) {
try {
document.replace(replacementOffset, replacementLength, replacementString);
} catch (BadLocationException x) {
// ignore
}
}

/*
* @see ICompletionProposal#getSelection(IDocument)
*/
public Point getSelection(IDocument document) {
return new Point(replacementOffset + cursorPosition, 0);
}

/*
* @see ICompletionProposal#getContextInformation()
*/
public IContextInformation getContextInformation() {
return contextInformation;
}

/*
* @see ICompletionProposal#getImage()
*/
public Image getImage() {
return image;
}

/*
* @see ICompletionProposal#getDisplayString()
*/
public String getDisplayString() {
if (displayString != null)
return displayString;
return replacementString;
}

@Override
public IInformationControlCreator getInformationControlCreator() {
return new IInformationControlCreator() {
public IInformationControl createInformationControl(Shell parent) {
return new BasicInformationControl(parent);
}
};
}

@Override
public CharSequence getPrefixCompletionText(IDocument document, int completionOffset) {
// TODO Auto-generated method stub
return null;
}

@Override
public int getPrefixCompletionStart(IDocument document, int completionOffset) {
// TODO Auto-generated method stub
return 0;
}

@Override
public String getAdditionalProposalInfo() {
// does not get called
return additionalProposalInfo.toString();
}

@Override
public Object getAdditionalProposalInfo(IProgressMonitor monitor) {
return additionalProposalInfo;
}

@Override
public StyledString getStyledDisplayString() {
StyledString str = new StyledString(displayString);

str.setStyle(0, replacementLength, new StyledString.Styler() {

@Override
public void applyStyles(TextStyle textStyle) {
textStyle.foreground = PlatformUI.getWorkbench().getDisplay()
.getSystemColor(SWT.COLOR_BLUE);
}
});

return str;
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,92 @@
package raven.sqdev.editors;

import java.util.ArrayList;
import java.util.List;

import org.eclipse.jface.text.ITextViewer;
import org.eclipse.jface.text.contentassist.CompletionProposal;
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.IContextInformationValidator;

import raven.sqdev.infoCollection.base.Keyword;
import raven.sqdev.util.EditorUtil;

/**
* A basic implementation of an <code>IContentAssistProcessor</code> using the
* keywords provided by the {@linkplain BasicKeywordProvider} to generate
* content assist for them
*
* @author Raven
*
*/
public class BasicContentAssistProcessor implements IContentAssistProcessor {
/**
* The editor this processor is working on
*/
protected BasicCodeEditor editor;

public BasicContentAssistProcessor(BasicCodeEditor editor) {
this.editor = editor;
}

@Override
public ICompletionProposal[] computeCompletionProposals(ITextViewer viewer, int offset) {
String prefix = EditorUtil.getWordPartBeforeOffset(viewer.getDocument(), offset);

List<Keyword> keywords;
// get the respective list of keywords
if (prefix.isEmpty()) {
keywords = editor.getBasicConfiguration().getKeywordScanner().getKeywordProvider()
.getKeywordList().getKeywords();
} else {
keywords = editor.getBasicConfiguration().getKeywordScanner().getKeywordProvider()
.getKeywordList().getListFor(prefix.charAt(0));
}

ArrayList<ICompletionProposal> proposals = new ArrayList<ICompletionProposal>();

// create proposals
for (Keyword currentKeyword : keywords) {
if (currentKeyword.getKeyword().toLowerCase().startsWith(prefix.toLowerCase())) {
// add a proposal
proposals.add(new BasicCompletionProposal(currentKeyword, offset - prefix.length(),
prefix.length()));
}
}

if (proposals.size() > 0) {
return proposals.toArray(new ICompletionProposal[proposals.size()]);
} else {
return new ICompletionProposal[] { new CompletionProposal("", offset, 0, 0, null,
"No proposals available!", null, null) };
}
}

@Override
public IContextInformation[] computeContextInformation(ITextViewer viewer, int offset) {
return null;
}

@Override
public char[] getCompletionProposalAutoActivationCharacters() {
return null;
}

@Override
public char[] getContextInformationAutoActivationCharacters() {
return null;
}

@Override
public String getErrorMessage() {
return null;
}

@Override
public IContextInformationValidator getContextInformationValidator() {
return null;
}

}
Loading

0 comments on commit 3d92df6

Please sign in to comment.