Search in sources :

Example 1 with ContentFormatter

use of org.eclipse.xtext.ui.editor.formatting2.ContentFormatter in project xtext-xtend by eclipse.

the class XtendFormatterPreview method doUpdate.

@SuppressWarnings("deprecation")
public void doUpdate(final Map<String, String> map) {
    checkEditorHandleIsSet();
    final MapBasedPreferenceValues values = new MapBasedPreferenceValues(map);
    String maxLineWidthValue = values.getPreference(maxLineWidth);
    if (maxLineWidthValue != null) {
        moveMarginToColumn(maxLineWidthValue);
    }
    StyledText widget = null;
    try {
        widget = (StyledText) editorHandle.getViewer().getControl();
        // disable redraw, otherwise this would causes funny animation effects during formating.
        widget.setRedraw(false);
        this.modelAccess.updateModel("", previewContent, "");
        XtextDocument document = editorHandle.getDocument();
        ContentFormatter formatter = formatterProvider.get();
        formatter.setPreferencesProvider(values);
        formatter.format(document, new Region(0, document.getLength()));
        // reset selection, otherwise the whole new content will be selected
        editorHandle.getViewer().setSelection(null);
    } finally {
        if (widget != null)
            widget.setRedraw(true);
    }
}
Also used : StyledText(org.eclipse.swt.custom.StyledText) MapBasedPreferenceValues(org.eclipse.xtext.preferences.MapBasedPreferenceValues) Region(org.eclipse.jface.text.Region) XtextDocument(org.eclipse.xtext.ui.editor.model.XtextDocument) ContentFormatter(org.eclipse.xtext.ui.editor.formatting2.ContentFormatter)

Aggregations

Region (org.eclipse.jface.text.Region)1 StyledText (org.eclipse.swt.custom.StyledText)1 MapBasedPreferenceValues (org.eclipse.xtext.preferences.MapBasedPreferenceValues)1 ContentFormatter (org.eclipse.xtext.ui.editor.formatting2.ContentFormatter)1 XtextDocument (org.eclipse.xtext.ui.editor.model.XtextDocument)1