Revert "PY-22514, CPP-8763, and Idea ultimate test failures: run initial"
[idea/community.git] / python / src / com / jetbrains / python / PyCharmInitialConfigurator.java
1 /*
2  * Copyright 2000-2017 JetBrains s.r.o.
3  *
4  * Licensed under the Apache License, Version 2.0 (the "License");
5  * you may not use this file except in compliance with the License.
6  * You may obtain a copy of the License at
7  *
8  * http://www.apache.org/licenses/LICENSE-2.0
9  *
10  * Unless required by applicable law or agreed to in writing, software
11  * distributed under the License is distributed on an "AS IS" BASIS,
12  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13  * See the License for the specific language governing permissions and
14  * limitations under the License.
15  */
16 package com.jetbrains.python;
17
18 import com.intellij.application.options.InitialConfigurationDialog;
19 import com.intellij.codeInsight.CodeInsightSettings;
20 import com.intellij.ide.AppLifecycleListener;
21 import com.intellij.ide.ui.UISettings;
22 import com.intellij.ide.util.PropertiesComponent;
23 import com.intellij.openapi.application.ApplicationManager;
24 import com.intellij.openapi.editor.ex.EditorSettingsExternalizable;
25 import com.intellij.openapi.fileTypes.FileTypeManager;
26 import com.intellij.openapi.util.registry.Registry;
27 import com.intellij.openapi.wm.WindowManager;
28 import com.intellij.psi.codeStyle.CodeStyleSettings;
29 import com.intellij.psi.codeStyle.CodeStyleSettingsManager;
30 import com.intellij.util.messages.MessageBus;
31 import com.jetbrains.python.codeInsight.PyCodeInsightSettings;
32 import com.jetbrains.python.testing.universalTests.PyUniversalTestLegacyInteropKt;
33 import org.jetbrains.annotations.NonNls;
34
35 import javax.swing.*;
36
37 /**
38  * @author yole
39  */
40 @SuppressWarnings({"UtilityClassWithoutPrivateConstructor", "UtilityClassWithPublicConstructor"})
41 public final class PyCharmInitialConfigurator {
42   @NonNls private static final String DISPLAYED_PROPERTY = "PyCharm.initialConfigurationShown";
43
44   public PyCharmInitialConfigurator(MessageBus bus, final PropertiesComponent propertiesComponent, final FileTypeManager fileTypeManager) {
45     if (!propertiesComponent.getBoolean("PyCharm.InitialConfiguration")) {
46       propertiesComponent.setValue("PyCharm.InitialConfiguration", "true");
47       EditorSettingsExternalizable.getInstance().setVirtualSpace(false);
48     }
49     if (!propertiesComponent.getBoolean("PyCharm.InitialConfiguration.V2")) {
50       propertiesComponent.setValue("PyCharm.InitialConfiguration.V2", true);
51       final CodeStyleSettings settings = CodeStyleSettingsManager.getInstance().getCurrentSettings();
52       settings.ALIGN_MULTILINE_PARAMETERS_IN_CALLS = true;
53       settings.getCommonSettings(PythonLanguage.getInstance()).ALIGN_MULTILINE_PARAMETERS_IN_CALLS = true;
54       UISettings.getInstance().SHOW_DIRECTORY_FOR_NON_UNIQUE_FILENAMES = true;
55     }
56     if (!propertiesComponent.getBoolean("PyCharm.InitialConfiguration.V3")) {
57       propertiesComponent.setValue("PyCharm.InitialConfiguration.V3", "true");
58       UISettings.getInstance().setShowMemoryIndicator(false);
59       final String ignoredFilesList = fileTypeManager.getIgnoredFilesList();
60       ApplicationManager.getApplication().invokeLater(() -> ApplicationManager.getApplication().runWriteAction(() -> FileTypeManager.getInstance().setIgnoredFilesList(ignoredFilesList + ";*$py.class")));
61     }
62     if (!propertiesComponent.getBoolean("PyCharm.InitialConfiguration.V4")) {
63       propertiesComponent.setValue("PyCharm.InitialConfiguration.V4", true);
64       PyCodeInsightSettings.getInstance().SHOW_IMPORT_POPUP = false;
65     }
66     if (!propertiesComponent.getBoolean("PyCharm.InitialConfiguration.V5")) {
67       propertiesComponent.setValue("PyCharm.InitialConfiguration.V5", true);
68       CodeInsightSettings.getInstance().REFORMAT_ON_PASTE = CodeInsightSettings.NO_REFORMAT;
69     }
70     if (!propertiesComponent.getBoolean("PyCharm.InitialConfiguration.V6")) {
71       propertiesComponent.setValue("PyCharm.InitialConfiguration.V6", true);
72       CodeInsightSettings.getInstance().INDENT_TO_CARET_ON_PASTE = true;
73     }
74
75     if (!propertiesComponent.isValueSet(DISPLAYED_PROPERTY)) {
76       bus.connect().subscribe(AppLifecycleListener.TOPIC, new AppLifecycleListener() {
77         @Override
78         public void welcomeScreenDisplayed() {
79           ApplicationManager.getApplication().invokeLater(() -> {
80             propertiesComponent.setValue(DISPLAYED_PROPERTY, "true");
81             showInitialConfigurationDialog();
82           });
83         }
84       });
85     }
86
87     Registry.get("ide.scratch.enabled").setValue(true);
88
89
90     /*
91     According to PyUniversalTestLegacyInteropKt we need to call "init"
92      */
93     PyUniversalTestLegacyInteropKt.init(bus);
94   }
95
96   private static void showInitialConfigurationDialog() {
97     final JFrame frame = WindowManager.getInstance().findVisibleFrame();
98     new InitialConfigurationDialog(frame, "Python").show();
99   }
100 }