blob: 982d55a65655fac2d7fd3bba3a98a147d5b6a52e [file] [log] [blame]
/*=============================================================================#
# Copyright (c) 2005, 2019 Stephan Wahlbrink and others.
#
# This program and the accompanying materials are made available under the
# terms of the Eclipse Public License 2.0 which is available at
# https://www.eclipse.org/legal/epl-2.0, or the Apache License, Version 2.0
# which is available at https://www.apache.org/licenses/LICENSE-2.0.
#
# SPDX-License-Identifier: EPL-2.0 OR Apache-2.0
#
# Contributors:
# Stephan Wahlbrink <sw@wahlbrink.eu> - initial API and implementation
#=============================================================================*/
package org.eclipse.statet.r.ui.editors;
import static org.eclipse.statet.r.ui.text.rd.IRdTextTokens.COMMENT;
import static org.eclipse.statet.r.ui.text.rd.IRdTextTokens.PLATFORM_SPECIF;
import static org.eclipse.statet.r.ui.text.rd.IRdTextTokens.TASK_TAG;
import java.util.Map;
import java.util.Set;
import org.eclipse.jface.preference.IPreferenceStore;
import org.eclipse.jface.text.ITextDoubleClickStrategy;
import org.eclipse.jface.text.source.ISourceViewer;
import org.eclipse.statet.ecommons.text.ICharPairMatcher;
import org.eclipse.statet.ecommons.text.PairMatcher;
import org.eclipse.statet.ecommons.text.ui.presentation.SingleTokenScanner;
import org.eclipse.statet.ecommons.text.ui.settings.TextStyleManager;
import org.eclipse.statet.ecommons.ui.ISettingsChangedHandler;
import org.eclipse.statet.base.ext.ui.text.CommentScanner;
import org.eclipse.statet.internal.r.ui.RUIPlugin;
import org.eclipse.statet.ltk.ui.LTKUIPreferences;
import org.eclipse.statet.ltk.ui.sourceediting.ISourceEditor;
import org.eclipse.statet.ltk.ui.sourceediting.SourceEditorViewerConfiguration;
import org.eclipse.statet.ltk.ui.sourceediting.assist.ContentAssist;
import org.eclipse.statet.r.core.IRCoreAccess;
import org.eclipse.statet.r.core.RCore;
import org.eclipse.statet.r.core.source.IRDocumentConstants;
import org.eclipse.statet.r.core.source.RdDocumentContentInfo;
import org.eclipse.statet.r.ui.text.rd.RdCodeScanner;
import org.eclipse.statet.r.ui.text.rd.RdDoubleClickStrategy;
/**
* Default Configuration for SourceViewer of R documentations.
*/
public class RdSourceViewerConfiguration extends SourceEditorViewerConfiguration
implements ISettingsChangedHandler {
private static final String[] CONTENT_TYPES= IRDocumentConstants.RDOC_CONTENT_TYPES.toArray(
new String[IRDocumentConstants.RDOC_CONTENT_TYPES.size()] );
private static final char[][] BRACKETS = { { '{', '}' } };
private final RdDoubleClickStrategy fDoubleClickStrategy;
private IRCoreAccess fRCoreAccess;
public RdSourceViewerConfiguration(final int flags) {
this(flags, null, null, null, null);
}
public RdSourceViewerConfiguration(final int flags,
final ISourceEditor sourceEditor,
final IRCoreAccess access,
final IPreferenceStore preferenceStore, final TextStyleManager textStyles) {
super(RdDocumentContentInfo.INSTANCE, flags, sourceEditor);
setCoreAccess(access);
setup((preferenceStore != null) ? preferenceStore : RUIPlugin.getInstance().getEditorPreferenceStore(),
LTKUIPreferences.getEditorDecorationPreferences(),
LTKUIPreferences.getAssistPreferences() );
setTextStyles(textStyles);
this.fDoubleClickStrategy = new RdDoubleClickStrategy();
}
protected void setCoreAccess(final IRCoreAccess access) {
this.fRCoreAccess = (access != null) ? access : RCore.getWorkbenchAccess();
}
@Override
protected void initTextStyles() {
setTextStyles(RUIPlugin.getInstance().getRdTextStyles());
}
@Override
protected void initScanners() {
final TextStyleManager textStyles= getTextStyles();
addScanner(IRDocumentConstants.RDOC_DEFAULT_CONTENT_TYPE,
new RdCodeScanner(textStyles) );
addScanner(IRDocumentConstants.RDOC_COMMENT_CONTENT_TYPE,
new CommentScanner(textStyles, COMMENT, TASK_TAG, this.fRCoreAccess.getPrefs()) );
addScanner(IRDocumentConstants.RDOC_COMMENT_CONTENT_TYPE,
new SingleTokenScanner(textStyles, PLATFORM_SPECIF ) );
}
@Override
public String[] getConfiguredContentTypes(final ISourceViewer sourceViewer) {
return CONTENT_TYPES;
}
@Override
public ICharPairMatcher getPairMatcher() {
return new PairMatcher(BRACKETS, getDocumentContentInfo(),
new String[] { IRDocumentConstants.RDOC_DEFAULT_CONTENT_TYPE }, '\\');
}
@Override
public ITextDoubleClickStrategy getDoubleClickStrategy(final ISourceViewer sourceViewer, final String contentType) {
return this.fDoubleClickStrategy;
}
@Override
public String[] getDefaultPrefixes(final ISourceViewer sourceViewer, final String contentType) {
return new String[] { "%", "" }; //$NON-NLS-1$ //$NON-NLS-2$
}
@Override
public void handleSettingsChanged(final Set<String> groupIds, final Map<String, Object> options) {
options.put(ISettingsChangedHandler.PREFERENCEACCESS_KEY, this.fRCoreAccess.getPrefs());
super.handleSettingsChanged(groupIds, options);
}
@Override
protected ContentAssist createContentAssistant(final ISourceViewer sourceViewer) {
return null;
}
}