From 0ad7d5f9d6dd8e4310f2fbfadfff9ffaebc15108 Mon Sep 17 00:00:00 2001 From: Konstantin Bulenkov Date: Tue, 4 Dec 2012 09:55:20 +0100 Subject: [PATCH] IDEA-95653 Opening Structure panel will switch to wrong file, or scroll file to the top. (cherry picked from commit 5b354e6f18ec83af6988fbfd60340074c7d5fdeb) --- .../ide/impl/StructureViewWrapperImpl.java | 23 ++++++++++++++++--- 1 file changed, 20 insertions(+), 3 deletions(-) diff --git a/platform/lang-impl/src/com/intellij/ide/impl/StructureViewWrapperImpl.java b/platform/lang-impl/src/com/intellij/ide/impl/StructureViewWrapperImpl.java index 05318c85b2d3..3ecf01ca4fd5 100644 --- a/platform/lang-impl/src/com/intellij/ide/impl/StructureViewWrapperImpl.java +++ b/platform/lang-impl/src/com/intellij/ide/impl/StructureViewWrapperImpl.java @@ -134,16 +134,23 @@ public class StructureViewWrapperImpl implements StructureViewWrapper, Disposabl } private void checkUpdate() { - if (myProject.isDisposed() || !myToolWindow.isVisible()) return; + if (myProject.isDisposed()) return; final Component owner = KeyboardFocusManager.getCurrentKeyboardFocusManager().getFocusOwner(); - if (/*SwingUtilities.isDescendingFrom(myToolWindow.getComponent(), owner) || */JBPopupFactory.getInstance().isPopupActive()) return; + if (SwingUtilities.isDescendingFrom(myToolWindow.getComponent(), owner) || JBPopupFactory.getInstance().isPopupActive()) return; final DataContext dataContext = DataManager.getInstance().getDataContext(owner); if (dataContext.getData(myKey) == this) return; if (PlatformDataKeys.PROJECT.getData(dataContext) != myProject) return; - final VirtualFile[] files = PlatformDataKeys.VIRTUAL_FILE_ARRAY.getData(dataContext); + final VirtualFile[] files = hasFocus() ? null : PlatformDataKeys.VIRTUAL_FILE_ARRAY.getData(dataContext); + if (!myToolWindow.isVisible()) { + if (files != null && files.length > 0) { + myFile = files[0]; + } + return; + } + if (files != null && files.length == 1) { setFile(files[0]); } @@ -160,6 +167,16 @@ public class StructureViewWrapperImpl implements StructureViewWrapper, Disposabl myFirstRun = false; } + private boolean hasFocus() { + final JComponent tw = myToolWindow.getComponent(); + Component owner = KeyboardFocusManager.getCurrentKeyboardFocusManager().getFocusOwner(); + while (owner != null) { + if (owner == tw) return true; + owner = owner.getParent(); + } + return false; + } + private void setFile(VirtualFile file) { if (!Comparing.equal(file, myFile)) { myFile = file;