platform: restart IDE notifications/dialogs unified
authorRoman Shevchenko <roman.shevchenko@jetbrains.com>
Mon, 22 Dec 2014 19:56:24 +0000 (20:56 +0100)
committerRoman Shevchenko <roman.shevchenko@jetbrains.com>
Mon, 22 Dec 2014 19:56:24 +0000 (20:56 +0100)
platform/platform-api/src/com/intellij/notification/Notifications.java
platform/platform-impl/src/com/intellij/ide/plugins/InstallPluginAction.java
platform/platform-impl/src/com/intellij/ide/plugins/InstalledPluginsManagerMain.java
platform/platform-impl/src/com/intellij/ide/plugins/PluginManager.java
platform/platform-impl/src/com/intellij/ide/plugins/PluginManagerConfigurable.java
platform/platform-impl/src/com/intellij/ide/plugins/PluginManagerMain.java
platform/platform-impl/src/com/intellij/openapi/updateSettings/impl/AbstractUpdateDialog.java
platform/platform-impl/src/com/intellij/openapi/updateSettings/impl/PluginUpdateInfoDialog.java
platform/platform-impl/src/com/intellij/openapi/updateSettings/impl/UpdateChecker.java
platform/platform-impl/src/com/intellij/openapi/updateSettings/impl/pluginsAdvertisement/PluginsAdvertiserDialog.java
platform/platform-resources-en/src/messages/IdeBundle.properties

index a82ac8075636ad74b4c8e605a8d3d9add6558896..7e6946bf8615d55e09e42a02be08254ea7309d93 100644 (file)
@@ -1,5 +1,5 @@
 /*
- * Copyright 2000-2013 JetBrains s.r.o.
+ * 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.
@@ -34,15 +34,16 @@ public interface Notifications {
   String SYSTEM_MESSAGES_GROUP_ID = "System Messages";
 
   void notify(@NotNull Notification notification);
-  void register(@NotNull final String groupDisplayName, @NotNull final NotificationDisplayType defaultDisplayType);
-  void register(@NotNull final String groupDisplayName, @NotNull final NotificationDisplayType defaultDisplayType, boolean shouldLog);
-  void register(@NotNull final String groupDisplayName, @NotNull final NotificationDisplayType defaultDisplayType, boolean shouldLog, boolean shouldReadAloud);
+
+  void register(@NotNull String groupDisplayName, @NotNull NotificationDisplayType defaultDisplayType);
+  void register(@NotNull String groupDisplayName, @NotNull NotificationDisplayType defaultDisplayType, boolean shouldLog);
+  void register(@NotNull String groupDisplayName, @NotNull NotificationDisplayType defaultDisplayType, boolean shouldLog, boolean shouldReadAloud);
 
   @SuppressWarnings({"UtilityClassWithoutPrivateConstructor"})
   class Bus {
     /**
      * Registration is OPTIONAL: BALLOON display type will be used by default.
-     * @deprecated use {@link com.intellij.notification.NotificationGroup}
+     * @deprecated use {@link NotificationGroup}
      */
     @SuppressWarnings("JavaDoc")
     public static void register(@NotNull final String group_id, @NotNull final NotificationDisplayType defaultDisplayType) {
@@ -80,7 +81,8 @@ public interface Notifications {
     private static void doNotify(Notification notification, @Nullable Project project) {
       if (project != null && !project.isDisposed()) {
         project.getMessageBus().syncPublisher(TOPIC).notify(notification);
-      } else {
+      }
+      else {
         Application app = ApplicationManager.getApplication();
         if (!app.isDisposed()) {
           app.getMessageBus().syncPublisher(TOPIC).notify(notification);
index d2de5fb0d98ba3436c26322f207902627d701f1c..90b7f64baf9d02c1090cc92e48f4a82e0ad46ea7 100644 (file)
@@ -158,7 +158,7 @@ public class InstallPluginAction extends AnAction implements DumbAware {
               }
 
               if (needToRestart) {
-                PluginManagerMain.notifyPluginsWereInstalled(list.size() == 1 ? list.get(0).getName() : null, null);
+                PluginManagerMain.notifyPluginsUpdated(null);
               }
             }
             if (onSuccess != null) {
index 2b74ee5f3f4422962b8398e23966168c6db2f9db..050d15696bbc959f6f5c3856242259967971a4c3 100644 (file)
@@ -24,8 +24,6 @@ import com.intellij.ide.ui.search.OptionDescription;
 import com.intellij.ide.util.PropertiesComponent;
 import com.intellij.openapi.actionSystem.*;
 import com.intellij.openapi.actionSystem.ex.ComboBoxAction;
-import com.intellij.openapi.application.ex.ApplicationEx;
-import com.intellij.openapi.application.ex.ApplicationManagerEx;
 import com.intellij.openapi.extensions.PluginId;
 import com.intellij.openapi.fileChooser.FileChooser;
 import com.intellij.openapi.fileChooser.FileChooserDescriptor;
@@ -492,11 +490,7 @@ public class InstalledPluginsManagerMain extends PluginManagerMain {
       chooseAndInstall(new InstalledPluginsTableModel(), new Consumer<Pair<File, IdeaPluginDescriptor>>() {
         @Override
         public void consume(Pair<File, IdeaPluginDescriptor> pair) {
-          ApplicationEx app = ApplicationManagerEx.getApplicationEx();
-          int response = app.isRestartCapable() ? PluginManagerConfigurable.showRestartIDEADialog() : PluginManagerConfigurable.showShutDownIDEADialog();
-          if (response == Messages.YES) {
-            app.restart(true);
-          }
+          PluginManagerConfigurable.shutdownOrRestartApp();
         }
       }, null);
     }
index 1c43e2f04ba400a196f8295c825c180225a55720..45ac584a505fa9d1635b7f1996b3ec67c72b15cd 100644 (file)
@@ -183,7 +183,7 @@ public class PluginManager extends PluginManagerCore {
           }
           else if (myPlugins2Enable != null && ENABLE.equals(description)) {
             disabledPlugins.removeAll(myPlugins2Enable);
-            PluginManagerMain.notifyPluginsWereUpdated("Changes were applied", null);
+            PluginManagerMain.notifyPluginsUpdated(null);
           }
 
           try {
index 5be8953fc2605055f056060fdb828d859dc96c67..c9fe4422585c5eed4ca92274c3d94a3ff027db6f 100644 (file)
@@ -17,7 +17,6 @@ package com.intellij.ide.plugins;
 
 import com.intellij.ide.IdeBundle;
 import com.intellij.openapi.application.ApplicationNamesInfo;
-import com.intellij.openapi.application.ex.ApplicationEx;
 import com.intellij.openapi.application.ex.ApplicationManagerEx;
 import com.intellij.openapi.options.BaseConfigurable;
 import com.intellij.openapi.options.Configurable;
@@ -87,6 +86,7 @@ public class PluginManagerConfigurable extends BaseConfigurable implements Searc
   }
 
   @Override
+  @NotNull
   public String getHelpTopic() {
     return ID;
   }
@@ -137,11 +137,8 @@ public class PluginManagerConfigurable extends BaseConfigurable implements Searc
     }
 
     if (myPluginManagerMain.isRequireShutdown()) {
-      final ApplicationEx app = ApplicationManagerEx.getApplicationEx();
-
-      int response = app.isRestartCapable() ? showRestartIDEADialog() : showShutDownIDEADialog();
-      if (response == Messages.YES) {
-        app.restart(true);
+      if (showRestartDialog() == Messages.YES) {
+        ApplicationManagerEx.getApplicationEx().restart(true);
       }
       else {
         myPluginManagerMain.ignoreChanges();
@@ -157,31 +154,25 @@ public class PluginManagerConfigurable extends BaseConfigurable implements Searc
   }
 
   @Messages.YesNoResult
-  public static int showShutDownIDEADialog() {
-    return showShutDownIDEADialog(IdeBundle.message("title.plugins.changed"));
-  }
-
-  @Messages.YesNoResult
-  private static int showShutDownIDEADialog(final String title) {
-    String message = IdeBundle.message("message.idea.shutdown.required", ApplicationNamesInfo.getInstance().getFullProductName());
-    return Messages.showYesNoDialog(message, title, "Shut Down", POSTPONE, Messages.getQuestionIcon());
+  public static int showRestartDialog() {
+    return showRestartDialog(IdeBundle.message("update.notifications.title"));
   }
 
   @Messages.YesNoResult
-  public static int showRestartIDEADialog() {
-    return showRestartIDEADialog(IdeBundle.message("title.plugins.changed"));
+  public static int showRestartDialog(@NotNull String title) {
+    String action = IdeBundle.message(ApplicationManagerEx.getApplicationEx().isRestartCapable() ? "ide.restart.action" : "ide.shutdown.action");
+    String message = IdeBundle.message("ide.restart.required.message", action, ApplicationNamesInfo.getInstance().getFullProductName());
+    return Messages.showYesNoDialog(message, title, action, IdeBundle.message("ide.postpone.action"), Messages.getQuestionIcon());
   }
 
-  @Messages.YesNoResult
-  private static int showRestartIDEADialog(final String title) {
-    String message = IdeBundle.message("message.idea.restart.required", ApplicationNamesInfo.getInstance().getFullProductName());
-    return Messages.showYesNoDialog(message, title, "Restart", POSTPONE, Messages.getQuestionIcon());
+  public static void shutdownOrRestartApp() {
+    shutdownOrRestartApp(IdeBundle.message("update.notifications.title"));
   }
 
-  public static void shutdownOrRestartApp(String title) {
-    final ApplicationEx app = ApplicationManagerEx.getApplicationEx();
-    int response = app.isRestartCapable() ? showRestartIDEADialog(title) : showShutDownIDEADialog(title);
-    if (response == Messages.YES) app.restart(true);
+  public static void shutdownOrRestartApp(@NotNull String title) {
+    if (showRestartDialog(title) == Messages.YES) {
+      ApplicationManagerEx.getApplicationEx().restart(true);
+    }
   }
 
   @Override
@@ -198,11 +189,12 @@ public class PluginManagerConfigurable extends BaseConfigurable implements Searc
   @Override
   @Nullable
   public Runnable enableSearch(final String option) {
-    return new Runnable(){
+    return new Runnable() {
       @Override
       public void run() {
-        if (myPluginManagerMain == null) return;
-        myPluginManagerMain.filter(option);
+        if (myPluginManagerMain != null) {
+          myPluginManagerMain.filter(option);
+        }
       }
     };
   }
index cc3ccc58e5a699ab5f969c1dff678fff3a98a30f..06b96138bebae63720bb6cc6900c1eead12eff48 100644 (file)
@@ -40,6 +40,7 @@ import com.intellij.openapi.project.DumbAwareAction;
 import com.intellij.openapi.project.Project;
 import com.intellij.openapi.ui.Messages;
 import com.intellij.openapi.ui.popup.JBPopupFactory;
+import com.intellij.openapi.updateSettings.impl.UpdateChecker;
 import com.intellij.openapi.updateSettings.impl.UpdateSettings;
 import com.intellij.openapi.util.text.StringUtil;
 import com.intellij.ui.*;
@@ -67,7 +68,6 @@ import java.awt.event.MouseEvent;
 import java.io.FileNotFoundException;
 import java.io.IOException;
 import java.net.URL;
-import java.util.ArrayList;
 import java.util.HashSet;
 import java.util.List;
 import java.util.Set;
@@ -617,38 +617,19 @@ public abstract class PluginManagerMain implements Disposable {
     return false;
   }
 
-
-  public static void notifyPluginsWereInstalled(@Nullable String pluginName, final Project project) {
-    notifyPluginsWereUpdated(pluginName != null
-                             ? "Plugin \'" + pluginName + "\' was successfully installed"
-                             : "Plugins were installed", project);
-  }
-
-  public static void notifyPluginsWereUpdated(final String title, @Nullable final Project project) {
+  public static void notifyPluginsUpdated(@Nullable Project project) {
     final ApplicationEx app = ApplicationManagerEx.getApplicationEx();
-    final boolean restartCapable = app.isRestartCapable();
-    String message =
-      restartCapable ? IdeBundle.message("message.idea.restart.required", ApplicationNamesInfo.getInstance().getFullProductName())
-                     : IdeBundle.message("message.idea.shutdown.required", ApplicationNamesInfo.getInstance().getFullProductName());
-    message += "<br><a href=";
-    message += restartCapable ? "\"restart\">Restart now" : "\"shutdown\">Shutdown";
-    message += "</a>";
-    PLUGIN_LIFECYCLE_NOTIFICATION_GROUP
-      .createNotification(title,
-                          XmlStringUtil.wrapInHtml(message), NotificationType.INFORMATION,
-                          new NotificationListener() {
-                            @Override
-                            public void hyperlinkUpdate(@NotNull Notification notification,
-                                                        @NotNull HyperlinkEvent event) {
-                              notification.expire();
-                              if (restartCapable) {
-                                app.restart(true);
-                              }
-                              else {
-                                app.exit(false, true);
-                              }
-                            }
-                          }).notify(project);
+    String title = IdeBundle.message("update.notifications.title");
+    String action = IdeBundle.message(app.isRestartCapable() ? "ide.restart.action" : "ide.shutdown.action");
+    String message = IdeBundle.message("ide.restart.required.notification", action, ApplicationNamesInfo.getInstance().getFullProductName());
+    NotificationListener listener = new NotificationListener() {
+      @Override
+      public void hyperlinkUpdate(@NotNull Notification notification, @NotNull HyperlinkEvent event) {
+        notification.expire();
+        app.restart(true);
+      }
+    };
+    UpdateChecker.NOTIFICATIONS.createNotification(title, XmlStringUtil.wrapInHtml(message), NotificationType.INFORMATION, listener).notify(project);
   }
 
   public class MyPluginsFilter extends FilterComponent {
index c3849760b73dbcc4974263f1bce29b2998097505..cde3f74ec4c682ce629836353d9347d2abb8def7 100644 (file)
@@ -46,13 +46,13 @@ public abstract class AbstractUpdateDialog extends DialogWrapper {
   protected AbstractUpdateDialog(boolean enableLink) {
     super(true);
     myEnableLink = enableLink;
-    setTitle(IdeBundle.message("updates.info.dialog.title"));
+    setTitle(IdeBundle.message("update.notifications.title"));
   }
 
   protected AbstractUpdateDialog(Component parent, boolean enableLink) {
     super(parent, true);
     myEnableLink = enableLink;
-    setTitle(IdeBundle.message("updates.info.dialog.title"));
+    setTitle(IdeBundle.message("update.notifications.title"));
   }
 
   @Override
index 4fd4928e9b47882a98db9e8c45caaeafa4952c70..eec9d3ca854d193321006cad7cbf432ae6c9e616 100644 (file)
@@ -22,7 +22,6 @@ import com.intellij.openapi.progress.ProgressIndicator;
 import com.intellij.openapi.progress.ProgressManager;
 import com.intellij.openapi.progress.Task;
 import com.intellij.ui.TableUtil;
-import com.intellij.util.containers.ContainerUtil;
 import org.jetbrains.annotations.NotNull;
 
 import javax.swing.*;
@@ -79,14 +78,7 @@ class PluginUpdateInfoDialog extends AbstractUpdateDialog {
         UpdateChecker.saveDisabledToUpdatePlugins();
         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();
-            }
-          }
-          PluginManagerMain.notifyPluginsWereInstalled(pluginName, null);
+          PluginManagerMain.notifyPluginsUpdated(null);
         }
       }
     });
index f9d5a61aba8471d44b7695ce66504d5f0a8e2455..18f0e0f5a4f1db20b8de6c03696d0feb2da3c2ae 100644 (file)
@@ -20,10 +20,7 @@ import com.intellij.ide.IdeBundle;
 import com.intellij.ide.plugins.*;
 import com.intellij.ide.util.PropertiesComponent;
 import com.intellij.notification.*;
-import com.intellij.openapi.application.ApplicationInfo;
-import com.intellij.openapi.application.ApplicationManager;
-import com.intellij.openapi.application.ApplicationNamesInfo;
-import com.intellij.openapi.application.PathManager;
+import com.intellij.openapi.application.*;
 import com.intellij.openapi.application.ex.ApplicationInfoEx;
 import com.intellij.openapi.diagnostic.IdeaLoggingEvent;
 import com.intellij.openapi.diagnostic.LogUtil;
@@ -44,6 +41,7 @@ import com.intellij.util.containers.ContainerUtil;
 import com.intellij.util.io.HttpRequests;
 import com.intellij.util.io.URLUtil;
 import com.intellij.util.ui.UIUtil;
+import com.intellij.xml.util.XmlStringUtil;
 import org.apache.http.client.utils.URIBuilder;
 import org.jdom.JDOMException;
 import org.jetbrains.annotations.Contract;
@@ -72,13 +70,8 @@ public final class UpdateChecker {
     SUCCESS, FAILED, CANCELED
   }
 
-  private static final NotNullLazyValue<NotificationGroup> GROUP = new NotNullLazyValue<NotificationGroup>() {
-    @NotNull
-    @Override
-    protected NotificationGroup compute() {
-      return new NotificationGroup(IdeBundle.message("update.available.group"), NotificationDisplayType.STICKY_BALLOON, true);
-    }
-  };
+  public static final NotificationGroup NOTIFICATIONS =
+    new NotificationGroup(IdeBundle.message("update.notifications.group"), NotificationDisplayType.STICKY_BALLOON, true);
 
   @NonNls private static final String INSTALLATION_UID = "installation.uid";
   @NonNls private static final String DISABLED_UPDATE = "disabled_update.txt";
@@ -456,7 +449,7 @@ public final class UpdateChecker {
     }
   }
 
-  private static void showNotification(@Nullable Project project, String message, boolean error, final @Nullable Runnable runnable) {
+  private static void showNotification(@Nullable Project project, String message, boolean error, @Nullable final Runnable runnable) {
     NotificationListener listener = null;
     if (runnable != null) {
       listener = new NotificationListener() {
@@ -468,9 +461,9 @@ public final class UpdateChecker {
       };
     }
 
-    String title = IdeBundle.message("updates.info.dialog.title");
+    String title = IdeBundle.message("update.notifications.title");
     NotificationType type = error ? NotificationType.ERROR : NotificationType.INFORMATION;
-    Notifications.Bus.notify(GROUP.getValue().createNotification(title, message, type, listener), project);
+    NOTIFICATIONS.createNotification(title, XmlStringUtil.wrapInHtml(message), type, listener).notify(project);
   }
 
   public static void addUpdateRequestParameter(@NotNull String name, @NotNull String value) {
index 4e8751266c5592ef355acb29dc0b74cc0b1c25e9..7008ad7c0aa62dff422660c7d15e77788983ae00 100644 (file)
@@ -90,7 +90,7 @@ public class PluginsAdvertiserDialog extends DialogWrapper {
     final Runnable notifyRunnable = new Runnable() {
       @Override
       public void run() {
-        PluginManagerMain.notifyPluginsWereInstalled(null, myProject);
+        PluginManagerMain.notifyPluginsUpdated(myProject);
       }
     };
     for (String pluginId : pluginsToEnable) {
index f71b57e4d3fa025669990096c2c4ff15075f6843..2cc34d3f50827be899ff49665a70f247485eb6de 100644 (file)
@@ -507,8 +507,11 @@ column.plugins.category=Category
 column.plugins.rate=Rating
 plugin.info.not.available=n/a
 plugin.info.unknown=unknown
-message.idea.shutdown.required=Shut down {0} to activate changes in plugins?
-message.idea.restart.required=Restart {0} to activate changes in plugins?
+ide.restart.required.message={0} {1} to activate changes in plugins?
+ide.restart.required.notification=<a href="#">{0}</a> {1} to activate changes in plugins?
+ide.restart.action=Restart
+ide.shutdown.action=Shutdown
+ide.postpone.action=Postpone
 title.plugins=Plugins
 title.plugins.changed=Plugins Changed
 plugin.status.not.specified=(not specified)
@@ -897,7 +900,8 @@ updates.checking.plugins=Checking for plugins update
 updates.error.connection.title=Connection Error
 updates.error.connection.failed=Connection failed. Please check your network connection and try again.
 updates.error.plugin.description.failed=Failed to load plugin descriptions from: \"{0}\"
-updates.info.dialog.title=Update Info
+update.notifications.title=Platform and Plugin Updates
+update.notifications.group=Platform and Plugin Updates
 updates.channel.name.message=<b>{0}</b>: {1}
 updates.channel.key.needed=You can evaluate the new version for {0} days or buy a license key or an upgrade online.
 updates.channel.existing.key=The new version can be used with your existing license key.
@@ -1154,7 +1158,6 @@ checkbox.allow.status.bar=Allow Status Bar
 checkbox.allow.line.numbers=Allow Line Numbers
 checkbox.allow.vcs.annotations=Allow VCS Annotations
 presentation.mode.fon.size=Font size\:
-update.available.group=Update Checker
 
 loading.editors=Loading files...