Java Code Examples for org.eclipse.swt.custom.StyledText#setCaretOffset()
The following examples show how to use
org.eclipse.swt.custom.StyledText#setCaretOffset() .
You can vote up the ones you like or vote down the ones you don't like,
and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: StyledTextCellEditor.java From translationstudio8 with GNU General Public License v2.0 | 6 votes |
private void selectText() { StyledText text = viewer.getTextWidget(); if (text == null || text.isDisposed()) { return; } // viewer.setSelectedRange(selectionOffset, selectionLength) int textLength = text.getText().length(); if (textLength > 0) { EditorSelectionEnum selectionMode = getSelectionMode(); if (selectionMode == EditorSelectionEnum.ALL) { text.setSelection(0, textLength); } else if (selectionMode == EditorSelectionEnum.END) { text.setSelection(textLength, textLength); } } text.setCaretOffset(textLength); }
Example 2
Source File: StyledTextCellEditor.java From tmxeditor8 with GNU General Public License v2.0 | 6 votes |
private void selectText() { StyledText text = viewer.getTextWidget(); if (text == null || text.isDisposed()) { return; } // viewer.setSelectedRange(selectionOffset, selectionLength) int textLength = text.getText().length(); if (textLength > 0) { EditorSelectionEnum selectionMode = getSelectionMode(); if (selectionMode == EditorSelectionEnum.ALL) { text.setSelection(0, textLength); } else if (selectionMode == EditorSelectionEnum.END) { text.setSelection(textLength, textLength); } } text.setCaretOffset(textLength); }
Example 3
Source File: ExpressionBuilder.java From birt with Eclipse Public License 1.0 | 6 votes |
/** * Insert a text string into the text area * * @param text */ protected void insertText( String text ) { StyledText textWidget = sourceViewer.getTextWidget( ); if ( !textWidget.isEnabled( ) ) { return; } int selectionStart = textWidget.getSelection( ).x; textWidget.insert( text ); textWidget.setSelection( selectionStart + text.length( ) ); textWidget.setFocus( ); if ( text.endsWith( "()" ) ) //$NON-NLS-1$ { textWidget.setCaretOffset( textWidget.getCaretOffset( ) - 1 ); // Move } }
Example 4
Source File: MarkExchangeHandler.java From e4macs with Eclipse Public License 1.0 | 6 votes |
/** * Support exchange for simple mark on TextConsole * * @see com.mulgasoft.emacsplus.commands.IConsoleDispatch#consoleDispatch(org.eclipse.ui.console.TextConsoleViewer, org.eclipse.ui.console.IConsoleView, org.eclipse.core.commands.ExecutionEvent) */ public Object consoleDispatch(TextConsoleViewer viewer, IConsoleView activePart, ExecutionEvent event) { int mark = viewer.getMark(); StyledText st = viewer.getTextWidget(); if (mark != -1) { try { st.setRedraw(false); int offset = st.getCaretOffset(); viewer.setMark(offset); st.setCaretOffset(mark); int len = offset - mark; viewer.setSelectedRange(offset, -len); } finally { st.setRedraw(true); } } return null; }
Example 5
Source File: ScriptConsoleViewer.java From Pydev with Eclipse Public License 1.0 | 6 votes |
/** * Sets the new caret position in the console. * * TODO: async should not be allowed (only clearing the shell at the constructor still uses that) */ @Override public void setCaretOffset(final int offset, boolean async) { final StyledText textWidget = getTextWidget(); if (textWidget != null) { if (async) { Display display = textWidget.getDisplay(); if (display != null) { display.asyncExec(new Runnable() { @Override public void run() { textWidget.setCaretOffset(offset); } }); } } else { textWidget.setCaretOffset(offset); } } }
Example 6
Source File: InteractiveConsoleView.java From gama with GNU General Public License v3.0 | 5 votes |
private void insertHistory(final boolean back) { if (history.size() == 0) { ViewsHelper.requestUserAttention(this, "No history"); return; } if (indexInHistory <= 0) { if (back) { ViewsHelper.requestUserAttention(this, "No more history"); } indexInHistory = 0; } else if (indexInHistory >= history.size() - 1) { if (!back) { ViewsHelper.requestUserAttention(this, "No more history"); } indexInHistory = history.size() - 1; } try { final StyledText text = viewer.getTextWidget(); final int lineIndex = text.getLineCount() - 1; final int nbChars = text.getCharCount(); final int firstOffset = text.getOffsetAtLine(lineIndex) + PROMPT.length(); viewer.getDocument().replace(firstOffset, nbChars - firstOffset, history.get(indexInHistory)); text.setCaretOffset(text.getCharCount()); if (back) { indexInHistory--; } else { indexInHistory++; } } catch (final org.eclipse.jface.text.BadLocationException e1) {} }
Example 7
Source File: StyledTextCellEditor.java From translationstudio8 with GNU General Public License v2.0 | 5 votes |
/** * 将指定文本添加到光标所在位置。 robert 2011-12-21 * @param canonicalValue * ; */ public void insertCanonicalValue(Object canonicalValue) { StyledText text = viewer.getTextWidget(); if (text == null || text.isDisposed()) { return; } int offset = text.getCaretOffset(); text.insert(canonicalValue.toString()); text.setCaretOffset(offset + canonicalValue.toString().length()); }
Example 8
Source File: CellEditor.java From tmxeditor8 with GNU General Public License v2.0 | 5 votes |
public void insertCanonicalValue(Object canonicalValue) { StyledText text = textViewer.getTextWidget(); if (text == null || text.isDisposed()) { return; } int offset = text.getCaretOffset(); text.insert(canonicalValue.toString()); text.setCaretOffset(offset + canonicalValue.toString().length()); }
Example 9
Source File: StyledTextCellEditor.java From tmxeditor8 with GNU General Public License v2.0 | 5 votes |
/** * 将指定文本添加到光标所在位置。 robert 2011-12-21 * @param canonicalValue * ; */ public void insertCanonicalValue(Object canonicalValue) { StyledText text = viewer.getTextWidget(); if (text == null || text.isDisposed()) { return; } int offset = text.getCaretOffset(); text.insert(canonicalValue.toString()); text.setCaretOffset(offset + canonicalValue.toString().length()); }
Example 10
Source File: ExpressionTreeSupport.java From birt with Eclipse Public License 1.0 | 5 votes |
/** * Insert a text string into the text area * * @param text */ protected void insertText( String text ) { StyledText textWidget = expressionViewer.getTextWidget( ); if ( !textWidget.isEnabled( ) ) { return; } int selectionStart = textWidget.getSelection( ).x; if ( text.equalsIgnoreCase( "x++" ) ) //$NON-NLS-1$ { text = textWidget.getSelectionText( ) + "++";//$NON-NLS-1$ } else if ( text.equalsIgnoreCase( "x--" ) )//$NON-NLS-1$ { text = textWidget.getSelectionText( ) + "--";//$NON-NLS-1$ } else if ( text.equalsIgnoreCase( "++x" ) )//$NON-NLS-1$ { text = "++" + textWidget.getSelectionText( );//$NON-NLS-1$ } else if ( text.equalsIgnoreCase( "--x" ) )//$NON-NLS-1$ { text = "--" + textWidget.getSelectionText( );//$NON-NLS-1$ } textWidget.insert( text ); textWidget.setSelection( selectionStart + text.length( ) ); textWidget.setFocus( ); if ( text.endsWith( "()" ) ) //$NON-NLS-1$ { textWidget.setCaretOffset( textWidget.getCaretOffset( ) - 1 ); // Move } }
Example 11
Source File: BrowseKillRingHandler.java From e4macs with Eclipse Public License 1.0 | 5 votes |
/** * Navigate up or down the ring entry by entry * * @param viewer the viewer on the console * @param dir FORWARD or BACKWARD */ private void browseRing(TextConsoleViewer viewer, int dir) { IDocument doc = viewer.getDocument(); StyledText st = viewer.getTextWidget(); if (doc != null && st != null) { int lines = doc.getNumberOfLines(); int off = st.getCaretOffset(); try { int l = doc.getLineOfOffset(off); KilledText okill = offsetHash.get(doc.getLineOffset(l)); KilledText nkill = null; int noff = -1; while ((l = l+dir) > -1 && l < lines){ off = doc.getLineOffset(l); KilledText tkill = offsetHash.get(off); if (nkill == null) { if (tkill != null && tkill != okill) { nkill = offsetHash.get(off); noff = off; if (dir == FORWARD) { break; } } } else { if (tkill != null && tkill != nkill){ break; } else { noff = off; } } } if (noff > -1) { st.setCaretOffset(noff); viewer.revealRange(noff, 0); } }catch (BadLocationException e) { } } }
Example 12
Source File: EditorComposite.java From RepDev with GNU General Public License v3.0 | 5 votes |
private Boolean matchVarAndGoto(Variable var, String varToMatch){ Object o; if(var.getName().equals(varToMatch)){ if( file.isLocal() ) o = RepDevMain.mainShell.openFile(new SymitarFile(file.getDir(), var.getFilename(), file.getType())); else o = RepDevMain.mainShell.openFile(new SymitarFile(sym, var.getFilename(), FileType.REPGEN)); EditorComposite editor = null; if (o instanceof EditorComposite) editor = (EditorComposite) o; // if (token.getStart() >= 0 && editor != null) { // editor.getStyledText().setTopIndex(Math.max(0, task.getLine() - 10)); try { StyledText newTxt = editor.getStyledText(); newTxt.setCaretOffset(newTxt.getText().length()); newTxt.showSelection(); newTxt.setCaretOffset(var.getPos()); editor.handleCaretChange(); // Drop Navigation Position RepDevMain.mainShell.addToNavHistory(file, txt.getLineAtOffset(txt.getCaretOffset())); newTxt.showSelection(); editor.lineHighlight(); } catch (IllegalArgumentException ex) { // Just ignore it } editor.getStyledText().setFocus(); return true; } return false; }
Example 13
Source File: EditorComposite.java From RepDev with GNU General Public License v3.0 | 5 votes |
private Boolean matchTokenAndGoto(Token token, String key, String nameToMAtch){ Object o; int i = 0; if(token.getTokenType() != null && token.getTokenType().equals(TokenType.DEFINED_VARIABLE)){ i = 1; } if(token.getTokenType() != null && (token.getTokenType().equals(TokenType.PROCEDURE) || token.getTokenType().equals(TokenType.DEFINED_VARIABLE)) && token.getStr().equalsIgnoreCase(nameToMAtch)){ if( file.isLocal() ) o = RepDevMain.mainShell.openFile(new SymitarFile(file.getDir(), key, file.getType())); else o = RepDevMain.mainShell.openFile(new SymitarFile(sym, key, FileType.REPGEN)); EditorComposite editor = null; if (o instanceof EditorComposite) editor = (EditorComposite) o; // if (token.getStart() >= 0 && editor != null) { // editor.getStyledText().setTopIndex(Math.max(0, task.getLine() - 10)); try { StyledText newTxt = editor.getStyledText(); newTxt.setCaretOffset(newTxt.getText().length()); newTxt.showSelection(); newTxt.setCaretOffset(token.getBefore().getStart()); editor.handleCaretChange(); // Drop Navigation Position RepDevMain.mainShell.addToNavHistory(file, txt.getLineAtOffset(txt.getCaretOffset())); newTxt.showSelection(); editor.lineHighlight(); } catch (IllegalArgumentException ex) { // Just ignore it } editor.getStyledText().setFocus(); return true; } return false; }
Example 14
Source File: UndoRedo.java From Rel with Apache License 2.0 | 4 votes |
public void restore(StyledText text) { text.setText(content); text.setCaretOffset(caretOffset); text.setTopIndex(topIndex); }