mirror of
https://gitflic.ru/project/openide/openide.git
synced 2026-09-27 10:03:11 +07:00
IDEA-121301 Setting a breakpoint after navigation to a folded method (added glyph click support)
This commit is contained in:
+7
-51
@@ -15,23 +15,19 @@
|
||||
*/
|
||||
package com.intellij.xdebugger.impl.actions.handlers;
|
||||
|
||||
import com.intellij.codeInsight.folding.impl.FoldingUtil;
|
||||
import com.intellij.codeInsight.folding.impl.actions.ExpandRegionAction;
|
||||
import com.intellij.openapi.actionSystem.AnActionEvent;
|
||||
import com.intellij.openapi.actionSystem.CommonDataKeys;
|
||||
import com.intellij.openapi.editor.Editor;
|
||||
import com.intellij.openapi.editor.FoldRegion;
|
||||
import com.intellij.openapi.project.Project;
|
||||
import com.intellij.openapi.vfs.VirtualFile;
|
||||
import com.intellij.xdebugger.XDebuggerManager;
|
||||
import com.intellij.xdebugger.XDebuggerUtil;
|
||||
import com.intellij.xdebugger.XSourcePosition;
|
||||
import com.intellij.xdebugger.XDebuggerManager;
|
||||
import com.intellij.xdebugger.breakpoints.XBreakpointProperties;
|
||||
import com.intellij.xdebugger.breakpoints.XLineBreakpoint;
|
||||
import com.intellij.xdebugger.breakpoints.XLineBreakpointType;
|
||||
import com.intellij.xdebugger.breakpoints.XBreakpointManager;
|
||||
import com.intellij.xdebugger.breakpoints.XLineBreakpointType;
|
||||
import com.intellij.xdebugger.impl.XDebuggerUtilImpl;
|
||||
import com.intellij.xdebugger.impl.actions.DebuggerActionHandler;
|
||||
import com.intellij.xdebugger.impl.breakpoints.XBreakpointUtil;
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
|
||||
/**
|
||||
@@ -63,52 +59,12 @@ public class XToggleLineBreakpointActionHandler extends DebuggerActionHandler {
|
||||
|
||||
public void perform(@NotNull final Project project, final AnActionEvent event) {
|
||||
XSourcePosition position = XDebuggerUtilImpl.getCaretPosition(project, event.getDataContext());
|
||||
if (position == null) return;
|
||||
if (position == null) {
|
||||
return;
|
||||
}
|
||||
|
||||
Editor editor = event.getData(CommonDataKeys.EDITOR);
|
||||
|
||||
// for folded text check each line and find out type with the biggest priority
|
||||
int lineStart = position.getLine();
|
||||
int linesEnd = lineStart;
|
||||
if (editor != null) {
|
||||
FoldRegion region = FoldingUtil.findFoldRegionStartingAtLine(editor, lineStart);
|
||||
if (region != null && !region.isExpanded()) {
|
||||
linesEnd = region.getDocument().getLineNumber(region.getEndOffset());
|
||||
}
|
||||
}
|
||||
|
||||
VirtualFile file = position.getFile();
|
||||
final XBreakpointManager breakpointManager = XDebuggerManager.getInstance(project).getBreakpointManager();
|
||||
XLineBreakpointType<?>[] lineTypes = XDebuggerUtil.getInstance().getLineBreakpointTypes();
|
||||
XLineBreakpointType<?> typeWinner = null;
|
||||
int lineWinner = -1;
|
||||
for (int line = lineStart; line <= linesEnd; line++) {
|
||||
int maxPriority = 0;
|
||||
for (XLineBreakpointType<?> type : lineTypes) {
|
||||
maxPriority = Math.max(maxPriority, type.getPriority());
|
||||
final XLineBreakpoint<? extends XBreakpointProperties> breakpoint = breakpointManager.findBreakpointAtLine(type, file, line);
|
||||
if (breakpoint != null && myTemporary && !breakpoint.isTemporary()) {
|
||||
breakpoint.setTemporary(true);
|
||||
} else if (type.canPutAt(file, line, project) || breakpoint != null) {
|
||||
if (typeWinner == null || type.getPriority() > typeWinner.getPriority()) {
|
||||
typeWinner = type;
|
||||
lineWinner = line;
|
||||
}
|
||||
}
|
||||
}
|
||||
// already found max priority type - stop
|
||||
if (typeWinner != null && typeWinner.getPriority() == maxPriority) {
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
if (typeWinner != null) {
|
||||
XDebuggerUtil.getInstance().toggleLineBreakpoint(project, typeWinner, file, lineWinner, myTemporary);
|
||||
}
|
||||
|
||||
ExpandRegionAction.expandRegionAtCaret(project, editor);
|
||||
if (editor != null && lineStart != lineWinner) {
|
||||
editor.getCaretModel().moveToOffset(editor.getDocument().getLineStartOffset(lineWinner));
|
||||
}
|
||||
XBreakpointUtil.toggleLineBreakpoint(project, position.getFile(), editor, position.getLine(), myTemporary);
|
||||
}
|
||||
}
|
||||
|
||||
+60
-2
@@ -15,13 +15,18 @@
|
||||
*/
|
||||
package com.intellij.xdebugger.impl.breakpoints;
|
||||
|
||||
import com.intellij.codeInsight.folding.impl.FoldingUtil;
|
||||
import com.intellij.codeInsight.folding.impl.actions.ExpandRegionAction;
|
||||
import com.intellij.openapi.editor.Document;
|
||||
import com.intellij.openapi.editor.Editor;
|
||||
import com.intellij.openapi.editor.FoldRegion;
|
||||
import com.intellij.openapi.editor.markup.GutterIconRenderer;
|
||||
import com.intellij.openapi.project.Project;
|
||||
import com.intellij.openapi.util.Pair;
|
||||
import com.intellij.xdebugger.breakpoints.XBreakpoint;
|
||||
import com.intellij.xdebugger.breakpoints.XBreakpointType;
|
||||
import com.intellij.openapi.vfs.VirtualFile;
|
||||
import com.intellij.xdebugger.XDebuggerManager;
|
||||
import com.intellij.xdebugger.XDebuggerUtil;
|
||||
import com.intellij.xdebugger.breakpoints.*;
|
||||
import com.intellij.xdebugger.impl.DebuggerSupport;
|
||||
import com.intellij.xdebugger.impl.breakpoints.ui.BreakpointItem;
|
||||
import com.intellij.xdebugger.impl.breakpoints.ui.BreakpointPanelProvider;
|
||||
@@ -117,4 +122,57 @@ public class XBreakpointUtil {
|
||||
}
|
||||
return null;
|
||||
}
|
||||
|
||||
/**
|
||||
* Toggle line breakpoint with editor support:
|
||||
* - unfolds folded block on the line
|
||||
* - if folded, checks if line breakpoints could be toggled inside folded text
|
||||
*/
|
||||
public static XLineBreakpoint toggleLineBreakpoint(Project project, VirtualFile file, Editor editor, int lineStart, boolean temporary) {
|
||||
// for folded text check each line and find out type with the biggest priority
|
||||
int linesEnd = lineStart;
|
||||
if (editor != null) {
|
||||
FoldRegion region = FoldingUtil.findFoldRegionStartingAtLine(editor, lineStart);
|
||||
if (region != null && !region.isExpanded()) {
|
||||
linesEnd = region.getDocument().getLineNumber(region.getEndOffset());
|
||||
}
|
||||
}
|
||||
|
||||
final XBreakpointManager breakpointManager = XDebuggerManager.getInstance(project).getBreakpointManager();
|
||||
XLineBreakpointType<?>[] lineTypes = XDebuggerUtil.getInstance().getLineBreakpointTypes();
|
||||
XLineBreakpointType<?> typeWinner = null;
|
||||
int lineWinner = -1;
|
||||
for (int line = lineStart; line <= linesEnd; line++) {
|
||||
int maxPriority = 0;
|
||||
for (XLineBreakpointType<?> type : lineTypes) {
|
||||
maxPriority = Math.max(maxPriority, type.getPriority());
|
||||
final XLineBreakpoint<? extends XBreakpointProperties> breakpoint = breakpointManager.findBreakpointAtLine(type, file, line);
|
||||
if (breakpoint != null && temporary && !breakpoint.isTemporary()) {
|
||||
breakpoint.setTemporary(true);
|
||||
} else if (type.canPutAt(file, line, project) || breakpoint != null) {
|
||||
if (typeWinner == null || type.getPriority() > typeWinner.getPriority()) {
|
||||
typeWinner = type;
|
||||
lineWinner = line;
|
||||
}
|
||||
}
|
||||
}
|
||||
// already found max priority type - stop
|
||||
if (typeWinner != null && typeWinner.getPriority() == maxPriority) {
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
XLineBreakpoint res = null;
|
||||
if (typeWinner != null) {
|
||||
res = XDebuggerUtil.getInstance().toggleLineBreakpoint(project, typeWinner, file, lineWinner, temporary);
|
||||
}
|
||||
|
||||
ExpandRegionAction.expandRegionAtCaret(project, editor);
|
||||
if (editor != null && lineStart != lineWinner) {
|
||||
editor.getCaretModel().moveToOffset(editor.getDocument().getLineStartOffset(lineWinner));
|
||||
}
|
||||
|
||||
return res;
|
||||
}
|
||||
}
|
||||
|
||||
+1
-2
@@ -49,7 +49,6 @@ import com.intellij.util.containers.BidirectionalMap;
|
||||
import com.intellij.util.ui.update.MergingUpdateQueue;
|
||||
import com.intellij.util.ui.update.Update;
|
||||
import com.intellij.xdebugger.XDebuggerManager;
|
||||
import com.intellij.xdebugger.XDebuggerUtil;
|
||||
import com.intellij.xdebugger.breakpoints.SuspendPolicy;
|
||||
import com.intellij.xdebugger.breakpoints.XBreakpoint;
|
||||
import com.intellij.xdebugger.breakpoints.XLineBreakpoint;
|
||||
@@ -276,7 +275,7 @@ public class XLineBreakpointManager {
|
||||
public void run() {
|
||||
if (!myProject.isDisposed() && myProject.isInitialized() && file.isValid()) {
|
||||
XLineBreakpoint breakpoint =
|
||||
XDebuggerUtil.getInstance().toggleLineBreakpoint(myProject, file, line, mouseEvent.isAltDown());
|
||||
XBreakpointUtil.toggleLineBreakpoint(myProject, file, editor, line, mouseEvent.isAltDown());
|
||||
if (!mouseEvent.isAltDown() && mouseEvent.isShiftDown() && breakpoint != null) {
|
||||
breakpoint.setSuspendPolicy(SuspendPolicy.NONE);
|
||||
String selection = editor.getSelectionModel().getSelectedText();
|
||||
|
||||
Reference in New Issue
Block a user