diff --git a/platform/platform-resources/src/idea/LangActions.xml b/platform/platform-resources/src/idea/LangActions.xml index 41f17bf279a5..3c8d9445f847 100644 --- a/platform/platform-resources/src/idea/LangActions.xml +++ b/platform/platform-resources/src/idea/LangActions.xml @@ -637,6 +637,7 @@ + diff --git a/platform/xdebugger-impl/src/com/intellij/xdebugger/impl/actions/ToggleBreakpointEnabledAction.java b/platform/xdebugger-impl/src/com/intellij/xdebugger/impl/actions/ToggleBreakpointEnabledAction.java new file mode 100644 index 000000000000..45f0df1645ad --- /dev/null +++ b/platform/xdebugger-impl/src/com/intellij/xdebugger/impl/actions/ToggleBreakpointEnabledAction.java @@ -0,0 +1,78 @@ +/* + * Copyright 2000-2014 JetBrains s.r.o. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +package com.intellij.xdebugger.impl.actions; + +import com.intellij.openapi.actionSystem.AnActionEvent; +import com.intellij.openapi.actionSystem.CommonDataKeys; +import com.intellij.openapi.editor.Caret; +import com.intellij.openapi.editor.Document; +import com.intellij.openapi.editor.Editor; +import com.intellij.openapi.project.DumbAwareAction; +import com.intellij.openapi.project.Project; +import com.intellij.util.Range; +import com.intellij.util.containers.HashSet; +import com.intellij.xdebugger.XDebuggerManager; +import com.intellij.xdebugger.breakpoints.XLineBreakpoint; +import com.intellij.xdebugger.impl.breakpoints.XBreakpointManagerImpl; +import com.intellij.xdebugger.impl.breakpoints.XLineBreakpointImpl; +import com.intellij.xdebugger.impl.breakpoints.XLineBreakpointManager; +import org.jetbrains.annotations.NotNull; + +import java.util.*; + +/** + * @author egor + */ +public class ToggleBreakpointEnabledAction extends DumbAwareAction { + @Override + public void actionPerformed(AnActionEvent e) { + Collection breakpoints = findLineBreakpoints(e); + for (XLineBreakpoint breakpoint : breakpoints) { + breakpoint.setEnabled(!breakpoint.isEnabled()); + } + } + + @Override + public void update(AnActionEvent e) { + e.getPresentation().setEnabled(!findLineBreakpoints(e).isEmpty()); + } + + @NotNull + private static Set findLineBreakpoints(AnActionEvent e) { + Project project = e.getProject(); + Editor editor = e.getData(CommonDataKeys.EDITOR); + if (project == null || editor == null) return Collections.emptySet(); + XBreakpointManagerImpl breakpointManager = (XBreakpointManagerImpl)XDebuggerManager.getInstance(project).getBreakpointManager(); + XLineBreakpointManager lineBreakpointManager = breakpointManager.getLineBreakpointManager(); + Document document = editor.getDocument(); + Collection> lineRanges = new ArrayList>(); + for (Caret caret : editor.getCaretModel().getAllCarets()) { + lineRanges.add(new Range(document.getLineNumber(caret.getSelectionStart()), document.getLineNumber(caret.getSelectionEnd()))); + } + + Collection breakpoints = lineBreakpointManager.getDocumentBreakpoints(document); + HashSet res = new HashSet(); + for (XLineBreakpointImpl breakpoint : breakpoints) { + int line = breakpoint.getLine(); + for (Range range : lineRanges) { + if (range.isWithin(line)) { + res.add(breakpoint); + } + } + } + return res; + } +} diff --git a/platform/xdebugger-impl/src/com/intellij/xdebugger/impl/breakpoints/XLineBreakpointManager.java b/platform/xdebugger-impl/src/com/intellij/xdebugger/impl/breakpoints/XLineBreakpointManager.java index 6f0ae7c459e6..e2252ea642a9 100644 --- a/platform/xdebugger-impl/src/com/intellij/xdebugger/impl/breakpoints/XLineBreakpointManager.java +++ b/platform/xdebugger-impl/src/com/intellij/xdebugger/impl/breakpoints/XLineBreakpointManager.java @@ -59,6 +59,7 @@ import org.jetbrains.annotations.NotNull; import java.awt.event.MouseEvent; import java.util.Collection; +import java.util.Collections; import java.util.List; /** @@ -165,6 +166,15 @@ public class XLineBreakpointManager { } } + @NotNull + public Collection getDocumentBreakpoints(Document document) { + Collection breakpoints = myBreakpoints.getKeysByValue(document); + if (breakpoints == null) { + breakpoints = Collections.emptyList(); + } + return breakpoints; + } + private void updateBreakpoints(@NotNull Document document) { Collection breakpoints = myBreakpoints.getKeysByValue(document); if (breakpoints == null) { diff --git a/resources/src/idea/JavaActions.xml b/resources/src/idea/JavaActions.xml index 81721a90017a..cae268102d76 100644 --- a/resources/src/idea/JavaActions.xml +++ b/resources/src/idea/JavaActions.xml @@ -117,7 +117,7 @@ - +