mirror of
https://github.com/eclipse-cdt/cdt
synced 2025-06-06 17:26:01 +02:00
Implementation of 'Run To Line' action.
This commit is contained in:
parent
e71171b519
commit
4b389fbd48
10 changed files with 416 additions and 184 deletions
|
@ -0,0 +1,32 @@
|
||||||
|
/*
|
||||||
|
*(c) Copyright QNX Software Systems Ltd. 2002.
|
||||||
|
* All Rights Reserved.
|
||||||
|
*
|
||||||
|
*/
|
||||||
|
package org.eclipse.cdt.debug.core;
|
||||||
|
|
||||||
|
import org.eclipse.core.resources.IResource;
|
||||||
|
import org.eclipse.debug.core.DebugException;
|
||||||
|
|
||||||
|
/**
|
||||||
|
*
|
||||||
|
* Provides the ability to run a debug target to the given line.
|
||||||
|
*
|
||||||
|
* @since Sep 19, 2002
|
||||||
|
*/
|
||||||
|
public interface IRunToLine
|
||||||
|
{
|
||||||
|
/**
|
||||||
|
* Returns whether this operation is currently available for this element.
|
||||||
|
*
|
||||||
|
* @return whether this operation is currently available
|
||||||
|
*/
|
||||||
|
public boolean canRunToLine( IResource resource, int lineNumber );
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Causes this element to run to specified location.
|
||||||
|
*
|
||||||
|
* @exception DebugException on failure. Reasons include:
|
||||||
|
*/
|
||||||
|
public void runToLine( IResource resource, int lineNumber ) throws DebugException;
|
||||||
|
}
|
|
@ -21,6 +21,7 @@ import org.eclipse.cdt.debug.core.ICWatchpoint;
|
||||||
import org.eclipse.cdt.debug.core.IFormattedMemoryBlock;
|
import org.eclipse.cdt.debug.core.IFormattedMemoryBlock;
|
||||||
import org.eclipse.cdt.debug.core.IFormattedMemoryRetrieval;
|
import org.eclipse.cdt.debug.core.IFormattedMemoryRetrieval;
|
||||||
import org.eclipse.cdt.debug.core.IRestart;
|
import org.eclipse.cdt.debug.core.IRestart;
|
||||||
|
import org.eclipse.cdt.debug.core.IRunToLine;
|
||||||
import org.eclipse.cdt.debug.core.IState;
|
import org.eclipse.cdt.debug.core.IState;
|
||||||
import org.eclipse.cdt.debug.core.cdi.CDIException;
|
import org.eclipse.cdt.debug.core.cdi.CDIException;
|
||||||
import org.eclipse.cdt.debug.core.cdi.ICDIBreakpointHit;
|
import org.eclipse.cdt.debug.core.cdi.ICDIBreakpointHit;
|
||||||
|
@ -55,6 +56,7 @@ import org.eclipse.cdt.debug.internal.core.CSourceLocator;
|
||||||
import org.eclipse.cdt.debug.internal.core.breakpoints.CBreakpoint;
|
import org.eclipse.cdt.debug.internal.core.breakpoints.CBreakpoint;
|
||||||
import org.eclipse.core.resources.IMarkerDelta;
|
import org.eclipse.core.resources.IMarkerDelta;
|
||||||
import org.eclipse.core.resources.IProject;
|
import org.eclipse.core.resources.IProject;
|
||||||
|
import org.eclipse.core.resources.IResource;
|
||||||
import org.eclipse.core.runtime.CoreException;
|
import org.eclipse.core.runtime.CoreException;
|
||||||
import org.eclipse.debug.core.DebugEvent;
|
import org.eclipse.debug.core.DebugEvent;
|
||||||
import org.eclipse.debug.core.DebugException;
|
import org.eclipse.debug.core.DebugException;
|
||||||
|
@ -82,6 +84,7 @@ public class CDebugTarget extends CDebugElement
|
||||||
implements IDebugTarget,
|
implements IDebugTarget,
|
||||||
ICDIEventListener,
|
ICDIEventListener,
|
||||||
IRestart,
|
IRestart,
|
||||||
|
IRunToLine,
|
||||||
IFormattedMemoryRetrieval,
|
IFormattedMemoryRetrieval,
|
||||||
IState,
|
IState,
|
||||||
ILaunchListener,
|
ILaunchListener,
|
||||||
|
@ -1789,4 +1792,26 @@ public class CDebugTarget extends CDebugElement
|
||||||
targetRequestFailed( e.getMessage(), null );
|
targetRequestFailed( e.getMessage(), null );
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/* (non-Javadoc)
|
||||||
|
* @see org.eclipse.cdt.debug.core.IRunToLine#canRunToLine(IResource, int)
|
||||||
|
*/
|
||||||
|
public boolean canRunToLine( IResource resource, int lineNumber )
|
||||||
|
{
|
||||||
|
// check if supports run to line
|
||||||
|
return canResume();
|
||||||
|
}
|
||||||
|
|
||||||
|
/* (non-Javadoc)
|
||||||
|
* @see org.eclipse.cdt.debug.core.IRunToLine#runToLine(IResource, int)
|
||||||
|
*/
|
||||||
|
public void runToLine( IResource resource, int lineNumber ) throws DebugException
|
||||||
|
{
|
||||||
|
if ( !canRunToLine( resource, lineNumber ) )
|
||||||
|
{
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
setInternalTemporaryBreakpoint( getCDISession().getBreakpointManager().createLocation( resource.getLocation().lastSegment(), null, lineNumber ) );
|
||||||
|
resume();
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
Binary file not shown.
After Width: | Height: | Size: 138 B |
Binary file not shown.
After Width: | Height: | Size: 104 B |
Binary file not shown.
After Width: | Height: | Size: 109 B |
|
@ -26,3 +26,4 @@ ManageBreakpointAction.label=Add/Remove C/C++ Brea&kpoint
|
||||||
BreakpointPropertiesAction.label=P&roperties...
|
BreakpointPropertiesAction.label=P&roperties...
|
||||||
ManageWatchpointAction.label=Add C/C++ &Watchpoint...
|
ManageWatchpointAction.label=Add C/C++ &Watchpoint...
|
||||||
AddExpressionAction.label=Add C/C++ &Expression...
|
AddExpressionAction.label=Add C/C++ &Expression...
|
||||||
|
RunToLineAction.label=Run To C/C++ &Line
|
|
@ -120,6 +120,23 @@
|
||||||
</pluginState>
|
</pluginState>
|
||||||
</enablement>
|
</enablement>
|
||||||
</action>
|
</action>
|
||||||
|
<action
|
||||||
|
id="org.eclipse.cdt.debug.ui.internal.actions.RunToLineActionDelegate"
|
||||||
|
hoverIcon="icons/full/clcl16/runtoline_co.gif"
|
||||||
|
class="org.eclipse.cdt.debug.internal.ui.actions.RunToLineActionDelegate"
|
||||||
|
disabledIcon="icons/full/dlcl16/runtoline_co.gif"
|
||||||
|
enablesFor="1"
|
||||||
|
icon="icons/full/elcl16/runtoline_co.gif"
|
||||||
|
helpContextId="run_to_line_action_context"
|
||||||
|
label="%RunToLineAction.label"
|
||||||
|
menubarPath="org.eclipse.ui.run/stepGroup">
|
||||||
|
<enablement>
|
||||||
|
<pluginState
|
||||||
|
value="activated"
|
||||||
|
id="org.eclipse.cdt.debug.ui">
|
||||||
|
</pluginState>
|
||||||
|
</enablement>
|
||||||
|
</action>
|
||||||
<action
|
<action
|
||||||
label="%ManageBreakpointAction.label"
|
label="%ManageBreakpointAction.label"
|
||||||
icon="icons/full/obj16/brkpi_obj.gif"
|
icon="icons/full/obj16/brkpi_obj.gif"
|
||||||
|
@ -175,9 +192,15 @@
|
||||||
icon="icons/full/clcl16/restart.gif"
|
icon="icons/full/clcl16/restart.gif"
|
||||||
helpContextId="restart_action_context"
|
helpContextId="restart_action_context"
|
||||||
class="org.eclipse.cdt.debug.internal.ui.actions.RestartActionDelegate"
|
class="org.eclipse.cdt.debug.internal.ui.actions.RestartActionDelegate"
|
||||||
menubarPath="threadGroup"
|
menubarPath="stepGroup"
|
||||||
enablesFor="1"
|
enablesFor="1"
|
||||||
id="org.eclipse.cdt.debug.internal.ui.actions.RestartActionDelegate">
|
id="org.eclipse.cdt.debug.internal.ui.actions.RestartActionDelegate">
|
||||||
|
<enablement>
|
||||||
|
<pluginState
|
||||||
|
value="activated"
|
||||||
|
id="org.eclipse.cdt.debug.ui">
|
||||||
|
</pluginState>
|
||||||
|
</enablement>
|
||||||
</action>
|
</action>
|
||||||
</viewerContribution>
|
</viewerContribution>
|
||||||
<viewerContribution
|
<viewerContribution
|
||||||
|
@ -222,6 +245,21 @@
|
||||||
</pluginState>
|
</pluginState>
|
||||||
</enablement>
|
</enablement>
|
||||||
</action>
|
</action>
|
||||||
|
<action
|
||||||
|
menubarPath="additions"
|
||||||
|
label="%RunToLineAction.label"
|
||||||
|
icon="icons/full/clcl16/runtoline_co.gif"
|
||||||
|
class="org.eclipse.cdt.debug.internal.ui.actions.RunToLineActionDelegate"
|
||||||
|
enablesFor="1"
|
||||||
|
id="org.eclipse.cdt.debug.internal.ui.actions.RunToLineActionDelegate"
|
||||||
|
helpContextId="run_to_line_action_context">
|
||||||
|
<enablement>
|
||||||
|
<pluginState
|
||||||
|
value="activated"
|
||||||
|
id="org.eclipse.cdt.debug.ui">
|
||||||
|
</pluginState>
|
||||||
|
</enablement>
|
||||||
|
</action>
|
||||||
</viewerContribution>
|
</viewerContribution>
|
||||||
<objectContribution
|
<objectContribution
|
||||||
objectClass="org.eclipse.cdt.debug.core.ICBreakpoint"
|
objectClass="org.eclipse.cdt.debug.core.ICBreakpoint"
|
||||||
|
|
|
@ -0,0 +1,224 @@
|
||||||
|
/*
|
||||||
|
*(c) Copyright QNX Software Systems Ltd. 2002.
|
||||||
|
* All Rights Reserved.
|
||||||
|
*
|
||||||
|
*/
|
||||||
|
package org.eclipse.cdt.debug.internal.ui.actions;
|
||||||
|
|
||||||
|
import org.eclipse.cdt.debug.ui.CDebugUIPlugin;
|
||||||
|
import org.eclipse.debug.core.model.IDebugTarget;
|
||||||
|
import org.eclipse.debug.ui.IDebugUIConstants;
|
||||||
|
import org.eclipse.jface.action.IAction;
|
||||||
|
import org.eclipse.jface.viewers.ISelection;
|
||||||
|
import org.eclipse.jface.viewers.ISelectionProvider;
|
||||||
|
import org.eclipse.ui.IEditorActionDelegate;
|
||||||
|
import org.eclipse.ui.IEditorPart;
|
||||||
|
import org.eclipse.ui.INullSelectionListener;
|
||||||
|
import org.eclipse.ui.IPartListener;
|
||||||
|
import org.eclipse.ui.ISelectionListener;
|
||||||
|
import org.eclipse.ui.IWorkbenchPage;
|
||||||
|
import org.eclipse.ui.IWorkbenchPart;
|
||||||
|
import org.eclipse.ui.IWorkbenchWindow;
|
||||||
|
import org.eclipse.ui.IWorkbenchWindowActionDelegate;
|
||||||
|
|
||||||
|
/**
|
||||||
|
*
|
||||||
|
* Enter type comment.
|
||||||
|
*
|
||||||
|
* @since Sep 19, 2002
|
||||||
|
*/
|
||||||
|
public abstract class AbstractEditorActionDelegate implements IWorkbenchWindowActionDelegate,
|
||||||
|
IEditorActionDelegate,
|
||||||
|
IPartListener,
|
||||||
|
ISelectionListener,
|
||||||
|
INullSelectionListener
|
||||||
|
{
|
||||||
|
private IAction fAction;
|
||||||
|
private IWorkbenchWindow fWorkbenchWindow;
|
||||||
|
private IWorkbenchPart fTargetPart;
|
||||||
|
private IEditorPart fTargetEditor;
|
||||||
|
private IDebugTarget fDebugTarget = null;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Constructor for AbstractEditorActionDelegate.
|
||||||
|
*/
|
||||||
|
public AbstractEditorActionDelegate()
|
||||||
|
{
|
||||||
|
}
|
||||||
|
|
||||||
|
/* (non-Javadoc)
|
||||||
|
* @see org.eclipse.ui.IWorkbenchWindowActionDelegate#dispose()
|
||||||
|
*/
|
||||||
|
public void dispose()
|
||||||
|
{
|
||||||
|
IWorkbenchWindow win = getWorkbenchWindow();
|
||||||
|
if ( win != null )
|
||||||
|
{
|
||||||
|
win.getPartService().removePartListener( this );
|
||||||
|
win.getSelectionService().removeSelectionListener( IDebugUIConstants.ID_DEBUG_VIEW, this );
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
/* (non-Javadoc)
|
||||||
|
* @see org.eclipse.ui.IWorkbenchWindowActionDelegate#init(IWorkbenchWindow)
|
||||||
|
*/
|
||||||
|
public void init( IWorkbenchWindow window )
|
||||||
|
{
|
||||||
|
setWorkbenchWindow( window );
|
||||||
|
IWorkbenchPage page = window.getActivePage();
|
||||||
|
if ( page != null )
|
||||||
|
{
|
||||||
|
setTargetPart( page.getActivePart() );
|
||||||
|
}
|
||||||
|
window.getPartService().addPartListener( this );
|
||||||
|
window.getSelectionService().addSelectionListener( IDebugUIConstants.ID_DEBUG_VIEW, this );
|
||||||
|
initializeDebugTarget();
|
||||||
|
update();
|
||||||
|
}
|
||||||
|
|
||||||
|
/* (non-Javadoc)
|
||||||
|
* @see org.eclipse.ui.IEditorActionDelegate#setActiveEditor(IAction, IEditorPart)
|
||||||
|
*/
|
||||||
|
public void setActiveEditor( IAction action, IEditorPart targetEditor )
|
||||||
|
{
|
||||||
|
setAction( action );
|
||||||
|
if ( getWorkbenchWindow() == null )
|
||||||
|
{
|
||||||
|
IWorkbenchWindow window = CDebugUIPlugin.getActiveWorkbenchWindow();
|
||||||
|
setWorkbenchWindow( window );
|
||||||
|
if ( window != null )
|
||||||
|
{
|
||||||
|
window.getSelectionService().addSelectionListener( IDebugUIConstants.ID_DEBUG_VIEW, this );
|
||||||
|
}
|
||||||
|
}
|
||||||
|
setTargetPart( targetEditor );
|
||||||
|
initializeDebugTarget();
|
||||||
|
update();
|
||||||
|
}
|
||||||
|
|
||||||
|
/* (non-Javadoc)
|
||||||
|
* @see org.eclipse.ui.IPartListener#partActivated(IWorkbenchPart)
|
||||||
|
*/
|
||||||
|
public void partActivated( IWorkbenchPart part )
|
||||||
|
{
|
||||||
|
setTargetPart( part );
|
||||||
|
}
|
||||||
|
|
||||||
|
/* (non-Javadoc)
|
||||||
|
* @see org.eclipse.ui.IPartListener#partBroughtToTop(IWorkbenchPart)
|
||||||
|
*/
|
||||||
|
public void partBroughtToTop( IWorkbenchPart part )
|
||||||
|
{
|
||||||
|
}
|
||||||
|
|
||||||
|
/* (non-Javadoc)
|
||||||
|
* @see org.eclipse.ui.IPartListener#partClosed(IWorkbenchPart)
|
||||||
|
*/
|
||||||
|
public void partClosed( IWorkbenchPart part )
|
||||||
|
{
|
||||||
|
if ( part == getTargetPart() )
|
||||||
|
{
|
||||||
|
setTargetPart( null );
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
/* (non-Javadoc)
|
||||||
|
* @see org.eclipse.ui.IPartListener#partDeactivated(IWorkbenchPart)
|
||||||
|
*/
|
||||||
|
public void partDeactivated(IWorkbenchPart part)
|
||||||
|
{
|
||||||
|
}
|
||||||
|
|
||||||
|
/* (non-Javadoc)
|
||||||
|
* @see org.eclipse.ui.IPartListener#partOpened(IWorkbenchPart)
|
||||||
|
*/
|
||||||
|
public void partOpened( IWorkbenchPart part )
|
||||||
|
{
|
||||||
|
}
|
||||||
|
|
||||||
|
/* (non-Javadoc)
|
||||||
|
* @see org.eclipse.ui.ISelectionListener#selectionChanged(IWorkbenchPart, ISelection)
|
||||||
|
*/
|
||||||
|
public void selectionChanged( IWorkbenchPart part, ISelection selection )
|
||||||
|
{
|
||||||
|
}
|
||||||
|
|
||||||
|
/* (non-Javadoc)
|
||||||
|
* @see org.eclipse.ui.IActionDelegate#run(IAction)
|
||||||
|
*/
|
||||||
|
public abstract void run( IAction action );
|
||||||
|
|
||||||
|
/* (non-Javadoc)
|
||||||
|
* @see org.eclipse.ui.IActionDelegate#selectionChanged(IAction, ISelection)
|
||||||
|
*/
|
||||||
|
public void selectionChanged(IAction action, ISelection selection)
|
||||||
|
{
|
||||||
|
setAction( action );
|
||||||
|
update();
|
||||||
|
}
|
||||||
|
|
||||||
|
protected IWorkbenchPart getTargetPart()
|
||||||
|
{
|
||||||
|
return fTargetPart;
|
||||||
|
}
|
||||||
|
|
||||||
|
protected void setTargetPart( IWorkbenchPart part )
|
||||||
|
{
|
||||||
|
fTargetPart = part;
|
||||||
|
}
|
||||||
|
|
||||||
|
protected ISelection getTargetSelection()
|
||||||
|
{
|
||||||
|
IWorkbenchPart part = getTargetPart();
|
||||||
|
if ( part != null )
|
||||||
|
{
|
||||||
|
ISelectionProvider provider = part.getSite().getSelectionProvider();
|
||||||
|
if ( provider != null )
|
||||||
|
{
|
||||||
|
return provider.getSelection();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
|
||||||
|
protected void setDebugTarget( IDebugTarget target )
|
||||||
|
{
|
||||||
|
fDebugTarget = target;
|
||||||
|
}
|
||||||
|
|
||||||
|
protected IDebugTarget getDebugTarget()
|
||||||
|
{
|
||||||
|
return fDebugTarget;
|
||||||
|
}
|
||||||
|
|
||||||
|
protected IAction getAction()
|
||||||
|
{
|
||||||
|
return fAction;
|
||||||
|
}
|
||||||
|
|
||||||
|
protected void setAction( IAction action )
|
||||||
|
{
|
||||||
|
fAction = action;
|
||||||
|
}
|
||||||
|
|
||||||
|
protected IWorkbenchWindow getWorkbenchWindow()
|
||||||
|
{
|
||||||
|
return fWorkbenchWindow;
|
||||||
|
}
|
||||||
|
|
||||||
|
protected void setWorkbenchWindow( IWorkbenchWindow workbenchWindow )
|
||||||
|
{
|
||||||
|
fWorkbenchWindow = workbenchWindow;
|
||||||
|
}
|
||||||
|
|
||||||
|
protected void update()
|
||||||
|
{
|
||||||
|
IAction action = getAction();
|
||||||
|
if ( action != null )
|
||||||
|
{
|
||||||
|
action.setEnabled( getDebugTarget() != null && getTargetPart() != null );
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
protected abstract void initializeDebugTarget();
|
||||||
|
}
|
|
@ -20,23 +20,13 @@ import org.eclipse.jface.action.IAction;
|
||||||
import org.eclipse.jface.dialogs.Dialog;
|
import org.eclipse.jface.dialogs.Dialog;
|
||||||
import org.eclipse.jface.text.ITextSelection;
|
import org.eclipse.jface.text.ITextSelection;
|
||||||
import org.eclipse.jface.viewers.ISelection;
|
import org.eclipse.jface.viewers.ISelection;
|
||||||
import org.eclipse.jface.viewers.ISelectionProvider;
|
|
||||||
import org.eclipse.jface.viewers.IStructuredSelection;
|
import org.eclipse.jface.viewers.IStructuredSelection;
|
||||||
import org.eclipse.jface.viewers.SelectionChangedEvent;
|
|
||||||
import org.eclipse.swt.widgets.Display;
|
import org.eclipse.swt.widgets.Display;
|
||||||
import org.eclipse.swt.widgets.Shell;
|
import org.eclipse.swt.widgets.Shell;
|
||||||
import org.eclipse.ui.IEditorActionDelegate;
|
|
||||||
import org.eclipse.ui.IEditorPart;
|
|
||||||
import org.eclipse.ui.INullSelectionListener;
|
|
||||||
import org.eclipse.ui.IPartListener;
|
|
||||||
import org.eclipse.ui.ISelectionListener;
|
|
||||||
import org.eclipse.ui.IViewPart;
|
import org.eclipse.ui.IViewPart;
|
||||||
import org.eclipse.ui.IWorkbenchPage;
|
import org.eclipse.ui.IWorkbenchPage;
|
||||||
import org.eclipse.ui.IWorkbenchPart;
|
import org.eclipse.ui.IWorkbenchPart;
|
||||||
import org.eclipse.ui.IWorkbenchWindow;
|
|
||||||
import org.eclipse.ui.IWorkbenchWindowActionDelegate;
|
|
||||||
import org.eclipse.ui.PartInitException;
|
import org.eclipse.ui.PartInitException;
|
||||||
import org.eclipse.ui.texteditor.ITextEditor;
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
*
|
*
|
||||||
|
@ -44,18 +34,8 @@ import org.eclipse.ui.texteditor.ITextEditor;
|
||||||
*
|
*
|
||||||
* @since Sep 17, 2002
|
* @since Sep 17, 2002
|
||||||
*/
|
*/
|
||||||
public class AddExpressionActionDelegate implements IWorkbenchWindowActionDelegate,
|
public class AddExpressionActionDelegate extends AbstractEditorActionDelegate
|
||||||
IEditorActionDelegate,
|
|
||||||
IPartListener,
|
|
||||||
ISelectionListener,
|
|
||||||
INullSelectionListener
|
|
||||||
{
|
{
|
||||||
private IAction fAction;
|
|
||||||
private IWorkbenchWindow fWorkbenchWindow;
|
|
||||||
private IWorkbenchPart fTargetPart;
|
|
||||||
private IEditorPart fTargetEditor;
|
|
||||||
private IDebugTarget fDebugTarget = null;
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Constructor for AddExpressionActionDelegate.
|
* Constructor for AddExpressionActionDelegate.
|
||||||
*/
|
*/
|
||||||
|
@ -63,76 +43,6 @@ public class AddExpressionActionDelegate implements IWorkbenchWindowActionDelega
|
||||||
{
|
{
|
||||||
}
|
}
|
||||||
|
|
||||||
/* (non-Javadoc)
|
|
||||||
* @see org.eclipse.ui.IWorkbenchWindowActionDelegate#dispose()
|
|
||||||
*/
|
|
||||||
public void dispose()
|
|
||||||
{
|
|
||||||
IWorkbenchWindow win = getWorkbenchWindow();
|
|
||||||
if ( win != null )
|
|
||||||
{
|
|
||||||
win.getPartService().removePartListener( this );
|
|
||||||
win.getSelectionService().removeSelectionListener( IDebugUIConstants.ID_DEBUG_VIEW, this );
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
/* (non-Javadoc)
|
|
||||||
* @see org.eclipse.ui.IWorkbenchWindowActionDelegate#init(IWorkbenchWindow)
|
|
||||||
*/
|
|
||||||
public void init( IWorkbenchWindow window )
|
|
||||||
{
|
|
||||||
setWorkbenchWindow( window );
|
|
||||||
IWorkbenchPage page = window.getActivePage();
|
|
||||||
if ( page != null )
|
|
||||||
{
|
|
||||||
setTargetPart( page.getActivePart() );
|
|
||||||
}
|
|
||||||
window.getPartService().addPartListener( this );
|
|
||||||
window.getSelectionService().addSelectionListener( IDebugUIConstants.ID_DEBUG_VIEW, this );
|
|
||||||
initializeDebugTarget();
|
|
||||||
update();
|
|
||||||
}
|
|
||||||
|
|
||||||
/* (non-Javadoc)
|
|
||||||
* @see org.eclipse.ui.IPartListener#partActivated(IWorkbenchPart)
|
|
||||||
*/
|
|
||||||
public void partActivated( IWorkbenchPart part )
|
|
||||||
{
|
|
||||||
setTargetPart( part );
|
|
||||||
}
|
|
||||||
|
|
||||||
/* (non-Javadoc)
|
|
||||||
* @see org.eclipse.ui.IPartListener#partBroughtToTop(IWorkbenchPart)
|
|
||||||
*/
|
|
||||||
public void partBroughtToTop( IWorkbenchPart part )
|
|
||||||
{
|
|
||||||
}
|
|
||||||
|
|
||||||
/* (non-Javadoc)
|
|
||||||
* @see org.eclipse.ui.IPartListener#partClosed(IWorkbenchPart)
|
|
||||||
*/
|
|
||||||
public void partClosed( IWorkbenchPart part )
|
|
||||||
{
|
|
||||||
if ( part == getTargetPart() )
|
|
||||||
{
|
|
||||||
setTargetPart( null );
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
/* (non-Javadoc)
|
|
||||||
* @see org.eclipse.ui.IPartListener#partDeactivated(IWorkbenchPart)
|
|
||||||
*/
|
|
||||||
public void partDeactivated( IWorkbenchPart part )
|
|
||||||
{
|
|
||||||
}
|
|
||||||
|
|
||||||
/* (non-Javadoc)
|
|
||||||
* @see org.eclipse.ui.IPartListener#partOpened(IWorkbenchPart)
|
|
||||||
*/
|
|
||||||
public void partOpened( IWorkbenchPart part )
|
|
||||||
{
|
|
||||||
}
|
|
||||||
|
|
||||||
/* (non-Javadoc)
|
/* (non-Javadoc)
|
||||||
* @see org.eclipse.ui.IActionDelegate#run(IAction)
|
* @see org.eclipse.ui.IActionDelegate#run(IAction)
|
||||||
*/
|
*/
|
||||||
|
@ -145,35 +55,6 @@ public class AddExpressionActionDelegate implements IWorkbenchWindowActionDelega
|
||||||
createExpression( dlg.getExpression() );
|
createExpression( dlg.getExpression() );
|
||||||
}
|
}
|
||||||
|
|
||||||
/* (non-Javadoc)
|
|
||||||
* @see org.eclipse.ui.IActionDelegate#selectionChanged(IAction, ISelection)
|
|
||||||
*/
|
|
||||||
public void selectionChanged( IAction action, ISelection selection )
|
|
||||||
{
|
|
||||||
setAction( action );
|
|
||||||
update();
|
|
||||||
}
|
|
||||||
|
|
||||||
protected IAction getAction()
|
|
||||||
{
|
|
||||||
return fAction;
|
|
||||||
}
|
|
||||||
|
|
||||||
protected void setAction( IAction action )
|
|
||||||
{
|
|
||||||
fAction = action;
|
|
||||||
}
|
|
||||||
|
|
||||||
protected IWorkbenchWindow getWorkbenchWindow()
|
|
||||||
{
|
|
||||||
return fWorkbenchWindow;
|
|
||||||
}
|
|
||||||
|
|
||||||
protected void setWorkbenchWindow( IWorkbenchWindow workbenchWindow )
|
|
||||||
{
|
|
||||||
fWorkbenchWindow = workbenchWindow;
|
|
||||||
}
|
|
||||||
|
|
||||||
protected String getSelectedText()
|
protected String getSelectedText()
|
||||||
{
|
{
|
||||||
ISelection selection = getTargetSelection();
|
ISelection selection = getTargetSelection();
|
||||||
|
@ -184,45 +65,6 @@ public class AddExpressionActionDelegate implements IWorkbenchWindowActionDelega
|
||||||
return "";
|
return "";
|
||||||
}
|
}
|
||||||
|
|
||||||
protected void update()
|
|
||||||
{
|
|
||||||
IAction action = getAction();
|
|
||||||
if ( action != null )
|
|
||||||
{
|
|
||||||
action.setEnabled( getDebugTarget() != null && getTargetPart() != null );
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
/* (non-Javadoc)
|
|
||||||
* @see org.eclipse.ui.IEditorActionDelegate#setActiveEditor(IAction, IEditorPart)
|
|
||||||
*/
|
|
||||||
public void setActiveEditor( IAction action, IEditorPart targetEditor )
|
|
||||||
{
|
|
||||||
setAction( action );
|
|
||||||
if ( getWorkbenchWindow() == null )
|
|
||||||
{
|
|
||||||
IWorkbenchWindow window = CDebugUIPlugin.getActiveWorkbenchWindow();
|
|
||||||
setWorkbenchWindow( window );
|
|
||||||
if ( window != null )
|
|
||||||
{
|
|
||||||
window.getSelectionService().addSelectionListener( IDebugUIConstants.ID_DEBUG_VIEW, this );
|
|
||||||
}
|
|
||||||
}
|
|
||||||
setTargetPart( targetEditor );
|
|
||||||
initializeDebugTarget();
|
|
||||||
update();
|
|
||||||
}
|
|
||||||
|
|
||||||
protected IWorkbenchPart getTargetPart()
|
|
||||||
{
|
|
||||||
return fTargetPart;
|
|
||||||
}
|
|
||||||
|
|
||||||
protected void setTargetPart( IWorkbenchPart part )
|
|
||||||
{
|
|
||||||
fTargetPart = part;
|
|
||||||
}
|
|
||||||
|
|
||||||
protected Shell getShell()
|
protected Shell getShell()
|
||||||
{
|
{
|
||||||
if ( getTargetPart() != null )
|
if ( getTargetPart() != null )
|
||||||
|
@ -234,20 +76,6 @@ public class AddExpressionActionDelegate implements IWorkbenchWindowActionDelega
|
||||||
return CDebugUIPlugin.getActiveWorkbenchShell();
|
return CDebugUIPlugin.getActiveWorkbenchShell();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
protected ISelection getTargetSelection()
|
|
||||||
{
|
|
||||||
IWorkbenchPart part = getTargetPart();
|
|
||||||
if ( part != null )
|
|
||||||
{
|
|
||||||
ISelectionProvider provider = part.getSite().getSelectionProvider();
|
|
||||||
if ( provider != null )
|
|
||||||
{
|
|
||||||
return provider.getSelection();
|
|
||||||
}
|
|
||||||
}
|
|
||||||
return null;
|
|
||||||
}
|
|
||||||
|
|
||||||
private void createExpression( final String text )
|
private void createExpression( final String text )
|
||||||
{
|
{
|
||||||
|
@ -273,6 +101,7 @@ public class AddExpressionActionDelegate implements IWorkbenchWindowActionDelega
|
||||||
}
|
}
|
||||||
} );
|
} );
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @see org.eclipse.ui.ISelectionListener#selectionChanged(IWorkbenchPart, ISelection)
|
* @see org.eclipse.ui.ISelectionListener#selectionChanged(IWorkbenchPart, ISelection)
|
||||||
*/
|
*/
|
||||||
|
@ -298,16 +127,6 @@ public class AddExpressionActionDelegate implements IWorkbenchWindowActionDelega
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
protected void setDebugTarget( IDebugTarget target )
|
|
||||||
{
|
|
||||||
fDebugTarget = target;
|
|
||||||
}
|
|
||||||
|
|
||||||
protected IDebugTarget getDebugTarget()
|
|
||||||
{
|
|
||||||
return fDebugTarget;
|
|
||||||
}
|
|
||||||
|
|
||||||
protected void initializeDebugTarget()
|
protected void initializeDebugTarget()
|
||||||
{
|
{
|
||||||
setDebugTarget( null );
|
setDebugTarget( null );
|
||||||
|
|
|
@ -0,0 +1,93 @@
|
||||||
|
/*
|
||||||
|
*(c) Copyright QNX Software Systems Ltd. 2002.
|
||||||
|
* All Rights Reserved.
|
||||||
|
*
|
||||||
|
*/
|
||||||
|
package org.eclipse.cdt.debug.internal.ui.actions;
|
||||||
|
|
||||||
|
import org.eclipse.cdt.debug.core.IRunToLine;
|
||||||
|
import org.eclipse.cdt.debug.ui.CDebugUIPlugin;
|
||||||
|
import org.eclipse.core.resources.IFile;
|
||||||
|
import org.eclipse.core.resources.IResource;
|
||||||
|
import org.eclipse.core.runtime.IAdaptable;
|
||||||
|
import org.eclipse.debug.core.DebugException;
|
||||||
|
import org.eclipse.debug.core.model.IDebugElement;
|
||||||
|
import org.eclipse.debug.core.model.IDebugTarget;
|
||||||
|
import org.eclipse.debug.ui.DebugUITools;
|
||||||
|
import org.eclipse.jface.action.IAction;
|
||||||
|
import org.eclipse.jface.text.ITextSelection;
|
||||||
|
import org.eclipse.ui.IEditorInput;
|
||||||
|
import org.eclipse.ui.IEditorPart;
|
||||||
|
import org.eclipse.ui.IFileEditorInput;
|
||||||
|
import org.eclipse.ui.texteditor.ITextEditor;
|
||||||
|
|
||||||
|
/**
|
||||||
|
*
|
||||||
|
* Enter type comment.
|
||||||
|
*
|
||||||
|
* @since Sep 19, 2002
|
||||||
|
*/
|
||||||
|
public class RunToLineActionDelegate extends AbstractEditorActionDelegate
|
||||||
|
{
|
||||||
|
/**
|
||||||
|
* Constructor for RunToLineActionDelegate.
|
||||||
|
*/
|
||||||
|
public RunToLineActionDelegate()
|
||||||
|
{
|
||||||
|
}
|
||||||
|
|
||||||
|
/* (non-Javadoc)
|
||||||
|
* @see org.eclipse.ui.IActionDelegate#run(IAction)
|
||||||
|
*/
|
||||||
|
public void run( IAction action )
|
||||||
|
{
|
||||||
|
if ( getTargetPart() != null && getTargetPart() instanceof ITextEditor )
|
||||||
|
{
|
||||||
|
IEditorInput input = ((ITextEditor)getTargetPart()).getEditorInput();
|
||||||
|
if ( input != null && input instanceof IFileEditorInput )
|
||||||
|
{
|
||||||
|
IFile file = ((IFileEditorInput)input).getFile();
|
||||||
|
if ( file != null )
|
||||||
|
{
|
||||||
|
ITextSelection selection= (ITextSelection)((ITextEditor)getTargetPart()).getSelectionProvider().getSelection();
|
||||||
|
int lineNumber = selection.getStartLine() + 1;
|
||||||
|
runToLine( file, lineNumber );
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
/* (non-Javadoc)
|
||||||
|
* @see org.eclipse.cdt.debug.internal.ui.actions.AbstractEditorActionDelegate#initializeDebugTarget()
|
||||||
|
*/
|
||||||
|
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 IRunToLine )
|
||||||
|
{
|
||||||
|
setDebugTarget( target );
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
protected void runToLine( IResource resource, int lineNumber )
|
||||||
|
{
|
||||||
|
if ( !((IRunToLine)getDebugTarget()).canRunToLine( resource, lineNumber ) )
|
||||||
|
{
|
||||||
|
getTargetPart().getSite().getShell().getDisplay().beep();
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
try
|
||||||
|
{
|
||||||
|
((IRunToLine)getDebugTarget()).runToLine( resource, lineNumber );
|
||||||
|
}
|
||||||
|
catch( DebugException e )
|
||||||
|
{
|
||||||
|
CDebugUIPlugin.errorDialog( e.getMessage(), e );
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
Loading…
Add table
Reference in a new issue