use of com.intellij.openapi.wm.ex.ToolWindowManagerEx in project intellij-plugins by JetBrains.
the class MxmlPreviewToolWindowManager method initToolWindow.
private void initToolWindow() {
toolWindowForm = new MxmlPreviewToolWindowForm();
String toolWindowId = FlashUIDesignerBundle.message("mxml.preview.tool.window.title");
toolWindow = ToolWindowManager.getInstance(project).registerToolWindow(toolWindowId, false, ToolWindowAnchor.RIGHT, project, false);
toolWindow.setIcon(PlatformIcons.UI_FORM_ICON);
PropertiesComponent propertiesComponent = PropertiesComponent.getInstance(project);
toolWindowVisible = propertiesComponent.getBoolean(SETTINGS_TOOL_WINDOW_VISIBLE);
if (toolWindowVisible) {
toolWindow.show(null);
} else {
toolWindow.hide(null);
}
((ToolWindowManagerEx) ToolWindowManager.getInstance(project)).addToolWindowManagerListener(new ToolWindowManagerAdapter() {
@Override
public void stateChanged() {
if (project.isDisposed() || toolWindow == null || !toolWindow.isAvailable()) {
return;
}
final boolean currentVisible = toolWindow.isVisible();
if (currentVisible == toolWindowVisible) {
return;
}
toolWindowVisible = currentVisible;
PropertiesComponent propertiesComponent = PropertiesComponent.getInstance(project);
if (currentVisible) {
propertiesComponent.setValue(SETTINGS_TOOL_WINDOW_VISIBLE, true);
if (!lastPreviewChecked) {
lastPreviewChecked = true;
if (checkLastImage()) {
return;
}
}
render(true, false);
} else {
propertiesComponent.unsetValue(SETTINGS_TOOL_WINDOW_VISIBLE);
}
}
});
JPanel contentPanel = toolWindowForm.getContentPanel();
ContentManager contentManager = toolWindow.getContentManager();
Content content = contentManager.getFactory().createContent(contentPanel, null, false);
content.setCloseable(false);
content.setPreferredFocusableComponent(contentPanel);
contentManager.addContent(content);
contentManager.setSelectedContent(content, true);
MessageBusConnection connection = ApplicationManager.getApplication().getMessageBus().connect(project);
connection.subscribe(DesignerApplicationManager.MESSAGE_TOPIC, new DocumentRenderedListener() {
private boolean isApplicable(DocumentFactoryManager.DocumentInfo info) {
return toolWindowVisible && toolWindowForm.getFile() != null && info.equals(DocumentFactoryManager.getInstance().getNullableInfo(toolWindowForm.getFile()));
}
@Override
public void documentRendered(DocumentFactoryManager.DocumentInfo info) {
if (isApplicable(info) && !toolWindowForm.waitingForGetDocument) {
UIUtil.invokeLaterIfNeeded(() -> render(false, false));
}
}
@Override
public void errorOccurred() {
}
});
}
use of com.intellij.openapi.wm.ex.ToolWindowManagerEx in project android by JetBrains.
the class NlAbstractWindowManager method initToolWindow.
protected void initToolWindow(@NotNull final String id, @NotNull Icon icon) {
myToolWindow = ToolWindowManager.getInstance(myProject).registerToolWindow(id, false, getAnchor(), myProject, true);
myToolWindow.setIcon(icon);
myToolWindow.setAvailable(false, null);
myToolWindow.setAutoHide(false);
myPreviousWindowType = myToolWindow.getType();
myPreviousWindowAnchor = getEditorMode();
((ToolWindowManagerEx) ToolWindowManager.getInstance(myProject)).addToolWindowManagerListener(new ToolWindowManagerAdapter() {
@Override
public void stateChanged() {
if (myProject.isDisposed()) {
return;
}
final ToolWindow window = ToolWindowManager.getInstance(myProject).getToolWindow(id);
ToolWindowType newWindowType = window.getType();
ToolWindowAnchor newWindowAnchor = getEditorMode();
if (newWindowType != myPreviousWindowType || newWindowAnchor != myPreviousWindowAnchor) {
// TODO: Report the window docking state
NlUsageTrackerManager.getInstance(myDesignSurface).logAction(LayoutEditorEvent.LayoutEditorEventType.UNKNOWN_EVENT_TYPE);
myPreviousWindowType = newWindowType;
myPreviousWindowAnchor = newWindowAnchor;
}
}
}, myProject);
initGearActions();
}
Aggregations