IDEA-47924 Updating a disabled plugin should prompt to enable it
authoranna <Anna.Kozlova@jetbrains.com>
Sun, 15 Jan 2012 15:18:29 +0000 (16:18 +0100)
committeranna <Anna.Kozlova@jetbrains.com>
Sun, 15 Jan 2012 15:18:29 +0000 (16:18 +0100)
platform/platform-impl/src/com/intellij/ide/plugins/ActionInstallPlugin.java
platform/platform-impl/src/com/intellij/ide/plugins/InstalledPluginsTableModel.java

index 15b3f9a1473484a912fed8fff772a08f15fa212c..05516fdf27ce3611d5770f8b1d248a8419dd8bc0 100644 (file)
@@ -15,6 +15,7 @@
  */
 package com.intellij.ide.plugins;
 
+import com.intellij.CommonBundle;
 import com.intellij.ide.IdeBundle;
 import com.intellij.notification.Notification;
 import com.intellij.notification.NotificationListener;
@@ -28,6 +29,7 @@ import com.intellij.openapi.application.ex.ApplicationEx;
 import com.intellij.openapi.application.ex.ApplicationManagerEx;
 import com.intellij.openapi.extensions.PluginId;
 import com.intellij.openapi.project.DumbAware;
+import com.intellij.openapi.ui.DialogWrapper;
 import com.intellij.openapi.ui.Messages;
 import com.intellij.openapi.util.IconLoader;
 import com.intellij.util.net.IOExceptionDialog;
@@ -37,6 +39,8 @@ import javax.swing.event.HyperlinkEvent;
 import java.io.IOException;
 import java.util.ArrayList;
 import java.util.Arrays;
+import java.util.HashSet;
+import java.util.Set;
 
 /**
  * @author lloix
@@ -115,6 +119,21 @@ public class ActionInstallPlugin extends AnAction implements DumbAware {
             installed.setRequireShutdown(true);
             if (!installed.isDisposed()) {
               getPluginTable().updateUI();
+              final InstalledPluginsTableModel pluginsModel = (InstalledPluginsTableModel)installed.getPluginsModel();
+              final Set<IdeaPluginDescriptor> disabled = new HashSet<IdeaPluginDescriptor>();
+              for (PluginNode node : list) {
+                final PluginId pluginId = node.getPluginId();
+                if (pluginsModel.isDisabled(pluginId)) {
+                  disabled.add(node);
+                }
+              }
+              if (!disabled.isEmpty()) {
+                String message = "Updated plugin" + (disabled.size() > 1 ? "s are " : " is ") + "disabled. Would you like to enable " + (disabled.size() > 1 ? "them" : "it") + "?";
+                if (Messages.showOkCancelDialog(host.pluginTable, message, CommonBundle.getWarningTitle(), Messages.getQuestionIcon()) ==
+                    DialogWrapper.OK_EXIT_CODE) {
+                  pluginsModel.enableRows(disabled.toArray(new IdeaPluginDescriptor[disabled.size()]), true);
+                }
+              }
             }
             else {
               notifyPluginsWereInstalled();
index f03df913a61a19fdef704438346c67da0bcf60da..7985f2f0470821908f23dda1eeb1601c8eb80271 100644 (file)
@@ -308,6 +308,11 @@ public class InstalledPluginsTableModel extends PluginTableModel {
     return enabled != null && enabled.booleanValue();
   }
 
+  public boolean isDisabled(final PluginId pluginId) {
+    final Boolean enabled = myEnabled.get(pluginId);
+    return enabled != null && !enabled.booleanValue();
+  }
+
   public Map<PluginId, Boolean> getEnabledMap() {
     return myEnabled;
   }