use of org.eclipse.swt.custom.StyledText in project eclipse.platform.text by eclipse.
the class GotoLineTest method goToLine.
private void goToLine(int line, int expectedResult) {
IWorkbench workbench = PlatformUI.getWorkbench();
IWorkbenchPage page = workbench.getActiveWorkbenchWindow().getActivePage();
try {
IEditorPart part = IDE.openEditor(page, fFile);
if (part instanceof ITextEditor) {
ITextEditor editor = (ITextEditor) part;
IAction action = editor.getAction(ITextEditorActionConstants.GOTO_LINE);
Accessor accessor = new Accessor(action, GotoLineAction.class);
accessor.invoke("gotoLine", new Class[] { int.class }, new Integer[] { Integer.valueOf(line) });
Control control = part.getAdapter(Control.class);
if (control instanceof StyledText) {
int caretLine = -1;
StyledText styledText = (StyledText) control;
int caret = styledText.getCaretOffset();
try {
IDocument document = editor.getDocumentProvider().getDocument(editor.getEditorInput());
caretLine = document.getLineOfOffset(caret);
} catch (BadLocationException e1) {
fail();
}
assertEquals(expectedResult, caretLine);
} else
fail();
} else
fail();
} catch (PartInitException e) {
fail();
}
}
use of org.eclipse.swt.custom.StyledText in project eclipse.platform.text by eclipse.
the class SegmentedModeTest method testShowNothing.
/*
* @see https://bugs.eclipse.org/bugs/show_bug.cgi?id=465684
*/
@Test
public void testShowNothing() {
IWorkbench workbench = PlatformUI.getWorkbench();
IWorkbenchPage page = workbench.getActiveWorkbenchWindow().getActivePage();
try {
while (Display.getDefault().readAndDispatch()) {
}
IEditorPart part = IDE.openEditor(page, fFile);
try {
if (part instanceof ITextEditor) {
ITextEditor editor = (ITextEditor) part;
editor.showHighlightRangeOnly(true);
editor.setHighlightRange(0, 0, true);
Control control = part.getAdapter(Control.class);
if (control instanceof StyledText) {
StyledText styledText = (StyledText) control;
String text = styledText.getText();
assertEquals("", text);
}
}
} finally {
page.saveEditor(part, false);
}
} catch (PartInitException e) {
assertTrue(false);
}
}
use of org.eclipse.swt.custom.StyledText in project eclipse.platform.text by eclipse.
the class RetrieverAction method extractSearchTextFromWidget.
protected final String extractSearchTextFromWidget(Control control) {
String sel = null;
if (control instanceof Combo) {
Combo combo = (Combo) control;
sel = combo.getText();
Point selection = combo.getSelection();
sel = sel.substring(selection.x, selection.y);
}
if (control instanceof CCombo) {
CCombo combo = (CCombo) control;
sel = combo.getText();
Point selection = combo.getSelection();
sel = sel.substring(selection.x, selection.y);
} else if (control instanceof Text) {
Text text = (Text) control;
sel = text.getSelectionText();
} else if (control instanceof FormText) {
FormText text = (FormText) control;
sel = text.getSelectionText();
} else if (control instanceof StyledText) {
StyledText text = (StyledText) control;
sel = text.getSelectionText();
} else if (control instanceof Tree) {
Tree tree = (Tree) control;
TreeItem[] s = tree.getSelection();
if (s.length > 0) {
sel = s[0].getText();
}
} else if (control instanceof Table) {
Table tree = (Table) control;
TableItem[] s = tree.getSelection();
if (s.length > 0) {
sel = s[0].getText();
}
} else if (control instanceof List) {
List list = (List) control;
String[] s = list.getSelection();
if (s.length > 0) {
sel = s[0];
}
}
if (sel != null) {
sel = trimSearchString(sel);
}
return sel;
}
use of org.eclipse.swt.custom.StyledText in project eclipse.platform.text by eclipse.
the class OverviewRuler method createControl.
@Override
public Control createControl(Composite parent, ITextViewer textViewer) {
fTextViewer = textViewer;
fHitDetectionCursor = parent.getDisplay().getSystemCursor(SWT.CURSOR_HAND);
fHeader = new Canvas(parent, SWT.NONE);
if (fAnnotationAccess instanceof IAnnotationAccessExtension) {
fHeader.addMouseTrackListener(new MouseTrackAdapter() {
/*
* @see org.eclipse.swt.events.MouseTrackAdapter#mouseHover(org.eclipse.swt.events.MouseEvent)
* @since 3.3
*/
@Override
public void mouseEnter(MouseEvent e) {
updateHeaderToolTipText();
}
});
}
fCanvas = new Canvas(parent, SWT.NO_BACKGROUND);
fCanvas.addPaintListener(new PaintListener() {
@Override
public void paintControl(PaintEvent event) {
if (fTextViewer != null)
doubleBufferPaint(event.gc);
}
});
fCanvas.addDisposeListener(new DisposeListener() {
@Override
public void widgetDisposed(DisposeEvent event) {
handleDispose();
fTextViewer = null;
}
});
fCanvas.addMouseListener(new MouseAdapter() {
@Override
public void mouseDown(MouseEvent event) {
handleMouseDown(event);
}
});
fCanvas.addMouseMoveListener(new MouseMoveListener() {
@Override
public void mouseMove(MouseEvent event) {
handleMouseMove(event);
}
});
fCanvas.addMouseWheelListener(new MouseWheelListener() {
@Override
public void mouseScrolled(MouseEvent e) {
handleMouseScrolled(e);
}
});
if (fTextViewer != null) {
fTextViewer.addTextListener(fInternalListener);
// on word wrap toggle a "resized" ControlEvent is fired: suggest a redraw of the ruler
fTextViewer.getTextWidget().addControlListener(new ControlAdapter() {
@Override
public void controlResized(ControlEvent e) {
if (fTextViewer == null) {
return;
}
StyledText textWidget = fTextViewer.getTextWidget();
if (textWidget != null && textWidget.getWordWrap()) {
redraw();
}
}
});
}
return fCanvas;
}
use of org.eclipse.swt.custom.StyledText in project eclipse.platform.text by eclipse.
the class OverviewRuler method doPaint.
/**
* Draws this overview ruler.
*
* @param gc the GC to draw into
*/
private void doPaint(GC gc) {
Rectangle r = new Rectangle(0, 0, 0, 0);
int yy, hh = ANNOTATION_HEIGHT;
IDocument document = fTextViewer.getDocument();
StyledText textWidget = fTextViewer.getTextWidget();
ITextViewerExtension5 extension = null;
IRegion visible = null;
if (fTextViewer instanceof ITextViewerExtension5)
extension = (ITextViewerExtension5) fTextViewer;
else
// legacy support
visible = fTextViewer.getVisibleRegion();
WidgetInfos infos = null;
for (Object annotationType : fAnnotationsSortedByLayer) {
if (skip(annotationType))
continue;
int[] style = new int[] { FilterIterator.PERSISTENT, FilterIterator.TEMPORARY };
for (int element : style) {
boolean areColorsComputed = false;
Color fill = null;
Color stroke = null;
Iterator<Annotation> e = new FilterIterator(annotationType, element, fCachedAnnotations.iterator());
while (e.hasNext()) {
Annotation a = e.next();
Position p = fModel.getPosition(a);
if (p == null)
continue;
if (visible != null && !p.overlapsWith(visible.getOffset(), visible.getLength()))
continue;
int annotationOffset = p.getOffset();
int annotationLength = p.getLength();
IRegion widgetRegion = null;
if (visible != null) {
annotationOffset = Math.max(p.getOffset(), visible.getOffset());
int annotationEnd = Math.min(p.getOffset() + p.getLength(), visible.getOffset() + visible.getLength());
annotationLength = annotationEnd - annotationOffset;
} else {
widgetRegion = extension.modelRange2WidgetRange(new Region(annotationOffset, annotationLength));
if (widgetRegion == null)
continue;
}
if (infos == null) {
infos = new WidgetInfos(textWidget, fCanvas);
r.x = INSET;
r.width = infos.bounds.width - (2 * INSET);
}
try {
int startOffset = visible != null ? annotationOffset - visible.getOffset() : widgetRegion.getOffset();
int startLine = textWidget.getLineAtOffset(startOffset);
yy = computeY(startLine, infos);
if (ANNOTATION_HEIGHT_SCALABLE) {
int numberOfLines = document.getNumberOfLines(annotationOffset, annotationLength);
// don't count empty trailing line
IRegion lastLine = document.getLineInformationOfOffset(annotationOffset + annotationLength);
if (lastLine.getOffset() == annotationOffset + annotationLength) {
numberOfLines--;
}
if (numberOfLines > 1) {
int yy2 = computeY(startLine + numberOfLines - 1, infos);
hh = Math.max(yy2 - yy, ANNOTATION_HEIGHT);
} else {
hh = ANNOTATION_HEIGHT;
}
}
fAnnotationHeight = hh;
if (!areColorsComputed) {
stroke = getStrokeColor(annotationType, element == FilterIterator.TEMPORARY);
fill = fUseSaturatedColors ? stroke : getFillColor(annotationType, element == FilterIterator.TEMPORARY);
areColorsComputed = true;
}
if (fill != null) {
gc.setBackground(fill);
gc.fillRectangle(INSET, yy, infos.bounds.width - (2 * INSET), hh);
}
if (stroke != null) {
gc.setForeground(stroke);
r.y = yy;
if (yy + hh == infos.bounds.height)
r.y--;
r.height = hh;
// NOTE: 0 means width is 1 but with optimized performance
gc.setLineWidth(0);
gc.drawRectangle(r);
}
} catch (BadLocationException x) {
}
}
}
}
if (DEBUG_DRAW) {
// draw debugging guides (boundaries):
if (infos == null)
infos = new WidgetInfos(textWidget, fCanvas);
gc.setForeground(gc.getDevice().getSystemColor(SWT.COLOR_DARK_MAGENTA));
yy = infos.thumbHeight / 2;
gc.drawLine(0, yy, infos.bounds.x / 2, yy);
yy = infos.bounds.height - infos.thumbHeight / 2;
gc.drawLine(0, yy, infos.bounds.x / 2, yy);
gc.setForeground(gc.getDevice().getSystemColor(SWT.COLOR_BLUE));
yy = 0;
gc.drawLine(0, yy, infos.bounds.x / 2, yy);
yy = infos.bounds.height - 1;
gc.drawLine(0, yy, infos.bounds.x / 2, yy);
}
}
Aggregations