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

Bug 228063: applied patch from Pawel Piech (WindRiver).

This commit is contained in:
Mikhail Khodjaiants 2008-05-02 12:23:21 +00:00
parent 72f98fc936
commit 532bcc93b8

View file

@ -7,16 +7,21 @@
* *
* Contributors: * Contributors:
* QNX Software Systems - Initial API and implementation * QNX Software Systems - Initial API and implementation
* Pawel Piech (WindRiver) - https://bugs.eclipse.org/bugs/show_bug.cgi?id=228063
*******************************************************************************/ *******************************************************************************/
package org.eclipse.cdt.debug.internal.ui.actions; package org.eclipse.cdt.debug.internal.ui.actions;
import org.eclipse.cdt.debug.core.model.ICDebugTarget; import org.eclipse.cdt.debug.core.model.ICDebugTarget;
import org.eclipse.cdt.debug.core.model.ISteppingModeTarget;
import org.eclipse.cdt.debug.core.model.ITargetProperties;
import org.eclipse.cdt.debug.ui.CDebugUIPlugin; import org.eclipse.cdt.debug.ui.CDebugUIPlugin;
import org.eclipse.cdt.debug.ui.ICDebugUIConstants; import org.eclipse.cdt.debug.ui.ICDebugUIConstants;
import org.eclipse.core.runtime.Preferences.IPropertyChangeListener; import org.eclipse.core.runtime.Preferences.IPropertyChangeListener;
import org.eclipse.core.runtime.Preferences.PropertyChangeEvent; import org.eclipse.core.runtime.Preferences.PropertyChangeEvent;
import org.eclipse.debug.core.model.IDebugElement; import org.eclipse.debug.core.model.IDebugElement;
import org.eclipse.debug.core.model.IDebugTarget; import org.eclipse.debug.core.model.IDebugTarget;
import org.eclipse.debug.core.model.IDisconnect;
import org.eclipse.debug.core.model.ITerminate;
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.jface.viewers.IStructuredSelection;
@ -31,7 +36,7 @@ import org.eclipse.ui.actions.ActionDelegate;
*/ */
public class ToggleInstructionStepModeActionDelegate extends ActionDelegate implements IViewActionDelegate, IPropertyChangeListener { public class ToggleInstructionStepModeActionDelegate extends ActionDelegate implements IViewActionDelegate, IPropertyChangeListener {
private ICDebugTarget fTarget = null; private ISteppingModeTarget fTarget = null;
private IAction fAction = null; private IAction fAction = null;
@ -62,9 +67,10 @@ public class ToggleInstructionStepModeActionDelegate extends ActionDelegate impl
* @see org.eclipse.ui.IActionDelegate2#dispose() * @see org.eclipse.ui.IActionDelegate2#dispose()
*/ */
public void dispose() { public void dispose() {
ICDebugTarget target = getTarget(); ISteppingModeTarget target = getTarget();
if ( target != null ) if ( target != null && target instanceof ITargetProperties ) {
target.removePropertyChangeListener( this ); ((ITargetProperties)target).removePropertyChangeListener( this );
}
setTarget( null ); setTarget( null );
setAction( null ); setAction( null );
} }
@ -83,7 +89,7 @@ public class ToggleInstructionStepModeActionDelegate extends ActionDelegate impl
*/ */
public void run( IAction action ) { public void run( IAction action ) {
boolean enabled = getAction().isChecked(); boolean enabled = getAction().isChecked();
ICDebugTarget target = getTarget(); ISteppingModeTarget target = getTarget();
if ( target != null ) { if ( target != null ) {
target.enableInstructionStepping( enabled ); target.enableInstructionStepping( enabled );
if ( enabled ) { if ( enabled ) {
@ -108,30 +114,41 @@ public class ToggleInstructionStepModeActionDelegate extends ActionDelegate impl
* @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 ) {
ICDebugTarget newTarget = null; ISteppingModeTarget newTarget = null;
if ( selection instanceof IStructuredSelection ) { if ( selection instanceof IStructuredSelection ) {
newTarget = getTargetFromSelection( ((IStructuredSelection)selection).getFirstElement() ); newTarget = getTargetFromSelection( ((IStructuredSelection)selection).getFirstElement() );
} }
ICDebugTarget oldTarget = getTarget(); ISteppingModeTarget oldTarget = getTarget();
if ( oldTarget != null && !oldTarget.equals( newTarget ) ) { if ( oldTarget != null && !oldTarget.equals( newTarget ) ) {
oldTarget.removePropertyChangeListener( this ); if ( oldTarget instanceof ITargetProperties ) {
((ITargetProperties)oldTarget).removePropertyChangeListener( this );
}
setTarget( null ); setTarget( null );
action.setChecked( false ); action.setChecked( false );
} }
if ( newTarget != null && !newTarget.isTerminated() && !newTarget.isDisconnected() ) { if ( newTarget != null && !isTerminated( newTarget ) ) {
setTarget( newTarget ); setTarget( newTarget );
newTarget.addPropertyChangeListener( this ); if ( newTarget instanceof ITargetProperties ) {
((ITargetProperties)newTarget).addPropertyChangeListener( this );
}
action.setChecked( newTarget.isInstructionSteppingEnabled() ); action.setChecked( newTarget.isInstructionSteppingEnabled() );
} }
action.setEnabled( newTarget != null && newTarget.supportsInstructionStepping() action.setEnabled(
&& !newTarget.isTerminated() && !newTarget.isDisconnected() ); newTarget != null
&& newTarget.supportsInstructionStepping()
&& !isTerminated( newTarget ) );
} }
private ICDebugTarget getTarget() { private boolean isTerminated( ISteppingModeTarget target ) {
return ( (target instanceof ITerminate && ((ITerminate)target).isTerminated())
|| (target instanceof IDisconnect && ((IDisconnect)target).isDisconnected()) );
}
private ISteppingModeTarget getTarget() {
return this.fTarget; return this.fTarget;
} }
private void setTarget( ICDebugTarget target ) { private void setTarget( ISteppingModeTarget target ) {
this.fTarget = target; this.fTarget = target;
} }