import com.intellij.openapi.Disposable;
import com.intellij.openapi.actionSystem.*;
import com.intellij.openapi.project.Project;
-import com.intellij.openapi.util.ActionCallback;
-import com.intellij.openapi.util.ActiveRunnable;
-import com.intellij.openapi.util.Disposer;
-import com.intellij.openapi.util.Ref;
+import com.intellij.openapi.util.*;
+import com.intellij.openapi.util.text.StringUtil;
import com.intellij.openapi.wm.IdeFocusManager;
import com.intellij.openapi.wm.IdeFrame;
import com.intellij.openapi.wm.ToolWindow;
import com.intellij.ui.tabs.JBTabs;
import com.intellij.ui.tabs.TabInfo;
import com.intellij.ui.tabs.TabsListener;
+import com.intellij.util.NotNullFunction;
import com.intellij.util.containers.ContainerUtil;
import com.intellij.util.ui.AbstractLayoutManager;
import com.intellij.util.ui.UIUtil;
}
private void storeDefaultIndices(Content[] contents) {
+ int i = 0;
for (Content content : contents) {
content.putUserData(RunnerLayout.DEFAULT_INDEX, getStateFor(content).getTab().getDefaultIndex());
+ //content.putUserData(CONTENT_NUMBER, i++);
}
}
getStateFor(content).assignTab(getTabFor(getSelectedGrid()));
getStateFor(content).setPlaceInGrid(myLayoutSettings.getDefaultGridPlace(content));
} else if (contents.size() == 1 && !wasRestoring) {
+ getStateFor(content).assignTab(null);
getStateFor(content).setPlaceInGrid(myLayoutSettings.getDefaultGridPlace(content));
}
getStateFor(content).setWindow(myWindow);
grid.processAddToUi(false);
}
- if (myManager.getComponent().isShowing()) {
+ if (myManager.getComponent().isShowing() && !isStateBeingRestored()) {
grid.restoreLastUiState();
}
if (myCurrentOver != null || myOriginal != null) {
Integer forcedDropIndex = content.getUserData(RunnerLayout.DROP_INDEX);
final int index = myTabs.getDropInfoIndex() + (myOriginal != null ? myOriginal.getTabOffsetFor(this) : 0);
+ final int dropIndex = forcedDropIndex != null ? forcedDropIndex : index;
+ if (forcedDropIndex == null) {
+ moveFollowingTabs(dropIndex);
+ }
+ final int defaultIndex = content.getUserData(RunnerLayout.DEFAULT_INDEX);
final TabImpl tab = myLayoutSettings.getOrCreateTab(forcedDropIndex != null ? forcedDropIndex : -1);
- final Integer defaultIndex = content.getUserData(RunnerLayout.DEFAULT_INDEX);
- tab.setDefaultIndex(defaultIndex != null ? defaultIndex : -1);
- tab.setIndex(forcedDropIndex != null ? forcedDropIndex : index);
+ tab.setDefaultIndex(defaultIndex);
+ tab.setIndex(dropIndex);
getStateFor(content).assignTab(tab);
+ content.putUserData(RunnerLayout.DROP_INDEX, null);
+ content.putUserData(RunnerLayout.DEFAULT_INDEX, null);
}
TabInfo tab = new TabInfo(grid).setObject(getStateFor(content).getTab()).setText("Tab");
return grid;
}
+ private void moveFollowingTabs(int index) {
+ if (myOriginal != null) {
+ myOriginal.moveFollowingTabs(index);
+ return;
+ }
+ moveFollowingTabs(index, myTabs);
+ for (RunnerContentUi child : myChildren) {
+ moveFollowingTabs(index, child.myTabs);
+ }
+ }
+
+ private static void moveFollowingTabs(int index, final JBRunnerTabs tabs) {
+ for (TabInfo info : tabs.getTabs()) {
+ final TabImpl tab = getTabFor(info);
+ final int tabIndex = tab != null ? tab.getIndex() : -1;
+ if (tabIndex >= index) {
+ tab.setIndex(tabIndex + 1);
+ }
+ }
+ }
+
private int getTabOffsetFor(RunnerContentUi ui) {
int offset = myTabs.getTabCount();
for (RunnerContentUi child : myChildren) {
return false;
}
- String title = t.getDisplayName();
Icon icon = t.getIcon();
GridImpl grid = getGridFor(tab);
boolean hasToolbarContent = grid.updateGridUI();
List<Content> contents = grid.getContents();
+ String title = contents.size() > 1 ? t.getDisplayName() : null;
if (title == null) {
- title = "";
- Iterator<Content> all = contents.iterator();
- while (all.hasNext()) {
- Content each = all.next();
- title += each.getTabName();
- if (all.hasNext()) {
- title += " | ";
- }
+ final String name = myLayoutSettings.getDefaultDisplayName(t.getDefaultIndex());
+ if (name != null && contents.size() > 1) {
+ title = name;
+ } else {
+ title = StringUtil.join(contents, new NotNullFunction<Content, String>() {
+ @NotNull
+ @Override
+ public String fun(Content dom) {
+ return dom.getTabName();
+ }
+ }, " | ");
}
}
tab.setDragOutDelegate(myTabs.getTabs().size() > 1 || !isOriginal() ? myDragOutDelegate : null);
Tab gridTab = grid.getTab();
- tab.setText(title).setIcon(gridTab != null && gridTab.isDefault() ? null : icon);
+ tab.setText(title).setIcon(gridTab != null && gridTab.isDefault() && contents.size() > 1 ? null : icon);
return hasToolbarContent;
}
}
public void beforeDispose() {
- if (myComponent.getRootPane() != null) {
- saveUiState();
- }
if (myOriginal != null) {
myDisposing = true;
fireContentClosed(null);