From 764632f0c3a65c2f13b45146b9ae58de754acce4 Mon Sep 17 00:00:00 2001 From: Mikhail Khodjaiants Date: Fri, 28 May 2004 20:31:36 +0000 Subject: [PATCH] New implementation of the "Add Expression" editor action. --- debug/org.eclipse.cdt.debug.ui/ChangeLog | 8 + .../icons/full/dtool16/watch_exp.gif | Bin 0 -> 94 bytes .../icons/full/etool16/watch_exp.gif | Bin 0 -> 125 bytes debug/org.eclipse.cdt.debug.ui/plugin.xml | 123 +------------ .../actions/AddExpressionActionDelegate.java | 165 ------------------ .../AddExpressionEditorActionDelegate.java | 91 ++++++++++ 6 files changed, 103 insertions(+), 284 deletions(-) create mode 100644 debug/org.eclipse.cdt.debug.ui/icons/full/dtool16/watch_exp.gif create mode 100644 debug/org.eclipse.cdt.debug.ui/icons/full/etool16/watch_exp.gif delete mode 100644 debug/org.eclipse.cdt.debug.ui/src/org/eclipse/cdt/debug/internal/ui/actions/AddExpressionActionDelegate.java create mode 100644 debug/org.eclipse.cdt.debug.ui/src/org/eclipse/cdt/debug/internal/ui/actions/AddExpressionEditorActionDelegate.java diff --git a/debug/org.eclipse.cdt.debug.ui/ChangeLog b/debug/org.eclipse.cdt.debug.ui/ChangeLog index 2c9d74bac29..8c41fe8b765 100644 --- a/debug/org.eclipse.cdt.debug.ui/ChangeLog +++ b/debug/org.eclipse.cdt.debug.ui/ChangeLog @@ -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 diff --git a/debug/org.eclipse.cdt.debug.ui/icons/full/dtool16/watch_exp.gif b/debug/org.eclipse.cdt.debug.ui/icons/full/dtool16/watch_exp.gif new file mode 100644 index 0000000000000000000000000000000000000000..38f60cd7d22d8c13acc57caa9f57c8d402ef8c5c GIT binary patch literal 94 zcmZ?wbhEHb6krfwn8?5|Z}G}Q2M_-L|DS<@LGdRGBLf2ygAR}llobH7^{4b_3Ld&S xjk(e5`n{gKrxCSR*n`5h&*?vw+4abYr{hfApG7fmZ(07I%-U{0XCVWFH2~u`BliFR literal 0 HcmV?d00001 diff --git a/debug/org.eclipse.cdt.debug.ui/icons/full/etool16/watch_exp.gif b/debug/org.eclipse.cdt.debug.ui/icons/full/etool16/watch_exp.gif new file mode 100644 index 0000000000000000000000000000000000000000..d37495a839176e3c214cedc3ee5ed3d5c1c1f8a7 GIT binary patch literal 125 zcmV-@0D}KVNk%w1VGsZi0HOc@Ic1e*lf`tM%8{|vtHj^P*y`2c@Bjb*A^8LW000L7 zEC2ui01yBW0009*c)HvQ;|$Q~I|O8+#EX-%EmjDL+93d}2U%NsSkgIzmZyYHZ#xB6 f;X-0P3c+53GxHf0g}_kB08FVQ19nUOF%kefcA7DH literal 0 HcmV?d00001 diff --git a/debug/org.eclipse.cdt.debug.ui/plugin.xml b/debug/org.eclipse.cdt.debug.ui/plugin.xml index adc0a925b8d..593fa38442c 100644 --- a/debug/org.eclipse.cdt.debug.ui/plugin.xml +++ b/debug/org.eclipse.cdt.debug.ui/plugin.xml @@ -223,20 +223,6 @@ - - - - - - @@ -467,9 +453,9 @@ id="org.eclipse.cdt.debug.ui.AsmEditorPopupActions"> @@ -546,107 +532,6 @@ id="org.eclipse.cdt.debug.internal.ui.actions.NaturalVariableFormatActionDelegate"> - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - diff --git a/debug/org.eclipse.cdt.debug.ui/src/org/eclipse/cdt/debug/internal/ui/actions/AddExpressionActionDelegate.java b/debug/org.eclipse.cdt.debug.ui/src/org/eclipse/cdt/debug/internal/ui/actions/AddExpressionActionDelegate.java deleted file mode 100644 index f9a269db5bc..00000000000 --- a/debug/org.eclipse.cdt.debug.ui/src/org/eclipse/cdt/debug/internal/ui/actions/AddExpressionActionDelegate.java +++ /dev/null @@ -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 ); - } - } - } -} diff --git a/debug/org.eclipse.cdt.debug.ui/src/org/eclipse/cdt/debug/internal/ui/actions/AddExpressionEditorActionDelegate.java b/debug/org.eclipse.cdt.debug.ui/src/org/eclipse/cdt/debug/internal/ui/actions/AddExpressionEditorActionDelegate.java new file mode 100644 index 00000000000..b9682692c42 --- /dev/null +++ b/debug/org.eclipse.cdt.debug.ui/src/org/eclipse/cdt/debug/internal/ui/actions/AddExpressionEditorActionDelegate.java @@ -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(); + } +}