public void updateSelection(MergeSourceViewer viewer, boolean includeScroll) { if (fSelection != null) viewer.getSourceViewer().setSelection(fSelection); if (includeScroll && fTopIndex != -1) { viewer.getSourceViewer().setTopIndex(fTopIndex); } }
public boolean show(ShowInContext context) { ISelection selection = context.getSelection(); if (selection instanceof IStructuredSelection) { for (Object element : ((IStructuredSelection) selection).toArray()) { if (element instanceof OutlineItem) { OutlineItem item = (OutlineItem) element; viewer.setSelection(new TextSelection(item.getOffset(), item.getLength()), true); return true; } } } else if (selection instanceof ITextSelection) { viewer.setSelection(selection, true); return true; } return false; }
protected void setSelection(ITextRegion textSelection, boolean reveal) { StyledText text = getSourceViewer().getTextWidget(); if (text.getText().length() >= textSelection.getOffset() + textSelection.getLength()) { getSourceViewer().setSelection(new TextSelection(textSelection.getOffset(), textSelection.getLength()), reveal); } }
fSourceViewer.setSelection(null);
public void update() { if (fWorkingValues == null) { fPreviewDocument.set(""); //$NON-NLS-1$ return; } // update the print margin final String value= fWorkingValues.get(DefaultCodeFormatterConstants.FORMATTER_LINE_SPLIT); final int lineWidth= getPositiveIntValue(value, 0); fMarginPainter.setMarginRulerColumn(lineWidth); // update the tab size final int tabSize= getPositiveIntValue(fWorkingValues.get(DefaultCodeFormatterConstants.FORMATTER_TAB_SIZE), 0); if (tabSize != fTabSize) fSourceViewer.getTextWidget().setTabs(tabSize); fTabSize= tabSize; final StyledText widget= (StyledText)fSourceViewer.getControl(); final int height= widget.getClientArea().height; final int top0= widget.getTopPixel(); final int totalPixels0= getHeightOfAllLines(widget); final int topPixelRange0= totalPixels0 > height ? totalPixels0 - height : 0; widget.setRedraw(false); doFormatPreview(); fSourceViewer.setSelection(null); final int totalPixels1= getHeightOfAllLines(widget); final int topPixelRange1= totalPixels1 > height ? totalPixels1 - height : 0; final int top1= topPixelRange0 > 0 ? (int)(topPixelRange1 * top0 / (double)topPixelRange0) : 0; widget.setTopPixel(top1); widget.setRedraw(true); }
fSourceViewer.getUndoManager().reset(); fSourceViewer.setSelection(null);
/** * Restores a previously saved selection in the document. * <p> * If no selection was previously saved, nothing happens. * * @since 3.0 */ protected void restoreSelection() { if (!fSelections.isEmpty()) { final IDocument document= getDocument(); final Position position= fSelections.pop(); try { document.removePosition(fSelectionCategory, position); Point currentSelection= getSelectedRange(); if (currentSelection == null || currentSelection.x != position.getOffset() || currentSelection.y != position.getLength()) { if (position instanceof ColumnPosition && getTextWidget().getBlockSelection()) { setSelection(new BlockTextSelection(document, document.getLineOfOffset(position.getOffset()), ((ColumnPosition) position).fStartColumn, document.getLineOfOffset(position.getOffset() + position.getLength()), ((ColumnPosition) position).fEndColumn, getTextWidget().getTabs())); } else { setSelectedRange(position.getOffset(), position.getLength()); } } if (fSelections.isEmpty()) clearRememberedSelection(); } catch (BadPositionCategoryException exception) { // Should not happen } catch (BadLocationException x) { // Should not happen } } }
/** * Restores a previously saved selection in the document. * <p> * If no selection was previously saved, nothing happens. * * @since 3.0 */ protected void restoreSelection() { if (!fSelections.isEmpty()) { final IDocument document= getDocument(); final Position position= fSelections.pop(); try { document.removePosition(fSelectionCategory, position); Point currentSelection= getSelectedRange(); if (currentSelection == null || currentSelection.x != position.getOffset() || currentSelection.y != position.getLength()) { if (position instanceof ColumnPosition && getTextWidget().getBlockSelection()) { setSelection(new BlockTextSelection(document, document.getLineOfOffset(position.getOffset()), ((ColumnPosition) position).fStartColumn, document.getLineOfOffset(position.getOffset() + position.getLength()), ((ColumnPosition) position).fEndColumn, getTextWidget().getTabs())); } else { setSelectedRange(position.getOffset(), position.getLength()); } } if (fSelections.isEmpty()) clearRememberedSelection(); } catch (BadPositionCategoryException exception) { // Should not happen } catch (BadLocationException x) { // Should not happen } } }