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));
}
}
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;
}
}
Aggregations