|
Lines 11-76
Link Here
|
| 11 |
package org.eclipse.cdt.debug.internal.ui.actions; |
11 |
package org.eclipse.cdt.debug.internal.ui.actions; |
| 12 |
|
12 |
|
| 13 |
|
13 |
|
| 14 |
import org.eclipse.cdt.debug.internal.core.model.CVariable; |
14 |
import org.eclipse.cdt.debug.internal.core.IWatchpointTarget; |
| 15 |
import org.eclipse.cdt.debug.internal.ui.actions.AddWatchpointDialog; |
|
|
| 16 |
import org.eclipse.cdt.debug.ui.CDebugUIPlugin; |
15 |
import org.eclipse.cdt.debug.ui.CDebugUIPlugin; |
| 17 |
import org.eclipse.debug.core.DebugException; |
16 |
import org.eclipse.core.runtime.IProgressMonitor; |
|
|
17 |
import org.eclipse.core.runtime.IStatus; |
| 18 |
import org.eclipse.core.runtime.Status; |
| 18 |
import org.eclipse.jface.action.IAction; |
19 |
import org.eclipse.jface.action.IAction; |
| 19 |
import org.eclipse.jface.viewers.ISelection; |
20 |
import org.eclipse.jface.viewers.ISelection; |
| 20 |
import org.eclipse.jface.viewers.IStructuredSelection; |
21 |
import org.eclipse.jface.viewers.StructuredSelection; |
| 21 |
import org.eclipse.jface.viewers.TreeSelection; |
22 |
import org.eclipse.jface.viewers.TreeSelection; |
| 22 |
import org.eclipse.jface.window.Window; |
23 |
import org.eclipse.jface.window.Window; |
| 23 |
import org.eclipse.ui.IActionDelegate; |
|
|
| 24 |
import org.eclipse.ui.IObjectActionDelegate; |
24 |
import org.eclipse.ui.IObjectActionDelegate; |
| 25 |
import org.eclipse.ui.IWorkbenchPart; |
25 |
import org.eclipse.ui.IWorkbenchPart; |
|
|
26 |
import org.eclipse.ui.progress.WorkbenchJob; |
| 26 |
|
27 |
|
| 27 |
|
28 |
/** |
| 28 |
public class AddWatchpointOnVariableActionDelegate extends AddWatchpointActionDelegate { |
29 |
* Invoked when user right clicks on an element in the Variables or Expressions |
|
|
30 |
* view and selects 'Add Watchpoint (C/C++)' |
| 31 |
*/ |
| 32 |
public class AddWatchpointOnVariableActionDelegate extends AddWatchpointActionDelegate implements IObjectActionDelegate { |
| 29 |
|
33 |
|
| 30 |
/** |
34 |
/** |
| 31 |
* Constructor for Action1. |
35 |
* The target variable/expression |
|
|
36 |
*/ |
| 37 |
private IWatchpointTarget fVar; |
| 38 |
|
| 39 |
/** |
| 40 |
* Constructor |
| 32 |
*/ |
41 |
*/ |
| 33 |
public AddWatchpointOnVariableActionDelegate() { |
42 |
public AddWatchpointOnVariableActionDelegate() { |
| 34 |
super(); |
43 |
super(); |
| 35 |
} |
44 |
} |
| 36 |
|
45 |
|
| 37 |
/** |
46 |
/* (non-Javadoc) |
| 38 |
* @see IObjectActionDelegate#setActivePart(IAction, IWorkbenchPart) |
47 |
* @see org.eclipse.ui.IObjectActionDelegate#setActivePart(org.eclipse.jface.action.IAction, org.eclipse.ui.IWorkbenchPart) |
| 39 |
*/ |
48 |
*/ |
| 40 |
public void setActivePart(IAction action, IWorkbenchPart targetPart) {} |
49 |
public void setActivePart(IAction action, IWorkbenchPart targetPart) { |
|
|
50 |
// Don't care. Our logic is agnostic to the view we're invoked from. |
| 51 |
} |
| 41 |
|
52 |
|
| 42 |
/** |
53 |
/* (non-Javadoc) |
| 43 |
* @see IActionDelegate#run(IAction) |
54 |
* @see org.eclipse.cdt.debug.internal.ui.actions.AddWatchpointActionDelegate#run(org.eclipse.jface.action.IAction) |
| 44 |
*/ |
55 |
*/ |
| 45 |
public void run(IAction action) { |
56 |
public void run(IAction action) { |
| 46 |
IStructuredSelection selection = getSelection(); |
57 |
if (fVar == null) { |
| 47 |
|
|
|
| 48 |
if (selection == null || selection.isEmpty()) { |
| 49 |
return; |
58 |
return; |
| 50 |
} |
59 |
} |
| 51 |
|
60 |
|
| 52 |
Object obj = ((TreeSelection)selection).getFirstElement(); |
61 |
final String expr = fVar.getExpression(); |
| 53 |
if (obj != null && obj instanceof CVariable) { |
62 |
if (expr == null) { |
| 54 |
CVariable var = (CVariable)obj; |
63 |
assert false : "how are we getting an empty expression?"; //$NON-NLS-1$ |
| 55 |
|
64 |
return; |
| 56 |
String expr = ""; |
|
|
| 57 |
|
| 58 |
try { |
| 59 |
expr = var.getExpressionString(); |
| 60 |
} catch (DebugException e) {} |
| 61 |
|
| 62 |
AddWatchpointDialog dlg = new AddWatchpointDialog(CDebugUIPlugin.getActiveWorkbenchShell(), |
| 63 |
getMemorySpaceManagement()); //$NON-NLS-1$ |
| 64 |
dlg.setExpression(expr); |
| 65 |
dlg.initializeRange(false, Integer.toString(var.sizeof())); |
| 66 |
if (dlg.open() == Window.OK) { |
| 67 |
addWatchpoint(dlg.getWriteAccess(), dlg.getReadAccess(), dlg.getExpression(), dlg.getMemorySpace(), dlg.getRange()); |
| 68 |
} |
| 69 |
} |
65 |
} |
|
|
66 |
|
| 67 |
// Getting the size of the variable/expression is an asynchronous |
| 68 |
// operation...or at least the API is (the CDI implementation reacts |
| 69 |
// synchronously) |
| 70 |
final IWatchpointTarget.GetSizeRequest request = new IWatchpointTarget.GetSizeRequest() { |
| 71 |
public void done() { |
| 72 |
// Now that we have the size, put up a dialog to create the watchpoint |
| 73 |
final int size = getSize(); |
| 74 |
assert size > 0 : "unexpected variale/expression size"; //$NON-NLS-1$ |
| 75 |
WorkbenchJob job = new WorkbenchJob("open watchpoint dialog") { //$NON-NLS-1$ |
| 76 |
@Override |
| 77 |
public IStatus runInUIThread(IProgressMonitor monitor) { |
| 78 |
AddWatchpointDialog dlg = new AddWatchpointDialog(CDebugUIPlugin.getActiveWorkbenchShell(), |
| 79 |
getMemorySpaceManagement()); |
| 80 |
dlg.setExpression(expr); |
| 81 |
dlg.initializeRange(false, Integer.toString(size)); |
| 82 |
if (dlg.open() == Window.OK) { |
| 83 |
addWatchpoint(dlg.getWriteAccess(), dlg.getReadAccess(), dlg.getExpression(), dlg.getMemorySpace(), dlg.getRange()); |
| 84 |
} |
| 85 |
return Status.OK_STATUS; |
| 86 |
} |
| 87 |
}; |
| 88 |
job.setSystem(true); |
| 89 |
job.schedule(); |
| 90 |
} |
| 91 |
}; |
| 92 |
fVar.getSize(request); |
| 70 |
} |
93 |
} |
| 71 |
|
94 |
|
| 72 |
/** |
95 |
/** |
| 73 |
* @see IActionDelegate#selectionChanged(IAction, ISelection) |
96 |
* Record the target variable/expression. |
|
|
97 |
* |
| 98 |
* @see org.eclipse.ui.actions.ActionDelegate#selectionChanged(org.eclipse.jface.action.IAction, |
| 99 |
* org.eclipse.jface.viewers.ISelection) |
| 74 |
*/ |
100 |
*/ |
| 75 |
public void selectionChanged(IAction action, ISelection selection) { |
101 |
public void selectionChanged(IAction action, ISelection selection) { |
| 76 |
if (selection == null || selection.isEmpty()) { |
102 |
if (selection == null || selection.isEmpty()) { |
|
Lines 79-94
Link Here
|
| 79 |
} |
105 |
} |
| 80 |
if (selection instanceof TreeSelection) { |
106 |
if (selection instanceof TreeSelection) { |
| 81 |
Object obj = ((TreeSelection)selection).getFirstElement(); |
107 |
Object obj = ((TreeSelection)selection).getFirstElement(); |
| 82 |
if (obj != null && obj instanceof CVariable) { |
108 |
action.setEnabled(obj instanceof IWatchpointTarget); |
| 83 |
action.setEnabled(true); |
109 |
if (obj instanceof IWatchpointTarget) { |
| 84 |
} else { |
110 |
fVar = (IWatchpointTarget)obj; |
| 85 |
action.setEnabled(false); |
111 |
return; |
| 86 |
} |
112 |
} |
|
|
113 |
assert false : "action installed in unexpected type of object"; //$NON-NLS-1$ |
| 87 |
} |
114 |
} |
|
|
115 |
else if (selection instanceof StructuredSelection) { |
| 116 |
// Not sure why, but sometimes we get an extraneous empty StructuredSelection. Seems harmless enough |
| 117 |
assert ((StructuredSelection)selection).getFirstElement() == null : "action installed in unexpected type of view/part"; //$NON-NLS-1$ |
| 118 |
} |
| 119 |
else { |
| 120 |
assert false : "action installed in unexpected type of view/part"; //$NON-NLS-1$ |
| 121 |
} |
| 122 |
action.setEnabled(false); |
| 88 |
} |
123 |
} |
| 89 |
|
|
|
| 90 |
private IStructuredSelection getSelection() { |
| 91 |
return (IStructuredSelection)getView().getViewSite().getSelectionProvider().getSelection(); |
| 92 |
} |
| 93 |
|
| 94 |
} |
124 |
} |