IDEA-95653 Opening Structure panel will switch to wrong file, or scroll file to the top.

(cherry picked from commit 5b354e6f18ec83af6988fbfd60340074c7d5fdeb)
This commit is contained in:
Konstantin Bulenkov
2012-12-05 16:15:21 +01:00
parent 3cd3c7dc8b
commit 0ad7d5f9d6
@@ -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;