Search in sources :

Example 1 with ToolWindowManagerImpl

use of com.intellij.openapi.wm.impl.ToolWindowManagerImpl in project intellij-community by JetBrains.

the class PreviewManagerImpl method checkGlobalState.

protected void checkGlobalState() {
    ToolWindowManagerImpl toolWindowManager = (ToolWindowManagerImpl) ToolWindowManager.getInstance(myProject);
    if (!isAvailable() && toolWindowManager.getToolWindow(ToolWindowId.PREVIEW) != null) {
        myHistory.clear();
        myContentManager.removeAllContents(true);
        toolWindowManager.unregisterToolWindow(ToolWindowId.PREVIEW);
        return;
    }
    if (isAvailable() && toolWindowManager.getToolWindow(ToolWindowId.PREVIEW) == null) {
        myToolWindow = (ToolWindowImpl) toolWindowManager.registerToolWindow(ToolWindowId.PREVIEW, myEmptyStatePanel, ToolWindowAnchor.RIGHT, myProject, false);
        myContentManager = myToolWindow.getContentManager();
        myToolWindow.setIcon(AllIcons.Toolwindows.ToolWindowPreview);
        myToolWindow.setContentUiType(ToolWindowContentUiType.COMBO, null);
        myToolWindow.setAutoHide(true);
        myEmptyStateContent = myContentManager.getContent(0);
        final MoveToStandardViewAction moveToStandardViewAction = new MoveToStandardViewAction();
        myContentManager.addContentManagerListener(new ContentManagerAdapter() {

            @Override
            public void selectionChanged(ContentManagerEvent event) {
                if (myInnerSelectionChange || event.getOperation() != ContentManagerEvent.ContentOperation.add)
                    return;
                PreviewInfo previewInfo = event.getContent().getUserData(INFO_KEY);
                if (previewInfo != null) {
                    preview(previewInfo, false);
                    myToolWindow.setTitleActions(previewInfo.supportsStandardPlace() ? moveToStandardViewAction : null);
                }
            }
        });
        moveToStandardViewAction.registerCustomShortcutSet(new ShortcutSet() {

            @NotNull
            @Override
            public Shortcut[] getShortcuts() {
                Keymap keymap = KeymapManager.getInstance().getActiveKeymap();
                return keymap.getShortcuts("ShowContent");
            }
        }, myToolWindow.getComponent());
        myToolWindow.setTitleActions(moveToStandardViewAction);
        ArrayList<AnAction> myGearActions = new ArrayList<>();
        for (PreviewPanelProvider provider : myProviders) {
            myGearActions.add(new ContentTypeToggleAction(provider));
        }
        myToolWindow.setAdditionalGearActions(new DefaultActionGroup("Preview", myGearActions));
        myToolWindow.activate(() -> myToolWindow.activate(null));
    }
}
Also used : ToolWindowManagerImpl(com.intellij.openapi.wm.impl.ToolWindowManagerImpl) PreviewPanelProvider(com.intellij.openapi.preview.PreviewPanelProvider) ContentManagerAdapter(com.intellij.ui.content.ContentManagerAdapter) NotNull(org.jetbrains.annotations.NotNull) PreviewInfo(com.intellij.openapi.preview.PreviewInfo) ContentManagerEvent(com.intellij.ui.content.ContentManagerEvent) Keymap(com.intellij.openapi.keymap.Keymap)

Aggregations

Keymap (com.intellij.openapi.keymap.Keymap)1 PreviewInfo (com.intellij.openapi.preview.PreviewInfo)1 PreviewPanelProvider (com.intellij.openapi.preview.PreviewPanelProvider)1 ToolWindowManagerImpl (com.intellij.openapi.wm.impl.ToolWindowManagerImpl)1 ContentManagerAdapter (com.intellij.ui.content.ContentManagerAdapter)1 ContentManagerEvent (com.intellij.ui.content.ContentManagerEvent)1 NotNull (org.jetbrains.annotations.NotNull)1