Skip to content

Commit

Permalink
[dynamic plugins] required plugin should not be disableable #IDEA-246104
Browse files Browse the repository at this point in the history
GitOrigin-RevId: 97182cadb411e3fbe56acf0e882810e88c97cb8a
  • Loading branch information
adkozlov authored and intellij-monorepo-bot committed Oct 20, 2020
1 parent d3bdfe2 commit 8377287
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 1 deletion.
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
// Copyright 2000-2020 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.plugins;

import com.intellij.externalDependencies.DependencyOnPlugin;
import com.intellij.externalDependencies.ExternalDependenciesManager;
import com.intellij.ide.IdeBundle;
import com.intellij.openapi.application.ex.ApplicationInfoEx;
import com.intellij.openapi.extensions.PluginId;
Expand Down Expand Up @@ -65,6 +67,15 @@ public Set<PluginId> getRequiredPlugins(PluginId pluginId) {
return myDependentToRequiredListMap.get(pluginId);
}

public boolean isRequiredPlugin(@NotNull IdeaPluginDescriptor descriptor) {
return myProject != null &&
ExternalDependenciesManager.getInstance(myProject)
.getDependencies(DependencyOnPlugin.class)
.stream()
.map(DependencyOnPlugin::getPluginId)
.anyMatch(descriptor.getPluginId().getIdString()::equals);
}

public final boolean isLoaded(@NotNull PluginId pluginId) {
return isLoaded(pluginId, getEnabledMap());
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -98,6 +98,7 @@ public class PluginDetailsPageComponent extends MultiPanel {

private ListPluginComponent myShowComponent;
private boolean myRequiresRestart = true;
private boolean myPluginIsRequired = false;

public PluginDetailsPageComponent(@NotNull MyPluginModel pluginModel, @NotNull LinkListener<Object> searchListener, boolean marketplace) {
myPluginModel = pluginModel;
Expand Down Expand Up @@ -458,6 +459,8 @@ public ActionCallback select(Integer key, boolean now) {
myPluginModel.appendOrUpdateDescriptor(descriptor);
myRequiresRestart = DynamicPlugins.checkCanUnloadWithoutRestart(descriptor) != null;
}

myPluginIsRequired = myPluginModel.isRequiredPlugin(myPlugin);
}

return super.select(key, now);
Expand Down Expand Up @@ -875,7 +878,8 @@ public void update(@NotNull AnActionEvent e) {
PluginEnabledState state = myPluginModel.getState(myPlugin);

boolean invisible = myNewState == state ||
myNewState.isPerProject() && (myRequiresRestart || e.getProject() == null);
myNewState.isPerProject() && (myRequiresRestart || e.getProject() == null) ||
!myNewState.isEnabled() && myPluginIsRequired;
e.getPresentation().setVisible(!invisible);
}
}
Expand Down

0 comments on commit 8377287

Please sign in to comment.