package com.huangzj.protoplugin.memo;

import com.intellij.openapi.project.Project;
import com.intellij.openapi.wm.ToolWindow;
import com.intellij.openapi.wm.ToolWindowFactory;
import com.intellij.openapi.wm.ex.ToolWindowEx;
import com.intellij.ui.content.ContentFactory;
import org.jetbrains.annotations.NotNull;

public final class MemoToolWindowFactory implements ToolWindowFactory {

    /** 与 {@code plugin.xml} 中 {@code <toolWindow id>} 一致 */
    public static final String TOOL_WINDOW_ID = "MyCustomMemo";

    /** 侧边栏与 View → Tool Windows 中显示的名称 */
    public static final String TOOL_WINDOW_STRIPE_TITLE = "我的自定义备忘录";

    @Override
    public void init(@NotNull ToolWindow toolWindow) {
        if (toolWindow instanceof ToolWindowEx ex) {
            ex.setStripeTitle(TOOL_WINDOW_STRIPE_TITLE);
        }
    }

    @Override
    public void createToolWindowContent(@NotNull Project project, @NotNull ToolWindow toolWindow) {
        MemoPanel panel = new MemoPanel(project);
        var content =
                ContentFactory.getInstance().createContent(panel, TOOL_WINDOW_STRIPE_TITLE, false);
        toolWindow.getContentManager().addContent(content);
    }
}
