From 14488bbd0aa8bf886d6ecd1b3aa31e89e55e0215 Mon Sep 17 00:00:00 2001 From: irengrig Date: Tue, 27 Mar 2012 19:04:47 +0400 Subject: [PATCH] vcs: keep tree state + list state between data reset only if special flag says that (example: in git log this component is reused but we shouldn't keep expansion/selection state) in commit dialog we should keep expansion/selection state between data reset --- .../vcs/changes/ui/ChangesBrowser.java | 4 +++ .../vcs/changes/ui/ChangesTreeList.java | 27 ++++++++++++------- .../changes/ui/CommitChangeListDialog.java | 1 + 3 files changed, 22 insertions(+), 10 deletions(-) diff --git a/platform/vcs-impl/src/com/intellij/openapi/vcs/changes/ui/ChangesBrowser.java b/platform/vcs-impl/src/com/intellij/openapi/vcs/changes/ui/ChangesBrowser.java index cb6c61738945..869ce5e21ee3 100644 --- a/platform/vcs-impl/src/com/intellij/openapi/vcs/changes/ui/ChangesBrowser.java +++ b/platform/vcs-impl/src/com/intellij/openapi/vcs/changes/ui/ChangesBrowser.java @@ -268,6 +268,10 @@ public class ChangesBrowser extends JPanel implements TypeSafeDataProvider { myViewer.setChangesToDisplay(getCurrentDisplayedChanges(), myToSelect); } + public void setAlwayExpandList(final boolean value) { + myViewer.setAlwaysExpandList(value); + } + private JComponent createToolbar() { DefaultActionGroup toolbarGroups = new DefaultActionGroup(); myToolBarGroup = new DefaultActionGroup(); diff --git a/platform/vcs-impl/src/com/intellij/openapi/vcs/changes/ui/ChangesTreeList.java b/platform/vcs-impl/src/com/intellij/openapi/vcs/changes/ui/ChangesTreeList.java index 0bc8382d0e4a..0e2a67525b70 100644 --- a/platform/vcs-impl/src/com/intellij/openapi/vcs/changes/ui/ChangesTreeList.java +++ b/platform/vcs-impl/src/com/intellij/openapi/vcs/changes/ui/ChangesTreeList.java @@ -75,6 +75,7 @@ public abstract class ChangesTreeList extends JPanel { private final Collection myIncludedChanges; private Runnable myDoubleClickHandler = EmptyRunnable.getInstance(); + private boolean myAlwaysExpandList; @NonNls private static final String TREE_CARD = "Tree"; @NonNls private static final String LIST_CARD = "List"; @@ -95,6 +96,7 @@ public abstract class ChangesTreeList extends JPanel { myInclusionListener = inclusionListener; myChangeDecorator = decorator; myIncludedChanges = new HashSet(initiallyIncluded); + myAlwaysExpandList = true; myCards = new CardLayout(); @@ -312,23 +314,24 @@ public abstract class ChangesTreeList extends JPanel { return sortedChanges.get(index); } }); - final TIntArrayList indices = new TIntArrayList(); - for (int i = 0; i < sortedChanges.size(); i++) { - T t = sortedChanges.get(i); - if (wasSelected.contains(t)) { - indices.add(i); - } - } - myList.setSelectedIndices(indices.toNativeArray()); final DefaultTreeModel model = buildTreeModel(changes, myChangeDecorator); TreeState state = null; - if (! wasEmpty) { + if (! myAlwaysExpandList && ! wasEmpty) { state = TreeState.createOn(myTree, (DefaultMutableTreeNode) myTree.getModel().getRoot()); } myTree.setModel(model); - if (! wasEmpty) { + if (! myAlwaysExpandList && ! wasEmpty) { state.applyTo(myTree, (DefaultMutableTreeNode) myTree.getModel().getRoot()); + + final TIntArrayList indices = new TIntArrayList(); + for (int i = 0; i < sortedChanges.size(); i++) { + T t = sortedChanges.get(i); + if (wasSelected.contains(t)) { + indices.add(i); + } + } + myList.setSelectedIndices(indices.toNativeArray()); return; } @@ -860,4 +863,8 @@ public abstract class ChangesTreeList extends JPanel { public void enableSelection(final boolean value) { myTree.setEnabled(value); } + + public void setAlwaysExpandList(boolean alwaysExpandList) { + myAlwaysExpandList = alwaysExpandList; + } } diff --git a/platform/vcs-impl/src/com/intellij/openapi/vcs/changes/ui/CommitChangeListDialog.java b/platform/vcs-impl/src/com/intellij/openapi/vcs/changes/ui/CommitChangeListDialog.java index 9089fe523273..e0fce56a2897 100644 --- a/platform/vcs-impl/src/com/intellij/openapi/vcs/changes/ui/CommitChangeListDialog.java +++ b/platform/vcs-impl/src/com/intellij/openapi/vcs/changes/ui/CommitChangeListDialog.java @@ -270,6 +270,7 @@ public class CommitChangeListDialog extends DialogWrapper implements CheckinProj } }; myBrowser = browser; + myBrowser.setAlwayExpandList(false); myBrowserExtender = browser.getExtender(); } myDiffDetails.setParent(myBrowser);