@Override public Point getSelection() { Point modelSelection= TextViewer.this.getSelectedRange(); Point widgetSelection= modelSelection2WidgetSelection(modelSelection); return widgetSelection != null ? widgetSelection : new Point(-1, -1); }
@Override public Point getSelection() { Point modelSelection= TextViewer.this.getSelectedRange(); Point widgetSelection= modelSelection2WidgetSelection(modelSelection); return widgetSelection != null ? widgetSelection : new Point(-1, -1); }
@Override public String getSelectionText() { Point s= TextViewer.this.getSelectedRange(); if (s.x > -1 && s.y > -1) { try { IDocument document= TextViewer.this.getDocument(); return document.get(s.x, s.y); } catch (BadLocationException x) { } } return ""; //$NON-NLS-1$ }
@Override public String getSelectionText() { Point s= TextViewer.this.getSelectedRange(); if (s.x > -1 && s.y > -1) { try { IDocument document= TextViewer.this.getDocument(); return document.get(s.x, s.y); } catch (BadLocationException x) { } } return ""; //$NON-NLS-1$ }
/** * A block is selected if the character preceding the start of the * selection is a new line character. * * @return <code>true</code> if a block is selected */ protected boolean isBlockSelected() { Point s= getSelectedRange(); if (s.y == 0) return false; try { IDocument document= getDocument(); int line= document.getLineOfOffset(s.x); int start= document.getLineOffset(line); return (s.x == start); } catch (BadLocationException x) { } return false; }
/** * A block is selected if the character preceding the start of the * selection is a new line character. * * @return <code>true</code> if a block is selected */ protected boolean isBlockSelected() { Point s= getSelectedRange(); if (s.y == 0) return false; try { IDocument document= getDocument(); int line= document.getLineOfOffset(s.x); int start= document.getLineOffset(line); return (s.x == start); } catch (BadLocationException x) { } return false; }
@Override public void replaceSelection(String text, boolean regExReplace) { Point s= TextViewer.this.getSelectedRange(); if (s.x > -1 && s.y > -1) { try { IRegion matchRegion= TextViewer.this.getFindReplaceDocumentAdapter().replace(text, regExReplace); int length= -1; if (matchRegion != null) length= matchRegion.getLength(); if (text != null && length > 0) TextViewer.this.setSelectedRange(s.x, length); } catch (BadLocationException x) { } } }
@Override public void replaceSelection(String text, boolean regExReplace) { Point s= TextViewer.this.getSelectedRange(); if (s.x > -1 && s.y > -1) { try { IRegion matchRegion= TextViewer.this.getFindReplaceDocumentAdapter().replace(text, regExReplace); int length= -1; if (matchRegion != null) length= matchRegion.getLength(); if (text != null && length > 0) TextViewer.this.setSelectedRange(s.x, length); } catch (BadLocationException x) { } } }
@Override public void getPreviousOffset(MovementEvent event) { if (event.movement != SWT.MOVEMENT_WORD_START) return; if (TRACE_DOUBLE_CLICK) { System.out.println("\n---"); //$NON-NLS-1$ print(event); } if (fDoubleClickSelection == null) { ITextDoubleClickStrategy s= (ITextDoubleClickStrategy) selectContentTypePlugin(getSelectedRange().x, fDoubleClickStrategies); if (s != null) { StyledText textWidget= getTextWidget(); s.doubleClicked(TextViewer.this); fDoubleClickSelection= textWidget.getSelection(); event.newOffset= fDoubleClickSelection.x; if (TRACE_DOUBLE_CLICK) System.out.println("- setting selection: x= " + fDoubleClickSelection.x + ", y= " + fDoubleClickSelection.y); //$NON-NLS-1$ //$NON-NLS-2$ } } else { if (fDoubleClickSelection.x <= event.offset && event.offset <= fDoubleClickSelection.y) event.newOffset= fDoubleClickSelection.x; } } }
@Override public void getPreviousOffset(MovementEvent event) { if (event.movement != SWT.MOVEMENT_WORD_START) return; if (TRACE_DOUBLE_CLICK) { System.out.println("\n---"); //$NON-NLS-1$ print(event); } if (fDoubleClickSelection == null) { ITextDoubleClickStrategy s= (ITextDoubleClickStrategy) selectContentTypePlugin(getSelectedRange().x, fDoubleClickStrategies); if (s != null) { StyledText textWidget= getTextWidget(); s.doubleClicked(TextViewer.this); fDoubleClickSelection= textWidget.getSelection(); event.newOffset= fDoubleClickSelection.x; if (TRACE_DOUBLE_CLICK) System.out.println("- setting selection: x= " + fDoubleClickSelection.x + ", y= " + fDoubleClickSelection.y); //$NON-NLS-1$ //$NON-NLS-2$ } } else { if (fDoubleClickSelection.x <= event.offset && event.offset <= fDoubleClickSelection.y) event.newOffset= fDoubleClickSelection.x; } } }
@Override public Point getLineSelection() { Point point= TextViewer.this.getSelectedRange(); try { IDocument document= TextViewer.this.getDocument(); // beginning of line int line= document.getLineOfOffset(point.x); int offset= document.getLineOffset(line); // end of line IRegion lastLineInfo= document.getLineInformationOfOffset(point.x + point.y); int lastLine= document.getLineOfOffset(point.x + point.y); int length; if (lastLineInfo.getOffset() == point.x + point.y && lastLine > 0) length= document.getLineOffset(lastLine - 1) + document.getLineLength(lastLine - 1) - offset; else length= lastLineInfo.getOffset() + lastLineInfo.getLength() - offset; return new Point(offset, length); } catch (BadLocationException e) { // should not happen return new Point(point.x, 0); } }
@Override public Point getLineSelection() { Point point= TextViewer.this.getSelectedRange(); try { IDocument document= TextViewer.this.getDocument(); // beginning of line int line= document.getLineOfOffset(point.x); int offset= document.getLineOffset(line); // end of line IRegion lastLineInfo= document.getLineInformationOfOffset(point.x + point.y); int lastLine= document.getLineOfOffset(point.x + point.y); int length; if (lastLineInfo.getOffset() == point.x + point.y && lastLine > 0) length= document.getLineOffset(lastLine - 1) + document.getLineLength(lastLine - 1) - offset; else length= lastLineInfo.getOffset() + lastLineInfo.getLength() - offset; return new Point(offset, length); } catch (BadLocationException e) { // should not happen return new Point(point.x, 0); } }
/** * Returns <code>true</code> if one line is completely selected or if multiple lines are selected. * Being completely selected means that all characters except the new line characters are * selected. * * @return <code>true</code> if one or multiple lines are selected * @since 2.0 */ protected boolean areMultipleLinesSelected() { Point s= getSelectedRange(); if (s.y == 0) return false; try { IDocument document= getDocument(); int startLine= document.getLineOfOffset(s.x); int endLine= document.getLineOfOffset(s.x + s.y); IRegion line= document.getLineInformation(startLine); return startLine != endLine || (s.x == line.getOffset() && s.y == line.getLength()); } catch (BadLocationException x) { } return false; }
/** * Returns <code>true</code> if one line is completely selected or if multiple lines are selected. * Being completely selected means that all characters except the new line characters are * selected. * * @return <code>true</code> if one or multiple lines are selected * @since 2.0 */ protected boolean areMultipleLinesSelected() { Point s= getSelectedRange(); if (s.y == 0) return false; try { IDocument document= getDocument(); int startLine= document.getLineOfOffset(s.x); int endLine= document.getLineOfOffset(s.x + s.y); IRegion line= document.getLineInformation(startLine); return startLine != endLine || (s.x == line.getOffset() && s.y == line.getLength()); } catch (BadLocationException x) { } return false; }
Point p= getSelectedRange(); if (p.x == -1 || p.y == -1) return TextSelection.emptySelection();
Point p= getSelectedRange(); if (p.x == -1 || p.y == -1) return TextSelection.emptySelection();
int caretOffset= fTextWidget.getCaretOffset(); fReverseSelection= caretOffset == range.x; Point selectionRange= getSelectedRange(); fSelection= new Position(selectionRange.x, selectionRange.y);
int caretOffset= fTextWidget.getCaretOffset(); fReverseSelection= caretOffset == range.x; Point selectionRange= getSelectedRange(); fSelection= new Position(selectionRange.x, selectionRange.y);