Search in sources :

Example 1 with ITextViewerExtension6

use of org.eclipse.jface.text.ITextViewerExtension6 in project xtext-eclipse by eclipse.

the class DefaultContentViewer method configureSourceViewer.

@Override
protected void configureSourceViewer(ISourceViewer sourceViewer) {
    sourceViewer.setEditable(false);
    sourceViewer.configure(sourceViewerConfiguration);
    if (sourceViewer instanceof ITextViewerExtension6) {
        ITextViewerExtension6 textViewerExtension6 = (ITextViewerExtension6) sourceViewer;
        textViewerExtension6.setHyperlinkDetectors(null, sourceViewerConfiguration.getHyperlinkStateMask(sourceViewer));
    }
    if (sourceViewer instanceof ITextViewerExtension2) {
        ITextViewerExtension2 textViewerExtension2 = (ITextViewerExtension2) sourceViewer;
        String[] configuredContentTypes = sourceViewerConfiguration.getConfiguredContentTypes(sourceViewer);
        for (String contentType : configuredContentTypes) {
            textViewerExtension2.removeTextHovers(contentType);
        }
    }
}
Also used : ITextViewerExtension2(org.eclipse.jface.text.ITextViewerExtension2) ITextViewerExtension6(org.eclipse.jface.text.ITextViewerExtension6)

Example 2 with ITextViewerExtension6

use of org.eclipse.jface.text.ITextViewerExtension6 in project xtext-eclipse by eclipse.

the class LinkedEditingUndoSupport method startRecording.

public void startRecording(XtextEditor editor) {
    this.editor = editor;
    ISourceViewer viewer = editor.getInternalSourceViewer();
    if (viewer instanceof ITextViewerExtension6) {
        IUndoManager undoManager = ((ITextViewerExtension6) viewer).getUndoManager();
        if (undoManager instanceof IUndoManagerExtension) {
            IUndoManagerExtension undoManagerExtension = (IUndoManagerExtension) undoManager;
            IUndoContext undoContext = undoManagerExtension.getUndoContext();
            IOperationHistory operationHistory = OperationHistoryFactory.getOperationHistory();
            startingUndoOperation = operationHistory.getUndoOperation(undoContext);
        }
    }
}
Also used : IUndoContext(org.eclipse.core.commands.operations.IUndoContext) IUndoManager(org.eclipse.jface.text.IUndoManager) ITextViewerExtension6(org.eclipse.jface.text.ITextViewerExtension6) IOperationHistory(org.eclipse.core.commands.operations.IOperationHistory) ISourceViewer(org.eclipse.jface.text.source.ISourceViewer) IUndoManagerExtension(org.eclipse.jface.text.IUndoManagerExtension)

Example 3 with ITextViewerExtension6

use of org.eclipse.jface.text.ITextViewerExtension6 in project eclipse.platform.text by eclipse.

the class AbstractTextEditor method handlePreferenceStoreChanged.

/**
 * Handles a property change event describing a change of the editor's
 * preference store and updates the preference related editor properties.
 * <p>
 * Subclasses may extend.
 * </p>
 *
 * @param event the property change event
 */
protected void handlePreferenceStoreChanged(PropertyChangeEvent event) {
    if (fSourceViewer == null)
        return;
    String property = event.getProperty();
    if (getFontPropertyPreferenceKey().equals(property))
        // There is a separate handler for font preference changes
        return;
    if (PREFERENCE_COLOR_FOREGROUND.equals(property) || PREFERENCE_COLOR_FOREGROUND_SYSTEM_DEFAULT.equals(property) || PREFERENCE_COLOR_BACKGROUND.equals(property) || PREFERENCE_COLOR_BACKGROUND_SYSTEM_DEFAULT.equals(property) || PREFERENCE_COLOR_SELECTION_FOREGROUND.equals(property) || PREFERENCE_COLOR_SELECTION_FOREGROUND_SYSTEM_DEFAULT.equals(property) || PREFERENCE_COLOR_SELECTION_BACKGROUND.equals(property) || PREFERENCE_COLOR_SELECTION_BACKGROUND_SYSTEM_DEFAULT.equals(property)) {
        initializeViewerColors(fSourceViewer);
    } else if (PREFERENCE_COLOR_FIND_SCOPE.equals(property)) {
        initializeFindScopeColor(fSourceViewer);
    } else if (PREFERENCE_USE_CUSTOM_CARETS.equals(property)) {
        updateCaret();
    } else if (PREFERENCE_WIDE_CARET.equals(property)) {
        updateCaret();
    }
    if (affectsTextPresentation(event))
        fSourceViewer.invalidateTextPresentation();
    if (PREFERENCE_HYPERLINKS_ENABLED.equals(property)) {
        if (fSourceViewer instanceof ITextViewerExtension6) {
            IHyperlinkDetector[] detectors = getSourceViewerConfiguration().getHyperlinkDetectors(fSourceViewer);
            int stateMask = getSourceViewerConfiguration().getHyperlinkStateMask(fSourceViewer);
            ITextViewerExtension6 textViewer6 = (ITextViewerExtension6) fSourceViewer;
            textViewer6.setHyperlinkDetectors(detectors, stateMask);
        }
        return;
    }
    if (PREFERENCE_HYPERLINK_KEY_MODIFIER.equals(property)) {
        if (fSourceViewer instanceof ITextViewerExtension6) {
            ITextViewerExtension6 textViewer6 = (ITextViewerExtension6) fSourceViewer;
            IHyperlinkDetector[] detectors = getSourceViewerConfiguration().getHyperlinkDetectors(fSourceViewer);
            int stateMask = getSourceViewerConfiguration().getHyperlinkStateMask(fSourceViewer);
            textViewer6.setHyperlinkDetectors(detectors, stateMask);
        }
        return;
    }
    if (PREFERENCE_RULER_CONTRIBUTIONS.equals(property)) {
        String[] difference = StringSetSerializer.getDifference((String) event.getOldValue(), (String) event.getNewValue());
        IColumnSupport support = getAdapter(IColumnSupport.class);
        for (int i = 0; i < difference.length; i++) {
            RulerColumnDescriptor desc = RulerColumnRegistry.getDefault().getColumnDescriptor(difference[i]);
            if (desc != null && support.isColumnSupported(desc)) {
                boolean newState = !support.isColumnVisible(desc);
                support.setColumnVisible(desc, newState);
            }
        }
        return;
    }
    if (PREFERENCE_SHOW_WHITESPACE_CHARACTERS.equals(property) || PREFERENCE_SHOW_LEADING_SPACES.equals(property) || PREFERENCE_SHOW_ENCLOSED_SPACES.equals(property) || PREFERENCE_SHOW_TRAILING_SPACES.equals(property) || PREFERENCE_SHOW_LEADING_IDEOGRAPHIC_SPACES.equals(property) || PREFERENCE_SHOW_ENCLOSED_IDEOGRAPHIC_SPACES.equals(property) || PREFERENCE_SHOW_TRAILING_IDEOGRAPHIC_SPACES.equals(property) || PREFERENCE_SHOW_LEADING_TABS.equals(property) || PREFERENCE_SHOW_ENCLOSED_TABS.equals(property) || PREFERENCE_SHOW_TRAILING_TABS.equals(property) || PREFERENCE_SHOW_CARRIAGE_RETURN.equals(property) || PREFERENCE_SHOW_LINE_FEED.equals(property) || PREFERENCE_WHITESPACE_CHARACTER_ALPHA_VALUE.equals(property)) {
        IAction action = getAction(ITextEditorActionConstants.SHOW_WHITESPACE_CHARACTERS);
        if (action instanceof IUpdate)
            ((IUpdate) action).update();
        return;
    }
    if (PREFERENCE_TEXT_DRAG_AND_DROP_ENABLED.equals(property)) {
        IPreferenceStore store = getPreferenceStore();
        if (store != null && store.getBoolean(PREFERENCE_TEXT_DRAG_AND_DROP_ENABLED))
            installTextDragAndDrop(getSourceViewer());
        else
            uninstallTextDragAndDrop(getSourceViewer());
        return;
    }
    if (PREFERENCE_HOVER_ENRICH_MODE.equals(property)) {
        if (fSourceViewer instanceof ITextViewerExtension8) {
            IPreferenceStore store = getPreferenceStore();
            if (store != null) {
                ((ITextViewerExtension8) fSourceViewer).setHoverEnrichMode(convertEnrichModePreference(store.getInt(PREFERENCE_HOVER_ENRICH_MODE)));
            }
        }
        return;
    }
}
Also used : IHyperlinkDetector(org.eclipse.jface.text.hyperlink.IHyperlinkDetector) IAction(org.eclipse.jface.action.IAction) ITextViewerExtension6(org.eclipse.jface.text.ITextViewerExtension6) Point(org.eclipse.swt.graphics.Point) RulerColumnDescriptor(org.eclipse.ui.texteditor.rulers.RulerColumnDescriptor) ITextViewerExtension8(org.eclipse.jface.text.ITextViewerExtension8) IColumnSupport(org.eclipse.ui.texteditor.rulers.IColumnSupport) IPreferenceStore(org.eclipse.jface.preference.IPreferenceStore)

Example 4 with ITextViewerExtension6

use of org.eclipse.jface.text.ITextViewerExtension6 in project eclipse.platform.text by eclipse.

the class AbstractDecoratedTextEditor method handlePreferenceStoreChanged.

@Override
protected void handlePreferenceStoreChanged(PropertyChangeEvent event) {
    try {
        ISourceViewer sourceViewer = getSourceViewer();
        if (sourceViewer == null)
            return;
        String property = event.getProperty();
        if (fSourceViewerDecorationSupport != null && fOverviewRuler != null && OVERVIEW_RULER.equals(property)) {
            if (isOverviewRulerVisible())
                showOverviewRuler();
            else
                hideOverviewRuler();
            return;
        }
        if (USE_SATURATED_COLORS_IN_OVERVIEW_RULER.equals(property)) {
            if (fOverviewRuler instanceof IOverviewRulerExtension) {
                ((IOverviewRulerExtension) fOverviewRuler).setUseSaturatedColors(isPrefUseSaturatedColorsOn());
                fOverviewRuler.update();
            }
        }
        if (DISABLE_OVERWRITE_MODE.equals(property)) {
            enableOverwriteMode(isOverwriteModeEnabled());
            return;
        }
        if (LINE_NUMBER_RULER.equals(property)) {
            // only handle visibility of the combined column, but not the number/change only state
            IColumnSupport columnSupport = getAdapter(IColumnSupport.class);
            if (isLineNumberRulerVisible() && fLineColumn == null) {
                RulerColumnDescriptor lineNumberColumnDescriptor = RulerColumnRegistry.getDefault().getColumnDescriptor(LineNumberColumn.ID);
                if (lineNumberColumnDescriptor != null)
                    columnSupport.setColumnVisible(lineNumberColumnDescriptor, true);
            } else if (!isLineNumberRulerVisible() && fLineColumn != null && !fLineColumn.isShowingChangeInformation()) {
                columnSupport.setColumnVisible(fLineColumn.getDescriptor(), false);
                fLineColumn = null;
            }
            return;
        }
        if (AbstractDecoratedTextEditorPreferenceConstants.QUICK_DIFF_ALWAYS_ON.equals(property)) {
            showChangeInformation(isPrefQuickDiffAlwaysOn());
        }
        if (AbstractDecoratedTextEditorPreferenceConstants.EDITOR_TAB_WIDTH.equals(property)) {
            IPreferenceStore store = getPreferenceStore();
            if (store != null)
                sourceViewer.getTextWidget().setTabs(store.getInt(AbstractDecoratedTextEditorPreferenceConstants.EDITOR_TAB_WIDTH));
            if (isTabsToSpacesConversionEnabled()) {
                uninstallTabsToSpacesConverter();
                installTabsToSpacesConverter();
            }
            return;
        }
        if (AbstractDecoratedTextEditorPreferenceConstants.EDITOR_SPACES_FOR_TABS.equals(property)) {
            if (isTabsToSpacesConversionEnabled())
                installTabsToSpacesConverter();
            else
                uninstallTabsToSpacesConverter();
            return;
        }
        if (AbstractDecoratedTextEditorPreferenceConstants.EDITOR_UNDO_HISTORY_SIZE.equals(property) && sourceViewer instanceof ITextViewerExtension6) {
            IPreferenceStore store = getPreferenceStore();
            if (store != null)
                ((ITextViewerExtension6) sourceViewer).getUndoManager().setMaximalUndoLevel(store.getInt(AbstractDecoratedTextEditorPreferenceConstants.EDITOR_UNDO_HISTORY_SIZE));
            return;
        }
        if (AbstractDecoratedTextEditorPreferenceConstants.SHOW_RANGE_INDICATOR.equals(property)) {
            if (isRangeIndicatorEnabled()) {
                getSourceViewer().setRangeIndicator(getRangeIndicator());
            } else {
                getSourceViewer().removeRangeIndication();
                getSourceViewer().setRangeIndicator(null);
            }
        }
        if (sourceViewer instanceof ITextViewerExtension6) {
            HyperlinkDetectorDescriptor[] descriptor = EditorsUI.getHyperlinkDetectorRegistry().getHyperlinkDetectorDescriptors();
            for (int i = 0; i < descriptor.length; i++) {
                if (descriptor[i].getId().equals(property) || (descriptor[i].getId() + HyperlinkDetectorDescriptor.STATE_MASK_POSTFIX).equals(property)) {
                    IHyperlinkDetector[] detectors = getSourceViewerConfiguration().getHyperlinkDetectors(sourceViewer);
                    int stateMask = getSourceViewerConfiguration().getHyperlinkStateMask(sourceViewer);
                    ITextViewerExtension6 textViewer6 = (ITextViewerExtension6) sourceViewer;
                    textViewer6.setHyperlinkDetectors(detectors, stateMask);
                    return;
                }
            }
        }
    } finally {
        super.handlePreferenceStoreChanged(event);
    }
}
Also used : IHyperlinkDetector(org.eclipse.jface.text.hyperlink.IHyperlinkDetector) ITextViewerExtension6(org.eclipse.jface.text.ITextViewerExtension6) RulerColumnDescriptor(org.eclipse.ui.texteditor.rulers.RulerColumnDescriptor) IColumnSupport(org.eclipse.ui.texteditor.rulers.IColumnSupport) ISourceViewer(org.eclipse.jface.text.source.ISourceViewer) IPreferenceStore(org.eclipse.jface.preference.IPreferenceStore) IOverviewRulerExtension(org.eclipse.jface.text.source.IOverviewRulerExtension) Point(org.eclipse.swt.graphics.Point)

Example 5 with ITextViewerExtension6

use of org.eclipse.jface.text.ITextViewerExtension6 in project xtext-xtend by eclipse.

the class UndoTest method testUndo.

@Test
public void testUndo() {
    try {
        StringConcatenation _builder = new StringConcatenation();
        _builder.append("class Foo {");
        _builder.newLine();
        _builder.append("\t");
        _builder.append("val java.lang.String x");
        _builder.newLine();
        _builder.append("\t");
        _builder.append("val java.util.ArrayList<String> y");
        _builder.newLine();
        _builder.append("}");
        _builder.newLine();
        final XtextEditor editor = this._workbenchTestHelper.openEditor("Foo", _builder.toString());
        this._organizeImportsHandler.doOrganizeImports(editor.getDocument());
        StringConcatenation _builder_1 = new StringConcatenation();
        _builder_1.append("import java.util.ArrayList");
        _builder_1.newLine();
        _builder_1.newLine();
        _builder_1.append("class Foo {");
        _builder_1.newLine();
        _builder_1.append("\t");
        _builder_1.append("val String x");
        _builder_1.newLine();
        _builder_1.append("\t");
        _builder_1.append("val ArrayList<String> y");
        _builder_1.newLine();
        _builder_1.append("}");
        _builder_1.newLine();
        Assert.assertEquals(_builder_1.toString(), editor.getDocument().get());
        final ISourceViewer viewer = editor.getInternalSourceViewer();
        Assert.assertTrue((viewer instanceof ITextViewerExtension6));
        final IUndoManager undoManager = ((ITextViewerExtension6) viewer).getUndoManager();
        undoManager.undo();
        StringConcatenation _builder_2 = new StringConcatenation();
        _builder_2.append("class Foo {");
        _builder_2.newLine();
        _builder_2.append("\t");
        _builder_2.append("val java.lang.String x");
        _builder_2.newLine();
        _builder_2.append("\t");
        _builder_2.append("val java.util.ArrayList<String> y");
        _builder_2.newLine();
        _builder_2.append("}");
        _builder_2.newLine();
        Assert.assertEquals(_builder_2.toString(), editor.getDocument().get());
    } catch (Throwable _e) {
        throw Exceptions.sneakyThrow(_e);
    }
}
Also used : IUndoManager(org.eclipse.jface.text.IUndoManager) ITextViewerExtension6(org.eclipse.jface.text.ITextViewerExtension6) XtextEditor(org.eclipse.xtext.ui.editor.XtextEditor) StringConcatenation(org.eclipse.xtend2.lib.StringConcatenation) ISourceViewer(org.eclipse.jface.text.source.ISourceViewer) Test(org.junit.Test)

Aggregations

ITextViewerExtension6 (org.eclipse.jface.text.ITextViewerExtension6)6 ISourceViewer (org.eclipse.jface.text.source.ISourceViewer)4 IUndoManager (org.eclipse.jface.text.IUndoManager)3 IOperationHistory (org.eclipse.core.commands.operations.IOperationHistory)2 IUndoContext (org.eclipse.core.commands.operations.IUndoContext)2 IPreferenceStore (org.eclipse.jface.preference.IPreferenceStore)2 IUndoManagerExtension (org.eclipse.jface.text.IUndoManagerExtension)2 IHyperlinkDetector (org.eclipse.jface.text.hyperlink.IHyperlinkDetector)2 Point (org.eclipse.swt.graphics.Point)2 IColumnSupport (org.eclipse.ui.texteditor.rulers.IColumnSupport)2 RulerColumnDescriptor (org.eclipse.ui.texteditor.rulers.RulerColumnDescriptor)2 InvocationTargetException (java.lang.reflect.InvocationTargetException)1 IProgressMonitor (org.eclipse.core.runtime.IProgressMonitor)1 IAction (org.eclipse.jface.action.IAction)1 IRunnableWithProgress (org.eclipse.jface.operation.IRunnableWithProgress)1 ITextViewerExtension2 (org.eclipse.jface.text.ITextViewerExtension2)1 ITextViewerExtension8 (org.eclipse.jface.text.ITextViewerExtension8)1 IOverviewRulerExtension (org.eclipse.jface.text.source.IOverviewRulerExtension)1 StringConcatenation (org.eclipse.xtend2.lib.StringConcatenation)1 XtextEditor (org.eclipse.xtext.ui.editor.XtextEditor)1