use of org.eclipse.jface.text.ITextViewerExtension in project xtext-eclipse by eclipse.
the class MarkRegionTargetWithoutStatusline method swapMarkAndCursor.
@Override
public void swapMarkAndCursor() {
if (!(fViewer instanceof ITextViewerExtension))
return;
ITextViewerExtension viewerExtension = ((ITextViewerExtension) fViewer);
int markPosition = viewerExtension.getMark();
if (markPosition == -1) {
return;
}
if (!isVisible(fViewer, markPosition)) {
return;
}
Point selection = fViewer.getSelectedRange();
viewerExtension.setMark(selection.x);
fViewer.setSelectedRange(markPosition, 0);
fViewer.revealRange(markPosition, 0);
}
use of org.eclipse.jface.text.ITextViewerExtension in project eclipse.platform.text by eclipse.
the class AbstractTextEditor method setWordWrap.
/**
* @see org.eclipse.ui.texteditor.ITextEditorExtension6#setWordWrap(boolean)
* @since 3.10
*/
@Override
public void setWordWrap(boolean enable) {
if (!isWordWrapSupported() || isWordWrapEnabled() == enable) {
return;
}
ISourceViewer viewer = getSourceViewer();
if (viewer != null) {
StyledText styledText = viewer.getTextWidget();
if (styledText != null) {
if (isBlockSelectionModeEnabled()) {
setBlockSelectionMode(false);
}
styledText.setWordWrap(enable);
if (fVerticalRuler != null) {
// update ruler layout so that it can consider
// changed horizontal scrollbar visibility
boolean updated = false;
if (viewer instanceof ITextViewerExtension) {
Control control = ((ITextViewerExtension) viewer).getControl();
if (control instanceof Composite) {
((Composite) control).layout();
updated = true;
}
}
if (!updated) {
fVerticalRuler.update();
}
}
}
}
}
use of org.eclipse.jface.text.ITextViewerExtension in project eclipse.platform.text by eclipse.
the class AbstractTextEditor method setFont.
/**
* Sets the font for the given viewer sustaining selection and scroll position.
*
* @param sourceViewer the source viewer
* @param font the font
* @since 2.0
*/
private void setFont(ISourceViewer sourceViewer, Font font) {
if (sourceViewer.getDocument() != null) {
ISelectionProvider provider = sourceViewer.getSelectionProvider();
ISelection selection = provider.getSelection();
int topIndex = sourceViewer.getTopIndex();
StyledText styledText = sourceViewer.getTextWidget();
Control parent = styledText;
if (sourceViewer instanceof ITextViewerExtension) {
ITextViewerExtension extension = (ITextViewerExtension) sourceViewer;
parent = extension.getControl();
}
parent.setRedraw(false);
styledText.setFont(font);
if (fVerticalRuler instanceof IVerticalRulerExtension) {
IVerticalRulerExtension e = (IVerticalRulerExtension) fVerticalRuler;
e.setFont(font);
}
provider.setSelection(selection);
sourceViewer.setTopIndex(topIndex);
if (parent instanceof Composite) {
Composite composite = (Composite) parent;
composite.layout(true);
}
parent.setRedraw(true);
} else {
StyledText styledText = sourceViewer.getTextWidget();
styledText.setFont(font);
if (fVerticalRuler instanceof IVerticalRulerExtension) {
IVerticalRulerExtension e = (IVerticalRulerExtension) fVerticalRuler;
e.setFont(font);
}
}
}
use of org.eclipse.jface.text.ITextViewerExtension in project eclipse.platform.text by eclipse.
the class CaseAction method run.
@Override
public void run() {
ITextEditor editor = getTextEditor();
if (editor == null)
return;
if (!validateEditorInputState())
return;
ISourceViewer viewer = ((AbstractTextEditor) editor).getSourceViewer();
if (viewer == null)
return;
IDocument document = viewer.getDocument();
if (document == null)
return;
StyledText st = viewer.getTextWidget();
if (st == null)
return;
ITextSelection selection = (ITextSelection) viewer.getSelectionProvider().getSelection();
int adjustment = 0;
try {
if (JFaceTextUtil.isEmpty(viewer, selection))
return;
IRegion[] ranges = JFaceTextUtil.getCoveredRanges(viewer, selection);
if (ranges.length > 1 && viewer instanceof ITextViewerExtension)
((ITextViewerExtension) viewer).getRewriteTarget().beginCompoundChange();
for (int i = 0; i < ranges.length; i++) {
IRegion region = ranges[i];
String target = document.get(region.getOffset(), region.getLength());
String replacement = (fToUpper ? target.toUpperCase() : target.toLowerCase());
if (!target.equals(replacement)) {
document.replace(region.getOffset(), region.getLength(), replacement);
// https://bugs.eclipse.org/bugs/show_bug.cgi?id=145326: replacement might be larger than the original
adjustment = replacement.length() - target.length();
}
}
if (ranges.length > 1 && viewer instanceof ITextViewerExtension)
((ITextViewerExtension) viewer).getRewriteTarget().endCompoundChange();
} catch (BadLocationException x) {
// ignore and return
return;
}
// reinstall selection and move it into view
if (!(selection instanceof IBlockTextSelection))
viewer.setSelectedRange(selection.getOffset(), selection.getLength() + adjustment);
else
viewer.getSelectionProvider().setSelection(selection);
// don't use the viewer's reveal feature in order to avoid jumping around
st.showSelection();
}
use of org.eclipse.jface.text.ITextViewerExtension in project eclipse.platform.text by eclipse.
the class IncrementalFindTarget method install.
/**
* Installs this target. I.e. adds all required listeners.
*/
private void install() {
if (fInstalled)
return;
StyledText text = fTextViewer.getTextWidget();
if (text == null)
return;
text.addMouseListener(this);
text.addFocusListener(this);
fTextViewer.addTextListener(this);
ISelectionProvider selectionProvider = fTextViewer.getSelectionProvider();
if (selectionProvider != null)
selectionProvider.addSelectionChangedListener(this);
if (fTextViewer instanceof ITextViewerExtension)
((ITextViewerExtension) fTextViewer).prependVerifyKeyListener(this);
else
text.addVerifyKeyListener(this);
ICommandService commandService = PlatformUI.getWorkbench().getAdapter(ICommandService.class);
if (commandService != null)
commandService.addExecutionListener(this);
fInstalled = true;
}
Aggregations