Java Code Examples for org.eclipse.swt.custom.StyledText#getSelection()
The following examples show how to use
org.eclipse.swt.custom.StyledText#getSelection() .
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: XtextEditor.java From xtext-eclipse with Eclipse Public License 2.0 | 6 votes |
@Override protected void setCaretPosition(final int position) { final ISourceViewer viewer = getSourceViewer(); final StyledText text = viewer.getTextWidget(); if (text != null && !text.isDisposed()) { final Point selection = text.getSelection(); final int caret = text.getCaretOffset(); final int offset = modelOffset2WidgetOffset(viewer, position); if (caret == selection.x) text.setSelectionRange(selection.y, offset - selection.y); else text.setSelectionRange(selection.x, offset - selection.x); } }
Example 2
Source File: XLIFFEditorImplWithNatTable.java From tmxeditor8 with GNU General Public License v2.0 | 6 votes |
/** * (non-Javadoc) * @see net.heartsome.cat.ts.ui.editors.IXliffEditor#getSelectPureText() */ public String getSelectPureText() { StyledTextCellEditor cellEditor = HsMultiActiveCellEditor.getFocusCellEditor(); String selectionText = null; if (cellEditor != null && !cellEditor.isClosed()) { StyledText styledText = cellEditor.getSegmentViewer().getTextWidget(); Point p = styledText.getSelection(); if (p != null) { if (p.x != p.y) { selectionText = cellEditor.getSelectedPureText(); } else { selectionText = ""; } } } if (selectionText != null) { // 将换行符替换为空 selectionText = selectionText.replaceAll("\n", ""); } return selectionText; }
Example 3
Source File: FindReplaceDialog.java From tmxeditor8 with GNU General Public License v2.0 | 6 votes |
/** * 替换 ; */ private void doReplace() { CellRegion activeCellRegion = ActiveCellRegion.getActiveCellRegion(); if (activeCellRegion == null) { return; } StyledTextCellEditor cellEditor = HsMultiActiveCellEditor.getTargetStyledEditor(); if(cellEditor != null){ StyledText text = cellEditor.getSegmentViewer().getTextWidget(); String sleText = text.getSelectionText(); if( sleText != null && sleText.toLowerCase().equals(cmbFind.getText().toLowerCase())){ Point p = text.getSelection(); text.replaceTextRange(p.x, p.y - p.x, cmbReplace.getText()); } } }
Example 4
Source File: FindReplaceDialog.java From translationstudio8 with GNU General Public License v2.0 | 6 votes |
/** * 替换 ; */ private void doReplace() { CellRegion activeCellRegion = ActiveCellRegion.getActiveCellRegion(); if (activeCellRegion == null) { return; } StyledTextCellEditor cellEditor = HsMultiActiveCellEditor.getTargetStyledEditor(); if(cellEditor != null){ StyledText text = cellEditor.getSegmentViewer().getTextWidget(); String sleText = text.getSelectionText(); String findStr = cmbFind.getText(); if (XliffEditorParameter.getInstance().isShowNonpirnttingCharacter()) { findStr = findStr.replaceAll("\\n", Constants.LINE_SEPARATOR_CHARACTER + "\n"); findStr = findStr.replaceAll("\\t", Constants.TAB_CHARACTER + "\u200B"); findStr = findStr.replaceAll(" ", Constants.SPACE_CHARACTER + "\u200B"); } if( sleText != null && sleText.toLowerCase().equals(findStr.toLowerCase())){ Point p = text.getSelection(); text.replaceTextRange(p.x, p.y - p.x, cmbReplace.getText()); } } }
Example 5
Source File: JavaEditor.java From Eclipse-Postfix-Code-Completion with Eclipse Public License 1.0 | 6 votes |
@Override protected void setCaretPosition(final int position) { final ISourceViewer viewer= getSourceViewer(); final StyledText text= viewer.getTextWidget(); if (text != null && !text.isDisposed()) { final Point selection= text.getSelection(); final int caret= text.getCaretOffset(); final int offset= modelOffset2WidgetOffset(viewer, position); if (caret == selection.x) text.setSelectionRange(selection.y, offset - selection.y); else text.setSelectionRange(selection.x, offset - selection.x); } }
Example 6
Source File: CompositeTabFolder.java From ldparteditor with MIT License | 6 votes |
public void delete() { CompositeTab selection = (CompositeTab) this.getSelection(); if (selection != null && !selection.getState().getFileNameObj().isReadOnly()) { if (!selection.getState().getFileNameObj().getVertexManager().isUpdated()){ return; } final StyledText ct = selection.getTextComposite(); final int x = ct.getSelection().x; if (ct.getSelection().y == x) { final int start = ct.getOffsetAtLine(ct.getLineAtOffset(x)); ct.setSelection(start, start + ct.getLine(ct.getLineAtOffset(x)).length()); } final int x2 = ct.getSelection().x; if (ct.getSelection().y == x2) { ct.forceFocus(); return; } ct.insert(""); //$NON-NLS-1$ ct.setSelection(new Point(x, x)); ct.forceFocus(); } }
Example 7
Source File: SubWordActions.java From Pydev with Eclipse Public License 1.0 | 6 votes |
@Override protected void setCaretPosition(final int position) { final ISourceViewer viewer = getSourceViewer(); final StyledText text = viewer.getTextWidget(); if (text != null && !text.isDisposed()) { final Point selection = text.getSelection(); final int caret = text.getCaretOffset(); final int offset = modelOffset2WidgetOffset(viewer, position); if (caret == selection.x) { text.setSelectionRange(selection.y, offset - selection.y); } else { text.setSelectionRange(selection.x, offset - selection.x); } } }
Example 8
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 9
Source File: SubWordActions.java From Pydev with Eclipse Public License 1.0 | 6 votes |
@Override protected void setCaretPosition(final int position) { final ISourceViewer viewer = getSourceViewer(); final StyledText text = viewer.getTextWidget(); if (text != null && !text.isDisposed()) { final Point selection = text.getSelection(); final int caret = text.getCaretOffset(); final int offset = modelOffset2WidgetOffset(viewer, position); if (caret == selection.x) { text.setSelectionRange(selection.y, offset - selection.y); } else { text.setSelectionRange(selection.x, offset - selection.x); } } }
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: CompositeTabFolder.java From ldparteditor with MIT License | 5 votes |
public void copy() { CompositeTab selection = (CompositeTab) this.getSelection(); if (selection != null) { final StyledText ct = selection.getTextComposite(); final int x = ct.getSelection().x; if (ct.getSelection().y == x) { final int start = ct.getOffsetAtLine(ct.getLineAtOffset(x)); ct.setSelection(start, start + ct.getLine(ct.getLineAtOffset(x)).length()); } ct.copy(); ct.forceFocus(); } }
Example 12
Source File: AbstractAutoEditTest.java From xtext-eclipse with Eclipse Public License 2.0 | 5 votes |
protected void pasteText(XtextEditor editor, String text) throws Exception { StyledText textWidget = editor.getInternalSourceViewer().getTextWidget(); Point selection = textWidget.getSelection(); Event event = new Event(); event.start = selection.x; event.end = selection.y; event.text = text; event.keyCode = KeyLookupFactory.getDefault().getCtrl(); textWidget.notifyListeners(SWT.KeyDown, event); Method sendKeyEvent = textWidget.getClass().getDeclaredMethod("sendKeyEvent", Event.class); sendKeyEvent.setAccessible(true); sendKeyEvent.invoke(textWidget, event); }
Example 13
Source File: ContentAssistant.java From APICloud-Studio with GNU General Public License v3.0 | 5 votes |
/** * @param cp * @param styledText * @param c * @param keyCode * @return */ private boolean isAutoActivationLocation(ICommonContentAssistProcessor cp, StyledText styledText, char c, int keyCode) { int offset = styledText.getCaretOffset(); Point selection = styledText.getSelection(); if (offset >= selection.x && offset <= selection.y) { offset = selection.x; } // Are we at beginning of file? if (offset == 0) { return true; } String line = styledText.getText(offset - 1, offset - 1); if (line.length() > 0) { return cp.isValidActivationCharacter(line.charAt(0), keyCode) || cp.isValidAutoActivationLocation(c, keyCode, fContentAssistSubjectControlAdapter.getDocument(), offset); } else { return false; } }
Example 14
Source File: JavaEditor.java From Eclipse-Postfix-Code-Completion with Eclipse Public License 1.0 | 5 votes |
@Override protected void setCaretPosition(final int position) { if (!validateEditorInputState()) return; final ISourceViewer viewer= getSourceViewer(); StyledText text= viewer.getTextWidget(); Point widgetSelection= text.getSelection(); if (isBlockSelectionModeEnabled() && widgetSelection.y != widgetSelection.x) { final int caret= text.getCaretOffset(); final int offset= modelOffset2WidgetOffset(viewer, position); if (caret == widgetSelection.x) text.setSelectionRange(widgetSelection.y, offset - widgetSelection.y); else text.setSelectionRange(widgetSelection.x, offset - widgetSelection.x); text.invokeAction(ST.DELETE_NEXT); } else { Point selection= viewer.getSelectedRange(); final int caret, length; if (selection.y != 0) { caret= selection.x; length= selection.y; } else { caret= widgetOffset2ModelOffset(viewer, text.getCaretOffset()); length= position - caret; } try { viewer.getDocument().replace(caret, length, ""); //$NON-NLS-1$ } catch (BadLocationException exception) { // Should not happen } } }
Example 15
Source File: SubWordActions.java From Pydev with Eclipse Public License 1.0 | 5 votes |
@Override protected void setCaretPosition(final int position) { if (!validateEditorInputState()) { return; } final ISourceViewer viewer = getSourceViewer(); StyledText text = viewer.getTextWidget(); Point widgetSelection = text.getSelection(); if (isBlockSelectionModeEnabled() && widgetSelection.y != widgetSelection.x) { final int caret = text.getCaretOffset(); final int offset = modelOffset2WidgetOffset(viewer, position); if (caret == widgetSelection.x) { text.setSelectionRange(widgetSelection.y, offset - widgetSelection.y); } else { text.setSelectionRange(widgetSelection.x, offset - widgetSelection.x); } text.invokeAction(ST.DELETE_NEXT); } else { Point selection = viewer.getSelectedRange(); final int caret, length; if (selection.y != 0) { caret = selection.x; length = selection.y; } else { caret = widgetOffset2ModelOffset(viewer, text.getCaretOffset()); length = position - caret; } try { viewer.getDocument().replace(caret, length, ""); //$NON-NLS-1$ } catch (BadLocationException exception) { // Should not happen } } }
Example 16
Source File: JavaEditor.java From Eclipse-Postfix-Code-Completion with Eclipse Public License 1.0 | 5 votes |
@Override protected void setCaretPosition(int position) { if (!validateEditorInputState()) return; final int length; final ISourceViewer viewer= getSourceViewer(); StyledText text= viewer.getTextWidget(); Point widgetSelection= text.getSelection(); if (isBlockSelectionModeEnabled() && widgetSelection.y != widgetSelection.x) { final int caret= text.getCaretOffset(); final int offset= modelOffset2WidgetOffset(viewer, position); if (caret == widgetSelection.x) text.setSelectionRange(widgetSelection.y, offset - widgetSelection.y); else text.setSelectionRange(widgetSelection.x, offset - widgetSelection.x); text.invokeAction(ST.DELETE_PREVIOUS); } else { Point selection= viewer.getSelectedRange(); if (selection.y != 0) { position= selection.x; length= selection.y; } else { length= widgetOffset2ModelOffset(viewer, text.getCaretOffset()) - position; } try { viewer.getDocument().replace(position, length, ""); //$NON-NLS-1$ } catch (BadLocationException exception) { // Should not happen } } }
Example 17
Source File: AbstractAutoEditTest.java From xtext-eclipse with Eclipse Public License 2.0 | 5 votes |
protected void pasteText(XtextEditor editor, String text) throws Exception { StyledText textWidget = editor.getInternalSourceViewer().getTextWidget(); Point selection = textWidget.getSelection(); Event event = new Event(); event.start = selection.x; event.end = selection.y; event.text = text; event.keyCode = KeyLookupFactory.getDefault().getCtrl(); textWidget.notifyListeners(SWT.KeyDown, event); Method sendKeyEvent = textWidget.getClass().getDeclaredMethod("sendKeyEvent", Event.class); sendKeyEvent.setAccessible(true); sendKeyEvent.invoke(textWidget, event); }
Example 18
Source File: SQLDataSetEditorPage.java From birt with Eclipse Public License 1.0 | 5 votes |
/** * Insert a text string into the text area * * @param text */ private void insertText( String text ) { if ( text == null ) return; StyledText textWidget = viewer.getTextWidget( ); int selectionStart = textWidget.getSelection( ).x; textWidget.insert( text ); textWidget.setSelection( selectionStart + text.length( ) ); textWidget.setFocus( ); }
Example 19
Source File: FindReplaceDialog.java From tmxeditor8 with GNU General Public License v2.0 | 5 votes |
private void replace() { if (tmxEditorImpWithNattable == null || tmxEditorImpWithNattable.isDispose()) { return; } String findStr = findTextCombo.getText(); if (findStr == null || findStr.length() == 0) { return; } String replaceStr = replaceTextCombo.getText(); if (replaceStr == null || replaceStr.length() == 0) { return; } CellEditor cellEditor = (CellEditor) TeActiveCellEditor.getCellEditor(); if (cellEditor != null) { StyledText text = cellEditor.getTextViewer().getTextWidget(); String sleText = cellEditor.getTextViewer().getSelectionText(); if (sleText != null && sleText.toLowerCase().equals(findStr.toLowerCase()) && !sleText.equals(replaceStr)) { Matcher matcher = PlaceHolderEditModeBuilder.PATTERN.matcher(sleText); StringBuilder sb = new StringBuilder(); while (matcher.find()) { sb.append(matcher.group()); } sb.insert(0, replaceStr); Point p = text.getSelection(); text.replaceTextRange(p.x, p.y - p.x, sb.toString()); text.setSelection(p.x, p.x + replaceStr.length()); TeActiveCellEditor.commitWithoutClose(); updateCombHistory(replaceTextCombo); } } }
Example 20
Source File: XtextEditor.java From xtext-eclipse with Eclipse Public License 2.0 | 5 votes |
@Override protected void setCaretPosition(final int position) { if (!validateEditorInputState()) return; final ISourceViewer viewer = getSourceViewer(); StyledText text = viewer.getTextWidget(); Point widgetSelection = text.getSelection(); if (isBlockSelectionModeEnabled() && widgetSelection.y != widgetSelection.x) { final int caret = text.getCaretOffset(); final int offset = modelOffset2WidgetOffset(viewer, position); if (caret == widgetSelection.x) text.setSelectionRange(widgetSelection.y, offset - widgetSelection.y); else text.setSelectionRange(widgetSelection.x, offset - widgetSelection.x); text.invokeAction(ST.DELETE_NEXT); } else { Point selection = viewer.getSelectedRange(); final int caret, length; if (selection.y != 0) { caret = selection.x; length = selection.y; } else { caret = widgetOffset2ModelOffset(viewer, text.getCaretOffset()); length = position - caret; } try { viewer.getDocument().replace(caret, length, ""); //$NON-NLS-1$ } catch (BadLocationException exception) { // Should not happen } } }