本文整理汇总了Java中org.eclipse.jface.text.DocumentCommand类的典型用法代码示例。如果您正苦于以下问题:Java DocumentCommand类的具体用法?Java DocumentCommand怎么用?Java DocumentCommand使用的例子?那么, 这里精选的类代码示例或许可以为您提供帮助。
DocumentCommand类属于org.eclipse.jface.text包,在下文中一共展示了DocumentCommand类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: customizeDocumentCommand
import org.eclipse.jface.text.DocumentCommand; //导入依赖的package包/类
@Override
public void customizeDocumentCommand(IDocument document, DocumentCommand command) {
if (command.text.equals("{")) {
int line;
try {
line = document.getLineOffset(command.offset);
String indent = getIndentOfLine(document, line);
command.text = "{" + "\r\n" + indent + "}";
configureCommand(command);
} catch (BadLocationException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
}
}
示例2: addClosingBracketAfterEnterIfRequired
import org.eclipse.jface.text.DocumentCommand; //导入依赖的package包/类
protected void addClosingBracketAfterEnterIfRequired(IDocument document, DocumentCommand command, String text, String textBefore, String textAfter) {
boolean isLineBreak = isLineBreak(text);
if (!isLineBreak) {
return;
}
String documentText = document.get();
String openingBracketBefore = getCloseAfterBracketBefore(documentText, command.offset);
if (openingBracketBefore == null) {
return;
}
// add additional indentation (because a line break was entered after an opening
// bracket)
command.text = command.text + "\t";
String closingBracket = bracketSet.getCounterpart(openingBracketBefore);
boolean closingBracketIsMissing = count(documentText, openingBracketBefore) != count(documentText, closingBracket);
// add closing bracket (if required)
if (closingBracketIsMissing) {
command.text = command.text + textAfter;
command.text = command.text + closingBracket;
}
command.shiftsCaret = false;
command.caretOffset = command.offset + textAfter.length() + 1;
}
示例3: getStringAt
import org.eclipse.jface.text.DocumentCommand; //导入依赖的package包/类
/**
* Returns a text String of the (line + <code>lineDif</code>).
* @param document IDocument that contains the line.
* @param command DocumentCommand that determines the line.
* @param delim are delimiters included
* @param lineDif 0 = current line, 1 = next line, -1 previous line etc...
* @return the text of the line.
*/
public String getStringAt(IDocument document,
DocumentCommand command, boolean delim, int lineDif) {
String line = "";
int lineBegin, lineLength;
try {
if (delim) {
lineLength = getLineLength(document, command, true, lineDif);
} else {
lineLength = getLineLength(document, command, false, lineDif);
}
if (lineLength > 0) {
lineBegin = document.getLineOffset(document
.getLineOfOffset(command.offset) + lineDif);
line = document.get(lineBegin, lineLength);
}
} catch (BadLocationException e) {
TexlipsePlugin.log("TexEditorTools.getStringAt", e);
}
return line;
}
示例4: dropItem
import org.eclipse.jface.text.DocumentCommand; //导入依赖的package包/类
/**
* Erases the \item -string from a line
*
* @param d
* @param c
*/
private void dropItem(IDocument d, DocumentCommand c) {
try {
if (itemSetted && itemAtLine == (d.getLineOfOffset(c.offset) - 1)) {
IRegion r = d.getLineInformationOfOffset(c.offset);
String line = d.get(r.getOffset(), r.getLength());
if ("\\item".equals(line.trim()) || "\\item[]".equals(line.trim())) {
c.shiftsCaret = false;
c.length = line.length();
c.offset = r.getOffset();
c.text = getIndentation(line);
c.caretOffset = c.offset + c.text.length();
}
}
} catch (BadLocationException e) {
TexlipsePlugin.log("TexAutoIndentStrategy:dropItem", e);
}
itemSetted = false;
}
示例5: customizeDocumentCommand
import org.eclipse.jface.text.DocumentCommand; //导入依赖的package包/类
@Override
public void customizeDocumentCommand(IDocument document, DocumentCommand command) {
if (command.text.equalsIgnoreCase("\"")) {
command.text = "\"\"";
configureCommand(command);
}
else if (command.text.equalsIgnoreCase("'")) {
command.text = "''";
configureCommand(command);
}
else if (command.text.equalsIgnoreCase("[")) {
command.text = "[]";
configureCommand(command);
}
else if (command.text.equalsIgnoreCase("(")) {
command.text = "()";
configureCommand(command);
}
}
示例6: customizeDocumentCommand
import org.eclipse.jface.text.DocumentCommand; //导入依赖的package包/类
@Override
public void customizeDocumentCommand(IDocument document, DocumentCommand command) {
if (!supportsSmartInsert(document)) {
return;
}
IStructuredModel model = null;
try {
model = StructuredModelManager.getModelManager().getExistingModelForRead(document);
if (model != null) {
if (command.text != null) {
smartInsertCloseEndEL(command, document, model);
}
}
} finally {
if (model != null)
model.releaseFromRead();
}
}
示例7: smartInsertCloseEndEL
import org.eclipse.jface.text.DocumentCommand; //导入依赖的package包/类
private void smartInsertCloseEndEL(DocumentCommand command, IDocument document, IStructuredModel model) {
try {
if (isPreferenceEnabled(AngularUIPreferenceNames.TYPING_COMPLETE_END_EL) && command.text.equals("{") //$NON-NLS-1$
&& document.getLength() > 0 && document.getChar(command.offset - 1) == '{') {
IDOMNode node = (IDOMNode) model.getIndexedRegion(command.offset - 1);
command.text += "}}";
command.shiftsCaret = false;
command.caretOffset = command.offset + 1;
command.doit = false;
}
} catch (BadLocationException e) {
}
}
示例8: customizeDocumentCommand
import org.eclipse.jface.text.DocumentCommand; //导入依赖的package包/类
@Override
public void customizeDocumentCommand(final IDocument doc, final DocumentCommand cmd) {
if (cmd.length != 0 || cmd.text == null) return;
try {
if (TextUtilities.endsWith(doc.getLegalLineDelimiters(), cmd.text) != -1) {
if (AutoEdit.isBlankLine(doc, cmd.offset)) {
int beg = AutoEdit.getLineOffset(doc, cmd.offset);
int len = cmd.offset - beg;
DeleteEdit blanks = new DeleteEdit(beg, len);
blanks.apply(doc);
cmd.offset = beg;
} else {
autoIndent(doc, cmd, false); // return entered
}
} else if (evaluateInsertPoint(doc, cmd)) {
autoIndent(doc, cmd, true); // insert point exceeds limit
} else if (evaluateLineWidth(doc, cmd)) {
wrapLines(doc, cmd); // line end exceeds limit
}
} catch (BadLocationException e) {}
}
示例9: createMethodTags
import org.eclipse.jface.text.DocumentCommand; //导入依赖的package包/类
private String createMethodTags(IDocument document, DocumentCommand command, String indentation,
String lineDelimiter, IFunction method) throws CoreException, BadLocationException {
IRegion partition = TextUtilities.getPartition(document, fPartitioning, command.offset, false);
IFunction inheritedMethod = getInheritedMethod(method);
String comment = CodeGeneration.getMethodComment(method, inheritedMethod, lineDelimiter);
if (comment != null) {
comment = comment.trim();
boolean javadocComment = comment.startsWith("/**"); //$NON-NLS-1$
if (!isFirstComment(document, command, method, javadocComment))
return null;
boolean isJavaDoc = partition.getLength() >= 3 && document.get(partition.getOffset(), 3).equals("/**"); //$NON-NLS-1$
if (javadocComment == isJavaDoc) {
return prepareTemplateComment(comment, indentation, method.getJavaScriptProject(), lineDelimiter);
}
}
return null;
}
示例10: customizeDocumentCommand
import org.eclipse.jface.text.DocumentCommand; //导入依赖的package包/类
public void customizeDocumentCommand(IDocument document, DocumentCommand command) {
if (!isSmartMode())
return;
if (command.text != null) {
if (command.length == 0) {
String[] lineDelimiters = document.getLegalLineDelimiters();
int index = TextUtilities.endsWith(lineDelimiters, command.text);
if (index > -1) {
// ends with line delimiter
if (lineDelimiters[index].equals(command.text))
// just the line delimiter
indentAfterNewLine(document, command);
return;
}
}
if (command.text.equals("/")) { //$NON-NLS-1$
indentAfterCommentEnd(document, command);
return;
}
}
}
示例11: handleCursorInFirstLine
import org.eclipse.jface.text.DocumentCommand; //导入依赖的package包/类
/**
* Expects the cursor to be in the same line as the start terminal
* puts any text between start terminal and cursor into a separate newline before the cursor.
* puts any text between cursor and end terminal into a separate newline after the cursor.
* puts the closing terminal into a separate line at the end.
* adds a closing terminal if not existent.
*/
protected CommandInfo handleCursorInFirstLine(IDocument document, DocumentCommand command, IRegion startTerminal,
IRegion stopTerminal) throws BadLocationException {
CommandInfo newC = new CommandInfo();
newC.isChange = true;
newC.offset = command.offset;
newC.text += command.text + indentationString;
newC.cursorOffset = command.offset + newC.text.length();
if (stopTerminal == null && atEndOfLineInput(document, command.offset)) {
newC.text += command.text + getRightTerminal();
}
if (stopTerminal != null && stopTerminal.getOffset() >= command.offset && util.isSameLine(document, stopTerminal.getOffset(), command.offset)) {
String string = document.get(command.offset, stopTerminal.getOffset() - command.offset);
if (string.trim().length() > 0)
newC.text += string.trim();
newC.text += command.text;
newC.length += string.length();
}
return newC;
}
示例12: internalCustomizeDocumentCommand
import org.eclipse.jface.text.DocumentCommand; //导入依赖的package包/类
@Override
protected void internalCustomizeDocumentCommand(IDocument document, DocumentCommand command)
throws BadLocationException {
if (command.text.equals("") && command.length == 1) {
if (command.offset + right.length() + left.length() > document.getLength())
return;
if (command.offset + command.length - left.length() < 0)
return;
if (command.length != left.length())
return;
String string = document.get(command.offset, left.length() + right.length());
if (string.equals(left + right)) {
command.length = left.length() + right.length();
}
}
}
示例13: internalCustomizeDocumentCommand
import org.eclipse.jface.text.DocumentCommand; //导入依赖的package包/类
@Override
protected void internalCustomizeDocumentCommand(IDocument document, DocumentCommand command)
throws BadLocationException {
if (command.length != 0)
return;
String[] lineDelimiters = document.getLegalLineDelimiters();
int delimiterIndex = TextUtilities.startsWith(lineDelimiters, command.text);
if (delimiterIndex != -1) {
MultiLineTerminalsEditStrategy bestStrategy = null;
IRegion bestStart = null;
for(MultiLineTerminalsEditStrategy strategy: strategies) {
IRegion candidate = strategy.findStartTerminal(document, command.offset);
if (candidate != null) {
if (bestStart == null || bestStart.getOffset() < candidate.getOffset()) {
bestStrategy = strategy;
bestStart = candidate;
}
}
}
if (bestStrategy != null) {
bestStrategy.internalCustomizeDocumentCommand(document, command);
}
}
}
示例14: checkAndPrepareForNewline
import org.eclipse.jface.text.DocumentCommand; //导入依赖的package包/类
private boolean checkAndPrepareForNewline(IDocument document,
DocumentCommand command) {
try {
String documentAndCommandText = document.get(0, command.offset)
+ command.text;
/*
* The only case where we want to add an indentation after newline is if
* there is a opening curly brace.
*/
Matcher matcher = NEWLINE_AFTER_OPEN_BRACE.matcher(documentAndCommandText);
if (!matcher.matches()) {
return false;
}
} catch (BadLocationException e) {
return false;
}
/*
* The StructuredAutoEditStrategyCSS will only add proper indentation if the
* last character is a newline. We remove the whitespace following the
* newline which was added by the XML autoedit strategy that comes before
* us.
*/
command.text = command.text.replaceAll("\\n\\s+$", "\n");
return command.text.endsWith("\n");
}
示例15: smartIndentOnBackspace
import org.eclipse.jface.text.DocumentCommand; //导入依赖的package包/类
public void smartIndentOnBackspace(IDocument doc, DocumentCommand cmd)
{
if (isUsingTab) { return; }
if ((cmd.offset == -1) || (doc.getLength() == 0)) { return; }
try
{
int len = doc.getLength();
int p = (cmd.offset != len) ? cmd.offset : (cmd.offset - 1);
int line = doc.getLineOfOffset(p);
int start = doc.getLineOffset(line);
int whiteend = findEndOfWhiteSpace(doc, start, start + doc.getLineLength(line));
if ((cmd.offset + 1) != whiteend) { return; }
int indent = indentWidthOf(doc.get(start, whiteend - start), fTabWidth);
indent = unIndent(indent, 1);
cmd.offset = start;
cmd.length = whiteend - start;
cmd.text = getIndentString(indent).toString();
}
catch (BadLocationException e)
{
}
}