fixed persisting after tabs reordering

This commit is contained in:
Dennis Ushakov
2012-01-26 22:10:49 +04:00
parent 603ef5529d
commit c28d5fc133
6 changed files with 47 additions and 27 deletions
@@ -22,6 +22,7 @@ public interface Tab {
void setDetached(final PlaceInGrid placeInGrid, final boolean detached);
int getIndex();
int getDefaultIndex();
boolean isDetached(final PlaceInGrid placeInGrid);
}
@@ -21,6 +21,7 @@ import javax.swing.*;
abstract class AbstractTab {
int myIndex;
int myDefaultIndex = -1;
String myDisplayName;
Icon myIcon;
@@ -38,6 +39,7 @@ abstract class AbstractTab {
void copyFrom(final AbstractTab from) {
myIndex = from.myIndex;
myDefaultIndex = from.myDefaultIndex;
myDisplayName = from.myDisplayName;
myIcon = from.myIcon;
@@ -307,7 +307,7 @@ public class GridCellImpl implements GridCell {
if (tab != null) {
tab.setDetached(myPlaceInGrid, false);
}
_detach(window).notifyWhenDone(result);
myContext.detachTo(window, this).notifyWhenDone(result);
} else {
result.setDone();
}
@@ -392,11 +392,6 @@ public class GridCellImpl implements GridCell {
}
}
private ActionCallback _detach(final int window) {
myContext.saveUiState();
return myContext.detachTo(window, this);
}
@Nullable
public Point getLocation() {
return DimensionService.getInstance().getLocation(getDimensionKey(), myContext.getProject());
@@ -132,6 +132,7 @@ public class RunnerContentUi implements ContentUI, Disposable, CellTransform.Fac
}
});
private int myWindow;
private boolean myDisposing;
public RunnerContentUi(Project project,
RunnerLayoutUi ui,
@@ -360,6 +361,10 @@ public class RunnerContentUi implements ContentUI, Disposable, CellTransform.Fac
}
final GridCellImpl gridCell = (GridCellImpl)cell;
final Content[] contents = gridCell.getContents();
storeDefaultIndices(contents);
for (Content content : contents) {
content.putUserData(RunnerLayout.DROP_INDEX, getStateFor(content).getTab().getIndex());
}
Dimension size = gridCell.getSize();
if (size == null) {
size = new Dimension(200, 200);
@@ -375,6 +380,12 @@ public class RunnerContentUi implements ContentUI, Disposable, CellTransform.Fac
return new ActionCallback.Done();
}
private void storeDefaultIndices(Content[] contents) {
for (Content content : contents) {
content.putUserData(RunnerLayout.DEFAULT_INDEX, getStateFor(content).getTab().getDefaultIndex());
}
}
@Override
public RelativeRectangle getAcceptArea() {
return new RelativeRectangle(myTabs.getComponent());
@@ -461,7 +472,7 @@ public class RunnerContentUi implements ContentUI, Disposable, CellTransform.Fac
@Override
public boolean isEmpty() {
return myTabs.isEmptyVisible();
return myTabs.isEmptyVisible() || myDisposing;
}
@Override
@@ -518,7 +529,7 @@ public class RunnerContentUi implements ContentUI, Disposable, CellTransform.Fac
@Override
public boolean isDisposeWhenEmpty() {
return true;
return myOriginal != null;
}
public boolean isCycleRoot() {
@@ -603,15 +614,14 @@ public class RunnerContentUi implements ContentUI, Disposable, CellTransform.Fac
grid = new GridImpl(this, mySessionName);
grid.setBorder(new EmptyBorder(1, 0, 0, 0));
if (myCurrentOver != null) {
final int index = ((JBRunnerTabs)myCurrentOver).getDropInfoIndex() + (myOriginal != null ? myOriginal.getTabOffsetFor(this) : 0);
for (TabInfo info : myTabs.getTabs()) {
final TabImpl tab = getTabFor(info);
if (tab != null && tab.getIndex() >= index) {
tab.setIndex(tab.getIndex() + 1);
}
}
getStateFor(content).assignTab(myLayoutSettings.getOrCreateTab(index));
if (myCurrentOver != null || myOriginal != null) {
Integer forcedDropIndex = content.getUserData(RunnerLayout.DROP_INDEX);
final int index = myTabs.getDropInfoIndex() + (myOriginal != null ? myOriginal.getTabOffsetFor(this) : 0);
final TabImpl tab = myLayoutSettings.getOrCreateTab(-1);
final Integer defaultIndex = content.getUserData(RunnerLayout.DEFAULT_INDEX);
tab.setDefaultIndex(defaultIndex != null ? defaultIndex : -1);
tab.setIndex(forcedDropIndex != null ? forcedDropIndex : index);
getStateFor(content).assignTab(tab);
}
TabInfo tab = new TabInfo(grid).setObject(getStateFor(content).getTab()).setText("Tab");
@@ -816,9 +826,9 @@ public class RunnerContentUi implements ContentUI, Disposable, CellTransform.Fac
doSaveUiState();
}
private int updateTabsIndices(final JBRunnerTabs tabs, int offset) {
private static int updateTabsIndices(final JBRunnerTabs tabs, int offset) {
for (TabInfo each : tabs.getTabs()) {
final int index = myTabs.getIndexOf(each);
final int index = tabs.getIndexOf(each);
final TabImpl tab = getTabFor(each);
if (tab != null) tab.setIndex(index + offset);
}
@@ -915,7 +925,8 @@ public class RunnerContentUi implements ContentUI, Disposable, CellTransform.Fac
saveUiState();
}
if (myOriginal != null) {
myManager.removeAllContents(true);
myDisposing = true;
fireContentClosed(null);
}
}
@@ -1465,6 +1476,8 @@ public class RunnerContentUi implements ContentUI, Disposable, CellTransform.Fac
final Content[] data = CONTENT_KEY.getData((DataProvider)component);
final List<Content> contents = Arrays.asList(data);
storeDefaultIndices(data);
final Dimension size = info.getComponent().getSize();
final Image image = myTabs.getComponentImage(info);
if (component instanceof Grid) {
@@ -20,6 +20,7 @@ import com.intellij.execution.ui.layout.LayoutAttractionPolicy;
import com.intellij.execution.ui.layout.PlaceInGrid;
import com.intellij.execution.ui.layout.Tab;
import com.intellij.openapi.util.Comparing;
import com.intellij.openapi.util.Key;
import com.intellij.openapi.util.Pair;
import com.intellij.openapi.util.text.StringUtil;
import com.intellij.ui.content.Content;
@@ -33,7 +34,8 @@ import javax.swing.*;
import java.util.*;
public class RunnerLayout {
public static final Key<Integer> DEFAULT_INDEX = Key.create("RunnerLayoutDefaultIndex");
public static final Key<Integer> DROP_INDEX = Key.create("RunnerLayoutDropIndex");
private final String myID;
protected Map<String, ViewImpl> myViews = new HashMap<String, ViewImpl>();
@@ -64,10 +66,6 @@ public class RunnerLayout {
return tab;
}
public TabImpl getDefaultTab() {
return getOrCreateTab(0);
}
private TabImpl createNewTab(final int index) {
final TabImpl tab;
@@ -153,7 +151,9 @@ public class RunnerLayout {
}
for (TabImpl eachTab : myTabs) {
eachTab.write(parentNode);
if (isUsed(eachTab)) {
eachTab.write(parentNode);
}
}
parentNode.addContent(XmlSerializer.serialize(myGeneral));
@@ -166,7 +166,7 @@ public class RunnerLayout {
myViews.clear();
for (TabImpl each : myTabs) {
final TabImpl.Default defaultTab = getOrCreateDefaultTab(each.getIndex());
final TabImpl.Default defaultTab = getOrCreateDefaultTab(each.getDefaultIndex());
each.copyFrom(defaultTab);
}
}
@@ -40,6 +40,10 @@ public class TabImpl extends AbstractTab implements Tab {
return myIndex;
}
public int getDefaultIndex() {
return myDefaultIndex >= 0 ? myDefaultIndex : myIndex;
}
public String getDisplayName() {
return myDisplayName;
}
@@ -52,6 +56,10 @@ public class TabImpl extends AbstractTab implements Tab {
myIndex = index;
}
public void setDefaultIndex(final int index) {
myDefaultIndex = index;
}
public void setDisplayName(final String displayName) {
myDisplayName = displayName;
}
@@ -161,6 +169,7 @@ public class TabImpl extends AbstractTab implements Tab {
public Default(final int index, final String displayName, final Icon icon) {
myIndex = index;
myDefaultIndex = index;
myDisplayName = displayName;
myIcon = icon;
}