Search in sources :

Example 1 with PreviewInfo

use of com.intellij.openapi.preview.PreviewInfo 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)

Example 2 with PreviewInfo

use of com.intellij.openapi.preview.PreviewInfo in project intellij-community by JetBrains.

the class PreviewManagerImpl method preview.

private <V, C> C preview(@NotNull final PreviewInfo<V, C> info, boolean requestFocus) {
    toggleToolWindow(true, null);
    Content content = getContent(info);
    Content selectedContent = myContentManager.getSelectedContent();
    if (selectedContent != content) {
        myInnerSelectionChange = true;
        try {
            PreviewInfo selectedInfo = selectedContent != null ? selectedContent.getUserData(INFO_KEY) : null;
            if (selectedInfo != null && selectedInfo.isModified(selectedInfo.getId() == info.getId())) {
                moveToStandardPlaceImpl(selectedInfo.getId(), selectedInfo.getData());
            }
            if (content == null) {
                content = addContent(info);
            }
        } finally {
            myInnerSelectionChange = false;
        }
    }
    if (content != null) {
        //Adjust usage order
        myContentManager.addContent(content, 0);
    }
    myInnerSelectionChange = true;
    try {
        if (content != null) {
            updateContentWithInfo(content, info);
            myContentManager.setSelectedContent(content, requestFocus);
        }
        return info.initComponent(requestFocus);
    } finally {
        myInnerSelectionChange = false;
    }
}
Also used : Content(com.intellij.ui.content.Content) PreviewInfo(com.intellij.openapi.preview.PreviewInfo)

Aggregations

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