/*
* Copyright 2008 Georgi Staykov
*
* This file is part of pscoder.
*
* pscoder is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* pscoder is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with pscoder. If not, see <http://www.gnu.org/licenses/>.
*/
package com.gstaykov.pscoder.editor;
import org.eclipse.core.runtime.Preferences;
import org.eclipse.jface.dialogs.DialogSettings;
import org.eclipse.jface.text.IDocument;
import org.eclipse.jface.text.contentassist.ContentAssistant;
import org.eclipse.jface.text.contentassist.IContentAssistProcessor;
import org.eclipse.jface.text.contentassist.IContentAssistant;
import org.eclipse.jface.text.presentation.IPresentationReconciler;
import org.eclipse.jface.text.presentation.PresentationReconciler;
import org.eclipse.jface.text.rules.DefaultDamagerRepairer;
import org.eclipse.jface.text.source.ISourceViewer;
import org.eclipse.jface.text.source.SourceViewerConfiguration;
import com.gstaykov.pscoder.Activator;
import com.gstaykov.pscoder.editor.completion.PowershellCompletionProcessor;
import com.gstaykov.pscoder.editor.syntax.PowershellCodeScanner;
import com.gstaykov.pscoder.editor.syntax.PowershellColors;
import com.gstaykov.pscoder.preferences.PreferenceConstants;
public class PowershellSourceViewerConfiguration extends SourceViewerConfiguration {
private Preferences preferences = Activator.getDefault().getPluginPreferences();
public IPresentationReconciler getPresentationReconciler(ISourceViewer sourceViewer) {
PresentationReconciler reconciler = new PresentationReconciler();
reconciler.setDocumentPartitioning(getConfiguredDocumentPartitioning(sourceViewer));
DefaultDamagerRepairer dr = new DefaultDamagerRepairer(new PowershellCodeScanner(new PowershellColors())); // TODO: make only one copy
reconciler.setDamager(dr, IDocument.DEFAULT_CONTENT_TYPE);
reconciler.setRepairer(dr, IDocument.DEFAULT_CONTENT_TYPE);
return reconciler;
}
public int getTabWidth(ISourceViewer sourceViewer) {
return preferences.getInt(PreferenceConstants.TAB_WIDTH);
}
@Override
public IContentAssistant getContentAssistant(ISourceViewer sourceViewer) {
ContentAssistant assistant = new ContentAssistant();
IContentAssistProcessor proc = new PowershellCompletionProcessor(); // FIXME: Don't we want only one copy here?
DialogSettings dsettings = new DialogSettings("pscoderContentAssist");
assistant.setContentAssistProcessor(proc, IDocument.DEFAULT_CONTENT_TYPE);
assistant.enableAutoActivation(true);
assistant.setRestoreCompletionProposalSize(dsettings);
return assistant;
}
}