IJPL-160019 Fix restoring tree paths on workspace switch

This regression is caused by the fact that CachedTreePresentation
doesn't work well yet with trees that are already loaded.
In this particular case, though, it's not desirable to use
presentation caching because the cached presentation
may not match the actual tree at all.

So let's introduce an internal method to skip presentation caching
and use it there.

GitOrigin-RevId: 1d756971f87b4a2803d3e05b9ec41de7b7a76bb6
This commit is contained in:
Sergei Tachenov
2024-10-11 16:16:05 +03:00
committed by intellij-monorepo-bot
parent 4111cfc875
commit 06fa278008
2 changed files with 19 additions and 2 deletions

View File

@@ -96,6 +96,7 @@ public abstract class AbstractProjectViewPane implements UiCompatibleDataProvide
private final Map<String,TreeState> myReadTreeState = new HashMap<>();
private final AtomicBoolean myTreeStateRestored = new AtomicBoolean();
boolean myNonEmptyTreeStateRestored = false;
boolean myPersistingPresentationEnabled = true;
private String mySubId;
private static final @NonNls String ELEMENT_SUB_PANE = "subPane";
private static final @NonNls String ATTRIBUTE_SUB_ID = "subId";
@@ -576,6 +577,17 @@ public abstract class AbstractProjectViewPane implements UiCompatibleDataProvide
}
}
@ApiStatus.Internal
public void writeExternalWithoutPresentations(Element element) {
myPersistingPresentationEnabled = false;
try {
writeExternal(element);
}
finally {
myPersistingPresentationEnabled = true;
}
}
public void writeExternal(Element element) {
saveExpandedPaths();
for (Map.Entry<String, TreeState> entry : myReadTreeState.entrySet()) {
@@ -591,7 +603,8 @@ public abstract class AbstractProjectViewPane implements UiCompatibleDataProvide
}
protected @NotNull TreeState createTreeState(@NotNull JTree tree) {
return TreeState.createOn(tree, true, false, Registry.is("ide.project.view.persist.cached.presentation", true));
var persistPresentation = myPersistingPresentationEnabled && Registry.is("ide.project.view.persist.cached.presentation", true);
return TreeState.createOn(tree, true, false, persistPresentation);
}
protected void saveExpandedPaths() {

View File

@@ -33,7 +33,11 @@ final class ProjectViewContextProvider extends WorkingContextProvider {
public void saveContext(@NotNull Project project, @NotNull Element toElement) throws WriteExternalException {
for (AbstractProjectViewPane pane : AbstractProjectViewPane.EP.getExtensions(project)) {
Element paneElement = new Element(pane.getId());
pane.writeExternal(paneElement);
// When switching between branches, we don't want to persist presentations,
// as they likely won't be applicable to another branch.
// Besides, it causes glitches, as the tree is already loaded,
// and the persist/restore presentation mechanism assumes an initially empty tree.
pane.writeExternalWithoutPresentations(paneElement);
toElement.addContent(paneElement);
}
}