diff options
author | Dani Megert | 2011-01-10 16:18:23 +0000 |
---|---|---|
committer | Dani Megert | 2011-01-10 16:18:23 +0000 |
commit | ea95e4f4fda1d968ce7f7af0d8b9e3139bebd77c (patch) | |
tree | da2382dd62acea645341485fd10a676e1ea645a3 | |
parent | 5faf5e2aab28f9811f6576a934362379be164995 (diff) | |
download | eclipse.platform.debug-ea95e4f4fda1d968ce7f7af0d8b9e3139bebd77c.tar.gz eclipse.platform.debug-ea95e4f4fda1d968ce7f7af0d8b9e3139bebd77c.tar.xz eclipse.platform.debug-ea95e4f4fda1d968ce7f7af0d8b9e3139bebd77c.zip |
Fixed bug 154784: [breakpoints] Undo support for deleting and toggling (off) breakpoints
7 files changed, 277 insertions, 92 deletions
diff --git a/org.eclipse.debug.core/core/org/eclipse/debug/internal/core/BreakpointManager.java b/org.eclipse.debug.core/core/org/eclipse/debug/internal/core/BreakpointManager.java index a369fad3e..5cddb5924 100644 --- a/org.eclipse.debug.core/core/org/eclipse/debug/internal/core/BreakpointManager.java +++ b/org.eclipse.debug.core/core/org/eclipse/debug/internal/core/BreakpointManager.java @@ -1,5 +1,5 @@ /******************************************************************************* - * Copyright (c) 2000, 2010 IBM Corporation and others. + * Copyright (c) 2000, 2011 IBM Corporation and others. * All rights reserved. This program and the accompanying materials * are made available under the terms of the Eclipse Public License v1.0 * which accompanies this distribution, and is available at @@ -21,17 +21,8 @@ import java.util.Map; import java.util.Set; import java.util.Vector; -import org.eclipse.core.resources.IMarker; -import org.eclipse.core.resources.IMarkerDelta; -import org.eclipse.core.resources.IProject; -import org.eclipse.core.resources.IResource; -import org.eclipse.core.resources.IResourceChangeEvent; -import org.eclipse.core.resources.IResourceChangeListener; -import org.eclipse.core.resources.IResourceDelta; -import org.eclipse.core.resources.IResourceDeltaVisitor; -import org.eclipse.core.resources.IWorkspace; -import org.eclipse.core.resources.IWorkspaceRunnable; -import org.eclipse.core.resources.ResourcesPlugin; +import com.ibm.icu.text.MessageFormat; + import org.eclipse.core.runtime.CoreException; import org.eclipse.core.runtime.IConfigurationElement; import org.eclipse.core.runtime.IExtensionPoint; @@ -43,6 +34,19 @@ import org.eclipse.core.runtime.Platform; import org.eclipse.core.runtime.SafeRunner; import org.eclipse.core.runtime.Status; import org.eclipse.core.runtime.jobs.Job; + +import org.eclipse.core.resources.IMarker; +import org.eclipse.core.resources.IMarkerDelta; +import org.eclipse.core.resources.IProject; +import org.eclipse.core.resources.IResource; +import org.eclipse.core.resources.IResourceChangeEvent; +import org.eclipse.core.resources.IResourceChangeListener; +import org.eclipse.core.resources.IResourceDelta; +import org.eclipse.core.resources.IResourceDeltaVisitor; +import org.eclipse.core.resources.IWorkspace; +import org.eclipse.core.resources.IWorkspaceRunnable; +import org.eclipse.core.resources.ResourcesPlugin; + import org.eclipse.debug.core.DebugException; import org.eclipse.debug.core.DebugPlugin; import org.eclipse.debug.core.IBreakpointListener; @@ -52,8 +56,6 @@ import org.eclipse.debug.core.IBreakpointsListener; import org.eclipse.debug.core.model.IBreakpoint; import org.eclipse.debug.core.model.IBreakpointImportParticipant; -import com.ibm.icu.text.MessageFormat; - /** * The breakpoint manager manages all registered breakpoints * for the debug plug-in. It is instantiated by the debug plug-in at startup. @@ -671,6 +673,13 @@ public class BreakpointManager implements IBreakpointManager, IResourceChangeLis * Removed breakpoints */ private List fRemoved = new ArrayList(); + + /** + * Added breakpoints. + * @since 3.7 + */ + private List fAdded= new ArrayList(); + /** * Changed breakpoints and associated marker deltas */ @@ -684,6 +693,7 @@ public class BreakpointManager implements IBreakpointManager, IResourceChangeLis protected void reset() { fMoved.clear(); fRemoved.clear(); + fAdded.clear(); fChanged.clear(); fChangedDeltas.clear(); } @@ -715,6 +725,13 @@ public class BreakpointManager implements IBreakpointManager, IResourceChangeLis DebugPlugin.log(e); } } + if (!fAdded.isEmpty()) { + try { + addBreakpoints((IBreakpoint[])fAdded.toArray(new IBreakpoint[fAdded.size()]), false); + } catch (CoreException e) { + DebugPlugin.log(e); + } + } if (!fChanged.isEmpty()) { fireUpdate(fChanged, fChangedDeltas, CHANGED); } @@ -770,6 +787,14 @@ public class BreakpointManager implements IBreakpointManager, IResourceChangeLis if (fPostChangMarkersChanged.contains(marker)) { handleChangeBreakpoint(marker, mDelta); fPostChangMarkersChanged.remove(marker); + } else if (getBreakpoint(marker) == null) { + try { + IBreakpoint breakpoint= createBreakpoint(marker); + breakpoint.setRegistered(true); + fAdded.add(breakpoint); + } catch (CoreException e) { + DebugPlugin.log(e); + } } fPostBuildMarkersAdded.add(marker); } diff --git a/org.eclipse.debug.ui/ui/org/eclipse/debug/internal/ui/actions/ActionMessages.java b/org.eclipse.debug.ui/ui/org/eclipse/debug/internal/ui/actions/ActionMessages.java index f1915829f..5c3a331ac 100644 --- a/org.eclipse.debug.ui/ui/org/eclipse/debug/internal/ui/actions/ActionMessages.java +++ b/org.eclipse.debug.ui/ui/org/eclipse/debug/internal/ui/actions/ActionMessages.java @@ -1,5 +1,5 @@ /******************************************************************************* - * Copyright (c) 2000, 2010 IBM Corporation and others. + * Copyright (c) 2000, 2011 IBM Corporation and others. * All rights reserved. This program and the accompanying materials * are made available under the terms of the Eclipse Public License v1.0 * which accompanies this distribution, and is available at @@ -103,8 +103,11 @@ public class ActionMessages extends NLS { public static String RemoveBreakpointAction_4; public static String RemoveBreakpointAction_5; public static String RemoveBreakpointAction_6; - public static String RemoveBreakpointAction_Exceptions_occurred_attempting_to_remove_a_breakpoint__5; - public static String RemoveBreakpointAction_Removing_a_breakpoint_4; + public static String RemoveBreakpointAction_Exceptions_occurred_attempting_to_remove_a_breakpoint__5; + public static String RemoveBreakpointAction_Removing_a_breakpoint_4; + + public static String DeleteBreakpointOperationName; + public static String DeleteBreakpointsOperationName; public static String RetargetRunToLineAction_0; diff --git a/org.eclipse.debug.ui/ui/org/eclipse/debug/internal/ui/actions/ActionMessages.properties b/org.eclipse.debug.ui/ui/org/eclipse/debug/internal/ui/actions/ActionMessages.properties index ab6c5ba7a..ad9f0e542 100644 --- a/org.eclipse.debug.ui/ui/org/eclipse/debug/internal/ui/actions/ActionMessages.properties +++ b/org.eclipse.debug.ui/ui/org/eclipse/debug/internal/ui/actions/ActionMessages.properties @@ -1,5 +1,5 @@ ############################################################################### -# Copyright (c) 2000, 2010 IBM Corporation and others. +# Copyright (c) 2000, 2011 IBM Corporation and others. # All rights reserved. This program and the accompanying materials # are made available under the terms of the Eclipse Public License v1.0 # which accompanies this distribution, and is available at @@ -59,6 +59,10 @@ RemoveBreakpointAction_5=OK RemoveBreakpointAction_6=Cancel RemoveBreakpointAction_Exceptions_occurred_attempting_to_remove_a_breakpoint__5=An exception occurred attempting to remove breakpoint(s). RemoveBreakpointAction_Removing_a_breakpoint_4=Removing a breakpoint + +DeleteBreakpointOperationName=Delete Breakpoint +DeleteBreakpointsOperationName=Delete Breakpoints + DeleteWorkingsetsMessageDialog_0=&Selected working set(s). DeleteWorkingsetsMessageDialog_1=&All breakpoints contained in selected working set(s). diff --git a/org.eclipse.debug.ui/ui/org/eclipse/debug/internal/ui/actions/breakpoints/RemoveAllBreakpointsAction.java b/org.eclipse.debug.ui/ui/org/eclipse/debug/internal/ui/actions/breakpoints/RemoveAllBreakpointsAction.java index dec17fb03..930aaabdd 100644 --- a/org.eclipse.debug.ui/ui/org/eclipse/debug/internal/ui/actions/breakpoints/RemoveAllBreakpointsAction.java +++ b/org.eclipse.debug.ui/ui/org/eclipse/debug/internal/ui/actions/breakpoints/RemoveAllBreakpointsAction.java @@ -1,5 +1,5 @@ /******************************************************************************* - * Copyright (c) 2000, 2007 IBM Corporation and others. + * Copyright (c) 2000, 2011 IBM Corporation and others. * All rights reserved. This program and the accompanying materials * are made available under the terms of the Eclipse Public License v1.0 * which accompanies this distribution, and is available at @@ -11,12 +11,24 @@ package org.eclipse.debug.internal.ui.actions.breakpoints; -import org.eclipse.core.resources.IMarkerDelta; +import org.eclipse.swt.widgets.Shell; + import org.eclipse.core.runtime.CoreException; import org.eclipse.core.runtime.IProgressMonitor; import org.eclipse.core.runtime.IStatus; import org.eclipse.core.runtime.Status; import org.eclipse.core.runtime.jobs.Job; + +import org.eclipse.core.resources.IMarkerDelta; + +import org.eclipse.jface.action.IAction; +import org.eclipse.jface.dialogs.IDialogConstants; +import org.eclipse.jface.dialogs.MessageDialogWithToggle; +import org.eclipse.jface.preference.IPreferenceStore; + +import org.eclipse.ui.IViewPart; +import org.eclipse.ui.IWorkbenchWindow; + import org.eclipse.debug.core.DebugPlugin; import org.eclipse.debug.core.IBreakpointManager; import org.eclipse.debug.core.IBreakpointsListener; @@ -25,11 +37,8 @@ import org.eclipse.debug.internal.ui.DebugUIPlugin; import org.eclipse.debug.internal.ui.actions.AbstractRemoveAllActionDelegate; import org.eclipse.debug.internal.ui.actions.ActionMessages; import org.eclipse.debug.internal.ui.preferences.IDebugPreferenceConstants; -import org.eclipse.jface.action.IAction; -import org.eclipse.jface.dialogs.IDialogConstants; -import org.eclipse.jface.dialogs.MessageDialogWithToggle; -import org.eclipse.jface.preference.IPreferenceStore; -import org.eclipse.ui.IWorkbenchWindow; + +import org.eclipse.debug.ui.DebugUITools; /** * Removes all breakpoints from the source (markers) and remove all @@ -37,6 +46,8 @@ import org.eclipse.ui.IWorkbenchWindow; */ public class RemoveAllBreakpointsAction extends AbstractRemoveAllActionDelegate implements IBreakpointsListener { + private Shell fShell; + /* (non-Javadoc) * @see org.eclipse.debug.internal.ui.actions.selection.AbstractRemoveAllActionDelegate#isEnabled() */ @@ -108,18 +119,35 @@ public class RemoveAllBreakpointsAction extends AbstractRemoveAllActionDelegate } } if (proceed) { - new Job(ActionMessages.RemoveAllBreakpointsAction_2) { - protected IStatus run(IProgressMonitor monitor) { - try { - breakpointManager.removeBreakpoints(breakpoints, true); - } catch (CoreException e) { - DebugUIPlugin.log(e); - return Status.CANCEL_STATUS; - } - return Status.OK_STATUS; - } - }.schedule(); + new Job(ActionMessages.RemoveAllBreakpointsAction_2) { + protected IStatus run(IProgressMonitor monitor) { + try { + DebugUITools.deleteBreakpoints(breakpoints, fShell, monitor); + } catch (CoreException e) { + DebugUIPlugin.log(e); + return Status.CANCEL_STATUS; + } + return Status.OK_STATUS; + } + }.schedule(); } } + /* + * @see org.eclipse.debug.internal.ui.actions.AbstractRemoveAllActionDelegate#init(org.eclipse.ui.IViewPart) + * @since 3.7 + */ + public void init(IViewPart view) { + super.init(view); + fShell= view.getSite().getShell(); + } + + /* + * @see org.eclipse.debug.internal.ui.actions.AbstractRemoveAllActionDelegate#init(org.eclipse.ui.IWorkbenchWindow) + * @since 3.7 + */ + public void init(IWorkbenchWindow window) { + super.init(window); + fShell= window.getShell(); + } } diff --git a/org.eclipse.debug.ui/ui/org/eclipse/debug/internal/ui/actions/breakpoints/RemoveBreakpointAction.java b/org.eclipse.debug.ui/ui/org/eclipse/debug/internal/ui/actions/breakpoints/RemoveBreakpointAction.java index 1a4aedc1f..cef9ad853 100644 --- a/org.eclipse.debug.ui/ui/org/eclipse/debug/internal/ui/actions/breakpoints/RemoveBreakpointAction.java +++ b/org.eclipse.debug.ui/ui/org/eclipse/debug/internal/ui/actions/breakpoints/RemoveBreakpointAction.java @@ -1,5 +1,5 @@ /******************************************************************************* - * Copyright (c) 2000, 2010 IBM Corporation and others. + * Copyright (c) 2000, 2011 IBM Corporation and others. * All rights reserved. This program and the accompanying materials * are made available under the terms of the Eclipse Public License v1.0 * which accompanies this distribution, and is available at @@ -15,22 +15,17 @@ package org.eclipse.debug.internal.ui.actions.breakpoints; import java.util.ArrayList; import java.util.Iterator; -import org.eclipse.core.resources.IWorkspaceRunnable; -import org.eclipse.core.resources.ResourcesPlugin; +import org.eclipse.swt.widgets.Shell; + import org.eclipse.core.runtime.CoreException; import org.eclipse.core.runtime.IProgressMonitor; import org.eclipse.core.runtime.IStatus; import org.eclipse.core.runtime.Status; import org.eclipse.core.runtime.jobs.Job; -import org.eclipse.debug.core.DebugPlugin; -import org.eclipse.debug.core.model.IBreakpoint; -import org.eclipse.debug.internal.ui.DebugUIPlugin; -import org.eclipse.debug.internal.ui.actions.AbstractRemoveActionDelegate; -import org.eclipse.debug.internal.ui.actions.ActionMessages; -import org.eclipse.debug.internal.ui.breakpoints.provisional.IBreakpointContainer; -import org.eclipse.debug.internal.ui.preferences.IDebugPreferenceConstants; -import org.eclipse.debug.internal.ui.views.breakpoints.BreakpointsView; -import org.eclipse.debug.internal.ui.views.breakpoints.WorkingSetCategory; + +import org.eclipse.core.resources.IWorkspaceRunnable; +import org.eclipse.core.resources.ResourcesPlugin; + import org.eclipse.jface.action.IAction; import org.eclipse.jface.dialogs.IDialogConstants; import org.eclipse.jface.dialogs.MessageDialog; @@ -38,10 +33,23 @@ import org.eclipse.jface.dialogs.MessageDialogWithToggle; import org.eclipse.jface.preference.IPreferenceStore; import org.eclipse.jface.viewers.IStructuredSelection; import org.eclipse.jface.window.Window; + import org.eclipse.ui.IWorkbenchWindow; import org.eclipse.ui.IWorkingSet; import org.eclipse.ui.PlatformUI; +import org.eclipse.debug.core.DebugPlugin; +import org.eclipse.debug.core.model.IBreakpoint; +import org.eclipse.debug.internal.ui.DebugUIPlugin; +import org.eclipse.debug.internal.ui.actions.AbstractRemoveActionDelegate; +import org.eclipse.debug.internal.ui.actions.ActionMessages; +import org.eclipse.debug.internal.ui.breakpoints.provisional.IBreakpointContainer; +import org.eclipse.debug.internal.ui.preferences.IDebugPreferenceConstants; +import org.eclipse.debug.internal.ui.views.breakpoints.BreakpointsView; +import org.eclipse.debug.internal.ui.views.breakpoints.WorkingSetCategory; + +import org.eclipse.debug.ui.DebugUITools; + public class RemoveBreakpointAction extends AbstractRemoveActionDelegate { /* (non-Javadoc) @@ -126,7 +134,9 @@ public class RemoveBreakpointAction extends AbstractRemoveActionDelegate { new Job(ActionMessages.RemoveBreakpointAction_2) { protected IStatus run(IProgressMonitor pmonitor) { try { - DebugPlugin.getDefault().getBreakpointManager().removeBreakpoints(breakpoints, true); + Shell shell= getView() != null ? getView().getSite().getShell() : null; + DebugUITools.deleteBreakpoints(breakpoints, shell, pmonitor); + for (int i = 0; i < sets.length; i++) { PlatformUI.getWorkbench().getWorkingSetManager().removeWorkingSet(sets[i]); } diff --git a/org.eclipse.debug.ui/ui/org/eclipse/debug/internal/ui/views/breakpoints/BreakpointsView.java b/org.eclipse.debug.ui/ui/org/eclipse/debug/internal/ui/views/breakpoints/BreakpointsView.java index 565da9acc..ee1034f73 100644 --- a/org.eclipse.debug.ui/ui/org/eclipse/debug/internal/ui/views/breakpoints/BreakpointsView.java +++ b/org.eclipse.debug.ui/ui/org/eclipse/debug/internal/ui/views/breakpoints/BreakpointsView.java @@ -1,5 +1,5 @@ /***************************************************************** - * Copyright (c) 2009, 2010 Texas Instruments and others + * Copyright (c) 2009, 2011 Texas Instruments and others * All rights reserved. This program and the accompanying materials * are made available under the terms of the Eclipse Public License v1.0 * which accompanies this distribution, and is available at @@ -18,7 +18,41 @@ import java.util.List; import java.util.Map; import java.util.Map.Entry; +import org.eclipse.swt.SWT; +import org.eclipse.swt.dnd.Clipboard; +import org.eclipse.swt.dnd.DND; +import org.eclipse.swt.dnd.Transfer; +import org.eclipse.swt.widgets.Composite; +import org.eclipse.swt.widgets.Display; +import org.eclipse.swt.widgets.TreeItem; + +import org.eclipse.core.commands.operations.IUndoContext; + import org.eclipse.core.runtime.IStatus; + +import org.eclipse.jface.action.IAction; +import org.eclipse.jface.action.IMenuManager; +import org.eclipse.jface.action.IToolBarManager; +import org.eclipse.jface.action.Separator; +import org.eclipse.jface.util.LocalSelectionTransfer; +import org.eclipse.jface.viewers.ISelection; +import org.eclipse.jface.viewers.IStructuredSelection; +import org.eclipse.jface.viewers.ITreeSelection; +import org.eclipse.jface.viewers.StructuredSelection; +import org.eclipse.jface.viewers.TreePath; +import org.eclipse.jface.viewers.Viewer; + +import org.eclipse.ui.IActionBars; +import org.eclipse.ui.IMemento; +import org.eclipse.ui.ISharedImages; +import org.eclipse.ui.IWorkbenchActionConstants; +import org.eclipse.ui.IWorkbenchCommandConstants; +import org.eclipse.ui.PlatformUI; +import org.eclipse.ui.actions.ActionFactory; +import org.eclipse.ui.actions.SelectionListenerAction; +import org.eclipse.ui.operations.RedoActionHandler; +import org.eclipse.ui.operations.UndoActionHandler; + import org.eclipse.debug.core.DebugPlugin; import org.eclipse.debug.core.IBreakpointManagerListener; import org.eclipse.debug.core.model.IBreakpoint; @@ -47,33 +81,11 @@ import org.eclipse.debug.internal.ui.viewers.model.provisional.VirtualTreeModelV import org.eclipse.debug.internal.ui.views.DebugUIViewsMessages; import org.eclipse.debug.internal.ui.views.variables.VariablesView; import org.eclipse.debug.internal.ui.views.variables.details.AvailableDetailPanesAction; + +import org.eclipse.debug.ui.DebugUITools; import org.eclipse.debug.ui.IBreakpointOrganizerDelegateExtension; import org.eclipse.debug.ui.IDebugModelPresentation; import org.eclipse.debug.ui.IDebugUIConstants; -import org.eclipse.jface.action.IAction; -import org.eclipse.jface.action.IMenuManager; -import org.eclipse.jface.action.IToolBarManager; -import org.eclipse.jface.action.Separator; -import org.eclipse.jface.util.LocalSelectionTransfer; -import org.eclipse.jface.viewers.ISelection; -import org.eclipse.jface.viewers.IStructuredSelection; -import org.eclipse.jface.viewers.ITreeSelection; -import org.eclipse.jface.viewers.StructuredSelection; -import org.eclipse.jface.viewers.TreePath; -import org.eclipse.jface.viewers.Viewer; -import org.eclipse.swt.SWT; -import org.eclipse.swt.dnd.Clipboard; -import org.eclipse.swt.dnd.DND; -import org.eclipse.swt.dnd.Transfer; -import org.eclipse.swt.widgets.Composite; -import org.eclipse.swt.widgets.Display; -import org.eclipse.swt.widgets.TreeItem; -import org.eclipse.ui.IMemento; -import org.eclipse.ui.ISharedImages; -import org.eclipse.ui.IWorkbenchActionConstants; -import org.eclipse.ui.PlatformUI; -import org.eclipse.ui.actions.ActionFactory; -import org.eclipse.ui.actions.SelectionListenerAction; /** * This class implements the breakpoints view. @@ -97,10 +109,18 @@ public class BreakpointsView extends VariablesView implements IBreakpointManager */ private boolean fFirstInputSet = false; + private UndoActionHandler fUndoAction; + private RedoActionHandler fRedoAction; + + public void dispose() { if (fClipboard != null) fClipboard.dispose(); DebugPlugin.getDefault().getBreakpointManager().removeBreakpointManagerListener(this); + + fUndoAction.dispose(); + fRedoAction.dispose(); + super.dispose(); } @@ -225,11 +245,12 @@ public class BreakpointsView extends VariablesView implements IBreakpointManager DebugPlugin.getDefault().getBreakpointManager().addBreakpointManagerListener(this); fClipboard = new Clipboard(getSite().getShell().getDisplay()); + IActionBars actionBars= getViewSite().getActionBars(); PasteBreakpointsAction paste = new PasteBreakpointsAction(this); setAction(PASTE_ACTION, paste); paste.setActionDefinitionId(ActionFactory.PASTE.getCommandId()); - getViewSite().getActionBars().setGlobalActionHandler(ActionFactory.PASTE.getId(), paste); + actionBars.setGlobalActionHandler(ActionFactory.PASTE.getId(), paste); getViewer().addSelectionChangedListener(paste); paste.setImageDescriptor(PlatformUI.getWorkbench().getSharedImages().getImageDescriptor(ISharedImages.IMG_TOOL_PASTE)); @@ -237,6 +258,14 @@ public class BreakpointsView extends VariablesView implements IBreakpointManager setAction(ACTION_REMOVE_FROM_GROUP, remove); getViewer().addSelectionChangedListener(remove); + IUndoContext undoContext= DebugUITools.getBreakpointsUndoContext(); + fUndoAction= new UndoActionHandler(getSite(), undoContext); + fUndoAction.setActionDefinitionId(IWorkbenchCommandConstants.EDIT_UNDO); + fRedoAction= new RedoActionHandler(getSite(), undoContext); + fRedoAction.setActionDefinitionId(IWorkbenchCommandConstants.EDIT_REDO); + actionBars.setGlobalActionHandler(ActionFactory.UNDO.getId(), fUndoAction); + actionBars.setGlobalActionHandler(ActionFactory.REDO.getId(), fRedoAction); + } /* diff --git a/org.eclipse.debug.ui/ui/org/eclipse/debug/ui/DebugUITools.java b/org.eclipse.debug.ui/ui/org/eclipse/debug/ui/DebugUITools.java index 7ec9714f3..c555aed0a 100644 --- a/org.eclipse.debug.ui/ui/org/eclipse/debug/ui/DebugUITools.java +++ b/org.eclipse.debug.ui/ui/org/eclipse/debug/ui/DebugUITools.java @@ -1,5 +1,5 @@ /******************************************************************************* - * Copyright (c) 2000, 2010 IBM Corporation and others. + * Copyright (c) 2000, 2011 IBM Corporation and others. * All rights reserved. This program and the accompanying materials * are made available under the terms of the Eclipse Public License v1.0 * which accompanies this distribution, and is available at @@ -13,9 +13,18 @@ package org.eclipse.debug.ui; import java.util.Set; +import org.eclipse.swt.custom.BusyIndicator; +import org.eclipse.swt.graphics.Color; +import org.eclipse.swt.graphics.Image; +import org.eclipse.swt.widgets.Shell; + import org.eclipse.core.commands.ExecutionEvent; import org.eclipse.core.commands.ExecutionException; -import org.eclipse.core.resources.IResource; +import org.eclipse.core.commands.operations.IOperationHistory; +import org.eclipse.core.commands.operations.IUndoContext; +import org.eclipse.core.commands.operations.IUndoableOperation; +import org.eclipse.core.commands.operations.ObjectUndoContext; + import org.eclipse.core.runtime.CoreException; import org.eclipse.core.runtime.IAdaptable; import org.eclipse.core.runtime.IConfigurationElement; @@ -24,11 +33,32 @@ import org.eclipse.core.runtime.IExtensionPoint; import org.eclipse.core.runtime.IProgressMonitor; import org.eclipse.core.runtime.IStatus; import org.eclipse.core.runtime.Platform; + +import org.eclipse.core.resources.IMarker; +import org.eclipse.core.resources.IResource; + +import org.eclipse.jface.preference.IPreferenceStore; +import org.eclipse.jface.resource.ImageDescriptor; +import org.eclipse.jface.viewers.ISelection; +import org.eclipse.jface.viewers.IStructuredSelection; +import org.eclipse.jface.window.Window; + +import org.eclipse.ui.IViewSite; +import org.eclipse.ui.IWorkbenchPage; +import org.eclipse.ui.IWorkbenchPartSite; +import org.eclipse.ui.IWorkbenchWindow; +import org.eclipse.ui.PlatformUI; +import org.eclipse.ui.console.IConsole; +import org.eclipse.ui.handlers.HandlerUtil; +import org.eclipse.ui.ide.undo.DeleteMarkersOperation; +import org.eclipse.ui.ide.undo.WorkspaceUndoUtil; + import org.eclipse.debug.core.DebugPlugin; import org.eclipse.debug.core.ILaunch; import org.eclipse.debug.core.ILaunchConfiguration; import org.eclipse.debug.core.ILaunchConfigurationType; import org.eclipse.debug.core.ILaunchDelegate; +import org.eclipse.debug.core.model.IBreakpoint; import org.eclipse.debug.core.model.IDebugElement; import org.eclipse.debug.core.model.IDebugTarget; import org.eclipse.debug.core.model.IProcess; @@ -39,6 +69,7 @@ import org.eclipse.debug.internal.ui.DebugUIPlugin; import org.eclipse.debug.internal.ui.DefaultLabelProvider; import org.eclipse.debug.internal.ui.DelegatingModelPresentation; import org.eclipse.debug.internal.ui.LazyModelPresentation; +import org.eclipse.debug.internal.ui.actions.ActionMessages; import org.eclipse.debug.internal.ui.contexts.DebugContextManager; import org.eclipse.debug.internal.ui.launchConfigurations.LaunchConfigurationDialog; import org.eclipse.debug.internal.ui.launchConfigurations.LaunchConfigurationManager; @@ -49,27 +80,13 @@ import org.eclipse.debug.internal.ui.memory.MemoryRenderingManager; import org.eclipse.debug.internal.ui.sourcelookup.SourceLookupFacility; import org.eclipse.debug.internal.ui.sourcelookup.SourceLookupUIUtils; import org.eclipse.debug.internal.ui.stringsubstitution.SelectedResourceManager; + import org.eclipse.debug.ui.contexts.IDebugContextListener; import org.eclipse.debug.ui.contexts.IDebugContextManager; import org.eclipse.debug.ui.contexts.IDebugContextService; import org.eclipse.debug.ui.memory.IMemoryRenderingManager; import org.eclipse.debug.ui.sourcelookup.ISourceContainerBrowser; import org.eclipse.debug.ui.sourcelookup.ISourceLookupResult; -import org.eclipse.jface.preference.IPreferenceStore; -import org.eclipse.jface.resource.ImageDescriptor; -import org.eclipse.jface.viewers.ISelection; -import org.eclipse.jface.viewers.IStructuredSelection; -import org.eclipse.jface.window.Window; -import org.eclipse.swt.custom.BusyIndicator; -import org.eclipse.swt.graphics.Color; -import org.eclipse.swt.graphics.Image; -import org.eclipse.swt.widgets.Shell; -import org.eclipse.ui.IViewSite; -import org.eclipse.ui.IWorkbenchPage; -import org.eclipse.ui.IWorkbenchPartSite; -import org.eclipse.ui.IWorkbenchWindow; -import org.eclipse.ui.console.IConsole; -import org.eclipse.ui.handlers.HandlerUtil; /** @@ -84,6 +101,13 @@ import org.eclipse.ui.handlers.HandlerUtil; public class DebugUITools { /** + * The undo context for breakpoints. + * + * @since 3.7 + */ + private static ObjectUndoContext fgBreakpointsUndoContext; + + /** * Returns the shared image managed under the given key, or <code>null</code> * if none. * <p> @@ -208,6 +232,68 @@ public class DebugUITools { return null; } + /** + * Return the undo context that should be used for operations involving breakpoints. + * + * @return the undo context for breakpoints + * @since 3.7 + */ + public static synchronized IUndoContext getBreakpointsUndoContext() { + if (fgBreakpointsUndoContext == null) { + fgBreakpointsUndoContext= new ObjectUndoContext(new Object(), "Breakpoints Context"); //$NON-NLS-1$ + fgBreakpointsUndoContext.addMatch(WorkspaceUndoUtil.getWorkspaceUndoContext()); + } + return fgBreakpointsUndoContext; + } + + /** + * Deletes the given breakpoints using the operation history, which allows to undo the deletion. + * + * @param breakpoints the breakpoints to delete + * @param shell the shell used for potential user interactions, or <code>null</code> if unknown + * @param progressMonitor the progress monitor + * @throws CoreException if the deletion fails + * @since 3.7 + */ + public static void deleteBreakpoints(IBreakpoint[] breakpoints, final Shell shell, IProgressMonitor progressMonitor) throws CoreException { + IMarker[] markers= new IMarker[breakpoints.length]; + for (int i= 0; i < breakpoints.length; i++) { + markers[i]= breakpoints[i].getMarker(); + if (markers[i] == null) + break; + } + + // We only offer undo support if all breakpoints have associated markers + boolean allowUndo= markers.length == breakpoints.length; + + DebugPlugin.getDefault().getBreakpointManager().removeBreakpoints(breakpoints, !allowUndo); + + if (allowUndo) { + + IAdaptable context= null; + if (shell != null) { + context= new IAdaptable() { + public Object getAdapter(Class adapter) { + if (adapter == Shell.class) + return shell; + return null; + } + }; + } + + String operationName= markers.length == 1 ? ActionMessages.DeleteBreakpointOperationName : ActionMessages.DeleteBreakpointsOperationName; + IUndoableOperation deleteMarkerOperation= new DeleteMarkersOperation(markers, operationName); + deleteMarkerOperation.removeContext(WorkspaceUndoUtil.getWorkspaceUndoContext()); + deleteMarkerOperation.addContext(DebugUITools.getBreakpointsUndoContext()); + IOperationHistory operationHistory= PlatformUI.getWorkbench().getOperationSupport().getOperationHistory(); + try { + operationHistory.execute(deleteMarkerOperation, progressMonitor, context); + } catch (ExecutionException e) { + throw new CoreException(DebugUIPlugin.newErrorStatus("Exception while deleting breakpoint markers", e)); //$NON-NLS-1$ + } + } + } + /** * Returns the currently active context for the given workbench part. Returns <code>null</code> * if there is no current debug context.</p> |