| /******************************************************************************* |
| * Copyright (c) 2000, 2017 IBM Corporation and others. |
| * All rights reserved. This program and the accompanying materials |
| * are made available under the terms of the Eclipse Public License v1.0 |
| * which accompanies this distribution, and is available at |
| * http://www.eclipse.org/legal/epl-v10.html |
| * |
| *******************************************************************************/ |
| package org.eclipse.dltk.internal.ui.editor; |
| |
| import java.util.ResourceBundle; |
| |
| import org.eclipse.dltk.ui.IContextMenuConstants; |
| import org.eclipse.dltk.ui.actions.IScriptEditorActionDefinitionIds; |
| import org.eclipse.jface.action.IAction; |
| import org.eclipse.jface.action.IMenuManager; |
| import org.eclipse.ui.IActionBars; |
| import org.eclipse.ui.IEditorPart; |
| import org.eclipse.ui.IWorkbenchActionConstants; |
| import org.eclipse.ui.IWorkbenchPage; |
| import org.eclipse.ui.texteditor.ITextEditor; |
| import org.eclipse.ui.texteditor.ITextEditorActionConstants; |
| import org.eclipse.ui.texteditor.ITextEditorActionDefinitionIds; |
| import org.eclipse.ui.texteditor.RetargetTextEditorAction; |
| |
| |
| public class SourceModuleEditorActionContributor extends BasicSourceModuleEditorActionContributor { |
| |
| private RetargetTextEditorAction fToggleInsertModeAction; |
| private ToggleMarkOccurrencesAction fToggleMarkOccurrencesAction; |
| |
| public SourceModuleEditorActionContributor() { |
| super(); |
| ResourceBundle b= ScriptEditorMessages.getBundleForConstructedKeys(); |
| fToggleInsertModeAction= new RetargetTextEditorAction(b, "SourceModuleEditorActionContributor.ToggleInsertMode.", IAction.AS_CHECK_BOX); //$NON-NLS-1$ |
| fToggleInsertModeAction.setActionDefinitionId(ITextEditorActionDefinitionIds.TOGGLE_INSERT_MODE); |
| fToggleMarkOccurrencesAction = new ToggleMarkOccurrencesAction(); |
| } |
| |
| @Override |
| public void init(IActionBars bars, IWorkbenchPage page) { |
| super.init(bars, page); |
| bars.setGlobalActionHandler( |
| IScriptEditorActionDefinitionIds.TOGGLE_MARK_OCCURRENCES, |
| fToggleMarkOccurrencesAction); |
| } |
| |
| @Override |
| public void contributeToMenu(IMenuManager menu) { |
| super.contributeToMenu(menu); |
| |
| IMenuManager editMenu= menu.findMenuUsingPath(IWorkbenchActionConstants.M_EDIT); |
| if (editMenu != null) { |
| editMenu.appendToGroup(IContextMenuConstants.GROUP_ADDITIONS, fToggleInsertModeAction); |
| } |
| } |
| |
| @Override |
| public void setActiveEditor(IEditorPart part) { |
| super.setActiveEditor(part); |
| |
| ITextEditor textEditor= null; |
| if (part instanceof ITextEditor) |
| textEditor= (ITextEditor) part; |
| |
| final IActionBars bars = getActionBars(); |
| fToggleInsertModeAction.setAction(getAction(textEditor, ITextEditorActionConstants.TOGGLE_INSERT_MODE)); |
| fToggleMarkOccurrencesAction.setEditor(textEditor); |
| IAction action = getAction(textEditor, |
| ITextEditorActionConstants.REFRESH); |
| bars.setGlobalActionHandler(ITextEditorActionConstants.REFRESH, action); |
| } |
| } |