1
0
Fork 0
mirror of https://github.com/eclipse-cdt/cdt synced 2025-07-24 09:25:31 +02:00

Added the "Toggle Watchpoint" object contribution action.

This commit is contained in:
Mikhail Khodjaiants 2004-06-15 22:09:22 +00:00
parent f88eb2a537
commit f5ae1a741d
8 changed files with 222 additions and 66 deletions

View file

@ -1,5 +1,15 @@
2004-06-15 Mikhail Khodjaiants
Breakpoint and expression related actions enablemnt should not depend
Added the "Toggle Watchpoint" object contribution action.
* plugin.properties
* plugin.xml
* ActionMessages.properties
* ToggleWatchpointActionDelegate.java: new
* ToggleBreakpointAdapter.java
* icons/full/elcl16/function_brkpt_co.gif: new
* icons/full/elcl16/watchpoint_co.gif: new
2004-06-15 Mikhail Khodjaiants
Breakpoint and expression related actions enablement should not depend
on the activation of the debuggger plugin.
* plugin.xml

Binary file not shown.

After

Width:  |  Height:  |  Size: 154 B

Binary file not shown.

After

Width:  |  Height:  |  Size: 231 B

View file

@ -33,6 +33,8 @@ EnableBreakpoint.label=&Toggle Breakpoint Enabled
BreakpointProperties.label=Breakpoint P&roperties...
ManageFunctionBreakpointAction.label=Toggle Breakpoint
ManageFunctionBreakpointAction.tooltip=Toggle Function/Method Breakpoint
ToggleWatchpointAction.label=Toggle Watchpoint
ToggleWatchpointAction.tooltip=Toggle Variable Watchpoint
BreakpointPropertiesAction.label=P&roperties...
GlobalManageWatchpointAction.label=Add &Watchpoint (C/C++)...
AddExpressionAction.label=Add &Expression...

View file

@ -657,7 +657,7 @@
id="org.eclipse.cdt.debug.ui.FunctionBreakpointActions">
<action
label="%ManageFunctionBreakpointAction.label"
icon="icons/full/obj16/funbrkp_obj.gif"
icon="icons/full/elcl16/function_brkpt_co.gif"
helpContextId="manage_function_breakpoint_action_context"
tooltip="%ManageFunctionBreakpointAction.tooltip"
class="org.eclipse.cdt.debug.internal.ui.actions.ManageFunctionBreakpointActionDelegate"
@ -666,6 +666,19 @@
id="org.eclipse.cdt.debug.internal.ui.actions.ManageFunctionBreakpointActionDelegate">
</action>
</objectContribution>
<objectContribution
objectClass="org.eclipse.cdt.core.model.IVariable"
id="org.eclipse.cdt.debug.ui.WatchpointActions">
<action
helpContextId="toggle_watchpoint_action_context"
enablesFor="1"
label="%ToggleWatchpointAction.label"
icon="icons/full/elcl16/watchpoint_co.gif"
class="org.eclipse.cdt.debug.internal.ui.actions.ToggleWatchpointActionDelegate"
tooltip="%ToggleWatchpointAction.tooltip"
menubarPath="additions"
id="org.eclipse.cdt.debug.internal.ui.actions.ToggleWatchpointActionDelegate"/>
</objectContribution>
<viewerContribution
targetID="org.eclipse.debug.ui.VariableView"
id="org.eclipse.debug.ui.variablesView.popupMenu">

View file

@ -21,6 +21,7 @@ ToggleBreakpointAdapter.Missing_document_1=Missing document
ToggleBreakpointAdapter.Missing_resource_1=Missing resource
ToggleBreakpointAdapter.Invalid_line_1=Invalid line
ToggleBreakpointAdapter.Empty_editor_2=Empty editor
ToggleWatchpointActionDelegate.Error_1=Error
ToggleBreakpointAdapter.Missing_document_2=Missing document
ToggleBreakpointAdapter.Missing_resource_2=Missing resource
ToggleBreakpointAdapter.Invalid_expression_1=Invalid expression:
@ -30,6 +31,7 @@ EnableDisableBreakpointRulerAction.Enabling_disabling_breakpoints_1=Enabling/dis
EnableDisableBreakpointRulerAction.Exceptions_occurred_enabling_or_disabling_breakpoint_1=Exceptions occurred enabling or disabling the breakpoint
EnableDisableBreakpointRulerAction.Disable_Breakpoint_1=&Disable Breakpoint
ToggleBreakpointRulerAction.Toggle_Breakpoint_1=Toggle &Breakpoint
ToggleWatchpointActionDelegate.Operation_failed_1=Operation failed.
ToggleBreakpointRulerAction.Error_1=Error
ToggleBreakpointRulerAction.Operation_failed_1=Operation failed
CBreakpointPropertiesRulerAction.Breakpoint_Properties=Breakpoint &Properties...

View file

@ -11,9 +11,11 @@
package org.eclipse.cdt.debug.internal.ui.actions;
import org.eclipse.cdt.core.model.CModelException;
import org.eclipse.cdt.core.model.IDeclaration;
import org.eclipse.cdt.core.model.IFunction;
import org.eclipse.cdt.core.model.ISourceRange;
import org.eclipse.cdt.core.model.ITranslationUnit;
import org.eclipse.cdt.core.model.IVariable;
import org.eclipse.cdt.debug.core.CDIDebugModel;
import org.eclipse.cdt.debug.core.model.ICAddressBreakpoint;
import org.eclipse.cdt.debug.core.model.ICFunctionBreakpoint;
@ -24,16 +26,15 @@ import org.eclipse.cdt.debug.internal.ui.views.disassembly.DisassemblyView;
import org.eclipse.cdt.debug.ui.CDebugUIPlugin;
import org.eclipse.cdt.debug.ui.ICDebugUIConstants;
import org.eclipse.core.resources.IResource;
import org.eclipse.core.resources.IWorkspaceRoot;
import org.eclipse.core.resources.ResourcesPlugin;
import org.eclipse.core.runtime.CoreException;
import org.eclipse.core.runtime.IPath;
import org.eclipse.core.runtime.IStatus;
import org.eclipse.core.runtime.Status;
import org.eclipse.debug.core.DebugPlugin;
import org.eclipse.debug.ui.actions.IToggleBreakpointsTarget;
import org.eclipse.jface.text.IDocument;
import org.eclipse.jface.text.ITextSelection;
import org.eclipse.jface.text.TextSelection;
import org.eclipse.jface.viewers.ISelection;
import org.eclipse.jface.viewers.IStructuredSelection;
import org.eclipse.jface.window.Window;
@ -163,7 +164,7 @@ public class ToggleBreakpointAdapter implements IToggleBreakpointsTarget {
if ( ss.size() == 1 && ss.getFirstElement() instanceof IFunction ) {
IFunction function = (IFunction)ss.getFirstElement();
String sourceHandle = getSourceHandle( function );
IResource resource = getFunctionResource( function );
IResource resource = getElementResource( function );
String functionName = getFunctionName( function );
ICFunctionBreakpoint breakpoint = CDIDebugModel.functionBreakpointExists( sourceHandle, resource, functionName );
if ( breakpoint != null ) {
@ -219,64 +220,81 @@ public class ToggleBreakpointAdapter implements IToggleBreakpointsTarget {
* @see org.eclipse.debug.ui.actions.IToggleBreakpointsTarget#toggleWatchpoints(org.eclipse.ui.IWorkbenchPart, org.eclipse.jface.viewers.ISelection)
*/
public void toggleWatchpoints( IWorkbenchPart part, ISelection selection ) throws CoreException {
IEditorPart editorPart = (IEditorPart)part;
IEditorInput input = editorPart.getEditorInput();
String errorMessage = null;
if ( input == null ) {
errorMessage = ActionMessages.getString( "ToggleBreakpointAdapter.Empty_editor_2" ); //$NON-NLS-1$
}
else {
ITextEditor textEditor = (ITextEditor)editorPart;
IDocument document = textEditor.getDocumentProvider().getDocument( input );
if ( document == null ) {
errorMessage = ActionMessages.getString( "ToggleBreakpointAdapter.Missing_document_2" ); //$NON-NLS-1$
}
else {
IResource resource = getResource( textEditor );
if ( resource == null ) {
errorMessage = ActionMessages.getString( "ToggleBreakpointAdapter.Missing_resource_2" ); //$NON-NLS-1$
}
else {
if ( !(resource instanceof IWorkspaceRoot) )
resource = resource.getProject();
String expression = ( selection instanceof TextSelection ) ? ((TextSelection)selection).getText().trim() : ""; //$NON-NLS-1$
AddWatchpointDialog dlg = new AddWatchpointDialog( textEditor.getSite().getShell(), true, false, expression );
if ( dlg.open() != Window.OK )
return;
expression = dlg.getExpression();
WatchpointExpressionVerifier wev = new WatchpointExpressionVerifier();
if ( !wev.isValidExpression( document, expression ) ) {
errorMessage = ActionMessages.getString( "ToggleBreakpointAdapter.Invalid_expression_1" ) + expression; //$NON-NLS-1$
}
else {
String sourceHandle = getSourceHandle( input );
ICWatchpoint watchpoint = CDIDebugModel.watchpointExists( sourceHandle, resource, expression );
if ( watchpoint != null ) {
DebugPlugin.getDefault().getBreakpointManager().removeBreakpoint( watchpoint, true );
}
else {
CDIDebugModel.createWatchpoint( sourceHandle,
resource,
dlg.getWriteAccess(),
dlg.getReadAccess(),
expression,
true,
0,
"", //$NON-NLS-1$
true );
}
return;
}
}
if ( selection instanceof IStructuredSelection ) {
IStructuredSelection ss = (IStructuredSelection)selection;
if ( ss.size() == 1 && ss.getFirstElement() instanceof IVariable ) {
toggleVariableWatchpoint( part, (IVariable)ss.getFirstElement() );
}
}
throw new CoreException( new Status( IStatus.ERROR, CDebugUIPlugin.getUniqueIdentifier(), ICDebugUIConstants.INTERNAL_ERROR, errorMessage, null ) );
// String errorMessage = null;
// if ( part instanceof IEditorPart ) {
// IEditorPart editorPart = (IEditorPart)part;
// IEditorInput input = editorPart.getEditorInput();
// if ( input == null ) {
// errorMessage = ActionMessages.getString( "ToggleBreakpointAdapter.Empty_editor_2" ); //$NON-NLS-1$
// }
// else {
// ITextEditor textEditor = (ITextEditor)editorPart;
// IDocument document = textEditor.getDocumentProvider().getDocument( input );
// if ( document == null ) {
// errorMessage = ActionMessages.getString( "ToggleBreakpointAdapter.Missing_document_2" ); //$NON-NLS-1$
// }
// else {
// IResource resource = getResource( textEditor );
// if ( resource == null ) {
// errorMessage = ActionMessages.getString( "ToggleBreakpointAdapter.Missing_resource_2" ); //$NON-NLS-1$
// }
// else {
// if ( !(resource instanceof IWorkspaceRoot) )
// resource = resource.getProject();
// String expression = ( selection instanceof TextSelection ) ? ((TextSelection)selection).getText().trim() : ""; //$NON-NLS-1$
// String sourceHandle = getSourceHandle( input );
// ICWatchpoint watchpoint = CDIDebugModel.watchpointExists( sourceHandle, resource, expression );
// if ( watchpoint != null ) {
// DebugPlugin.getDefault().getBreakpointManager().removeBreakpoint( watchpoint, true );
// }
// else {
// AddWatchpointDialog dlg = new AddWatchpointDialog( textEditor.getSite().getShell(), true, false, expression );
// if ( dlg.open() != Window.OK )
// return;
// expression = dlg.getExpression();
// WatchpointExpressionVerifier wev = new WatchpointExpressionVerifier();
// if ( !wev.isValidExpression( document, expression ) ) {
// errorMessage = ActionMessages.getString( "ToggleBreakpointAdapter.Invalid_expression_1" ) + expression; //$NON-NLS-1$
// }
// else {
// CDIDebugModel.createWatchpoint( sourceHandle,
// resource,
// dlg.getWriteAccess(),
// dlg.getReadAccess(),
// expression,
// true,
// 0,
// "", //$NON-NLS-1$
// true );
// }
// }
// return;
// }
// }
// }
// }
// throw new CoreException( new Status( IStatus.ERROR, CDebugUIPlugin.getUniqueIdentifier(), ICDebugUIConstants.INTERNAL_ERROR, errorMessage, null ) );
}
/* (non-Javadoc)
* @see org.eclipse.debug.ui.actions.IToggleBreakpointsTarget#canToggleWatchpoints(org.eclipse.ui.IWorkbenchPart, org.eclipse.jface.viewers.ISelection)
*/
public boolean canToggleWatchpoints( IWorkbenchPart part, ISelection selection ) {
if ( selection instanceof IStructuredSelection ) {
IStructuredSelection ss = (IStructuredSelection)selection;
if ( ss.size() == 1 ) {
return ( ss.getFirstElement() instanceof IVariable );
}
}
// if ( selection instanceof ITextSelection ) {
// return true;
// }
return false;
}
@ -318,28 +336,51 @@ public class ToggleBreakpointAdapter implements IToggleBreakpointsTarget {
return ""; //$NON-NLS-1$
}
private String getSourceHandle( IFunction function ) {
ITranslationUnit tu = function.getTranslationUnit();
private void toggleVariableWatchpoint( IWorkbenchPart part, IVariable variable ) throws CoreException {
String sourceHandle = getSourceHandle( variable );
IResource resource = getElementResource( variable );
String expression = getVariableName( variable );
ICWatchpoint watchpoint = CDIDebugModel.watchpointExists( sourceHandle, resource, expression );
if ( watchpoint != null ) {
DebugPlugin.getDefault().getBreakpointManager().removeBreakpoint( watchpoint, true );
}
else {
AddWatchpointDialog dlg = new AddWatchpointDialog( part.getSite().getShell(), true, false, expression );
if ( dlg.open() != Window.OK )
return;
expression = dlg.getExpression();
CDIDebugModel.createWatchpoint( sourceHandle,
resource,
dlg.getWriteAccess(),
dlg.getReadAccess(),
expression,
true,
0,
"", //$NON-NLS-1$
true );
}
}
private String getSourceHandle( IDeclaration declaration ) {
ITranslationUnit tu = declaration.getTranslationUnit();
if ( tu != null ) {
IResource resource = tu.getResource();
if ( resource != null ) {
return resource.getLocation().toOSString();
IPath path = tu.getPath();
if ( path != null ) {
return path.toOSString();
}
return tu.getPath().toOSString();
}
return ""; //$NON-NLS-1$
}
private IResource getFunctionResource( IFunction function ) {
ITranslationUnit tu = function.getTranslationUnit();
return (tu != null) ? tu.getResource() : function.getCProject().getProject();
private IResource getElementResource( IDeclaration declaration ) {
return declaration.getUnderlyingResource();
}
private String getFunctionName( IFunction function ) {
String functionName = function.getElementName();
StringBuffer name = new StringBuffer( functionName );
if ( functionName.indexOf( "::" ) != -1 ) //$NON-NLS-1$
{
//??????
if ( functionName.indexOf( "::" ) != -1 && functionName.indexOf( '(' ) == -1 ) { //$NON-NLS-1$
String[] params = function.getParameterTypes();
name.append( '(' );
if ( params.length == 0 ) {
@ -356,4 +397,8 @@ public class ToggleBreakpointAdapter implements IToggleBreakpointsTarget {
}
return name.toString();
}
private String getVariableName( IVariable variable ) {
return variable.getElementName();
}
}

View file

@ -0,0 +1,84 @@
/**********************************************************************
* 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.core.runtime.CoreException;
import org.eclipse.debug.internal.ui.DebugUIPlugin;
import org.eclipse.jface.action.IAction;
import org.eclipse.jface.viewers.ISelection;
import org.eclipse.ui.IObjectActionDelegate;
import org.eclipse.ui.IWorkbenchPart;
import org.eclipse.ui.actions.ActionDelegate;
/**
* The delegate of the "Toggle Watchpoint" action.
*/
public class ToggleWatchpointActionDelegate extends ActionDelegate implements IObjectActionDelegate {
private ToggleBreakpointAdapter fBreakpointAdapter;
private IWorkbenchPart fTargetPart;
private ISelection fSelection;
/**
* Constructor for ToggleWatchpointActionDelegate.
*/
public ToggleWatchpointActionDelegate() {
fBreakpointAdapter = new ToggleBreakpointAdapter();
}
/* (non-Javadoc)
* @see org.eclipse.ui.IObjectActionDelegate#setActivePart(org.eclipse.jface.action.IAction, org.eclipse.ui.IWorkbenchPart)
*/
public void setActivePart( IAction action, IWorkbenchPart targetPart ) {
fTargetPart = targetPart;
}
/* (non-Javadoc)
* @see org.eclipse.ui.IActionDelegate#run(org.eclipse.jface.action.IAction)
*/
public void run( IAction action ) {
try {
getBreakpointAdapter().toggleWatchpoints( getTargetPart(), getSelection() );
}
catch( CoreException e ) {
DebugUIPlugin.errorDialog( getTargetPart().getSite().getShell(),
ActionMessages.getString( "ToggleWatchpointActionDelegate.Error_1" ), //$NON-NLS-1$
ActionMessages.getString( "ToggleWatchpointActionDelegate.Operation_failed_1" ), //$NON-NLS-1$
e.getStatus() );
}
}
/* (non-Javadoc)
* @see org.eclipse.ui.IActionDelegate#selectionChanged(org.eclipse.jface.action.IAction, org.eclipse.jface.viewers.ISelection)
*/
public void selectionChanged( IAction action, ISelection selection ) {
setSelection( selection );
action.setEnabled( getBreakpointAdapter().canToggleWatchpoints( getTargetPart(), getSelection() ) );
}
private IWorkbenchPart getTargetPart() {
return fTargetPart;
}
private ISelection getSelection() {
return fSelection;
}
private ToggleBreakpointAdapter getBreakpointAdapter() {
return fBreakpointAdapter;
}
private void setSelection( ISelection selection ) {
fSelection = selection;
}
}