X-Git-Url: https://gerrit.simantics.org/r/gitweb?p=simantics%2Fplatform.git;a=blobdiff_plain;f=bundles%2Forg.simantics.document.ui%2Fsrc%2Forg%2Fsimantics%2Fdocument%2Fui%2FCSSCompletionAssistProcessor.java;h=fe909fabda887e9e7e15f13b9fe0773efe210e66;hp=033b9c5763c1525d02527c9491c32278fb86ae4b;hb=refs%2Fchanges%2F38%2F238%2F2;hpb=24e2b34260f219f0d1644ca7a138894980e25b14 diff --git a/bundles/org.simantics.document.ui/src/org/simantics/document/ui/CSSCompletionAssistProcessor.java b/bundles/org.simantics.document.ui/src/org/simantics/document/ui/CSSCompletionAssistProcessor.java index 033b9c576..fe909fabd 100644 --- a/bundles/org.simantics.document.ui/src/org/simantics/document/ui/CSSCompletionAssistProcessor.java +++ b/bundles/org.simantics.document.ui/src/org/simantics/document/ui/CSSCompletionAssistProcessor.java @@ -1,77 +1,77 @@ -package org.simantics.document.ui; - -import org.eclipse.jface.text.BadLocationException; -import org.eclipse.jface.text.IDocument; -import org.eclipse.jface.text.ITextSelection; -import org.eclipse.jface.text.ITextViewer; -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; - -public class CSSCompletionAssistProcessor implements IContentAssistProcessor { - - private String lastError = ""; - private CSSTextEditorEnvironment environment; - - public CSSCompletionAssistProcessor(CSSTextEditorEnvironment environment) { - this.environment = environment; - } - - @Override - public ICompletionProposal[] computeCompletionProposals(ITextViewer viewer, int tmpOffset) { - ITextSelection selection= (ITextSelection) viewer.getSelectionProvider().getSelection(); - // adjust offset to end of normalized selection - if (selection.getOffset() == tmpOffset) - tmpOffset = selection.getOffset() + selection.getLength(); - final int offset = tmpOffset; - IDocument document = viewer.getDocument(); - String tmpPrefix = ""; - try { - tmpPrefix = getPrefix(document, offset); - } catch (BadLocationException e) { - e.printStackTrace(); - } - environment.updateEnvironment(document); - return environment.getCompletionProposals(tmpPrefix, offset); - } - - private static String getPrefix(IDocument doc, int offset) throws BadLocationException { - if (doc == null || offset >= doc.getLength()) - return ""; - - int length= 0; - while (--offset >= 0 && Character.isJavaIdentifierPart(doc.getChar(offset)) || doc.getChar(offset) == '.') - length++; - - return doc.get(offset + 1, length); - } - - @Override - public IContextInformation[] computeContextInformation(ITextViewer viewer, int offset) { - return null; - } - - private static final char[] AUTO_ACTIVATION_CHARS = new char[] { '.', '(' }; - - @Override - public char[] getCompletionProposalAutoActivationCharacters() { - return AUTO_ACTIVATION_CHARS; - } - - @Override - public char[] getContextInformationAutoActivationCharacters() { - return null; - } - - @Override - public String getErrorMessage() { - return lastError; - } - - @Override - public IContextInformationValidator getContextInformationValidator() { - return null; - } - -} +package org.simantics.document.ui; + +import org.eclipse.jface.text.BadLocationException; +import org.eclipse.jface.text.IDocument; +import org.eclipse.jface.text.ITextSelection; +import org.eclipse.jface.text.ITextViewer; +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; + +public class CSSCompletionAssistProcessor implements IContentAssistProcessor { + + private String lastError = ""; + private CSSTextEditorEnvironment environment; + + public CSSCompletionAssistProcessor(CSSTextEditorEnvironment environment) { + this.environment = environment; + } + + @Override + public ICompletionProposal[] computeCompletionProposals(ITextViewer viewer, int tmpOffset) { + ITextSelection selection= (ITextSelection) viewer.getSelectionProvider().getSelection(); + // adjust offset to end of normalized selection + if (selection.getOffset() == tmpOffset) + tmpOffset = selection.getOffset() + selection.getLength(); + final int offset = tmpOffset; + IDocument document = viewer.getDocument(); + String tmpPrefix = ""; + try { + tmpPrefix = getPrefix(document, offset); + } catch (BadLocationException e) { + e.printStackTrace(); + } + environment.updateEnvironment(document); + return environment.getCompletionProposals(tmpPrefix, offset); + } + + private static String getPrefix(IDocument doc, int offset) throws BadLocationException { + if (doc == null || offset >= doc.getLength()) + return ""; + + int length= 0; + while (--offset >= 0 && Character.isJavaIdentifierPart(doc.getChar(offset)) || doc.getChar(offset) == '.') + length++; + + return doc.get(offset + 1, length); + } + + @Override + public IContextInformation[] computeContextInformation(ITextViewer viewer, int offset) { + return null; + } + + private static final char[] AUTO_ACTIVATION_CHARS = new char[] { '.', '(' }; + + @Override + public char[] getCompletionProposalAutoActivationCharacters() { + return AUTO_ACTIVATION_CHARS; + } + + @Override + public char[] getContextInformationAutoActivationCharacters() { + return null; + } + + @Override + public String getErrorMessage() { + return lastError; + } + + @Override + public IContextInformationValidator getContextInformationValidator() { + return null; + } + +}