Search in sources :

Example 1 with TabbedContentImpl

use of com.intellij.ui.content.impl.TabbedContentImpl in project intellij-community by JetBrains.

the class ContentUtilEx method addTabbedContent.

public static void addTabbedContent(@NotNull ContentManager manager, @NotNull JComponent contentComponent, @NotNull String groupPrefix, @NotNull String tabName, boolean select, @Nullable Disposable childDisposable) {
    if (PropertiesComponent.getInstance().getBoolean(TabbedContent.SPLIT_PROPERTY_PREFIX + groupPrefix)) {
        final Content content = ContentFactory.SERVICE.getInstance().createContent(contentComponent, getFullName(groupPrefix, tabName), true);
        content.putUserData(Content.TABBED_CONTENT_KEY, Boolean.TRUE);
        content.putUserData(Content.TAB_GROUP_NAME_KEY, groupPrefix);
        for (Content c : manager.getContents()) {
            if (c.getComponent() == contentComponent) {
                if (select) {
                    manager.setSelectedContent(c);
                }
                return;
            }
        }
        addContent(manager, content, select);
        registerDisposable(content, childDisposable, contentComponent);
        return;
    }
    TabbedContent tabbedContent = findTabbedContent(manager, groupPrefix);
    if (tabbedContent == null) {
        final Disposable disposable = Disposer.newDisposable();
        tabbedContent = new TabbedContentImpl(contentComponent, tabName, true, groupPrefix);
        ContentsUtil.addOrReplaceContent(manager, tabbedContent, select);
        Disposer.register(tabbedContent, disposable);
    } else {
        for (Pair<String, JComponent> tab : new ArrayList<>(tabbedContent.getTabs())) {
            if (Comparing.equal(tab.second, contentComponent)) {
                tabbedContent.removeContent(tab.second);
            }
        }
        if (select) {
            manager.setSelectedContent(tabbedContent, true, true);
        }
        tabbedContent.addContent(contentComponent, tabName, true);
    }
    registerDisposable(tabbedContent, childDisposable, contentComponent);
}
Also used : Disposable(com.intellij.openapi.Disposable) TabbedContent(com.intellij.ui.content.TabbedContent) Content(com.intellij.ui.content.Content) TabbedContent(com.intellij.ui.content.TabbedContent) ArrayList(java.util.ArrayList) TabbedContentImpl(com.intellij.ui.content.impl.TabbedContentImpl)

Aggregations

Disposable (com.intellij.openapi.Disposable)1 Content (com.intellij.ui.content.Content)1 TabbedContent (com.intellij.ui.content.TabbedContent)1 TabbedContentImpl (com.intellij.ui.content.impl.TabbedContentImpl)1 ArrayList (java.util.ArrayList)1