1 11 package org.eclipse.debug.internal.ui.actions.breakpoints; 12 13 14 import org.eclipse.core.resources.IMarkerDelta; 15 import org.eclipse.core.runtime.CoreException; 16 import org.eclipse.core.runtime.IProgressMonitor; 17 import org.eclipse.core.runtime.IStatus; 18 import org.eclipse.core.runtime.Status; 19 import org.eclipse.core.runtime.jobs.Job; 20 import org.eclipse.debug.core.DebugPlugin; 21 import org.eclipse.debug.core.IBreakpointManager; 22 import org.eclipse.debug.core.IBreakpointsListener; 23 import org.eclipse.debug.core.model.IBreakpoint; 24 import org.eclipse.debug.internal.ui.DebugUIPlugin; 25 import org.eclipse.debug.internal.ui.actions.AbstractRemoveAllActionDelegate; 26 import org.eclipse.debug.internal.ui.actions.ActionMessages; 27 import org.eclipse.debug.internal.ui.preferences.IDebugPreferenceConstants; 28 import org.eclipse.jface.action.IAction; 29 import org.eclipse.jface.dialogs.IDialogConstants; 30 import org.eclipse.jface.dialogs.MessageDialogWithToggle; 31 import org.eclipse.jface.preference.IPreferenceStore; 32 import org.eclipse.ui.IWorkbenchWindow; 33 34 38 public class RemoveAllBreakpointsAction extends AbstractRemoveAllActionDelegate implements IBreakpointsListener { 39 40 43 protected boolean isEnabled() { 44 return DebugPlugin.getDefault().getBreakpointManager().hasBreakpoints(); 45 } 46 47 50 public void breakpointsAdded(IBreakpoint[] breakpoints) { 51 update(); 52 } 53 54 57 public void breakpointsChanged(IBreakpoint[] breakpoints, IMarkerDelta[] deltas) { 58 } 59 60 63 public void breakpointsRemoved(IBreakpoint[] breakpoints, IMarkerDelta[] deltas) { 64 if (getAction() != null) { 65 update(); 66 } 67 } 68 69 72 protected void initialize() { 73 DebugPlugin.getDefault().getBreakpointManager().addBreakpointListener(this); 74 } 75 76 79 public void dispose() { 80 DebugPlugin.getDefault().getBreakpointManager().removeBreakpointListener(this); 81 super.dispose(); 82 } 83 84 87 public void run(IAction action) { 88 final IBreakpointManager breakpointManager= DebugPlugin.getDefault().getBreakpointManager(); 89 final IBreakpoint[] breakpoints = breakpointManager.getBreakpoints(); 90 if (breakpoints.length < 1) { 91 return; 92 } 93 IWorkbenchWindow window= DebugUIPlugin.getActiveWorkbenchWindow(); 94 if (window == null) { 95 return; 96 } 97 IPreferenceStore store = DebugUIPlugin.getDefault().getPreferenceStore(); 98 boolean prompt = store.getBoolean(IDebugPreferenceConstants.PREF_PROMPT_REMOVE_ALL_BREAKPOINTS); 99 boolean proceed = true; 100 if(prompt) { 101 MessageDialogWithToggle mdwt = MessageDialogWithToggle.openYesNoQuestion(window.getShell(), ActionMessages.RemoveAllBreakpointsAction_0, 102 ActionMessages.RemoveAllBreakpointsAction_1, ActionMessages.RemoveAllBreakpointsAction_3, !prompt, null, null); 103 if(mdwt.getReturnCode() != IDialogConstants.YES_ID){ 104 proceed = false; 105 } 106 else { 107 store.setValue(IDebugPreferenceConstants.PREF_PROMPT_REMOVE_ALL_BREAKPOINTS, !mdwt.getToggleState()); 108 } 109 } 110 if (proceed) { 111 new Job(ActionMessages.RemoveAllBreakpointsAction_2) { 112 protected IStatus run(IProgressMonitor monitor) { 113 try { 114 breakpointManager.removeBreakpoints(breakpoints, true); 115 } catch (CoreException e) { 116 DebugUIPlugin.log(e); 117 return Status.CANCEL_STATUS; 118 } 119 return Status.OK_STATUS; 120 } 121 }.schedule(); 122 } 123 } 124 125 } 126 | Popular Tags |