mirror of
https://github.com/eclipse-cdt/cdt
synced 2025-04-22 22:22:11 +02:00
Reviewed and applied patch for 180673. "Remove all Global Variables" action in the Variables view was enabled even when there were no global variables in the view.
This commit is contained in:
parent
f74e2a2c72
commit
39e042242d
1 changed files with 80 additions and 1 deletions
|
@ -11,11 +11,16 @@
|
|||
package org.eclipse.cdt.debug.internal.ui.actions;
|
||||
|
||||
import org.eclipse.cdt.debug.core.ICGlobalVariableManager;
|
||||
import org.eclipse.cdt.debug.core.model.IGlobalVariableDescriptor;
|
||||
import org.eclipse.core.runtime.IAdaptable;
|
||||
import org.eclipse.debug.core.DebugEvent;
|
||||
import org.eclipse.debug.core.DebugPlugin;
|
||||
import org.eclipse.debug.core.IDebugEventSetListener;
|
||||
import org.eclipse.debug.core.model.IDebugTarget;
|
||||
import org.eclipse.debug.core.model.IDebugElement;
|
||||
import org.eclipse.debug.ui.DebugUITools;
|
||||
import org.eclipse.jface.action.IAction;
|
||||
import org.eclipse.jface.viewers.ISelection;
|
||||
import org.eclipse.ui.IViewActionDelegate;
|
||||
import org.eclipse.ui.IViewPart;
|
||||
import org.eclipse.ui.actions.ActionDelegate;
|
||||
|
@ -23,12 +28,41 @@ import org.eclipse.ui.actions.ActionDelegate;
|
|||
/**
|
||||
* A delegate for the "Remove All Globals" action.
|
||||
*/
|
||||
public class RemoveAllGlobalsActionDelegate extends ActionDelegate implements IViewActionDelegate {
|
||||
public class RemoveAllGlobalsActionDelegate extends ActionDelegate implements IViewActionDelegate, IDebugEventSetListener {
|
||||
|
||||
private IAction fAction;
|
||||
|
||||
/* (non-Javadoc)
|
||||
* @see org.eclipse.ui.IViewActionDelegate#init(org.eclipse.ui.IViewPart)
|
||||
*/
|
||||
public void init( IViewPart view ) {
|
||||
DebugPlugin.getDefault().addDebugEventListener(this);
|
||||
}
|
||||
|
||||
/*
|
||||
* (non-Javadoc)
|
||||
* @see org.eclipse.ui.actions.ActionDelegate#init(org.eclipse.jface.action.IAction)
|
||||
*/
|
||||
public void init( IAction action ) {
|
||||
DebugPlugin.getDefault().addDebugEventListener(this);
|
||||
fAction = action;
|
||||
}
|
||||
|
||||
/*
|
||||
* (non-Javadoc)
|
||||
* @see org.eclipse.ui.actions.ActionDelegate#selectionChanged(org.eclipse.jface.action.IAction, org.eclipse.jface.viewers.ISelection)
|
||||
*/
|
||||
public void selectionChanged(IAction action, ISelection selection) {
|
||||
update();
|
||||
}
|
||||
|
||||
/*
|
||||
* (non-Javadoc)
|
||||
* @see org.eclipse.ui.actions.ActionDelegate#dispose()
|
||||
*/
|
||||
public void dispose() {
|
||||
DebugPlugin.getDefault().removeDebugEventListener(this);
|
||||
fAction = null;
|
||||
}
|
||||
|
||||
/* (non-Javadoc)
|
||||
|
@ -48,4 +82,49 @@ public class RemoveAllGlobalsActionDelegate extends ActionDelegate implements IV
|
|||
}
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Enables/disables the action based on whether there are any globals in the
|
||||
* variables view.
|
||||
*/
|
||||
private void update() {
|
||||
final IAction action = fAction;
|
||||
if (action != null) {
|
||||
final IAdaptable context = DebugUITools.getDebugContext();
|
||||
boolean enabled = false;
|
||||
if (context instanceof IDebugElement) {
|
||||
final ICGlobalVariableManager gvm = (ICGlobalVariableManager) ((IDebugElement) context)
|
||||
.getDebugTarget().getAdapter(
|
||||
ICGlobalVariableManager.class);
|
||||
if (gvm != null) {
|
||||
final IGlobalVariableDescriptor[] globals = gvm
|
||||
.getDescriptors();
|
||||
enabled = globals != null && globals.length > 0;
|
||||
}
|
||||
}
|
||||
action.setEnabled(enabled);
|
||||
}
|
||||
}
|
||||
|
||||
/*
|
||||
* (non-Javadoc)
|
||||
* @see org.eclipse.debug.core.IDebugEventSetListener#handleDebugEvents(org.eclipse.debug.core.DebugEvent[])
|
||||
*/
|
||||
public void handleDebugEvents( DebugEvent[] events ) {
|
||||
// The ICGlobalVariableManager will fire a target content-changed
|
||||
// event when a global is added or removed. Update the enable/disable
|
||||
// state of this action accordingly
|
||||
|
||||
if (fAction != null) {
|
||||
for (int i = 0; i < events.length; i++) {
|
||||
final DebugEvent event = events[i];
|
||||
if (event.getSource() instanceof IDebugTarget
|
||||
&& event.getKind() == DebugEvent.CHANGE
|
||||
&& event.getDetail() == DebugEvent.CONTENT ) {
|
||||
update();
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Add table
Reference in a new issue