From a4bd5322e297b16e74745c06946ff65357387d30 Mon Sep 17 00:00:00 2001 From: Konstantin Bulenkov Date: Mon, 8 Feb 2010 16:16:13 +0300 Subject: [PATCH 1/3] DataProvider for Navigatable elements; correct editor layer for selection from psi elements tree --- .../internal/psiView/PsiViewerDialog.java | 72 ++++++++++++++----- 1 file changed, 54 insertions(+), 18 deletions(-) diff --git a/platform/lang-impl/src/com/intellij/internal/psiView/PsiViewerDialog.java b/platform/lang-impl/src/com/intellij/internal/psiView/PsiViewerDialog.java index ae12700b4086..24d0d6a542cd 100644 --- a/platform/lang-impl/src/com/intellij/internal/psiView/PsiViewerDialog.java +++ b/platform/lang-impl/src/com/intellij/internal/psiView/PsiViewerDialog.java @@ -18,10 +18,7 @@ package com.intellij.internal.psiView; import com.intellij.lang.ASTNode; import com.intellij.lang.Language; import com.intellij.lang.LanguageUtil; -import com.intellij.openapi.actionSystem.AnAction; -import com.intellij.openapi.actionSystem.AnActionEvent; -import com.intellij.openapi.actionSystem.DefaultActionGroup; -import com.intellij.openapi.actionSystem.Presentation; +import com.intellij.openapi.actionSystem.*; import com.intellij.openapi.actionSystem.ex.ComboBoxAction; import com.intellij.openapi.application.ApplicationManager; import com.intellij.openapi.editor.Document; @@ -59,6 +56,7 @@ import com.intellij.ui.treeStructure.Tree; import com.intellij.util.IncorrectOperationException; import com.intellij.util.ui.UIUtil; import com.intellij.util.ui.tree.TreeUtil; +import org.jetbrains.annotations.NonNls; import org.jetbrains.annotations.NotNull; import org.jetbrains.annotations.Nullable; @@ -76,7 +74,7 @@ import java.util.List; /** * @author Konstantin Bulenkov */ -public class PsiViewerDialog extends DialogWrapper { +public class PsiViewerDialog extends DialogWrapper implements DataProvider { private final Project myProject; private final Tree myTree; @@ -479,6 +477,36 @@ public class PsiViewerDialog extends DialogWrapper { myTree.setRootVisible(false); } + public Object getData(@NonNls String dataId) { + if (PlatformDataKeys.NAVIGATABLE.is(dataId)) { + String fqn = null; + if (myTree.hasFocus()) { + final TreePath path = myTree.getSelectionPath(); + if (path != null) { + DefaultMutableTreeNode node = (DefaultMutableTreeNode)path.getLastPathComponent(); + if (!(node.getUserObject() instanceof ViewerNodeDescriptor)) return null; + ViewerNodeDescriptor descriptor = (ViewerNodeDescriptor)node.getUserObject(); + Object elementObject = descriptor.getElement(); + final PsiElement element = elementObject instanceof PsiElement + ? (PsiElement)elementObject + : elementObject instanceof ASTNode ? ((ASTNode)elementObject).getPsi() : null; + if (element != null) { + fqn = element.getClass().getName(); + } + } + } else if (myRefs.hasFocus()) { + final Object value = myRefs.getSelectedValue(); + if (value instanceof String) { + fqn = (String)value; + } + } + if (fqn != null) { + return getContainingFileForClass(fqn); + } + } + return null; + } + private class MyTreeSelectionListener implements TreeSelectionListener { private final TextAttributes myAttributes; @@ -518,7 +546,7 @@ public class PsiViewerDialog extends DialogWrapper { final int textLength = myEditor.getDocument().getTextLength(); if (end <= textLength) { myEditor.getMarkupModel() - .addRangeHighlighter(start, end, HighlighterLayer.FIRST + 1, myAttributes, HighlighterTargetArea.EXACT_RANGE); + .addRangeHighlighter(start, end, HighlighterLayer.LAST, myAttributes, HighlighterTargetArea.EXACT_RANGE); if (myTree.hasFocus()) { myEditor.getCaretModel().moveToOffset(start); myEditor.getScrollingModel().scrollToCaret(ScrollType.MAKE_VISIBLE); @@ -594,6 +622,24 @@ public class PsiViewerDialog extends DialogWrapper { return index >= elements.length ? null : elements[index]; } + @Nullable + private PsiFile getContainingFileForClass(String fqn) { + String filename = fqn; + if (fqn.contains(".")) { + filename = fqn.substring(fqn.lastIndexOf('.') + 1); + } + if (filename.contains("$")) { + filename = filename.substring(0, filename.indexOf('$')); + } + filename += ".java"; + final PsiFile[] files = FilenameIndex.getFilesByName(myProject, filename, GlobalSearchScope.allScope(myProject)); + if (files != null && files.length > 0) { + return files[0]; + } + return null; + } + + @Nullable public static TreeNode findNodeWithObject(final Object object, final TreeModel model, final Object parent) { for (int i = 0; i < model.getChildCount(parent); i++) { @@ -637,18 +683,8 @@ public class PsiViewerDialog extends DialogWrapper { final Object value = myRefs.getSelectedValue(); if (value instanceof String) { final String fqn = (String)value; - String filename = fqn; - if (fqn.contains(".")) { - filename = fqn.substring(fqn.lastIndexOf('.') + 1); - } - if (filename.contains("$")) { - filename = filename.substring(0, filename.indexOf('$')); - } - filename += ".java"; - final PsiFile[] files = FilenameIndex.getFilesByName(myProject, filename, GlobalSearchScope.allScope(myProject)); - if (files != null && files.length > 0) { - files[0].navigate(true); - } + final PsiFile file = getContainingFileForClass(fqn); + if (file != null) file.navigate(true); } } From e1d5370379e345a34a2df04bcd1eac34987ae915 Mon Sep 17 00:00:00 2001 From: Kirill Kalishev Date: Mon, 8 Feb 2010 16:16:35 +0300 Subject: [PATCH 2/3] IDEA-51296 Cursor is lost after rerunning contents of the Run Pane --- .../intellij/execution/ui/RunContentManagerImpl.java | 11 +++++++++-- 1 file changed, 9 insertions(+), 2 deletions(-) diff --git a/platform/lang-impl/src/com/intellij/execution/ui/RunContentManagerImpl.java b/platform/lang-impl/src/com/intellij/execution/ui/RunContentManagerImpl.java index cab83d8903a1..232c64880345 100644 --- a/platform/lang-impl/src/com/intellij/execution/ui/RunContentManagerImpl.java +++ b/platform/lang-impl/src/com/intellij/execution/ui/RunContentManagerImpl.java @@ -248,6 +248,9 @@ public class RunContentManagerImpl implements RunContentManager, Disposable { public void showRunContent(@NotNull final Executor executor, final RunContentDescriptor descriptor) { if(ApplicationManager.getApplication().isUnitTestMode()) return; + final ToolWindow toolWindow = ToolWindowManager.getInstance(myProject).getToolWindow(executor.getToolWindowId()); + final boolean wasInActiveWindow = toolWindow != null && toolWindow.isActive(); + final ContentManager contentManager = getContentManagerForRunner(executor); RunContentDescriptor oldDescriptor = chooseReuseContentForDescriptor(contentManager, descriptor); @@ -303,8 +306,12 @@ public class RunContentManagerImpl implements RunContentManager, Disposable { ApplicationManager.getApplication().invokeLater(new Runnable() { public void run() { - final ToolWindow toolWindow = ToolWindowManager.getInstance(myProject).getToolWindow(executor.getToolWindowId()); - toolWindow.show(null); + ToolWindow window = ToolWindowManager.getInstance(myProject).getToolWindow(executor.getToolWindowId()); + if (wasInActiveWindow) { + window.activate(null, true, false); + } else { + window.show(null); + } } }); } From cfb5954c5730daa27a150b68f6d779b486c94f0c Mon Sep 17 00:00:00 2001 From: Kirill Kalishev Date: Mon, 8 Feb 2010 16:20:10 +0300 Subject: [PATCH 3/3] focus stealing fix is enabled back --- platform/platform-resources-en/src/misc/registry.properties | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/platform/platform-resources-en/src/misc/registry.properties b/platform/platform-resources-en/src/misc/registry.properties index 114dfdbf81ef..7a61ae259dfa 100644 --- a/platform/platform-resources-en/src/misc/registry.properties +++ b/platform/platform-resources-en/src/misc/registry.properties @@ -17,7 +17,7 @@ actionSystem.playback.useTypingTargets=true actionSystem.focusIdleTimeout=20 actionSystem.mac.screenMenuNotUpdatedFix=false actionSystem.keyGestures.enabled=false -actionSystem.suspendFocusTransferIfApplicationInactive=false +actionSystem.suspendFocusTransferIfApplicationInactive=true actionSystem.noContextComponentWhileFocusTransfer=true ide.debugMode=true