OLD | NEW |
(Empty) | |
| 1 // Copyright (c) 2010 The Chromium Authors. All rights reserved. |
| 2 // Use of this source code is governed by a BSD-style license that can be |
| 3 // found in the LICENSE file. |
| 4 |
| 5 package org.chromium.debug.ui.actions; |
| 6 |
| 7 import org.chromium.debug.core.model.DebugTargetImpl; |
| 8 import org.chromium.debug.core.model.WorkspaceBridge.BreakpointHandler; |
| 9 import org.chromium.sdk.JavascriptVm; |
| 10 import org.chromium.sdk.JavascriptVm.ExceptionCatchType; |
| 11 import org.eclipse.jface.action.IAction; |
| 12 import org.eclipse.jface.viewers.ISelection; |
| 13 import org.eclipse.jface.viewers.IStructuredSelection; |
| 14 import org.eclipse.ui.IWorkbenchWindow; |
| 15 import org.eclipse.ui.IWorkbenchWindowActionDelegate; |
| 16 |
| 17 public class ExceptionBreakpoints implements IWorkbenchWindowActionDelegate { |
| 18 public static class Caught extends ExceptionBreakpoints { |
| 19 public Caught() { |
| 20 super(JavascriptVm.ExceptionCatchType.CAUGHT); |
| 21 } |
| 22 } |
| 23 public static class Uncaught extends ExceptionBreakpoints { |
| 24 public Uncaught() { |
| 25 super(JavascriptVm.ExceptionCatchType.UNCAUGHT); |
| 26 } |
| 27 } |
| 28 |
| 29 private ExceptionBreakpoints(ExceptionCatchType catchType) { |
| 30 this.catchType = catchType; |
| 31 } |
| 32 |
| 33 private final JavascriptVm.ExceptionCatchType catchType; |
| 34 private Performer currentPerformer = null; |
| 35 |
| 36 public void run(IAction action) { |
| 37 if (currentPerformer == null) { |
| 38 return; |
| 39 } |
| 40 currentPerformer.run(action); |
| 41 currentPerformer = null; |
| 42 } |
| 43 |
| 44 public void selectionChanged(IAction action, ISelection selection) { |
| 45 currentPerformer = createPerformer(selection); |
| 46 action.setEnabled(currentPerformer != null); |
| 47 if (currentPerformer != null) { |
| 48 action.setChecked(currentPerformer.getCurrentCheckedState()); |
| 49 } |
| 50 } |
| 51 |
| 52 private Performer createPerformer(ISelection selection) { |
| 53 DebugTargetImpl target = getDebugTarget(selection); |
| 54 if (target == null) { |
| 55 return null; |
| 56 } |
| 57 final BreakpointHandler breakpointHandler = |
| 58 target.getWorkspaceRelations().getBreakpointHandler(); |
| 59 final Boolean state = breakpointHandler.getBreakExceptionState(catchType); |
| 60 return new Performer() { |
| 61 @Override boolean getCurrentCheckedState() { |
| 62 return state == Boolean.TRUE; |
| 63 } |
| 64 @Override void run(IAction action) { |
| 65 boolean newValue = !getCurrentCheckedState(); |
| 66 breakpointHandler.setBreakExceptionState(catchType, newValue); |
| 67 } |
| 68 }; |
| 69 } |
| 70 |
| 71 private DebugTargetImpl getDebugTarget(ISelection selection) { |
| 72 if (selection instanceof IStructuredSelection == false) { |
| 73 return null; |
| 74 } |
| 75 IStructuredSelection structuredSelection = (IStructuredSelection) selection; |
| 76 if (structuredSelection.size() != 1) { |
| 77 return null; |
| 78 } |
| 79 return SynchronizeBreakpoints.getDebugTargetImpl(structuredSelection.getFirs
tElement()); |
| 80 } |
| 81 |
| 82 public void dispose() { |
| 83 } |
| 84 |
| 85 public void init(IWorkbenchWindow window) { |
| 86 } |
| 87 |
| 88 private static abstract class Performer { |
| 89 abstract void run(IAction action); |
| 90 abstract boolean getCurrentCheckedState(); |
| 91 } |
| 92 } |
OLD | NEW |