diff options
Diffstat (limited to 'org.eclipse.debug.ui/ui/org/eclipse/debug/ui/actions/RulerRunToLineActionDelegate.java')
-rw-r--r-- | org.eclipse.debug.ui/ui/org/eclipse/debug/ui/actions/RulerRunToLineActionDelegate.java | 129 |
1 files changed, 129 insertions, 0 deletions
diff --git a/org.eclipse.debug.ui/ui/org/eclipse/debug/ui/actions/RulerRunToLineActionDelegate.java b/org.eclipse.debug.ui/ui/org/eclipse/debug/ui/actions/RulerRunToLineActionDelegate.java new file mode 100644 index 000000000..afb7d952f --- /dev/null +++ b/org.eclipse.debug.ui/ui/org/eclipse/debug/ui/actions/RulerRunToLineActionDelegate.java @@ -0,0 +1,129 @@ +/******************************************************************************* + * Copyright (c) 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 + * + * Contributors: + * IBM Corporation - initial API and implementation + *******************************************************************************/ +package org.eclipse.debug.ui.actions; + +import org.eclipse.jface.action.IAction; +import org.eclipse.jface.text.source.IVerticalRulerInfo; +import org.eclipse.swt.widgets.Event; +import org.eclipse.ui.IActionDelegate2; +import org.eclipse.ui.IEditorPart; +import org.eclipse.ui.texteditor.AbstractRulerActionDelegate; +import org.eclipse.ui.texteditor.ITextEditor; + +/** + * A run to line action that can be contributed to a an editor or view. The + * action will perform the "run to line" operation for parts that provide an + * appropriate <code>IRunToLineTarget</code> adapter. + * <p> + * Following is example plug-in XML used to contribute this action to an editor. + * Note that the label attribute of this action is not displayed in the editor. + * Instead, the label of the created action is displayed. + * + * <pre> + * <extension point="org.eclipse.ui.editorActions"> + * <editorContribution + * targetID="example.editor" + * id="example.rulerActions"> + * <action + * label="Not Used" + * class="org.eclipse.debug.ui.actions.RulerRunToLineActionDelegate" + * style="push" + * actionID="RulerClick" + * id="example.doubleClickBreakpointAction"/> + * </editorContribution> + * </extension> + * </pre> + * </p> + * <p> + * This action can also be contributed to a vertical ruler context menu via the + * <code>popupMenus</code> extension point, by referencing the ruler's context + * menu identifier in the <code>targetID</code> attribute. + * + * <pre> + * <extension point="org.eclipse.ui.popupMenus"> + * <viewerContribution + * targetID="example.rulerContextMenuId" + * id="example.RulerPopupActions"> + * <action + * label="Run to Line" + * class="org.eclipse.debug.ui.actions.RulerRunToLineActionDelegate" + * menubarPath="additions" + * id="example.rulerContextMenu.runToLineAction"> + * </action> + * </viewerContribution> + * </pre> + * </p> + * <p> + * Clients may refer to this class as an action delegate in plug-in XML. + * </p> + * + * @since 3.12 + * @noextend This class is not intended to be subclassed by clients. + * @noinstantiate This class is not intended to be instantiated by clients. + */ +public class RulerRunToLineActionDelegate extends AbstractRulerActionDelegate implements IActionDelegate2 { + + private IEditorPart fEditor = null; + private RunToLineAction fDelegate = null; + + /* (non-Javadoc) + * @see org.eclipse.ui.texteditor.AbstractRulerActionDelegate#createAction(org.eclipse.ui.texteditor.ITextEditor, org.eclipse.jface.text.source.IVerticalRulerInfo) + */ + @Override + protected IAction createAction(ITextEditor editor, IVerticalRulerInfo rulerInfo) { + fDelegate = new RunToLineAction(editor, null, rulerInfo); + return fDelegate; + } + + /* (non-Javadoc) + * @see org.eclipse.ui.IEditorActionDelegate#setActiveEditor(org.eclipse.jface.action.IAction, org.eclipse.ui.IEditorPart) + */ + @Override + public void setActiveEditor(IAction callerAction, IEditorPart targetEditor) { + if (fEditor != null) { + if (fDelegate != null) { + fDelegate.dispose(); + fDelegate = null; + } + } + fEditor = targetEditor; + super.setActiveEditor(callerAction, targetEditor); + } + + /* (non-Javadoc) + * @see org.eclipse.ui.IActionDelegate2#init(org.eclipse.jface.action.IAction) + */ + @Override + public void init(IAction action) { + } + + /* (non-Javadoc) + * @see org.eclipse.ui.IActionDelegate2#dispose() + */ + @Override + public void dispose() { + if (fDelegate != null) { + fDelegate.dispose(); + } + fDelegate = null; + fEditor = null; + } + + /* (non-Javadoc) + * @see org.eclipse.ui.IActionDelegate2#runWithEvent(org.eclipse.jface.action.IAction, org.eclipse.swt.widgets.Event) + */ + @Override + public void runWithEvent(IAction action, Event event) { + if(fDelegate != null) { + fDelegate.runWithEvent(event); + } + } +} |