mirror of
https://github.com/eclipse-cdt/cdt
synced 2025-04-23 22:52:11 +02:00
Implementation of the "Toggle Method Breakpoint" retargettable action.
This commit is contained in:
parent
55cf39aba4
commit
9418154ba3
6 changed files with 164 additions and 115 deletions
|
@ -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
|
||||
Added transparency to the icons.
|
||||
* icons/full/cview16/sharedlibraries_view.gif
|
||||
|
|
|
@ -31,9 +31,8 @@ ShowDebuggerConsoleAction.tooltip=Show Debugger Console On Target Selection
|
|||
AddBreakpoint.label=Toggle &Breakpoint
|
||||
EnableBreakpoint.label=&Toggle Breakpoint Enabled
|
||||
BreakpointProperties.label=Breakpoint P&roperties...
|
||||
GlobalManageBreakpointAction.label=Add/Remove Brea&kpoint (C/C++)
|
||||
ManageFunctionBreakpointAction.label=Add/Remove Breakpoint
|
||||
ManageFunctionBreakpointAction.tooltip=Add/Remove Function Breakpoint
|
||||
ManageFunctionBreakpointAction.label=Toggle Breakpoint
|
||||
ManageFunctionBreakpointAction.tooltip=Toggle Function/Method Breakpoint
|
||||
BreakpointPropertiesAction.label=P&roperties...
|
||||
GlobalManageWatchpointAction.label=Add &Watchpoint (C/C++)...
|
||||
AddExpressionAction.label=Add &Expression...
|
||||
|
|
|
@ -1349,6 +1349,16 @@
|
|||
type="org.eclipse.debug.ui.actions.IRunToLineTarget">
|
||||
</adapter>
|
||||
</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
|
||||
point="org.eclipse.ui.themes">
|
||||
|
|
|
@ -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.
|
||||
AbstractRefreshActionDelegate.Error_1=Error
|
||||
AbstractRefreshActionDelegate.Error(s)_occurred_refreshing_the_view_1=Error(s) occurred refreshing the view.
|
||||
ManageFunctionBreakpointActionDelegate.Error_1=Error
|
||||
ManageFunctionBreakpointActionDelegate.Operation_failed_1=Operation failed.
|
||||
|
|
|
@ -1,143 +1,81 @@
|
|||
/*
|
||||
*(c) Copyright QNX Software Systems Ltd. 2002.
|
||||
* All Rights Reserved.
|
||||
/**********************************************************************
|
||||
* 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.core.model.ICElement;
|
||||
import org.eclipse.cdt.core.model.IFunction;
|
||||
import org.eclipse.cdt.core.model.IMethod;
|
||||
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.jface.viewers.IStructuredSelection;
|
||||
import org.eclipse.ui.IObjectActionDelegate;
|
||||
import org.eclipse.ui.IWorkbenchPart;
|
||||
import org.eclipse.ui.actions.ActionDelegate;
|
||||
|
||||
/**
|
||||
* Enter type comment.
|
||||
*
|
||||
* @since Apr 2, 2003
|
||||
* The delegate of the "Toggle Function Breakpoint" action.
|
||||
*/
|
||||
public class ManageFunctionBreakpointActionDelegate extends ActionDelegate
|
||||
implements IObjectActionDelegate
|
||||
{
|
||||
// private IFunction fFunction = null;
|
||||
private ICElement fElement = null;
|
||||
public class ManageFunctionBreakpointActionDelegate extends ActionDelegate implements IObjectActionDelegate {
|
||||
|
||||
/**
|
||||
*
|
||||
*/
|
||||
public ManageFunctionBreakpointActionDelegate()
|
||||
{
|
||||
private ToggleBreakpointAdapter fBreakpointAdapter;
|
||||
|
||||
private IWorkbenchPart fTargetPart;
|
||||
|
||||
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)
|
||||
*/
|
||||
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)
|
||||
*/
|
||||
public void run( IAction action )
|
||||
{
|
||||
if ( getMethod() != null )
|
||||
manageBreakpoint( getMethod() );
|
||||
else if ( getFunction() != null )
|
||||
manageBreakpoint( getFunction() );
|
||||
public void run( IAction action ) {
|
||||
try {
|
||||
getBreakpointAdapter().toggleMethodBreakpoints( getTargetPart(), getSelection() );
|
||||
}
|
||||
catch( CoreException e ) {
|
||||
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)
|
||||
*/
|
||||
public void selectionChanged( IAction action, ISelection selection )
|
||||
{
|
||||
if ( selection instanceof IStructuredSelection )
|
||||
{
|
||||
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 void selectionChanged( IAction action, ISelection selection ) {
|
||||
setSelection( selection );
|
||||
action.setEnabled( getBreakpointAdapter().canToggleMethodBreakpoints( getTargetPart(), getSelection() ) );
|
||||
}
|
||||
|
||||
public ICElement getElement()
|
||||
{
|
||||
return fElement;
|
||||
private IWorkbenchPart getTargetPart() {
|
||||
return fTargetPart;
|
||||
}
|
||||
|
||||
public void setElement( ICElement element )
|
||||
{
|
||||
fElement = element;
|
||||
private ISelection getSelection() {
|
||||
return fSelection;
|
||||
}
|
||||
|
||||
private boolean enablesFor( ICElement element )
|
||||
{
|
||||
// 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 ToggleBreakpointAdapter getBreakpointAdapter() {
|
||||
return fBreakpointAdapter;
|
||||
}
|
||||
|
||||
private void manageBreakpoint( IMethod method )
|
||||
{
|
||||
// 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 void setSelection( ISelection selection ) {
|
||||
fSelection = selection;
|
||||
}
|
||||
|
||||
private IMethod getMethod()
|
||||
{
|
||||
return ( getElement() != null ) ? (IMethod)getElement().getAdapter( IMethod.class ) : null;
|
||||
}
|
||||
}
|
||||
}
|
|
@ -10,8 +10,13 @@
|
|||
***********************************************************************/
|
||||
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.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.ICWatchpoint;
|
||||
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.TextSelection;
|
||||
import org.eclipse.jface.viewers.ISelection;
|
||||
import org.eclipse.jface.viewers.IStructuredSelection;
|
||||
import org.eclipse.jface.window.Window;
|
||||
import org.eclipse.ui.IEditorInput;
|
||||
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)
|
||||
*/
|
||||
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)
|
||||
* @see org.eclipse.debug.ui.actions.IToggleBreakpointsTarget#canToggleMethodBreakpoints(org.eclipse.ui.IWorkbenchPart, org.eclipse.jface.viewers.ISelection)
|
||||
*/
|
||||
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;
|
||||
}
|
||||
|
||||
|
@ -254,7 +307,7 @@ public class ToggleBreakpointAdapter implements IToggleBreakpointsTarget {
|
|||
|
||||
private String getSourceHandle( IEditorInput input ) throws CoreException {
|
||||
if ( input instanceof IFileEditorInput ) {
|
||||
return ((IFileEditorInput)input).getFile().getFullPath().toOSString();
|
||||
return ((IFileEditorInput)input).getFile().getLocation().toOSString();
|
||||
}
|
||||
if ( input instanceof IStorageEditorInput ) {
|
||||
return ((IStorageEditorInput)input).getStorage().getName();
|
||||
|
@ -264,4 +317,43 @@ public class ToggleBreakpointAdapter implements IToggleBreakpointsTarget {
|
|||
}
|
||||
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();
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Add table
Reference in a new issue