/*
* 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.commands.IHandler;
import org.eclipse.jface.action.IAction;
import org.eclipse.swt.widgets.Composite;
import org.eclipse.ui.contexts.IContextService;
import org.eclipse.ui.editors.text.TextEditor;
import org.eclipse.ui.handlers.IHandlerService;
import org.eclipse.ui.texteditor.ContentAssistAction;
import org.eclipse.ui.texteditor.ITextEditorActionDefinitionIds;
import com.gstaykov.pscoder.editor.handlers.CommentHandler;
import com.gstaykov.pscoder.editor.handlers.GoToDefinitionHandler;
import com.gstaykov.pscoder.editor.handlers.QuickOutlineHandler;
import com.gstaykov.pscoder.editor.handlers.RebuildCADHandler;
public class PowershellEditor extends TextEditor {
private static final String EDITOR_CONTEXT_ID = "com.gstaykov.pscoder.editor";
protected void initializeEditor() {
super.initializeEditor();
setSourceViewerConfiguration(new PowershellSourceViewerConfiguration());
}
protected void createActions() {
super.createActions();
IAction action = new ContentAssistAction(PowershellResourceBundle.getResourceBundle(), "ContentAssistProposal.", this);
action.setActionDefinitionId(ITextEditorActionDefinitionIds.CONTENT_ASSIST_PROPOSALS);
setAction("ContentAssistProposal", action);
}
@Override
public void createPartControl(Composite parent) {
super.createPartControl(parent);
activateContext();
activateHandlers();
}
private void activateContext() {
IContextService contextService = (IContextService)getSite().getService(IContextService.class);
contextService.activateContext(EDITOR_CONTEXT_ID);
}
private void activateHandlers() {
IHandlerService handlerService = (IHandlerService)getSite().getService(IHandlerService.class);
IHandler rebuildCAD = new RebuildCADHandler();
handlerService.activateHandler("com.gstaykov.pscoder.rebuildcad", rebuildCAD);
IHandler commentHandler = new CommentHandler();
handlerService.activateHandler("com.gstaykov.pscoder.addcomment", commentHandler);
IHandler goToDefinitionHandler = new GoToDefinitionHandler();
handlerService.activateHandler("com.gstaykov.pscoder.gotodefinition", goToDefinitionHandler);
IHandler quickOutlineHandler = new QuickOutlineHandler();
handlerService.activateHandler("com.gstaykov.pscoder.quickoutline", quickOutlineHandler);
}
}