Dynamic load/unload for lang.psiStructureViewFactory

GitOrigin-RevId: 012f2274dac5028420e96d7b76887e403c5ce1f9
This commit is contained in:
Dmitry Jemerov
2019-10-01 18:14:31 +00:00
committed by intellij-monorepo-bot
parent f5d90f53c8
commit ac08f78c70
6 changed files with 55 additions and 57 deletions
@@ -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();
@@ -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<KeyedLazyInstance<PsiStructureViewFactory>> EP_NAME = ExtensionPointName.create("com.intellij.lang.psiStructureViewFactory");
@Nullable
StructureViewBuilder getStructureViewBuilder(@NotNull PsiFile psiFile);
@@ -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<KeyedLazyInstance<PsiStructureViewFactory>>() {
@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();
@@ -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;
@@ -204,7 +204,8 @@
<extensionPoint name="customFoldingProvider"
interface="com.intellij.lang.folding.CustomFoldingProvider"/>
<extensionPoint name="lang.psiStructureViewFactory"
beanClass="com.intellij.lang.LanguageExtensionPoint">
beanClass="com.intellij.lang.LanguageExtensionPoint"
dynamic="true">
<with attribute="implementationClass" implements="com.intellij.lang.PsiStructureViewFactory"/>
</extensionPoint>
@@ -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;