1
0
Fork 0
mirror of https://github.com/eclipse-cdt/cdt synced 2025-06-08 10:16:03 +02:00

Implementation of the "Toggle Method Breakpoint" retargettable action.

This commit is contained in:
Mikhail Khodjaiants 2004-06-14 20:46:18 +00:00
parent 55cf39aba4
commit 9418154ba3
6 changed files with 164 additions and 115 deletions

View file

@ -1,3 +1,11 @@
2004-06-14 Mikhail Khodjaiants
Implementation of the "Toggle Method Breakpoint" retargettable action.
* plugin.properties
* plugin.xml
* ActionMessages.properties
* ManageFunctionBreakpointActionDelegate.java
* ToggleBreakpointAdapter.java
2004-06-14 Mikhail Khodjaiants 2004-06-14 Mikhail Khodjaiants
Added transparency to the icons. Added transparency to the icons.
* icons/full/cview16/sharedlibraries_view.gif * icons/full/cview16/sharedlibraries_view.gif

View file

@ -31,9 +31,8 @@ ShowDebuggerConsoleAction.tooltip=Show Debugger Console On Target Selection
AddBreakpoint.label=Toggle &Breakpoint AddBreakpoint.label=Toggle &Breakpoint
EnableBreakpoint.label=&Toggle Breakpoint Enabled EnableBreakpoint.label=&Toggle Breakpoint Enabled
BreakpointProperties.label=Breakpoint P&roperties... BreakpointProperties.label=Breakpoint P&roperties...
GlobalManageBreakpointAction.label=Add/Remove Brea&kpoint (C/C++) ManageFunctionBreakpointAction.label=Toggle Breakpoint
ManageFunctionBreakpointAction.label=Add/Remove Breakpoint ManageFunctionBreakpointAction.tooltip=Toggle Function/Method Breakpoint
ManageFunctionBreakpointAction.tooltip=Add/Remove Function Breakpoint
BreakpointPropertiesAction.label=P&roperties... BreakpointPropertiesAction.label=P&roperties...
GlobalManageWatchpointAction.label=Add &Watchpoint (C/C++)... GlobalManageWatchpointAction.label=Add &Watchpoint (C/C++)...
AddExpressionAction.label=Add &Expression... AddExpressionAction.label=Add &Expression...

View file

@ -1349,6 +1349,16 @@
type="org.eclipse.debug.ui.actions.IRunToLineTarget"> type="org.eclipse.debug.ui.actions.IRunToLineTarget">
</adapter> </adapter>
</factory> </factory>
<factory
class="org.eclipse.cdt.debug.internal.ui.actions.RetargettableActionAdapterFactory"
adaptableType="org.eclipse.ui.views.contentoutline.ContentOutline">
<adapter
type="org.eclipse.debug.ui.actions.IToggleBreakpointsTarget">
</adapter>
<adapter
type="org.eclipse.debug.ui.actions.IRunToLineTarget">
</adapter>
</factory>
</extension> </extension>
<extension <extension
point="org.eclipse.ui.themes"> point="org.eclipse.ui.themes">

View file

@ -41,3 +41,5 @@ ResumeAtLineActionDelegate.Operation_is_not_supported_1=Operation is not support
AddGlobalsActionDelegate.Error(s)_occured_adding_globals_1=Error(s) occured adding globals. AddGlobalsActionDelegate.Error(s)_occured_adding_globals_1=Error(s) occured adding globals.
AbstractRefreshActionDelegate.Error_1=Error AbstractRefreshActionDelegate.Error_1=Error
AbstractRefreshActionDelegate.Error(s)_occurred_refreshing_the_view_1=Error(s) occurred refreshing the view. AbstractRefreshActionDelegate.Error(s)_occurred_refreshing_the_view_1=Error(s) occurred refreshing the view.
ManageFunctionBreakpointActionDelegate.Error_1=Error
ManageFunctionBreakpointActionDelegate.Operation_failed_1=Operation failed.

View file

@ -1,143 +1,81 @@
/* /**********************************************************************
*(c) Copyright QNX Software Systems Ltd. 2002. * Copyright (c) 2004 QNX Software Systems and others.
* All Rights Reserved. * 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; package org.eclipse.cdt.debug.internal.ui.actions;
import org.eclipse.cdt.core.model.ICElement; import org.eclipse.core.runtime.CoreException;
import org.eclipse.cdt.core.model.IFunction; import org.eclipse.debug.internal.ui.DebugUIPlugin;
import org.eclipse.cdt.core.model.IMethod;
import org.eclipse.jface.action.IAction; import org.eclipse.jface.action.IAction;
import org.eclipse.jface.viewers.ISelection; import org.eclipse.jface.viewers.ISelection;
import org.eclipse.jface.viewers.IStructuredSelection;
import org.eclipse.ui.IObjectActionDelegate; import org.eclipse.ui.IObjectActionDelegate;
import org.eclipse.ui.IWorkbenchPart; import org.eclipse.ui.IWorkbenchPart;
import org.eclipse.ui.actions.ActionDelegate; import org.eclipse.ui.actions.ActionDelegate;
/** /**
* Enter type comment. * The delegate of the "Toggle Function Breakpoint" action.
*
* @since Apr 2, 2003
*/ */
public class ManageFunctionBreakpointActionDelegate extends ActionDelegate public class ManageFunctionBreakpointActionDelegate extends ActionDelegate implements IObjectActionDelegate {
implements IObjectActionDelegate
{
// private IFunction fFunction = null;
private ICElement fElement = null;
/** private ToggleBreakpointAdapter fBreakpointAdapter;
*
*/ private IWorkbenchPart fTargetPart;
public ManageFunctionBreakpointActionDelegate()
{ private ISelection fSelection;
public ManageFunctionBreakpointActionDelegate() {
fBreakpointAdapter = new ToggleBreakpointAdapter();
} }
/* (non-Javadoc) /*(non-Javadoc)
* @see org.eclipse.ui.IObjectActionDelegate#setActivePart(org.eclipse.jface.action.IAction, org.eclipse.ui.IWorkbenchPart) * @see org.eclipse.ui.IObjectActionDelegate#setActivePart(org.eclipse.jface.action.IAction, org.eclipse.ui.IWorkbenchPart)
*/ */
public void setActivePart( IAction action, IWorkbenchPart targetPart ) public void setActivePart( IAction action, IWorkbenchPart targetPart ) {
{ fTargetPart = targetPart;
} }
/* (non-Javadoc) /*(non-Javadoc)
* @see org.eclipse.ui.IActionDelegate#run(org.eclipse.jface.action.IAction) * @see org.eclipse.ui.IActionDelegate#run(org.eclipse.jface.action.IAction)
*/ */
public void run( IAction action ) public void run( IAction action ) {
{ try {
if ( getMethod() != null ) getBreakpointAdapter().toggleMethodBreakpoints( getTargetPart(), getSelection() );
manageBreakpoint( getMethod() ); }
else if ( getFunction() != null ) catch( CoreException e ) {
manageBreakpoint( getFunction() ); DebugUIPlugin.errorDialog( getTargetPart().getSite().getShell(),
ActionMessages.getString( "ManageFunctionBreakpointActionDelegate.Error_1" ), //$NON-NLS-1$
ActionMessages.getString( "ManageFunctionBreakpointActionDelegate.Operation_failed_1" ), //$NON-NLS-1$
e.getStatus() );
}
} }
/* (non-Javadoc) /*(non-Javadoc)
* @see org.eclipse.ui.IActionDelegate#selectionChanged(org.eclipse.jface.action.IAction, org.eclipse.jface.viewers.ISelection) * @see org.eclipse.ui.IActionDelegate#selectionChanged(org.eclipse.jface.action.IAction, org.eclipse.jface.viewers.ISelection)
*/ */
public void selectionChanged( IAction action, ISelection selection ) public void selectionChanged( IAction action, ISelection selection ) {
{ setSelection( selection );
if ( selection instanceof IStructuredSelection ) action.setEnabled( getBreakpointAdapter().canToggleMethodBreakpoints( getTargetPart(), getSelection() ) );
{
Object element = ((IStructuredSelection)selection).getFirstElement();
if ( element instanceof ICElement )
{
boolean enabled = enablesFor( (ICElement)element );
action.setEnabled( enabled );
if ( enabled )
{
setElement( (ICElement)element );
return;
}
}
}
action.setEnabled( false );
setElement( null );
} }
public ICElement getElement() private IWorkbenchPart getTargetPart() {
{ return fTargetPart;
return fElement;
} }
public void setElement( ICElement element ) private ISelection getSelection() {
{ return fSelection;
fElement = element;
} }
private boolean enablesFor( ICElement element ) private ToggleBreakpointAdapter getBreakpointAdapter() {
{ return fBreakpointAdapter;
// for now
return true;
}
private void manageBreakpoint( IFunction function )
{
// try
// {
// ICFunctionBreakpoint breakpoint = CDebugModel.functionBreakpointExists( function );
// if ( breakpoint != null )
// {
// DebugPlugin.getDefault().getBreakpointManager().removeBreakpoint( breakpoint, true );
// }
// else
// {
// CDebugModel.createFunctionBreakpoint( function, true, 0, "", true ); //$NON-NLS-1$
// }
// }
// catch( CoreException e )
// {
// CDebugUIPlugin.errorDialog( CDebugUIPlugin.getResourceString("internal.ui.actions.ManageFunctionBreakpointActionDelegate.Cannot_add_breakpoint"), e ); //$NON-NLS-1$
// }
}
private IFunction getFunction()
{
return ( getElement() != null ) ? (IFunction)getElement().getAdapter( IFunction.class ) : null;
} }
private void manageBreakpoint( IMethod method ) private void setSelection( ISelection selection ) {
{ fSelection = selection;
// try
// {
// ICFunctionBreakpoint breakpoint = CDebugModel.methodBreakpointExists( method );
// if ( breakpoint != null )
// {
// DebugPlugin.getDefault().getBreakpointManager().removeBreakpoint( breakpoint, true );
// }
// else
// {
// CDebugModel.createMethodBreakpoint( method, true, 0, "", true ); //$NON-NLS-1$
// }
// }
// catch( CoreException e )
// {
// CDebugUIPlugin.errorDialog( CDebugUIPlugin.getResourceString("internal.ui.actions.ManageFunctionBreakpointActionDelegate.Cannot_add_breakpoint"), e ); //$NON-NLS-1$
// }
} }
}
private IMethod getMethod()
{
return ( getElement() != null ) ? (IMethod)getElement().getAdapter( IMethod.class ) : null;
}
}

View file

@ -10,8 +10,13 @@
***********************************************************************/ ***********************************************************************/
package org.eclipse.cdt.debug.internal.ui.actions; package org.eclipse.cdt.debug.internal.ui.actions;
import org.eclipse.cdt.core.model.CModelException;
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.debug.core.CDIDebugModel; import org.eclipse.cdt.debug.core.CDIDebugModel;
import org.eclipse.cdt.debug.core.model.ICAddressBreakpoint; import org.eclipse.cdt.debug.core.model.ICAddressBreakpoint;
import org.eclipse.cdt.debug.core.model.ICFunctionBreakpoint;
import org.eclipse.cdt.debug.core.model.ICLineBreakpoint; import org.eclipse.cdt.debug.core.model.ICLineBreakpoint;
import org.eclipse.cdt.debug.core.model.ICWatchpoint; import org.eclipse.cdt.debug.core.model.ICWatchpoint;
import org.eclipse.cdt.debug.internal.ui.views.disassembly.DisassemblyEditorInput; import org.eclipse.cdt.debug.internal.ui.views.disassembly.DisassemblyEditorInput;
@ -30,6 +35,7 @@ import org.eclipse.jface.text.IDocument;
import org.eclipse.jface.text.ITextSelection; import org.eclipse.jface.text.ITextSelection;
import org.eclipse.jface.text.TextSelection; import org.eclipse.jface.text.TextSelection;
import org.eclipse.jface.viewers.ISelection; import org.eclipse.jface.viewers.ISelection;
import org.eclipse.jface.viewers.IStructuredSelection;
import org.eclipse.jface.window.Window; import org.eclipse.jface.window.Window;
import org.eclipse.ui.IEditorInput; import org.eclipse.ui.IEditorInput;
import org.eclipse.ui.IEditorPart; import org.eclipse.ui.IEditorPart;
@ -152,13 +158,60 @@ public class ToggleBreakpointAdapter implements IToggleBreakpointsTarget {
* @see org.eclipse.debug.ui.actions.IToggleBreakpointsTarget#toggleMethodBreakpoints(org.eclipse.ui.IWorkbenchPart, org.eclipse.jface.viewers.ISelection) * @see org.eclipse.debug.ui.actions.IToggleBreakpointsTarget#toggleMethodBreakpoints(org.eclipse.ui.IWorkbenchPart, org.eclipse.jface.viewers.ISelection)
*/ */
public void toggleMethodBreakpoints( IWorkbenchPart part, ISelection selection ) throws CoreException { public void toggleMethodBreakpoints( IWorkbenchPart part, ISelection selection ) throws CoreException {
// TODO Auto-generated method stub if ( selection instanceof IStructuredSelection ) {
IStructuredSelection ss = (IStructuredSelection)selection;
if ( ss.size() == 1 && ss.getFirstElement() instanceof IFunction ) {
IFunction function = (IFunction)ss.getFirstElement();
String sourceHandle = getSourceHandle( function );
IResource resource = getFunctionResource( function );
String functionName = getFunctionName( function );
ICFunctionBreakpoint breakpoint = CDIDebugModel.functionBreakpointExists( sourceHandle, resource, functionName );
if ( breakpoint != null ) {
DebugPlugin.getDefault().getBreakpointManager().removeBreakpoint( breakpoint, true );
}
else {
int lineNumber = -1;
int charStart = -1;
int charEnd = -1;
try {
ISourceRange sourceRange = function.getSourceRange();
if ( sourceRange != null ) {
charStart = sourceRange.getStartPos();
charEnd = charStart + sourceRange.getLength();
// for now
if ( charEnd == 0 )
lineNumber = sourceRange.getStartLine();
}
}
catch( CModelException e ) {
DebugPlugin.log( e );
}
CDIDebugModel.createFunctionBreakpoint( sourceHandle,
resource,
functionName,
charStart,
charEnd,
lineNumber,
true,
0,
"", //$NON-NLS-1$
true );
}
}
}
} }
/* (non-Javadoc) /* (non-Javadoc)
* @see org.eclipse.debug.ui.actions.IToggleBreakpointsTarget#canToggleMethodBreakpoints(org.eclipse.ui.IWorkbenchPart, org.eclipse.jface.viewers.ISelection) * @see org.eclipse.debug.ui.actions.IToggleBreakpointsTarget#canToggleMethodBreakpoints(org.eclipse.ui.IWorkbenchPart, org.eclipse.jface.viewers.ISelection)
*/ */
public boolean canToggleMethodBreakpoints( IWorkbenchPart part, ISelection selection ) { public boolean canToggleMethodBreakpoints( IWorkbenchPart part, ISelection selection ) {
if ( selection instanceof IStructuredSelection ) {
IStructuredSelection ss = (IStructuredSelection)selection;
if ( ss.size() == 1 ) {
return ( ss.getFirstElement() instanceof IFunction );
}
}
return false; return false;
} }
@ -254,7 +307,7 @@ public class ToggleBreakpointAdapter implements IToggleBreakpointsTarget {
private String getSourceHandle( IEditorInput input ) throws CoreException { private String getSourceHandle( IEditorInput input ) throws CoreException {
if ( input instanceof IFileEditorInput ) { if ( input instanceof IFileEditorInput ) {
return ((IFileEditorInput)input).getFile().getFullPath().toOSString(); return ((IFileEditorInput)input).getFile().getLocation().toOSString();
} }
if ( input instanceof IStorageEditorInput ) { if ( input instanceof IStorageEditorInput ) {
return ((IStorageEditorInput)input).getStorage().getName(); return ((IStorageEditorInput)input).getStorage().getName();
@ -264,4 +317,43 @@ public class ToggleBreakpointAdapter implements IToggleBreakpointsTarget {
} }
return ""; //$NON-NLS-1$ return ""; //$NON-NLS-1$
} }
private String getSourceHandle( IFunction function ) {
ITranslationUnit tu = function.getTranslationUnit();
if ( tu != null ) {
IResource resource = tu.getResource();
if ( resource != null ) {
return resource.getLocation().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 String getFunctionName( IFunction function ) {
String functionName = function.getElementName();
StringBuffer name = new StringBuffer( functionName );
if ( functionName.indexOf( "::" ) != -1 ) //$NON-NLS-1$
{
String[] params = function.getParameterTypes();
name.append( '(' );
if ( params.length == 0 ) {
name.append( "void" ); //$NON-NLS-1$
}
else {
for( int i = 0; i < params.length; ++i ) {
name.append( params[i] );
if ( i != params.length - 1 )
name.append( ',' );
}
}
name.append( ')' );
}
return name.toString();
}
} }