mirror of
https://gitflic.ru/project/openide/openide.git
synced 2026-09-27 10:03:11 +07:00
[tabs] do not dispose tabs while spliting them
This commit is contained in:
@@ -16,6 +16,7 @@
|
||||
package com.intellij.ui.content.impl;
|
||||
|
||||
import com.intellij.ide.util.PropertiesComponent;
|
||||
import com.intellij.openapi.util.Disposer;
|
||||
import com.intellij.openapi.util.Pair;
|
||||
import com.intellij.ui.content.ContentManager;
|
||||
import com.intellij.ui.content.TabbedContent;
|
||||
@@ -76,7 +77,7 @@ public class TabbedContentImpl extends ContentImpl implements TabbedContent {
|
||||
int index = myTabs.indexOf(toRemove);
|
||||
if (index != -1) {
|
||||
myTabs.remove(index);
|
||||
index = index > 0 ? index-1 : index;
|
||||
index = index > 0 ? index - 1 : index;
|
||||
if (index < myTabs.size()) {
|
||||
selectContent(index);
|
||||
}
|
||||
@@ -144,7 +145,7 @@ public class TabbedContentImpl extends ContentImpl implements TabbedContent {
|
||||
int selectedTab = ContentUtilEx.getSelectedTab(this);
|
||||
ContentManager manager = getManager();
|
||||
String prefix = getTitlePrefix();
|
||||
manager.removeContent(this, true);
|
||||
manager.removeContent(this, false);
|
||||
PropertiesComponent.getInstance().setValue(SPLIT_PROPERTY_PREFIX + prefix, Boolean.TRUE.toString());
|
||||
for (int i = 0; i < copy.size(); i++) {
|
||||
final boolean select = i == selectedTab;
|
||||
@@ -152,6 +153,7 @@ public class TabbedContentImpl extends ContentImpl implements TabbedContent {
|
||||
final String tabName = copy.get(i).first;
|
||||
ContentUtilEx.addTabbedContent(manager, component, prefix, tabName, select);
|
||||
}
|
||||
Disposer.dispose(this);
|
||||
}
|
||||
|
||||
@Override
|
||||
|
||||
@@ -17,10 +17,7 @@ package com.intellij.util;
|
||||
|
||||
import com.intellij.ide.util.PropertiesComponent;
|
||||
import com.intellij.openapi.Disposable;
|
||||
import com.intellij.openapi.util.Comparing;
|
||||
import com.intellij.openapi.util.Condition;
|
||||
import com.intellij.openapi.util.Disposer;
|
||||
import com.intellij.openapi.util.Pair;
|
||||
import com.intellij.openapi.util.*;
|
||||
import com.intellij.ui.content.Content;
|
||||
import com.intellij.ui.content.ContentFactory;
|
||||
import com.intellij.ui.content.ContentManager;
|
||||
@@ -37,6 +34,8 @@ import java.util.List;
|
||||
* @author Konstantin Bulenkov
|
||||
*/
|
||||
public class ContentUtilEx extends ContentsUtil {
|
||||
public static final String DISPOSABLE_KEY = "TabContentDisposable";
|
||||
|
||||
public static void addTabbedContent(ContentManager manager, JComponent contentComponent, String groupPrefix, String tabName, boolean select) {
|
||||
addTabbedContent(manager, contentComponent, groupPrefix, tabName, select, null);
|
||||
}
|
||||
@@ -56,6 +55,9 @@ public class ContentUtilEx extends ContentsUtil {
|
||||
}
|
||||
}
|
||||
addContent(manager, content, select);
|
||||
|
||||
registerDisposable(content, childDisposable, contentComponent);
|
||||
|
||||
return;
|
||||
}
|
||||
|
||||
@@ -79,8 +81,23 @@ public class ContentUtilEx extends ContentsUtil {
|
||||
tabbedContent.addContent(contentComponent, tabName, true);
|
||||
}
|
||||
|
||||
registerDisposable(tabbedContent, childDisposable, contentComponent);
|
||||
}
|
||||
|
||||
private static void registerDisposable(@NotNull Content content,
|
||||
@Nullable Disposable childDisposable,
|
||||
@NotNull JComponent contentComponent) {
|
||||
if (childDisposable != null) {
|
||||
Disposer.register(tabbedContent, childDisposable);
|
||||
Disposer.register(content, childDisposable);
|
||||
assert contentComponent.getClientProperty(DISPOSABLE_KEY) == null;
|
||||
contentComponent.putClientProperty(DISPOSABLE_KEY, childDisposable);
|
||||
Disposer.register(childDisposable, () -> contentComponent.putClientProperty(DISPOSABLE_KEY, null));
|
||||
}
|
||||
else {
|
||||
Object disposableByKey = contentComponent.getClientProperty(DISPOSABLE_KEY);
|
||||
if (disposableByKey != null && disposableByKey instanceof Disposable) {
|
||||
Disposer.register(content, (Disposable)disposableByKey);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -154,7 +171,7 @@ public class ContentUtilEx extends ContentsUtil {
|
||||
public static int getSelectedTab(@NotNull TabbedContent content) {
|
||||
final JComponent current = content.getComponent();
|
||||
int index = 0;
|
||||
for (Pair<String,JComponent> tab : content.getTabs()) {
|
||||
for (Pair<String, JComponent> tab : content.getTabs()) {
|
||||
if (tab.second == current) {
|
||||
return index;
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user