mirror of
https://gitflic.ru/project/openide/openide.git
synced 2026-09-27 10:03:11 +07:00
Update on exit option
This commit is contained in:
@@ -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<PluginDownloader> 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<PluginDownloader> 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() {
|
||||
|
||||
+11
-2
@@ -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<PluginDownloader> myUploadedPlugins;
|
||||
protected boolean myShowConfirmation = true;
|
||||
|
||||
protected AbstractUpdateDialog(boolean canBeParent, boolean enableLink, final List<PluginDownloader> 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;
|
||||
}
|
||||
}
|
||||
+2
-2
@@ -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) {
|
||||
|
||||
+3
-4
@@ -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<PluginDownloader> 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;
|
||||
|
||||
+9
-3
@@ -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<PluginDownloader> updatePlugins) {
|
||||
public static void showNoUpdatesDialog(boolean enableLink, final List<PluginDownloader> updatePlugins, boolean showConfirmation) {
|
||||
NoUpdatesDialog dialog = new NoUpdatesDialog(true, updatePlugins, enableLink);
|
||||
dialog.setShowConfirmation(showConfirmation);
|
||||
dialog.show();
|
||||
}
|
||||
|
||||
|
||||
+5
-1
@@ -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<Element> {
|
||||
LOG.info(e);
|
||||
}
|
||||
}
|
||||
|
||||
public boolean isUpdateOnExit() {
|
||||
return UpdateSettingsConfigurable.ON_EXIT.equals(CHECK_PERIOD);
|
||||
}
|
||||
}
|
||||
|
||||
+4
-1
@@ -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<Object, String> PERIOD_VALUE_MAP = new HashMap<Object, String>();
|
||||
|
||||
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));
|
||||
|
||||
|
||||
@@ -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
|
||||
|
||||
|
||||
Reference in New Issue
Block a user