1
0
Fork 0
mirror of https://github.com/eclipse-cdt/cdt synced 2025-04-29 19:45:01 +02:00

New implementation of the "Add Expression" editor action.

This commit is contained in:
Mikhail Khodjaiants 2004-05-28 20:31:36 +00:00
parent c17d871ba5
commit 764632f0c3
6 changed files with 103 additions and 284 deletions

View file

@ -1,3 +1,11 @@
2004-05-28 Mikhail Khodjaiants
New implementation of the "Add Expression" editor action.
* AddExpressionActionDelegate.java: removed
* AddExpressionEditorActionDelegate.java: new
* icons/full/dtool16/watch_exp.gif: new
* icons/full/etool16/watch_exp.gif: new
* plugin.xml
2004-05-28 Mikhail Khodjaiants
Changed the error handling of the "Add Globals" and "Enable/Disable Variable" actions.
* AddGlobalsActionDelegate.java

Binary file not shown.

After

Width:  |  Height:  |  Size: 94 B

Binary file not shown.

After

Width:  |  Height:  |  Size: 125 B

View file

@ -223,20 +223,6 @@
</pluginState>
</enablement>
</action>
<action
label="%GlobalAddExpressionAction.label"
icon="icons/full/obj16/expression_obj.gif"
helpContextId="add_expression_action_context"
class="org.eclipse.cdt.debug.internal.ui.actions.AddExpressionActionDelegate"
menubarPath="org.eclipse.ui.run/cExpressionGroup"
id="org.eclipse.cdt.debug.internal.ui.actions.AddExpressionActionDelegate">
<enablement>
<pluginState
value="activated"
id="org.eclipse.cdt.debug.ui">
</pluginState>
</enablement>
</action>
<action
id="org.eclipse.cdt.debug.internal.ui.actions.SignalZeroWorkbenchActionDelegate"
hoverIcon="icons/full/clcl16/signal0_co.gif"
@ -344,9 +330,9 @@
id="org.eclipse.cdt.debug.ui.CEditorPopupActions">
<action
label="%AddExpressionAction.label"
icon="icons/full/obj16/expression_obj.gif"
icon="icons/full/etool16/watch_exp.gif"
helpContextId="add_expression_action_context"
class="org.eclipse.cdt.debug.internal.ui.actions.AddExpressionActionDelegate"
class="org.eclipse.cdt.debug.internal.ui.actions.AddExpressionEditorActionDelegate"
menubarPath="additions"
id="org.eclipse.cdt.debug.internal.ui.actions.AddExpressionActionDelegate">
<enablement>
@ -467,9 +453,9 @@
id="org.eclipse.cdt.debug.ui.AsmEditorPopupActions">
<action
label="%AddExpressionAction.label"
icon="icons/full/obj16/expression_obj.gif"
icon="icons/full/etool16/watch_exp.gif"
helpContextId="add_expression_action_context"
class="org.eclipse.cdt.debug.internal.ui.actions.AddExpressionActionDelegate"
class="org.eclipse.cdt.debug.internal.ui.actions.AddExpressionEditorActionDelegate"
menubarPath="additions"
id="org.eclipse.cdt.debug.internal.ui.actions.AddExpressionActionDelegate">
<enablement>
@ -546,107 +532,6 @@
id="org.eclipse.cdt.debug.internal.ui.actions.NaturalVariableFormatActionDelegate">
</action>
</objectContribution>
<viewerContribution
targetID="#DisassemblyEditorRulerContext"
id="org.eclipse.cdt.debug.ui.DisassemblyEditorRulerActions">
<!--
<action
label="%RunToLineAction.label"
icon="icons/full/clcl16/runtoline_co.gif"
helpContextId="run_to_line_action_context"
class="org.eclipse.cdt.debug.internal.ui.actions.RunToLineRulerActionDelegate"
menubarPath="debug"
id="org.eclipse.cdt.debug.internal.ui.actions.RunToLineRulerActionDelegate">
</action>
-->
<action
label="%BreakpointProperties.label"
helpContextId="breakpoint_properties_action_context"
class="org.eclipse.cdt.debug.internal.ui.actions.CBreakpointPropertiesRulerActionDelegate"
menubarPath="debug"
id="org.eclipse.cdt.debug.internal.ui.actions.CBreakpointPropertiesRulerActionDelegate">
<enablement>
<pluginState
value="activated"
id="org.eclipse.cdt.debug.ui">
</pluginState>
</enablement>
</action>
<action
label="%EnableBreakpoint.label"
helpContextId="enable_disable_breakpoint_action_context"
class="org.eclipse.cdt.debug.internal.ui.actions.EnableDisableBreakpointRulerActionDelegate"
menubarPath="debug"
id="org.eclipse.cdt.debug.internal.ui.actions.EnableDisableBreakpointRulerActionDelegate">
<enablement>
<pluginState
value="activated"
id="org.eclipse.cdt.debug.ui">
</pluginState>
</enablement>
</action>
<action
label="%AddBreakpoint.label"
helpContextId="manage_breakpoint_action_context"
class="org.eclipse.cdt.debug.internal.ui.actions.ManageBreakpointRulerActionDelegate"
menubarPath="debug"
id="org.eclipse.cdt.debug.internal.ui.actions.ManageBreakpointRulerActionDelegate">
<enablement>
<pluginState
value="activated"
id="org.eclipse.cdt.debug.ui">
</pluginState>
</enablement>
</action>
</viewerContribution>
<viewerContribution
targetID="#DisassemblyEditorContext"
id="org.eclipse.cdt.debug.ui.DisassemblyEditorPopupActions">
<action
label="%AddExpressionAction.label"
icon="icons/full/obj16/expression_obj.gif"
helpContextId="add_expression_action_context"
class="org.eclipse.cdt.debug.internal.ui.actions.AddExpressionActionDelegate"
menubarPath="additions"
id="org.eclipse.cdt.debug.internal.ui.actions.AddExpressionActionDelegate">
<enablement>
<pluginState
value="activated"
id="org.eclipse.cdt.debug.ui">
</pluginState>
</enablement>
</action>
<action
label="%JumpToLineAction.label"
icon="icons/full/clcl16/jump_co.gif"
helpContextId="jump_to_line_action_context"
class="org.eclipse.cdt.debug.internal.ui.actions.JumpToLineActionDelegate"
menubarPath="additions"
enablesFor="1"
id="org.eclipse.cdt.debug.internal.ui.actions.JumpToLineActionDelegate">
<enablement>
<pluginState
value="activated"
id="org.eclipse.cdt.debug.ui">
</pluginState>
</enablement>
</action>
<action
label="%RunToLineAction.label"
icon="icons/full/clcl16/runtoline_co.gif"
helpContextId="run_to_line_action_context"
class="org.eclipse.cdt.debug.internal.ui.actions.RunToLineActionDelegate"
menubarPath="additions"
enablesFor="1"
id="org.eclipse.cdt.debug.internal.ui.actions.RunToLineActionDelegate">
<enablement>
<pluginState
value="activated"
id="org.eclipse.cdt.debug.ui">
</pluginState>
</enablement>
</action>
</viewerContribution>
<viewerContribution
targetID="org.eclipse.cdt.debug.ui.SharedLibrariesView"
id="org.eclipse.cdt.debug.ui.SharedLibrariesViewPopupActions">

View file

@ -1,165 +0,0 @@
/*
*(c) Copyright QNX Software Systems Ltd. 2002.
* All Rights Reserved.
*
*/
package org.eclipse.cdt.debug.internal.ui.actions;
import org.eclipse.cdt.debug.core.CDebugModel;
import org.eclipse.cdt.debug.core.model.ICExpressionEvaluator;
import org.eclipse.cdt.debug.ui.CDebugUIPlugin;
import org.eclipse.core.runtime.IAdaptable;
import org.eclipse.debug.core.DebugException;
import org.eclipse.debug.core.DebugPlugin;
import org.eclipse.debug.core.model.IDebugElement;
import org.eclipse.debug.core.model.IDebugTarget;
import org.eclipse.debug.core.model.IExpression;
import org.eclipse.debug.ui.DebugUITools;
import org.eclipse.debug.ui.IDebugUIConstants;
import org.eclipse.jface.action.IAction;
import org.eclipse.jface.text.ITextSelection;
import org.eclipse.jface.viewers.ISelection;
import org.eclipse.jface.viewers.IStructuredSelection;
import org.eclipse.jface.window.Window;
import org.eclipse.swt.widgets.Display;
import org.eclipse.swt.widgets.Shell;
import org.eclipse.ui.IViewPart;
import org.eclipse.ui.IWorkbenchPage;
import org.eclipse.ui.IWorkbenchPart;
import org.eclipse.ui.PartInitException;
/**
*
* Enter type comment.
*
* @since Sep 17, 2002
*/
public class AddExpressionActionDelegate extends AbstractEditorActionDelegate
{
/**
* Constructor for AddExpressionActionDelegate.
*/
public AddExpressionActionDelegate()
{
}
/* (non-Javadoc)
* @see org.eclipse.ui.IActionDelegate#run(IAction)
*/
public void run( IAction action )
{
String text = getSelectedText();
ExpressionDialog dlg = new ExpressionDialog( getShell(), text );
if ( dlg.open() != Window.OK )
return;
createExpression( dlg.getExpression() );
}
protected String getSelectedText()
{
ISelection selection = getTargetSelection();
if ( selection != null && selection instanceof ITextSelection )
{
return ((ITextSelection)selection).getText().trim();
}
return ""; //$NON-NLS-1$
}
protected Shell getShell()
{
return ( getTargetPart() != null ) ?
getTargetPart().getSite().getShell() : CDebugUIPlugin.getActiveWorkbenchShell();
}
private void createExpression( final String text )
{
final Display display = CDebugUIPlugin.getStandardDisplay();
if ( display.isDisposed() )
{
return;
}
display.asyncExec( new Runnable()
{
public void run()
{
try
{
IExpression expression = CDebugModel.createExpression( getDebugTarget(), text );
DebugPlugin.getDefault().getExpressionManager().addExpression( expression );
showExpressionView();
}
catch( DebugException e )
{
CDebugUIPlugin.errorDialog( CDebugUIPlugin.getResourceString("internal.ui.actions.AddExpressionActionDelegate.Evaluation_of_expression_failed"), e ); //$NON-NLS-1$
}
}
} );
}
/**
* @see org.eclipse.ui.ISelectionListener#selectionChanged(IWorkbenchPart, ISelection)
*/
public void selectionChanged( IWorkbenchPart part, ISelection selection )
{
IDebugTarget target = null;
if ( part != null && part.getSite().getId().equals( IDebugUIConstants.ID_DEBUG_VIEW ) )
{
if ( selection instanceof IStructuredSelection )
{
Object element = ((IStructuredSelection)selection).getFirstElement();
if ( element != null && element instanceof IDebugElement )
{
IDebugTarget target1 = ((IDebugElement)element).getDebugTarget();
if ( target1 != null && target1 instanceof ICExpressionEvaluator )
{
target = target1;
}
}
}
setDebugTarget( target );
update();
}
}
protected void initializeDebugTarget()
{
setDebugTarget( null );
IAdaptable context = DebugUITools.getDebugContext();
if ( context != null && context instanceof IDebugElement )
{
IDebugTarget target = ((IDebugElement)context).getDebugTarget();
if ( target != null && target instanceof ICExpressionEvaluator )
{
setDebugTarget( target );
}
}
}
/**
* Make the expression view visible or open one if required.
*
*/
protected void showExpressionView()
{
IWorkbenchPage page = CDebugUIPlugin.getActivePage();
if ( page != null )
{
IViewPart part = page.findView( IDebugUIConstants.ID_EXPRESSION_VIEW );
if ( part == null )
{
try
{
page.showView( IDebugUIConstants.ID_EXPRESSION_VIEW );
}
catch( PartInitException e )
{
CDebugUIPlugin.log( e.getStatus() );
}
}
else
{
page.bringToTop( part );
}
}
}
}

View file

@ -0,0 +1,91 @@
/**********************************************************************
* Copyright (c) 2004 QNX Software Systems and others.
* All rights reserved. This program and the accompanying materials
* are made available under the terms of the Common Public License v1.0
* which accompanies this distribution, and is available at
* http://www.eclipse.org/legal/cpl-v10.html
*
* Contributors:
* QNX Software Systems - Initial API and implementation
***********************************************************************/
package org.eclipse.cdt.debug.internal.ui.actions;
import org.eclipse.cdt.debug.ui.CDebugUIPlugin;
import org.eclipse.core.runtime.IAdaptable;
import org.eclipse.debug.core.DebugPlugin;
import org.eclipse.debug.core.model.IDebugElement;
import org.eclipse.debug.core.model.IWatchExpression;
import org.eclipse.debug.ui.DebugUITools;
import org.eclipse.jface.action.IAction;
import org.eclipse.jface.text.ITextSelection;
import org.eclipse.jface.viewers.ISelection;
import org.eclipse.jface.viewers.ISelectionProvider;
import org.eclipse.jface.window.Window;
import org.eclipse.swt.widgets.Shell;
import org.eclipse.ui.IEditorActionDelegate;
import org.eclipse.ui.IEditorPart;
import org.eclipse.ui.IWorkbenchPart;
import org.eclipse.ui.actions.ActionDelegate;
/**
* The "Add Expression" action contribution to editors.
*/
public class AddExpressionEditorActionDelegate extends ActionDelegate implements IEditorActionDelegate {
private IEditorPart fEditorPart;
/* (non-Javadoc)
* @see org.eclipse.ui.IEditorActionDelegate#setActiveEditor(org.eclipse.jface.action.IAction, org.eclipse.ui.IEditorPart)
*/
public void setActiveEditor( IAction action, IEditorPart targetEditor ) {
setEditorPart( targetEditor );
}
private IEditorPart getEditorPart() {
return fEditorPart;
}
private void setEditorPart( IEditorPart editorPart ) {
fEditorPart = editorPart;
}
public void run( IAction action ) {
String text = getSelectedText();
ExpressionDialog dlg = new ExpressionDialog( getShell(), text );
if ( dlg.open() != Window.OK )
return;
createExpression( dlg.getExpression() );
}
private String getSelectedText() {
ISelection selection = getTargetSelection();
if ( selection != null && selection instanceof ITextSelection ) {
return ((ITextSelection)selection).getText().trim();
}
return ""; //$NON-NLS-1$
}
protected ISelection getTargetSelection() {
IWorkbenchPart part = getEditorPart();
if ( part != null ) {
ISelectionProvider provider = part.getSite().getSelectionProvider();
if ( provider != null ) {
return provider.getSelection();
}
}
return null;
}
private void createExpression( String text ) {
IWatchExpression watchExpression= DebugPlugin.getDefault().getExpressionManager().newWatchExpression( text );
DebugPlugin.getDefault().getExpressionManager().addExpression( watchExpression );
IAdaptable context = DebugUITools.getDebugContext();
if ( context instanceof IDebugElement )
watchExpression.setExpressionContext( (IDebugElement)context );
}
protected Shell getShell() {
return ( getEditorPart() != null ) ? getEditorPart().getSite().getShell() : CDebugUIPlugin.getActiveWorkbenchShell();
}
}