From 11b536d64c0b7ce48a2cca0085cdd1d49396d2ae Mon Sep 17 00:00:00 2001 From: "Egor.Ushakov" Date: Tue, 8 Sep 2015 13:10:41 +0300 Subject: [PATCH] IDEA-144791 Smart Step Into (Shift+F7): Focus issue in debugger --- .../actions/JvmSmartStepIntoHandler.java | 4 +-- .../xdebugger/impl/XDebuggerUtilImpl.java | 2 +- .../XDebuggerSmartStepIntoHandler.java | 29 ++++++++++--------- .../xdebugger/impl/ui/DebuggerUIUtil.java | 25 ++++++++++++++-- 4 files changed, 41 insertions(+), 19 deletions(-) diff --git a/java/debugger/impl/src/com/intellij/debugger/actions/JvmSmartStepIntoHandler.java b/java/debugger/impl/src/com/intellij/debugger/actions/JvmSmartStepIntoHandler.java index e917fb2a1df7..f680a15392df 100644 --- a/java/debugger/impl/src/com/intellij/debugger/actions/JvmSmartStepIntoHandler.java +++ b/java/debugger/impl/src/com/intellij/debugger/actions/JvmSmartStepIntoHandler.java @@ -26,7 +26,6 @@ import com.intellij.openapi.extensions.ExtensionPointName; import com.intellij.openapi.fileEditor.TextEditor; import com.intellij.psi.PsiElement; import com.intellij.psi.PsiMethod; -import com.intellij.ui.awt.RelativePoint; import com.intellij.ui.components.JBList; import com.intellij.ui.popup.list.ListPopupImpl; import com.intellij.xdebugger.impl.actions.XDebuggerActions; @@ -87,8 +86,7 @@ public abstract class JvmSmartStepIntoHandler { } }); highlightTarget(popupStep, firstTarget); - final RelativePoint point = DebuggerUIUtil.calcPopupLocation(editor, position.getLine()); - popup.show(point); + DebuggerUIUtil.showPopupForEditorLine(popup, editor, position.getLine()); } return true; } diff --git a/platform/xdebugger-impl/src/com/intellij/xdebugger/impl/XDebuggerUtilImpl.java b/platform/xdebugger-impl/src/com/intellij/xdebugger/impl/XDebuggerUtilImpl.java index 2be5184b0d2a..72f02ca2ff50 100644 --- a/platform/xdebugger-impl/src/com/intellij/xdebugger/impl/XDebuggerUtilImpl.java +++ b/platform/xdebugger-impl/src/com/intellij/xdebugger/impl/XDebuggerUtilImpl.java @@ -152,7 +152,7 @@ public class XDebuggerUtilImpl extends XDebuggerUtil { else { List.XLineBreakpointVariant> variants = type.computeVariants(project, position); if (!variants.isEmpty() && editor != null) { - RelativePoint relativePoint = DebuggerUIUtil.calcPopupLocation(editor, line); + RelativePoint relativePoint = DebuggerUIUtil.getPositionForPopup(editor, line); if (variants.size() > 1 && relativePoint != null) { final AsyncResult res = new AsyncResult(); class MySelectionListener implements ListSelectionListener { diff --git a/platform/xdebugger-impl/src/com/intellij/xdebugger/impl/actions/handlers/XDebuggerSmartStepIntoHandler.java b/platform/xdebugger-impl/src/com/intellij/xdebugger/impl/actions/handlers/XDebuggerSmartStepIntoHandler.java index 2b84d05011c2..831327dc2c0a 100644 --- a/platform/xdebugger-impl/src/com/intellij/xdebugger/impl/actions/handlers/XDebuggerSmartStepIntoHandler.java +++ b/platform/xdebugger-impl/src/com/intellij/xdebugger/impl/actions/handlers/XDebuggerSmartStepIntoHandler.java @@ -1,5 +1,5 @@ /* - * Copyright 2000-2009 JetBrains s.r.o. + * Copyright 2000-2015 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. @@ -16,13 +16,14 @@ package com.intellij.xdebugger.impl.actions.handlers; import com.intellij.openapi.actionSystem.DataContext; +import com.intellij.openapi.editor.Editor; import com.intellij.openapi.fileEditor.FileEditor; import com.intellij.openapi.fileEditor.FileEditorManager; import com.intellij.openapi.fileEditor.TextEditor; import com.intellij.openapi.ui.popup.JBPopupFactory; +import com.intellij.openapi.ui.popup.ListPopup; import com.intellij.openapi.ui.popup.PopupStep; import com.intellij.openapi.ui.popup.util.BaseListPopupStep; -import com.intellij.ui.awt.RelativePoint; import com.intellij.xdebugger.XDebugSession; import com.intellij.xdebugger.XSourcePosition; import com.intellij.xdebugger.impl.actions.XDebuggerSuspendedActionHandler; @@ -46,20 +47,21 @@ public class XDebuggerSmartStepIntoHandler extends XDebuggerSuspendedActionHandl @Override protected void perform(@NotNull XDebugSession session, DataContext dataContext) { - final XSmartStepIntoHandler handler = session.getDebugProcess().getSmartStepIntoHandler(); - final XSourcePosition position = session.getTopFramePosition(); + XSmartStepIntoHandler handler = session.getDebugProcess().getSmartStepIntoHandler(); + XSourcePosition position = session.getTopFramePosition(); if (position == null || handler == null) return; - final FileEditor editor = FileEditorManager.getInstance(session.getProject()).getSelectedEditor(position.getFile()); - if (!(editor instanceof TextEditor)) return; - - final RelativePoint relativePoint = DebuggerUIUtil.calcPopupLocation(((TextEditor)editor).getEditor(), position.getLine()); - doSmartStepInto(handler, position, session, relativePoint); + FileEditor editor = FileEditorManager.getInstance(session.getProject()).getSelectedEditor(position.getFile()); + if (editor instanceof TextEditor) { + doSmartStepInto(handler, position, session, ((TextEditor)editor).getEditor()); + } } private static void doSmartStepInto(final XSmartStepIntoHandler handler, - XSourcePosition position, final XDebugSession session, RelativePoint relativePoint) { - final List variants = handler.computeSmartStepVariants(position); + XSourcePosition position, + final XDebugSession session, + Editor editor) { + List variants = handler.computeSmartStepVariants(position); if (variants.isEmpty()) { session.stepInto(); return; @@ -69,7 +71,7 @@ public class XDebuggerSmartStepIntoHandler extends XDebuggerSuspendedActionHandl return; } - JBPopupFactory.getInstance().createListPopup(new BaseListPopupStep(handler.getPopupTitle(position), variants) { + ListPopup popup = JBPopupFactory.getInstance().createListPopup(new BaseListPopupStep(handler.getPopupTitle(position), variants) { @Override public Icon getIconFor(V aValue) { return aValue.getIcon(); @@ -86,6 +88,7 @@ public class XDebuggerSmartStepIntoHandler extends XDebuggerSuspendedActionHandl session.smartStepInto(handler, selectedValue); return FINAL_CHOICE; } - }).show(relativePoint); + }); + DebuggerUIUtil.showPopupForEditorLine(popup, editor, position.getLine()); } } diff --git a/platform/xdebugger-impl/src/com/intellij/xdebugger/impl/ui/DebuggerUIUtil.java b/platform/xdebugger-impl/src/com/intellij/xdebugger/impl/ui/DebuggerUIUtil.java index 0e724958f385..c5e79244a3eb 100644 --- a/platform/xdebugger-impl/src/com/intellij/xdebugger/impl/ui/DebuggerUIUtil.java +++ b/platform/xdebugger-impl/src/com/intellij/xdebugger/impl/ui/DebuggerUIUtil.java @@ -21,11 +21,9 @@ import com.intellij.openapi.actionSystem.ActionManager; import com.intellij.openapi.actionSystem.AnAction; import com.intellij.openapi.application.ApplicationManager; import com.intellij.openapi.editor.Editor; -import com.intellij.openapi.editor.EditorGutter; import com.intellij.openapi.editor.LogicalPosition; import com.intellij.openapi.editor.colors.EditorColorsScheme; import com.intellij.openapi.editor.colors.EditorColorsUtil; -import com.intellij.openapi.editor.ex.EditorGutterComponentEx; import com.intellij.openapi.keymap.KeymapUtil; import com.intellij.openapi.project.Project; import com.intellij.openapi.ui.popup.*; @@ -97,6 +95,7 @@ public class DebuggerUIUtil { ApplicationManager.getApplication().invokeLater(runnable); } + @Deprecated public static RelativePoint calcPopupLocation(@NotNull Editor editor, final int line) { Point p = editor.logicalPositionToXY(new LogicalPosition(line + 1, 0)); @@ -107,6 +106,28 @@ public class DebuggerUIUtil { return new RelativePoint(editor.getContentComponent(), p); } + @Nullable + public static RelativePoint getPositionForPopup(@NotNull Editor editor, int line) { + Point p = editor.logicalPositionToXY(new LogicalPosition(line + 1, 0)); + return editor.getScrollingModel().getVisibleArea().contains(p) ? new RelativePoint(editor.getContentComponent(), p) : null; + } + + public static void showPopupForEditorLine(@NotNull JBPopup popup, @NotNull Editor editor, int line) { + RelativePoint point = getPositionForPopup(editor, line); + if (point != null) { + popup.show(point); + } + else { + Project project = editor.getProject(); + if (project != null) { + popup.showCenteredInCurrentWindow(project); + } + else { + popup.showInFocusCenter(); + } + } + } + public static void showValuePopup(@NotNull XFullValueEvaluator evaluator, @NotNull MouseEvent event, @NotNull Project project, @Nullable Editor editor) { EditorTextField textArea = new TextViewer("Evaluating...", project); textArea.setBackground(HintUtil.INFORMATION_COLOR);