From f2a05352d8681e978754d9a97fe189f7d55a2f10 Mon Sep 17 00:00:00 2001 From: Konstantin Bulenkov Date: Wed, 14 Apr 2010 16:00:50 +0400 Subject: [PATCH] Update on exit option --- .../com/intellij/idea/IdeaApplication.java | 46 ++++++++++++------- .../impl/AbstractUpdateDialog.java | 13 +++++- .../impl/CheckForUpdateAction.java | 4 +- .../updateSettings/impl/NoUpdatesDialog.java | 7 ++- .../updateSettings/impl/UpdateChecker.java | 12 +++-- .../updateSettings/impl/UpdateSettings.java | 6 ++- .../impl/UpdateSettingsConfigurable.java | 5 +- .../src/messages/IdeBundle.properties | 1 + 8 files changed, 64 insertions(+), 30 deletions(-) diff --git a/platform/platform-impl/src/com/intellij/idea/IdeaApplication.java b/platform/platform-impl/src/com/intellij/idea/IdeaApplication.java index 88686b89ac7f..c22f0d9dbac3 100644 --- a/platform/platform-impl/src/com/intellij/idea/IdeaApplication.java +++ b/platform/platform-impl/src/com/intellij/idea/IdeaApplication.java @@ -1,5 +1,5 @@ /* - * Copyright 2000-2009 JetBrains s.r.o. + * Copyright 2000-2010 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. @@ -29,9 +29,7 @@ import com.intellij.openapi.diagnostic.Logger; import com.intellij.openapi.extensions.ExtensionPoint; import com.intellij.openapi.extensions.Extensions; import com.intellij.openapi.project.Project; -import com.intellij.openapi.updateSettings.impl.PluginDownloader; -import com.intellij.openapi.updateSettings.impl.UpdateChannel; -import com.intellij.openapi.updateSettings.impl.UpdateChecker; +import com.intellij.openapi.updateSettings.impl.*; import com.intellij.openapi.util.Comparing; import com.intellij.openapi.util.InvalidDataException; import com.intellij.openapi.util.SystemInfo; @@ -196,22 +194,21 @@ public class IdeaApplication { } }, ModalityState.NON_MODAL); + app.addApplicationListener(new ApplicationAdapter() { + @Override + public boolean canExitApplication() { + if (UpdateSettings.getInstance().isUpdateOnExit()) { + updatePlugins(false); + } + return true; + } + }); + app.invokeLater(new Runnable() { public void run() { if (UpdateChecker.isMyVeryFirstOpening() && UpdateChecker.checkNeeded()) { - try { - UpdateChecker.setMyVeryFirstOpening(false); - final UpdateChannel newVersion = UpdateChecker.checkForUpdates(); - final List updatedPlugins = UpdateChecker.updatePlugins(false); - if (newVersion != null) { - UpdateChecker.showUpdateInfoDialog(true, newVersion, updatedPlugins); - } else if (updatedPlugins != null) { - UpdateChecker.showNoUpdatesDialog(true, updatedPlugins); - } - } - catch (ConnectionException e) { - // It's not a problem on automatic check - } + UpdateChecker.setMyVeryFirstOpening(false); + updatePlugins(true); } if (myPerformProjectLoad) { @@ -226,6 +223,21 @@ public class IdeaApplication { } }, ModalityState.NON_MODAL); } + + private void updatePlugins(boolean showConfirmation) { + try { + final UpdateChannel newVersion = UpdateChecker.checkForUpdates(); + final List updatedPlugins = UpdateChecker.updatePlugins(false); + if (newVersion != null) { + UpdateChecker.showUpdateInfoDialog(true, newVersion, updatedPlugins); + } else if (updatedPlugins != null) { + UpdateChecker.showNoUpdatesDialog(true, updatedPlugins, showConfirmation); + } + } + catch (ConnectionException e) { + // It's not a problem on automatic check + } + } } private void loadProject() { diff --git a/platform/platform-impl/src/com/intellij/openapi/updateSettings/impl/AbstractUpdateDialog.java b/platform/platform-impl/src/com/intellij/openapi/updateSettings/impl/AbstractUpdateDialog.java index 00212be88d89..25364e867361 100644 --- a/platform/platform-impl/src/com/intellij/openapi/updateSettings/impl/AbstractUpdateDialog.java +++ b/platform/platform-impl/src/com/intellij/openapi/updateSettings/impl/AbstractUpdateDialog.java @@ -1,5 +1,5 @@ /* - * Copyright 2000-2009 JetBrains s.r.o. + * Copyright 2000-2010 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. @@ -37,6 +37,7 @@ import java.util.List; public abstract class AbstractUpdateDialog extends DialogWrapper { private final boolean myEnableLink; protected final List myUploadedPlugins; + protected boolean myShowConfirmation = true; protected AbstractUpdateDialog(boolean canBeParent, boolean enableLink, final List updatePlugins) { super(canBeParent); @@ -95,7 +96,7 @@ public abstract class AbstractUpdateDialog extends DialogWrapper { } protected void doOKAction() { - if (doDownloadAndPrepare()) { + if (doDownloadAndPrepare() && isShowConfirmation()) { final ApplicationEx app = ApplicationManagerEx.getApplicationEx(); if (app.isRestartCapable()) { app.restart(); @@ -121,4 +122,12 @@ public abstract class AbstractUpdateDialog extends DialogWrapper { if (myUploadedPlugins != null) UpdateChecker.install(myUploadedPlugins); //update on restart super.doCancelAction(); } + + public void setShowConfirmation(boolean showConfirmation) { + myShowConfirmation = showConfirmation; + } + + public boolean isShowConfirmation() { + return myShowConfirmation; + } } \ No newline at end of file diff --git a/platform/platform-impl/src/com/intellij/openapi/updateSettings/impl/CheckForUpdateAction.java b/platform/platform-impl/src/com/intellij/openapi/updateSettings/impl/CheckForUpdateAction.java index 7ce314b11cdd..0d131f1ef3ed 100644 --- a/platform/platform-impl/src/com/intellij/openapi/updateSettings/impl/CheckForUpdateAction.java +++ b/platform/platform-impl/src/com/intellij/openapi/updateSettings/impl/CheckForUpdateAction.java @@ -1,5 +1,5 @@ /* - * Copyright 2000-2009 JetBrains s.r.o. + * Copyright 2000-2010 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. @@ -44,7 +44,7 @@ public class CheckForUpdateAction extends AnAction implements DumbAware { UpdateChecker.showUpdateInfoDialog(enableLink, newVersion, updatedPlugins); } else { - UpdateChecker.showNoUpdatesDialog(enableLink, updatedPlugins); + UpdateChecker.showNoUpdatesDialog(enableLink, updatedPlugins, true); } } catch (ConnectionException e) { diff --git a/platform/platform-impl/src/com/intellij/openapi/updateSettings/impl/NoUpdatesDialog.java b/platform/platform-impl/src/com/intellij/openapi/updateSettings/impl/NoUpdatesDialog.java index b7ba16704a85..85a714e5a375 100644 --- a/platform/platform-impl/src/com/intellij/openapi/updateSettings/impl/NoUpdatesDialog.java +++ b/platform/platform-impl/src/com/intellij/openapi/updateSettings/impl/NoUpdatesDialog.java @@ -1,5 +1,5 @@ /* - * Copyright 2000-2009 JetBrains s.r.o. + * Copyright 2000-2010 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. @@ -27,7 +27,6 @@ import java.util.List; * @author pti */ class NoUpdatesDialog extends AbstractUpdateDialog { - protected NoUpdatesDialog(final boolean canBeParent, final List updatePlugins, boolean enableLink) { super(canBeParent, enableLink, updatePlugins); setTitle(IdeBundle.message("updates.info.dialog.title")); @@ -54,14 +53,14 @@ class NoUpdatesDialog extends AbstractUpdateDialog { @Override protected boolean doDownloadAndPrepare() { boolean hasSmthToUpdate = super.doDownloadAndPrepare(); - if (hasSmthToUpdate && + if (hasSmthToUpdate && isShowConfirmation() && Messages.showYesNoDialog(IdeBundle.message("message.idea.restart.required", ApplicationNamesInfo.getInstance().getProductName()), IdeBundle.message("title.plugins"), Messages.getQuestionIcon()) != 0) { hasSmthToUpdate = false; } return hasSmthToUpdate; } - + private class NoUpdatesPanel { private JPanel myPanel; private JPanel myPluginsPanel; diff --git a/platform/platform-impl/src/com/intellij/openapi/updateSettings/impl/UpdateChecker.java b/platform/platform-impl/src/com/intellij/openapi/updateSettings/impl/UpdateChecker.java index e3f39d7b317b..048b9a60a07c 100644 --- a/platform/platform-impl/src/com/intellij/openapi/updateSettings/impl/UpdateChecker.java +++ b/platform/platform-impl/src/com/intellij/openapi/updateSettings/impl/UpdateChecker.java @@ -1,5 +1,5 @@ /* - * Copyright 2000-2009 JetBrains s.r.o. + * Copyright 2000-2010 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. @@ -83,6 +83,9 @@ public final class UpdateChecker { public static String ADDITIONAL_REQUEST_OPTIONS = ""; + private UpdateChecker() { + } + public static enum DownloadPatchResult { SUCCESS, FAILED, CANCELED } @@ -117,11 +120,13 @@ public final class UpdateChecker { } public static boolean checkNeeded() { - final UpdateSettings settings = UpdateSettings.getInstance(); if (settings == null || getUpdateUrl() == null) return false; final String checkPeriod = settings.CHECK_PERIOD; + if (checkPeriod.equals(UpdateSettingsConfigurable.ON_EXIT)) { + return false; + } if (checkPeriod.equals(UpdateSettingsConfigurable.ON_START_UP)) { checkInterval = 0; } @@ -375,8 +380,9 @@ public final class UpdateChecker { return document[0]; } - public static void showNoUpdatesDialog(boolean enableLink, final List updatePlugins) { + public static void showNoUpdatesDialog(boolean enableLink, final List updatePlugins, boolean showConfirmation) { NoUpdatesDialog dialog = new NoUpdatesDialog(true, updatePlugins, enableLink); + dialog.setShowConfirmation(showConfirmation); dialog.show(); } diff --git a/platform/platform-impl/src/com/intellij/openapi/updateSettings/impl/UpdateSettings.java b/platform/platform-impl/src/com/intellij/openapi/updateSettings/impl/UpdateSettings.java index 06d96d2d9f3b..df6fd65e158a 100644 --- a/platform/platform-impl/src/com/intellij/openapi/updateSettings/impl/UpdateSettings.java +++ b/platform/platform-impl/src/com/intellij/openapi/updateSettings/impl/UpdateSettings.java @@ -1,5 +1,5 @@ /* - * Copyright 2000-2009 JetBrains s.r.o. + * Copyright 2000-2010 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. @@ -73,4 +73,8 @@ public class UpdateSettings implements PersistentStateComponent { LOG.info(e); } } + + public boolean isUpdateOnExit() { + return UpdateSettingsConfigurable.ON_EXIT.equals(CHECK_PERIOD); + } } diff --git a/platform/platform-impl/src/com/intellij/openapi/updateSettings/impl/UpdateSettingsConfigurable.java b/platform/platform-impl/src/com/intellij/openapi/updateSettings/impl/UpdateSettingsConfigurable.java index e6aaf219f12d..876b9c19f9ff 100644 --- a/platform/platform-impl/src/com/intellij/openapi/updateSettings/impl/UpdateSettingsConfigurable.java +++ b/platform/platform-impl/src/com/intellij/openapi/updateSettings/impl/UpdateSettingsConfigurable.java @@ -1,5 +1,5 @@ /* - * Copyright 2000-2009 JetBrains s.r.o. + * Copyright 2000-2010 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. @@ -52,6 +52,7 @@ public class UpdateSettingsConfigurable extends BaseConfigurable implements Sear @NonNls public static final String DAILY = "Daily"; @NonNls public static final String WEEKLY = "Weekly"; @NonNls public static final String MONTHLY = "Monthly"; + @NonNls public static final String ON_EXIT = "On every exit"; private static final Map PERIOD_VALUE_MAP = new HashMap(); static { @@ -59,6 +60,7 @@ public class UpdateSettingsConfigurable extends BaseConfigurable implements Sear PERIOD_VALUE_MAP.put(DAILY, IdeBundle.message("updates.check.period.daily")); PERIOD_VALUE_MAP.put(WEEKLY, IdeBundle.message("updates.check.period.weekly")); PERIOD_VALUE_MAP.put(MONTHLY, IdeBundle.message("updates.check.period.monthly")); + PERIOD_VALUE_MAP.put(ON_EXIT, IdeBundle.message("updates.check.period.on.exit")); } public JComponent createComponent() { @@ -150,6 +152,7 @@ public class UpdateSettingsConfigurable extends BaseConfigurable implements Sear myPeriodCombo.addItem(DAILY); myPeriodCombo.addItem(WEEKLY); myPeriodCombo.addItem(MONTHLY); + myPeriodCombo.addItem(ON_EXIT); myPeriodCombo.setRenderer(new MappingListCellRenderer(PERIOD_VALUE_MAP)); diff --git a/platform/platform-resources-en/src/messages/IdeBundle.properties b/platform/platform-resources-en/src/messages/IdeBundle.properties index 893fe5e91a2f..0a8e3f8fade9 100644 --- a/platform/platform-resources-en/src/messages/IdeBundle.properties +++ b/platform/platform-resources-en/src/messages/IdeBundle.properties @@ -1059,4 +1059,5 @@ FileChooser.listViewActionLabelText=List FileChooser.detailsViewActionLabelText=Details FileChooser.refreshActionLabelText=Refresh browsers.settings=Web Browsers +updates.check.period.on.exit=On every exit