add "don't ask option" when ask to change dark/bright editor theme appcode/163.1863 clion/163.1866 dbe/163.1865 idea/163.1864 idea/163.1868 phpstorm/163.1867 pycharm/163.1872 pycharm/163.1877 rubymine/163.1870 webstorm/163.1875 webstorm/163.1876
authorKonstantin Bulenkov <kb@jetbrains.com>
Mon, 25 Jul 2016 00:55:52 +0000 (02:55 +0200)
committerKonstantin Bulenkov <kb@jetbrains.com>
Mon, 25 Jul 2016 00:55:52 +0000 (02:55 +0200)
platform/lang-impl/src/com/intellij/application/options/colors/ColorAndFontOptions.java

index 8b943bcb5776622a06247a973f31aa2bfff2c727..549f49d9c473f3a1b7b7c1dece0f4f154315e9fe 100644 (file)
@@ -23,9 +23,10 @@ import com.intellij.ide.ui.LafManager;
 import com.intellij.ide.ui.laf.LafManagerImpl;
 import com.intellij.ide.ui.laf.darcula.DarculaInstaller;
 import com.intellij.ide.ui.laf.darcula.DarculaLookAndFeelInfo;
+import com.intellij.ide.util.PropertiesComponent;
 import com.intellij.openapi.Disposable;
 import com.intellij.openapi.application.ApplicationBundle;
-import com.intellij.openapi.application.ex.ApplicationInfoEx;
+import com.intellij.openapi.application.ApplicationNamesInfo;
 import com.intellij.openapi.diagnostic.Logger;
 import com.intellij.openapi.editor.colors.ColorKey;
 import com.intellij.openapi.editor.colors.EditorColorsManager;
@@ -42,6 +43,7 @@ import com.intellij.openapi.options.SearchableConfigurable;
 import com.intellij.openapi.options.colors.*;
 import com.intellij.openapi.project.Project;
 import com.intellij.openapi.project.ProjectManager;
+import com.intellij.openapi.ui.DialogWrapper;
 import com.intellij.openapi.ui.Messages;
 import com.intellij.openapi.util.Comparing;
 import com.intellij.openapi.util.Disposer;
@@ -265,28 +267,8 @@ public class ColorAndFontOptions extends SearchableConfigurable.Parent.Abstract
         EditorColorsManagerImpl.schemeChangedOrSwitched();
       }
 
-      final boolean dark = ColorUtil.isDark(activeOriginalScheme.getDefaultBackground());
-      final String productName = ApplicationInfoEx.getInstanceEx().getFullApplicationName();
-      final LafManager lafManager = LafManager.getInstance();
-      if (dark && !UIUtil.isUnderDarcula()) {
-        if (Messages.showYesNoDialog(
-          "Looks like you have set a dark editor theme. Would you like to set dark theme for entire " + productName,
-          "Change " + productName + " theme?",
-          Messages.getQuestionIcon()) == Messages.YES) {
-          lafManager.setCurrentLookAndFeel(new DarculaLookAndFeelInfo());
-          DarculaInstaller.install();
-        }
-      } else if (!dark && UIUtil.isUnderDarcula()) {
-        if (lafManager instanceof LafManagerImpl
-            &&
-            Messages.showYesNoDialog(
-              "Looks like you have set a bright editor theme. Would you like to set bright theme for entire " + productName,
-              "Change " + productName + " theme",
-              Messages.getQuestionIcon()) == Messages.YES) {
-          lafManager.setCurrentLookAndFeel(((LafManagerImpl)lafManager).getDefaultLaf());
-          DarculaInstaller.uninstall();
-        }
-      }
+      final boolean isEditorThemeDark = ColorUtil.isDark(activeOriginalScheme.getDefaultBackground());
+      changeLafIfNecessary(isEditorThemeDark);
 
       reset();
     }
@@ -295,6 +277,53 @@ public class ColorAndFontOptions extends SearchableConfigurable.Parent.Abstract
     }
   }
 
+  private static void changeLafIfNecessary(boolean isDarkEditorTheme) {
+    String propKey = "change.laf.on.editor.theme.change";
+    String value = PropertiesComponent.getInstance().getValue(propKey);
+    if ("false".equals(value)) return;
+    boolean applyAlways = "true".equals(value);
+    DialogWrapper.DoNotAskOption doNotAskOption = new DialogWrapper.DoNotAskOption.Adapter() {
+      @Override
+      public void rememberChoice(boolean isSelected, int exitCode) {
+        if (isSelected) {
+          PropertiesComponent.getInstance().setValue(propKey, Boolean.toString(exitCode == Messages.YES));
+        }
+      }
+
+      @Override
+      public boolean shouldSaveOptionsOnCancel() {
+        return true;
+      }
+    };
+
+    final String productName = ApplicationNamesInfo.getInstance().getFullProductName();
+    final LafManager lafManager = LafManager.getInstance();
+    if (isDarkEditorTheme && !UIUtil.isUnderDarcula()) {
+      if (applyAlways || Messages.showYesNoDialog(
+        "Looks like you have set a dark editor theme. Would you like to set dark theme for entire " + productName,
+        "Change " + productName + " theme", Messages.YES_BUTTON, Messages.NO_BUTTON,
+        Messages.getQuestionIcon(), doNotAskOption) == Messages.YES) {
+        lafManager.setCurrentLookAndFeel(new DarculaLookAndFeelInfo());
+        lafManager.updateUI();
+        //noinspection SSBasedInspection
+        SwingUtilities.invokeLater(DarculaInstaller::install);
+      }
+    } else if (!isDarkEditorTheme && UIUtil.isUnderDarcula()) {
+
+      if (lafManager instanceof LafManagerImpl
+          &&
+          (applyAlways || Messages.showYesNoDialog(
+            "Looks like you have set a bright editor theme. Would you like to set bright theme for entire " + productName,
+            "Change " + productName + " theme", Messages.YES_BUTTON, Messages.NO_BUTTON,
+            Messages.getQuestionIcon(), doNotAskOption) == Messages.YES)) {
+        lafManager.setCurrentLookAndFeel(((LafManagerImpl)lafManager).getDefaultLaf());
+        lafManager.updateUI();
+        //noinspection SSBasedInspection
+        SwingUtilities.invokeLater(DarculaInstaller::uninstall);
+      }
+    }
+  }
+
   private boolean myIsReset = false;
 
   private void resetSchemesCombo(Object source) {