-
Notifications
You must be signed in to change notification settings - Fork 104
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Breakpoint Enable All feature + Code review changes
- Loading branch information
Showing
8 changed files
with
244 additions
and
1 deletion.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
97 changes: 97 additions & 0 deletions
97
...se.debug.ui/ui/org/eclipse/debug/internal/ui/actions/AbstractEnableAllActionDelegate.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,97 @@ | ||
/******************************************************************************* | ||
* Copyright (c) 2024 IBM Corporation and others. | ||
* | ||
* This program and the accompanying materials | ||
* are made available under the terms of the Eclipse Public License 2.0 | ||
* which accompanies this distribution, and is available at | ||
* https://www.eclipse.org/legal/epl-2.0/ | ||
* | ||
* SPDX-License-Identifier: EPL-2.0 | ||
* | ||
* Contributors: | ||
* IBM Corporation - initial API and implementation | ||
*******************************************************************************/ | ||
package org.eclipse.debug.internal.ui.actions; | ||
|
||
import org.eclipse.jface.action.IAction; | ||
import org.eclipse.jface.viewers.ISelection; | ||
import org.eclipse.swt.widgets.Event; | ||
import org.eclipse.ui.IActionDelegate2; | ||
import org.eclipse.ui.IViewActionDelegate; | ||
import org.eclipse.ui.IViewPart; | ||
import org.eclipse.ui.IWorkbenchWindow; | ||
import org.eclipse.ui.IWorkbenchWindowActionDelegate; | ||
|
||
public abstract class AbstractEnableAllActionDelegate | ||
implements IViewActionDelegate, IActionDelegate2, IWorkbenchWindowActionDelegate { | ||
|
||
private IAction fAction; | ||
|
||
/** | ||
* Needed for reflective creation | ||
*/ | ||
|
||
@Override | ||
public void dispose() { | ||
fAction = null; | ||
} | ||
|
||
@Override | ||
public void init(IAction action) { | ||
fAction = action; | ||
} | ||
|
||
/** | ||
* Returns this delegate's action. | ||
* | ||
* @return the underlying <code>IAction</code> | ||
*/ | ||
protected IAction getAction() { | ||
return fAction; | ||
} | ||
|
||
@Override | ||
public void runWithEvent(IAction action, Event event) { | ||
run(action); | ||
} | ||
|
||
@Override | ||
public void init(IViewPart view) { | ||
initialize(); | ||
update(); | ||
} | ||
|
||
@Override | ||
public void init(IWorkbenchWindow window) { | ||
initialize(); | ||
update(); | ||
} | ||
|
||
/** | ||
* Initializes any listeners, etc. | ||
*/ | ||
protected abstract void initialize(); | ||
|
||
/** | ||
* Update enablement. | ||
*/ | ||
protected void update() { | ||
IAction action = getAction(); | ||
if (action != null) { | ||
action.setEnabled(isEnabled()); | ||
} | ||
} | ||
|
||
@Override | ||
public void selectionChanged(IAction action, ISelection s) { | ||
// do nothing | ||
} | ||
|
||
@Override | ||
public void run(IAction action) { | ||
|
||
} | ||
|
||
protected abstract boolean isEnabled(); | ||
|
||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
129 changes: 129 additions & 0 deletions
129
...g.ui/ui/org/eclipse/debug/internal/ui/actions/breakpoints/EnableAllBreakpointsAction.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,129 @@ | ||
/******************************************************************************* | ||
* Copyright (c) 2024 IBM Corporation and others. | ||
* | ||
* This program and the accompanying materials | ||
* are made available under the terms of the Eclipse Public License 2.0 | ||
* which accompanies this distribution, and is available at | ||
* https://www.eclipse.org/legal/epl-2.0/ | ||
* | ||
* SPDX-License-Identifier: EPL-2.0 | ||
* | ||
* Contributors: | ||
* IBM Corporation - initial API and implementation | ||
*******************************************************************************/ | ||
package org.eclipse.debug.internal.ui.actions.breakpoints; | ||
|
||
import org.eclipse.core.resources.IMarkerDelta; | ||
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.IBreakpointManager; | ||
import org.eclipse.debug.core.IBreakpointsListener; | ||
import org.eclipse.debug.core.model.IBreakpoint; | ||
import org.eclipse.debug.internal.ui.DebugUIPlugin; | ||
import org.eclipse.debug.internal.ui.actions.AbstractEnableAllActionDelegate; | ||
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; | ||
|
||
public class EnableAllBreakpointsAction extends AbstractEnableAllActionDelegate implements IBreakpointsListener { | ||
|
||
@Override | ||
protected boolean isEnabled() { | ||
boolean allEnabled = true; | ||
IBreakpointManager breakpointManager = DebugPlugin.getDefault().getBreakpointManager(); | ||
IBreakpoint[] breakpoints = breakpointManager.getBreakpoints(); | ||
|
||
for (IBreakpoint bp : breakpoints) { | ||
try { | ||
if (!bp.isEnabled()) { | ||
allEnabled = false; | ||
break; | ||
} | ||
} catch (CoreException e) { | ||
DebugUIPlugin.log(e); | ||
} | ||
} | ||
if (breakpoints.length > 0 && allEnabled) { | ||
return false; | ||
} | ||
return true; | ||
} | ||
|
||
@Override | ||
public void breakpointsAdded(IBreakpoint[] breakpoints) { | ||
update(); | ||
} | ||
|
||
@Override | ||
public void breakpointsChanged(IBreakpoint[] breakpoints, IMarkerDelta[] deltas) { | ||
update(); | ||
} | ||
|
||
@Override | ||
public void breakpointsRemoved(IBreakpoint[] breakpoints, IMarkerDelta[] deltas) { | ||
if (getAction() != null) { | ||
update(); | ||
} | ||
} | ||
|
||
@Override | ||
protected void initialize() { | ||
DebugPlugin.getDefault().getBreakpointManager().addBreakpointListener(this); | ||
} | ||
|
||
@Override | ||
public void dispose() { | ||
DebugPlugin.getDefault().getBreakpointManager().removeBreakpointListener(this); | ||
super.dispose(); | ||
} | ||
|
||
@Override | ||
public void run(IAction action) { | ||
IBreakpointManager breakpointManager = DebugPlugin.getDefault().getBreakpointManager(); | ||
IBreakpoint[] breakpoints = breakpointManager.getBreakpoints(); | ||
if (breakpoints.length < 1) { | ||
return; | ||
} | ||
IWorkbenchWindow window = DebugUIPlugin.getActiveWorkbenchWindow(); | ||
if (window == null) { | ||
return; | ||
} | ||
IPreferenceStore store = DebugUIPlugin.getDefault().getPreferenceStore(); | ||
boolean prompt = store.getBoolean(IDebugPreferenceConstants.PREF_PROMPT_ENABLE_ALL_BREAKPOINTS); | ||
boolean proceed = true; | ||
if (prompt) { | ||
MessageDialogWithToggle mdwt = MessageDialogWithToggle.openYesNoQuestion(window.getShell(), | ||
ActionMessages.EnableAllBreakpointsAction_0, ActionMessages.EnableAllBreakpointsAction_1, | ||
ActionMessages.EnableAllBreakpointsAction_3, !prompt, null, null); | ||
if (mdwt.getReturnCode() != IDialogConstants.YES_ID) { | ||
proceed = false; | ||
} else { | ||
store.setValue(IDebugPreferenceConstants.PREF_PROMPT_ENABLE_ALL_BREAKPOINTS, !mdwt.getToggleState()); | ||
} | ||
} | ||
if (proceed) { | ||
new Job(ActionMessages.EnableAllBreakpointsAction_1) { | ||
@Override | ||
protected IStatus run(IProgressMonitor monitor) { | ||
try { | ||
for (IBreakpoint breakpoint : breakpoints) { | ||
breakpoint.setEnabled(true); | ||
} | ||
} catch (CoreException e) { | ||
DebugUIPlugin.log(e); | ||
return Status.CANCEL_STATUS; | ||
} | ||
return Status.OK_STATUS; | ||
} | ||
}.schedule(); | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters