diff options
Diffstat (limited to 'platform/lang-impl/src/com/intellij/codeInsight/documentation/DockablePopupManager.java')
-rw-r--r-- | platform/lang-impl/src/com/intellij/codeInsight/documentation/DockablePopupManager.java | 75 |
1 files changed, 40 insertions, 35 deletions
diff --git a/platform/lang-impl/src/com/intellij/codeInsight/documentation/DockablePopupManager.java b/platform/lang-impl/src/com/intellij/codeInsight/documentation/DockablePopupManager.java index 83f17299987b..e0d17d3c164b 100644 --- a/platform/lang-impl/src/com/intellij/codeInsight/documentation/DockablePopupManager.java +++ b/platform/lang-impl/src/com/intellij/codeInsight/documentation/DockablePopupManager.java @@ -23,7 +23,7 @@ import com.intellij.openapi.Disposable; import com.intellij.openapi.actionSystem.*; import com.intellij.openapi.editor.Editor; import com.intellij.openapi.project.Project; -import com.intellij.openapi.util.AsyncResult; +import com.intellij.openapi.util.Disposer; import com.intellij.openapi.wm.ToolWindow; import com.intellij.openapi.wm.ToolWindowAnchor; import com.intellij.openapi.wm.ToolWindowType; @@ -34,6 +34,7 @@ import com.intellij.psi.PsiFile; import com.intellij.psi.impl.source.tree.injected.InjectedLanguageUtil; import com.intellij.psi.util.PsiUtilBase; import com.intellij.ui.content.*; +import com.intellij.util.Consumer; import com.intellij.util.ui.UIUtil; import com.intellij.util.ui.update.Activatable; import com.intellij.util.ui.update.UiNotifyConnector; @@ -136,30 +137,33 @@ public abstract class DockablePopupManager<T extends JComponent & Disposable> { protected AnAction[] createActions() { - return new AnAction[]{ - new ToggleAction(getAutoUpdateTitle(), getAutoUpdateDescription(), - AllIcons.General.AutoscrollFromSource) { - @Override - public boolean isSelected(AnActionEvent e) { - return myAutoUpdateDocumentation; - } - - @Override - public void setSelected(AnActionEvent e, boolean state) { - PropertiesComponent.getInstance().setValue(getAutoUpdateEnabledProperty(), String.valueOf(state)); - myAutoUpdateDocumentation = state; - restartAutoUpdate(state); - } - }, - new AnAction("Restore Popup", getRestorePopupDescription(), AllIcons.Actions.Cancel) { - @Override - public void actionPerformed(AnActionEvent e) { - restorePopupBehavior(); - } - }}; + ToggleAction toggleAutoUpdateAction = new ToggleAction(getAutoUpdateTitle(), getAutoUpdateDescription(), + AllIcons.General.AutoscrollFromSource) { + @Override + public boolean isSelected(AnActionEvent e) { + return myAutoUpdateDocumentation; + } + + @Override + public void setSelected(AnActionEvent e, boolean state) { + PropertiesComponent.getInstance().setValue(getAutoUpdateEnabledProperty(), String.valueOf(state)); + myAutoUpdateDocumentation = state; + restartAutoUpdate(state); + } + }; + return new AnAction[]{toggleAutoUpdateAction, createRestorePopupAction()}; + } + + @NotNull + protected AnAction createRestorePopupAction() { + return new AnAction("Restore Popup", getRestorePopupDescription(), AllIcons.Actions.Cancel) { + @Override + public void actionPerformed(AnActionEvent e) { + restorePopupBehavior(); + } + }; } - protected void restartAutoUpdate(final boolean state) { if (state && myToolWindow != null) { if (myAutoUpdateRequest == null) { @@ -189,12 +193,16 @@ public abstract class DockablePopupManager<T extends JComponent & Disposable> { public void updateComponent() { if (myProject.isDisposed()) return; - AsyncResult<DataContext> asyncResult = DataManager.getInstance().getDataContextFromFocus(); - DataContext dataContext = asyncResult.getResult(); - if (dataContext == null) { - return; - } + DataManager.getInstance().getDataContextFromFocus().doWhenDone(new Consumer<DataContext>() { + @Override + public void consume(@NotNull DataContext dataContext) { + if (!myProject.isOpen()) return; + updateComponentInner(dataContext); + } + }); + } + private void updateComponentInner(@NotNull DataContext dataContext) { if (CommonDataKeys.PROJECT.getData(dataContext) != myProject) { return; } @@ -228,13 +236,10 @@ public abstract class DockablePopupManager<T extends JComponent & Disposable> { protected void restorePopupBehavior() { if (myToolWindow != null) { PropertiesComponent.getInstance().setValue(getShowInToolWindowProperty(), Boolean.FALSE.toString()); - - final Content[] contents = myToolWindow.getContentManager().getContents(); - for (final Content content : contents) { - myToolWindow.getContentManager().removeContent(content, true); - } - - ToolWindowManagerEx.getInstanceEx(myProject).unregisterToolWindow(getToolwindowId()); + ToolWindowManagerEx toolWindowManagerEx = ToolWindowManagerEx.getInstanceEx(myProject); + toolWindowManagerEx.hideToolWindow(getToolwindowId(), false); + toolWindowManagerEx.unregisterToolWindow(getToolwindowId()); + Disposer.dispose(myToolWindow.getContentManager()); myToolWindow = null; restartAutoUpdate(false); } |