IDEA-134416 (ask-for-restart logic simplified and moved entirely into PluginUpdateDia...
authorRoman Shevchenko <roman.shevchenko@jetbrains.com>
Wed, 17 Dec 2014 12:57:07 +0000 (13:57 +0100)
committerRoman Shevchenko <roman.shevchenko@jetbrains.com>
Wed, 17 Dec 2014 13:25:01 +0000 (14:25 +0100)
platform/platform-impl/src/com/intellij/openapi/updateSettings/impl/PluginUpdateInfoDialog.java
platform/platform-impl/src/com/intellij/openapi/updateSettings/impl/UpdateInfoDialog.java
platform/platform-resources-en/src/messages/IdeBundle.properties

index aac0888d60108f05e245ff9326027d785946dad8..4fd4928e9b47882a98db9e8c45caaeafa4952c70 100644 (file)
@@ -17,12 +17,11 @@ package com.intellij.openapi.updateSettings.impl;
 
 import com.intellij.ide.IdeBundle;
 import com.intellij.ide.plugins.PluginManagerMain;
+import com.intellij.openapi.application.ApplicationManager;
 import com.intellij.openapi.progress.ProgressIndicator;
 import com.intellij.openapi.progress.ProgressManager;
 import com.intellij.openapi.progress.Task;
-import com.intellij.openapi.util.Ref;
 import com.intellij.ui.TableUtil;
-import com.intellij.util.Consumer;
 import com.intellij.util.containers.ContainerUtil;
 import org.jetbrains.annotations.NotNull;
 
@@ -35,16 +34,22 @@ import java.util.Collection;
  */
 class PluginUpdateInfoDialog extends AbstractUpdateDialog {
   private final Collection<PluginDownloader> myUploadedPlugins;
+  private final boolean myPlatformUpdate;
 
   public PluginUpdateInfoDialog(Collection<PluginDownloader> uploadedPlugins, boolean enableLink) {
     super(enableLink);
     myUploadedPlugins = uploadedPlugins;
+    myPlatformUpdate = false;
     init();
   }
 
-  protected PluginUpdateInfoDialog(Component parent, @NotNull Collection<PluginDownloader> updatePlugins, boolean enableLink) {
-    super(parent, enableLink);
+  /**
+   * Used from {@link UpdateInfoDialog} when both platform and plugin updates are available.
+   */
+  PluginUpdateInfoDialog(Component parent, @NotNull Collection<PluginDownloader> updatePlugins) {
+    super(parent, false);
     myUploadedPlugins = updatePlugins;
+    myPlatformUpdate = true;
     init();
   }
 
@@ -55,64 +60,36 @@ class PluginUpdateInfoDialog extends AbstractUpdateDialog {
 
   @Override
   protected String getOkButtonText() {
-    return IdeBundle.message("update.plugins.update.action");
-  }
-
-  @NotNull
-  @Override
-  protected Action[] createActions() {
-    return new Action[]{getOKAction(), getCancelAction()};
+    if (!myPlatformUpdate) {
+      return IdeBundle.message("update.plugins.update.action");
+    }
+    else {
+      boolean canRestart = ApplicationManager.getApplication().isRestartCapable();
+      return IdeBundle.message(canRestart ? "update.restart.plugins.update.action" : "update.shutdown.plugins.update.action");
+    }
   }
 
   @Override
   protected void doOKAction() {
     super.doOKAction();
-    final Ref<Boolean> result = new Ref<Boolean>();
-    final Consumer<ProgressIndicator> runnable = new Consumer<ProgressIndicator>() {
+
+    ProgressManager.getInstance().run(new Task.Modal(null, IdeBundle.message("progress.downloading.plugins"), true) {
       @Override
-      public void consume(@NotNull ProgressIndicator indicator) {
+      public void run(@NotNull ProgressIndicator indicator) {
         UpdateChecker.saveDisabledToUpdatePlugins();
-        result.set(UpdateChecker.installPluginUpdates(myUploadedPlugins, indicator));
-      }
-    };
-
-    final String progressTitle = "Download plugins...";
-    if (downloadModal()) {
-      ProgressManager.getInstance().run(new Task.Modal(null, progressTitle, true) {
-        @Override
-        public void run(@NotNull ProgressIndicator indicator) {
-          runnable.consume(indicator);
-        }
-      });
-    }
-    else {
-      ProgressManager.getInstance().run(new Task.Backgroundable(null, progressTitle, true) {
-        @Override
-        public void run(@NotNull ProgressIndicator indicator) {
-          runnable.consume(indicator);
-        }
-
-        @Override
-        public void onSuccess() {
-          final Boolean installed = result.get();
-          if (installed != null && installed.booleanValue()) {
-            final String pluginName;
-            if (myUploadedPlugins.size() == 1) {
-              final PluginDownloader firstItem = ContainerUtil.getFirstItem(myUploadedPlugins);
-              pluginName = firstItem != null ? firstItem.getPluginName() : null;
+        boolean updated = UpdateChecker.installPluginUpdates(myUploadedPlugins, indicator);
+        if (updated && !myPlatformUpdate) {
+          String pluginName = null;
+          if (myUploadedPlugins.size() == 1) {
+            PluginDownloader plugin = ContainerUtil.getFirstItem(myUploadedPlugins);
+            if (plugin != null) {
+              pluginName = plugin.getPluginName();
             }
-            else {
-              pluginName = null;
-            }
-            PluginManagerMain.notifyPluginsWereInstalled(pluginName, null);
           }
+          PluginManagerMain.notifyPluginsWereInstalled(pluginName, null);
         }
-      });
-    }
-  }
-
-  protected boolean downloadModal() {
-    return false;
+      }
+    });
   }
 
   private class PluginUpdateInfoPanel {
index 2236d7c9c32bb650e18b1f18aa7ceb0d0c8deefd..deb42588cbcc42b5af5f912fcbdef8ccad3d2ce8 100644 (file)
@@ -88,7 +88,7 @@ class UpdateInfoDialog extends AbstractUpdateDialog {
     List<Action> actions = ContainerUtil.newArrayList();
 
     if (myPatch != null) {
-      final boolean canRestart = ApplicationManager.getApplication().isRestartCapable();
+      boolean canRestart = ApplicationManager.getApplication().isRestartCapable();
       String button = IdeBundle.message(canRestart ? "updates.download.and.restart.button" : "updates.download.and.install.button");
       actions.add(new AbstractAction(button) {
         {
@@ -97,7 +97,7 @@ class UpdateInfoDialog extends AbstractUpdateDialog {
 
         @Override
         public void actionPerformed(ActionEvent e) {
-          downloadPatch(canRestart);
+          downloadPatch();
         }
       });
     }
@@ -138,21 +138,11 @@ class UpdateInfoDialog extends AbstractUpdateDialog {
     return IdeBundle.message("updates.remind.later.button");
   }
 
-  private void downloadPatch(final boolean canRestart) {
-    final UpdateChecker.DownloadPatchResult result = UpdateChecker.installPlatformUpdate(myPatch, myLatestBuild.getNumber(), myForceHttps);
+  private void downloadPatch() {
+    UpdateChecker.DownloadPatchResult result = UpdateChecker.installPlatformUpdate(myPatch, myLatestBuild.getNumber(), myForceHttps);
     if (result == UpdateChecker.DownloadPatchResult.SUCCESS) {
       if (myUpdatedPlugins != null && !myUpdatedPlugins.isEmpty()) {
-        new PluginUpdateInfoDialog(getContentPanel(), myUpdatedPlugins, true){
-          @Override
-          protected boolean downloadModal() {
-            return true;
-          }
-
-          @Override
-          protected String getOkButtonText() {
-            return IdeBundle.message(canRestart ? "update.restart.plugins.update.action" : "update.shutdown.plugins.update.action");
-          }
-        }.show();
+        new PluginUpdateInfoDialog(getContentPanel(), myUpdatedPlugins).show();
       }
       restart();
     }
index e149bab78ae7819715a12191c30f37a886f402dc..f71b57e4d3fa025669990096c2c4ff15075f6843 100644 (file)
@@ -528,6 +528,7 @@ progress.download.plugins=Download Plugins
 button.http.proxy.settings=&HTTP Proxy Settings...
 group.vendor=Vendor
 plugin.status.installed=Installed
+progress.downloading.plugins=Downloading plugins
 progress.downloading.plugin=Downloading plugin ''{0}''
 error.cannot.create.temp.dir=Unable to create temp directory ''{0}''
 error.connection.failed.with.http.code.N=Connection failed with HTTP code {0}