blob: e608f17afe2e39d31253825d1633766914cb2645 [file] [log] [blame]
package org.eclipse.ui.tests.internal;
import org.eclipse.swt.graphics.Point;
import org.eclipse.swt.widgets.Composite;
import org.eclipse.jface.text.source.IVerticalRuler;
import org.eclipse.jface.text.source.SourceViewer;
import org.eclipse.jface.viewers.ISelection;
import org.eclipse.jface.viewers.SelectionChangedEvent;
public class ExtendedSourceViewer extends SourceViewer {
/**
* Constructs a new source viewer. The vertical ruler is initially visible.
* The viewer has not yet been initialized with a source viewer configuration.
*
* @param parent the parent of the viewer's control
* @param ruler the vertical ruler used by this source viewer
* @param styles the SWT style bits
*/
public ExtendedSourceViewer(Composite parent, IVerticalRuler ruler, int styles) {
super(parent, ruler, styles);
}
/*
* @see Viewer#getSelection()
*/
public ISelection getSelection() {
Point p= getSelectedRange();
if (p.x == -1 || p.y == -1)
return ExtendedTextSelection.emptySelection();
return new ExtendedTextSelection(getDocument(), p.x, p.y);
}
/**
* Sends out a selection changed event to all registered listeners.
*
* @param offset the offset of the newly selected range
* @param length the length of the newly selected range
*/
protected void selectionChanged(int offset, int length) {
ISelection selection= new ExtendedTextSelection(getDocument(), offset, length);
SelectionChangedEvent event= new SelectionChangedEvent(this, selection);
fireSelectionChanged(event);
}
}