diff --git a/platform/editor-ui-api/src/com/intellij/ide/structureView/StructureView.java b/platform/editor-ui-api/src/com/intellij/ide/structureView/StructureView.java index 5d237e3b099e..c4c25bf742a0 100644 --- a/platform/editor-ui-api/src/com/intellij/ide/structureView/StructureView.java +++ b/platform/editor-ui-api/src/com/intellij/ide/structureView/StructureView.java @@ -1,22 +1,9 @@ -/* - * Copyright 2000-2015 JetBrains s.r.o. - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ +// Copyright 2000-2019 JetBrains s.r.o. Use of this source code is governed by the Apache 2.0 license that can be found in the LICENSE file. package com.intellij.ide.structureView; import com.intellij.openapi.Disposable; import com.intellij.openapi.fileEditor.FileEditor; +import org.jetbrains.annotations.ApiStatus; import org.jetbrains.annotations.NotNull; import javax.swing.*; @@ -74,6 +61,10 @@ public interface StructureView extends Disposable { */ void storeState(); + @ApiStatus.Internal + default void disableStoreState() { + } + @NotNull StructureViewModel getTreeModel(); diff --git a/platform/editor-ui-api/src/com/intellij/lang/PsiStructureViewFactory.java b/platform/editor-ui-api/src/com/intellij/lang/PsiStructureViewFactory.java index b20f7ecdab54..4eb27ec4c0ea 100644 --- a/platform/editor-ui-api/src/com/intellij/lang/PsiStructureViewFactory.java +++ b/platform/editor-ui-api/src/com/intellij/lang/PsiStructureViewFactory.java @@ -1,18 +1,4 @@ -/* - * Copyright 2000-2015 JetBrains s.r.o. - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ +// Copyright 2000-2019 JetBrains s.r.o. Use of this source code is governed by the Apache 2.0 license that can be found in the LICENSE file. /* * @author max @@ -20,7 +6,9 @@ package com.intellij.lang; import com.intellij.ide.structureView.StructureViewBuilder; +import com.intellij.openapi.extensions.ExtensionPointName; import com.intellij.psi.PsiFile; +import com.intellij.util.KeyedLazyInstance; import org.jetbrains.annotations.NotNull; import org.jetbrains.annotations.Nullable; @@ -30,7 +18,7 @@ import org.jetbrains.annotations.Nullable; */ @FunctionalInterface public interface PsiStructureViewFactory { - String EP_NAME = "com.intellij.lang.psiStructureViewFactory"; + ExtensionPointName> EP_NAME = ExtensionPointName.create("com.intellij.lang.psiStructureViewFactory"); @Nullable StructureViewBuilder getStructureViewBuilder(@NotNull PsiFile psiFile); diff --git a/platform/lang-impl/src/com/intellij/ide/impl/StructureViewWrapperImpl.java b/platform/lang-impl/src/com/intellij/ide/impl/StructureViewWrapperImpl.java index a7a068a1935d..b7c22882505e 100644 --- a/platform/lang-impl/src/com/intellij/ide/impl/StructureViewWrapperImpl.java +++ b/platform/lang-impl/src/com/intellij/ide/impl/StructureViewWrapperImpl.java @@ -9,10 +9,12 @@ import com.intellij.ide.projectView.impl.ProjectRootsUtil; import com.intellij.ide.structureView.*; import com.intellij.ide.structureView.impl.StructureViewComposite; import com.intellij.ide.structureView.newStructureView.StructureViewComponent; +import com.intellij.lang.PsiStructureViewFactory; import com.intellij.openapi.Disposable; import com.intellij.openapi.actionSystem.*; import com.intellij.openapi.application.ModalityState; import com.intellij.openapi.diagnostic.Logger; +import com.intellij.openapi.extensions.ExtensionPointAdapter; import com.intellij.openapi.fileEditor.FileEditor; import com.intellij.openapi.fileEditor.FileEditorManager; import com.intellij.openapi.fileEditor.FileEditorProvider; @@ -41,6 +43,7 @@ import com.intellij.psi.PsiElement; import com.intellij.ui.components.JBPanelWithEmptyText; import com.intellij.ui.content.*; import com.intellij.util.BitUtil; +import com.intellij.util.KeyedLazyInstance; import com.intellij.util.ui.TimerUtil; import com.intellij.util.ui.UIUtil; import com.intellij.util.ui.update.MergingUpdateQueue; @@ -151,6 +154,17 @@ public class StructureViewWrapperImpl implements StructureViewWrapper, Disposabl } }); Disposer.register(myToolWindow.getContentManager(), this); + + PsiStructureViewFactory.EP_NAME.addExtensionPointListener(new ExtensionPointAdapter>() { + @Override + public void extensionListChanged() { + StructureViewComponent.clearStructureViewState(myProject); + if (myStructureView != null) { + myStructureView.disableStoreState(); + } + rebuild(); + } + }, this); } private void checkUpdate() { @@ -322,7 +336,6 @@ public class StructureViewWrapperImpl implements StructureViewWrapper, Disposabl myStructureView = structureViewBuilder.createStructureView(editor, myProject); myFileEditor = editor; Disposer.register(this, myStructureView); - updateHeaderActions(myStructureView); if (myStructureView instanceof StructureView.Scrollable) { ((StructureView.Scrollable)myStructureView).setReferenceSizeWhileInitializing(referenceSize); @@ -348,6 +361,8 @@ public class StructureViewWrapperImpl implements StructureViewWrapper, Disposabl } } + updateHeaderActions(myStructureView); + if (myModuleStructureComponent == null && myStructureView == null) { JBPanelWithEmptyText panel = new JBPanelWithEmptyText() { @Override @@ -380,7 +395,7 @@ public class StructureViewWrapperImpl implements StructureViewWrapper, Disposabl } } - private void updateHeaderActions(StructureView structureView) { + private void updateHeaderActions(@Nullable StructureView structureView) { AnAction[] titleActions = AnAction.EMPTY_ARRAY; if (structureView instanceof StructureViewComponent) { JTree tree = ((StructureViewComponent)structureView).getTree(); diff --git a/platform/lang-impl/src/com/intellij/ide/structureView/newStructureView/StructureViewComponent.java b/platform/lang-impl/src/com/intellij/ide/structureView/newStructureView/StructureViewComponent.java index 3cb9915f14c0..1283e39e0655 100644 --- a/platform/lang-impl/src/com/intellij/ide/structureView/newStructureView/StructureViewComponent.java +++ b/platform/lang-impl/src/com/intellij/ide/structureView/newStructureView/StructureViewComponent.java @@ -1,8 +1,7 @@ -// Copyright 2000-2018 JetBrains s.r.o. Use of this source code is governed by the Apache 2.0 license that can be found in the LICENSE file. +// Copyright 2000-2019 JetBrains s.r.o. Use of this source code is governed by the Apache 2.0 license that can be found in the LICENSE file. package com.intellij.ide.structureView.newStructureView; -import com.intellij.concurrency.SensitiveProgressWrapper; import com.intellij.ide.CopyPasteDelegator; import com.intellij.ide.DataManager; import com.intellij.ide.PsiCopyPasteManager; @@ -25,13 +24,13 @@ import com.intellij.openapi.diagnostic.Logger; import com.intellij.openapi.fileEditor.FileEditor; import com.intellij.openapi.fileEditor.FileEditorManager; import com.intellij.openapi.keymap.impl.IdeMouseEventDispatcher; -import com.intellij.openapi.progress.ProgressIndicator; -import com.intellij.openapi.progress.util.ProgressIndicatorBase; -import com.intellij.openapi.progress.util.ProgressIndicatorUtils; import com.intellij.openapi.project.IndexNotReadyException; import com.intellij.openapi.project.Project; import com.intellij.openapi.ui.SimpleToolWindowPanel; -import com.intellij.openapi.util.*; +import com.intellij.openapi.util.Comparing; +import com.intellij.openapi.util.Disposer; +import com.intellij.openapi.util.Key; +import com.intellij.openapi.util.ModificationTracker; import com.intellij.openapi.util.registry.Registry; import com.intellij.openapi.util.registry.RegistryValue; import com.intellij.openapi.wm.IdeFocusManager; @@ -76,7 +75,6 @@ import java.util.List; import java.util.concurrent.TimeUnit; import java.util.concurrent.atomic.AtomicBoolean; import java.util.concurrent.atomic.AtomicInteger; -import java.util.function.Supplier; public class StructureViewComponent extends SimpleToolWindowPanel implements TreeActionsOwner, DataProvider, StructureView.Scrollable { private static final Logger LOG = Logger.getInstance("#com.intellij.ide.structureView.newStructureView.StructureViewComponent"); @@ -102,6 +100,7 @@ public class StructureViewComponent extends SimpleToolWindowPanel implements Tre private boolean myAutoscrollFeedback; private volatile boolean myDisposed; + private boolean myStoreStateDisabled; private final Alarm myAutoscrollAlarm = new Alarm(this); @@ -308,7 +307,7 @@ public class StructureViewComponent extends SimpleToolWindowPanel implements Tre @Override public void storeState() { - if (isDisposed() || !myProject.isOpen()) return; + if (isDisposed() || !myProject.isOpen() || myStoreStateDisabled) return; Object root = myTree.getModel().getRoot(); if (root == null) return; TreeState state = TreeState.createOn(myTree, new TreePath(root)); @@ -318,6 +317,11 @@ public class StructureViewComponent extends SimpleToolWindowPanel implements Tre UIUtil.putClientProperty(myTree, STRUCTURE_VIEW_STATE_RESTORED_KEY, null); } + @Override + public void disableStoreState() { + myStoreStateDisabled = true; + } + @Override public void restoreState() { TreeState state = myFileEditor == null ? null : myFileEditor.getUserData(STRUCTURE_VIEW_STATE_KEY); @@ -568,6 +572,12 @@ public class StructureViewComponent extends SimpleToolWindowPanel implements Tre return !myProject.isDisposed() && StructureViewFactoryEx.getInstanceEx(myProject).isActionActive(name); } + public static void clearStructureViewState(Project project) { + for (FileEditor editor : FileEditorManager.getInstance(project).getAllEditors()) { + editor.putUserData(STRUCTURE_VIEW_STATE_KEY, null); + } + } + private final class MyAutoScrollToSourceHandler extends AutoScrollToSourceHandler { private boolean myShouldAutoScroll = true; diff --git a/platform/platform-resources/src/META-INF/LangExtensionPoints.xml b/platform/platform-resources/src/META-INF/LangExtensionPoints.xml index 2fd612f3f103..4873c29df5b0 100644 --- a/platform/platform-resources/src/META-INF/LangExtensionPoints.xml +++ b/platform/platform-resources/src/META-INF/LangExtensionPoints.xml @@ -204,7 +204,8 @@ + beanClass="com.intellij.lang.LanguageExtensionPoint" + dynamic="true"> diff --git a/platform/structure-view-impl/src/com/intellij/ide/structureView/impl/StructureViewComposite.java b/platform/structure-view-impl/src/com/intellij/ide/structureView/impl/StructureViewComposite.java index 8dd8bfb570fa..939b96f86c47 100644 --- a/platform/structure-view-impl/src/com/intellij/ide/structureView/impl/StructureViewComposite.java +++ b/platform/structure-view-impl/src/com/intellij/ide/structureView/impl/StructureViewComposite.java @@ -1,18 +1,4 @@ -/* - * Copyright 2000-2014 JetBrains s.r.o. - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ +// Copyright 2000-2019 JetBrains s.r.o. Use of this source code is governed by the Apache 2.0 license that can be found in the LICENSE file. package com.intellij.ide.structureView.impl; @@ -117,6 +103,13 @@ public class StructureViewComposite implements StructureView { } } + @Override + public void disableStoreState() { + for (StructureViewDescriptor descriptor : myStructureViews) { + descriptor.structureView.disableStoreState(); + } + } + @NotNull public StructureViewDescriptor[] getStructureViews() { return myStructureViews;