public ExternalAnnotationsManagerImpl(
      @NotNull final Project project, final PsiManager psiManager) {
    super(psiManager);
    myBus = project.getMessageBus();
    final MessageBusConnection connection = myBus.connect(project);
    connection.subscribe(
        ProjectTopics.PROJECT_ROOTS,
        new ModuleRootAdapter() {
          @Override
          public void rootsChanged(ModuleRootEvent event) {
            dropCache();
          }
        });

    final MyVirtualFileListener fileListener = new MyVirtualFileListener();
    VirtualFileManager.getInstance().addVirtualFileListener(fileListener);
    Disposer.register(
        myPsiManager.getProject(),
        new Disposable() {
          @Override
          public void dispose() {
            VirtualFileManager.getInstance().removeVirtualFileListener(fileListener);
          }
        });
  }
  private void upgradeIfNeeded(final MessageBus bus) {
    final MessageBusConnection connection = bus.connect();
    connection.subscribe(
        ChangeListManagerImpl.LISTS_LOADED,
        new LocalChangeListsLoadedListener() {
          @Override
          public void processLoadedLists(final List<LocalChangeList> lists) {
            if (lists.isEmpty()) return;
            SvnConfiguration.SvnSupportOptions supportOptions = null;
            try {
              ChangeListManager.getInstance(myProject)
                  .setReadOnly(SvnChangeProvider.ourDefaultListName, true);
              supportOptions = myConfiguration.getSupportOptions(myProject);

              if (!supportOptions.changeListsSynchronized()) {
                processChangeLists(lists);
              }
            } catch (ProcessCanceledException e) {
              //
            } finally {
              if (supportOptions != null) {
                supportOptions.upgrade();
              }
            }

            connection.disconnect();
          }
        });
  }
  private void onAppClosing() {
    final MessageBus messageBus = ApplicationManager.getApplication().getMessageBus();

    messageBus
        .connect()
        .subscribe(
            AppLifecycleListener.TOPIC,
            new AppLifecycleListener() {
              @Override
              public void appFrameCreated(
                  String[] commandLineArgs, @NotNull Ref<Boolean> willOpenProject) {}

              @Override
              public void appStarting(Project projectFromCommandLine) {}

              @Override
              public void projectFrameClosed() {}

              @Override
              public void projectOpenFailed() {}

              @Override
              public void welcomeScreenDisplayed() {}

              @Override
              public void appClosing() {
                for (Project project : ProjectManager.getInstance().getOpenProjects()) {
                  if (project.isInitialized()) {
                    doPersistProjectUsages(project);
                  }
                }
                persistOnClosing = false;
              }
            });
  }
  public void initComponent() {
    log.info("Initializing WakaTime plugin v" + VERSION + " (https://wakatime.com/)");
    // System.out.println("Initializing WakaTime plugin v" + VERSION + " (https://wakatime.com/)");

    // Set runtime constants
    IDE_NAME = PlatformUtils.getPlatformPrefix();
    IDE_VERSION = ApplicationInfo.getInstance().getFullVersion();

    if (!Dependencies.isCLIInstalled()) {
      log.info("Downloading and installing wakatime-cli ...");
      Dependencies.installCLI();
    } else if (Dependencies.isCLIOld()) {
      log.info("Upgrading wakatime-cli ...");
      Dependencies.upgradeCLI();
    }

    if (Dependencies.isPythonInstalled()) {

      WakaTime.DEBUG = WakaTime.isDebugEnabled();
      if (WakaTime.DEBUG) {
        log.setLevel(Level.DEBUG);
        log.debug("Logging level set to DEBUG");
      }

      log.debug("Python location: " + Dependencies.getPythonLocation());
      log.debug("CLI location: " + Dependencies.getCLILocation());

      // prompt for apiKey if it does not already exist
      if (ApiKey.getApiKey().equals("")) {
        Project project = ProjectManager.getInstance().getDefaultProject();
        ApiKey apiKey = new ApiKey(project);
        apiKey.promptForApiKey();
      }
      log.debug("Api Key: " + ApiKey.getApiKey());

      // add WakaTime item to File menu
      ActionManager am = ActionManager.getInstance();
      PluginMenu action = new PluginMenu();
      am.registerAction("WakaTimeApiKey", action);
      DefaultActionGroup fileMenu = (DefaultActionGroup) am.getAction("FileMenu");
      fileMenu.addSeparator();
      fileMenu.add(action);

      // Setup message listeners
      MessageBus bus = ApplicationManager.getApplication().getMessageBus();
      connection = bus.connect();
      connection.subscribe(AppTopics.FILE_DOCUMENT_SYNC, new CustomSaveListener());
      EditorFactory.getInstance()
          .getEventMulticaster()
          .addDocumentListener(new CustomDocumentListener());

      log.debug("Finished initializing WakaTime plugin");

    } else {
      Messages.showErrorDialog(
          "WakaTime requires Python to be installed.\nYou can install it from https://www.python.org/downloads/\nAfter installing Python, restart your IDE.",
          "Error");
    }
  }
 VirtualFilePointerManagerImpl(
     @NotNull VirtualFileManager virtualFileManager,
     @NotNull MessageBus bus,
     @NotNull TempFileSystem tempFileSystem,
     @NotNull LocalFileSystem localFileSystem) {
   myVirtualFileManager = virtualFileManager;
   myBus = bus;
   bus.connect().subscribe(VirtualFileManager.VFS_CHANGES, this);
   myTempFileSystem = tempFileSystem;
   myLocalFileSystem = localFileSystem;
 }
 public TodoIndex(MessageBus messageBus) {
   messageBus
       .connect()
       .subscribe(
           IndexPatternProvider.INDEX_PATTERNS_CHANGED,
           new PropertyChangeListener() {
             @Override
             public void propertyChange(PropertyChangeEvent evt) {
               FileBasedIndex.requestRebuild(NAME);
             }
           });
 }
 VirtualFilePointerManagerImpl(
     @NotNull VirtualFileManager virtualFileManager,
     @NotNull MessageBus bus,
     @NotNull TempFileSystem tempFileSystem,
     @NotNull LocalFileSystem localFileSystem,
     @NotNull JarFileSystem jarFileSystem) {
   myVirtualFileManager = virtualFileManager;
   myBus = bus;
   bus.connect().subscribe(VirtualFileManager.VFS_CHANGES, this);
   TEMP_FILE_SYSTEM = tempFileSystem;
   LOCAL_FILE_SYSTEM = localFileSystem;
   JAR_FILE_SYSTEM = jarFileSystem;
 }
 public ResolveCache(@NotNull MessageBus messageBus) {
   for (int i = 0; i < myMaps.length; i++) {
     myMaps[i] = createWeakMap();
   }
   messageBus
       .connect()
       .subscribe(
           PsiManagerImpl.ANY_PSI_CHANGE_TOPIC,
           new AnyPsiChangeListener.Adapter() {
             @Override
             public void beforePsiChanged(boolean isPhysical) {
               clearCache(isPhysical);
             }
           });
 }
  public ProjectLevelVcsManagerImpl(
      Project project,
      final FileStatusManager manager,
      MessageBus messageBus,
      final FileIndexFacade excludedFileIndex) {
    myProject = project;
    myMessageBus = messageBus;
    mySerialization = new ProjectLevelVcsManagerSerialization();
    myOptionsAndConfirmations = new OptionsAndConfirmations();

    myDefaultVcsRootPolicy = DefaultVcsRootPolicy.getInstance(project);

    myBackgroundableActionHandlerMap =
        new EnumMap<VcsBackgroundableActions, BackgroundableActionEnabledHandler>(
            VcsBackgroundableActions.class);
    myInitialization = new VcsInitialization(myProject);
    myMappings = new NewMappings(myProject, myMessageBus, this, manager);
    myMappingsToRoots = new MappingsToRoots(myMappings, myProject);

    if (!myProject.isDefault()) {
      myVcsEventListenerManager = new VcsEventsListenerManagerImpl();
    }

    myVcsHistoryCache = new VcsHistoryCache();
    myContentRevisionCache = new ContentRevisionCache();
    myConnect = myMessageBus.connect();
    myVcsFileListenerContextHelper = VcsFileListenerContextHelper.getInstance(myProject);
    VcsListener vcsListener =
        new VcsListener() {
          @Override
          public void directoryMappingChanged() {
            myVcsHistoryCache.clear();
            myVcsFileListenerContextHelper.possiblySwitchActivation(hasActiveVcss());
          }
        };
    myExcludedIndex = excludedFileIndex;
    myConnect.subscribe(ProjectLevelVcsManager.VCS_CONFIGURATION_CHANGED, vcsListener);
    myConnect.subscribe(ProjectLevelVcsManager.VCS_CONFIGURATION_CHANGED_IN_PLUGIN, vcsListener);
    myConnect.subscribe(
        UpdatedFilesListener.UPDATED_FILES,
        new UpdatedFilesListener() {
          @Override
          public void consume(Set<String> strings) {
            myContentRevisionCache.clearCurrent(strings);
          }
        });
    myAnnotationLocalChangesListener = new VcsAnnotationLocalChangesListenerImpl(myProject, this);
  }
Beispiel #10
0
  @Override
  public void registerRunnableToRunOnChange(@NotNull final Runnable runnable) {
    myMessageBus
        .connect()
        .subscribe(
            ANY_PSI_CHANGE_TOPIC,
            new AnyPsiChangeListener() {
              @Override
              public void beforePsiChanged(boolean isPhysical) {
                if (isPhysical) runnable.run();
              }

              @Override
              public void afterPsiChanged(boolean isPhysical) {}
            });
  }
Beispiel #11
0
  @Override
  public void registerRunnableToRunAfterAnyChange(
      @NotNull final Runnable runnable) { // includes non-physical changes
    myMessageBus
        .connect()
        .subscribe(
            ANY_PSI_CHANGE_TOPIC,
            new AnyPsiChangeListener() {
              @Override
              public void beforePsiChanged(boolean isPhysical) {}

              @Override
              public void afterPsiChanged(boolean isPhysical) {
                runnable.run();
              }
            });
  }
Beispiel #12
0
  public void addRequest(final Runnable request, final int delay, boolean runWithActiveFrameOnly) {
    if (runWithActiveFrameOnly && !ApplicationManager.getApplication().isActive()) {
      final MessageBus bus = ApplicationManager.getApplication().getMessageBus();
      final MessageBusConnection connection = bus.connect(this);
      connection.subscribe(
          ApplicationActivationListener.TOPIC,
          new ApplicationActivationListener() {
            @Override
            public void applicationActivated(IdeFrame ideFrame) {
              connection.disconnect();
              addRequest(request, delay);
            }

            @Override
            public void applicationDeactivated(IdeFrame ideFrame) {}
          });
    } else {
      addRequest(request, delay);
    }
  }
  public JavaResolveCache(
      @Nullable(
              "can be null in com.intellij.core.JavaCoreApplicationEnvironment.JavaCoreApplicationEnvironment")
          MessageBus messageBus) {
    if (messageBus != null) {
      messageBus
          .connect()
          .subscribe(
              PsiManagerImpl.ANY_PSI_CHANGE_TOPIC,
              new AnyPsiChangeListener() {
                @Override
                public void beforePsiChanged(boolean isPhysical) {
                  clearCaches(isPhysical);
                }

                @Override
                public void afterPsiChanged(boolean isPhysical) {}
              });
    }
  }
Beispiel #14
0
  private void installListeners() {
    FileStatusManager.getInstance(myProject)
        .addFileStatusListener(myFileStatusListener = new FileStatusChangeListener());
    VirtualFileManager.getInstance()
        .addVirtualFileListener(myFileListener = new FileChangesListener());
    VirtualFileManager.getInstance()
        .addVirtualFileManagerListener(myVirtualFileManagerListener = new RefreshListener());
    myDirectoryMappingListener =
        new VcsListener() {
          public void directoryMappingChanged() {
            rebuildTreeLater();
          }
        };
    myProject.getComponent(ProjectLevelVcsManager.class).addVcsListener(myDirectoryMappingListener);
    ChangeListManager.getInstance(myProject)
        .addChangeListListener(myChangeListListener = new ChangeListUpdateListener());
    myMessageBusConnection = myBus.connect();
    myMessageBusConnection.subscribe(
        FileEditorManagerListener.FILE_EDITOR_MANAGER,
        new FileEditorManagerAdapter() {
          @Override
          public void fileOpened(FileEditorManager source, VirtualFile file) {
            if (myProjectView.isAutoscrollFromSource(getId())) {
              selectNode(file, false);
            }
          }

          @Override
          public void selectionChanged(FileEditorManagerEvent event) {
            if (myProjectView.isAutoscrollFromSource(getId())) {
              VirtualFile newFile = event.getNewFile();
              if (newFile != null) {
                selectNode(newFile, false);
              }
            }
          }
        });
  }
  protected PsiDocumentManagerBase(
      @NotNull final Project project,
      @NotNull PsiManager psiManager,
      @NotNull MessageBus bus,
      @NonNls @NotNull final DocumentCommitProcessor documentCommitProcessor) {
    myProject = project;
    myPsiManager = psiManager;
    myDocumentCommitProcessor = documentCommitProcessor;
    mySynchronizer = new PsiToDocumentSynchronizer(this, bus);
    myPsiManager.addPsiTreeChangeListener(mySynchronizer);
    bus.connect()
        .subscribe(
            PsiDocumentTransactionListener.TOPIC,
            new PsiDocumentTransactionListener() {
              @Override
              public void transactionStarted(@NotNull Document document, @NotNull PsiFile file) {
                myUncommittedDocuments.remove(document);
              }

              @Override
              public void transactionCompleted(@NotNull Document document, @NotNull PsiFile file) {}
            });
  }
  public KotlinJavaPsiFacade(@NotNull Project project) {
    this.project = project;

    final PsiModificationTracker modificationTracker =
        PsiManager.getInstance(project).getModificationTracker();
    MessageBus bus = project.getMessageBus();

    bus.connect()
        .subscribe(
            PsiModificationTracker.TOPIC,
            new PsiModificationTracker.Listener() {
              private long lastTimeSeen = -1L;

              @Override
              public void modificationCountChanged() {
                long now = modificationTracker.getJavaStructureModificationCount();
                if (lastTimeSeen != now) {
                  lastTimeSeen = now;

                  packageCache = null;
                }
              }
            });
  }
 VirtualFilePointerManagerImpl(
     @NotNull VirtualFileManagerEx virtualFileManagerEx, MessageBus bus) {
   myVirtualFileManager = virtualFileManagerEx;
   myBus = bus;
   bus.connect().subscribe(VirtualFileManager.VFS_CHANGES, new VFSEventsProcessor());
 }
 @Override
 public void addVcsListener(VcsListener listener) {
   final MessageBusConnection connection = myMessageBus.connect();
   connection.subscribe(VCS_CONFIGURATION_CHANGED, listener);
   myAdapters.put(listener, connection);
 }
  /** @noinspection UnusedParameters */
  public PyCharmEduInitialConfigurator(
      MessageBus bus,
      CodeInsightSettings codeInsightSettings,
      final PropertiesComponent propertiesComponent,
      FileTypeManager fileTypeManager,
      final ProjectManagerEx projectManager) {
    final UISettings uiSettings = UISettings.getInstance();
    if (!propertiesComponent.getBoolean(CONFIGURED_V2)) {
      EditorSettingsExternalizable editorSettings = EditorSettingsExternalizable.getInstance();
      editorSettings.setEnsureNewLineAtEOF(true);

      propertiesComponent.setValue(CONFIGURED_V2, true);
    }
    if (!propertiesComponent.getBoolean(CONFIGURED_V1)) {
      patchMainMenu();
      uiSettings.SHOW_NAVIGATION_BAR = false;
      propertiesComponent.setValue(CONFIGURED_V1, true);
      propertiesComponent.setValue("ShowDocumentationInToolWindow", true);
    }

    if (!propertiesComponent.getBoolean(CONFIGURED)) {
      propertiesComponent.setValue(CONFIGURED, "true");
      propertiesComponent.setValue("toolwindow.stripes.buttons.info.shown", "true");

      uiSettings.HIDE_TOOL_STRIPES = false;
      uiSettings.SHOW_MEMORY_INDICATOR = false;
      uiSettings.SHOW_DIRECTORY_FOR_NON_UNIQUE_FILENAMES = true;
      uiSettings.SHOW_MAIN_TOOLBAR = false;

      codeInsightSettings.REFORMAT_ON_PASTE = CodeInsightSettings.NO_REFORMAT;

      GeneralSettings.getInstance().setShowTipsOnStartup(false);

      EditorSettingsExternalizable.getInstance().setVirtualSpace(false);
      EditorSettingsExternalizable.getInstance().getOptions().ARE_LINE_NUMBERS_SHOWN = true;
      final CodeStyleSettings settings =
          CodeStyleSettingsManager.getInstance().getCurrentSettings();
      settings.ALIGN_MULTILINE_PARAMETERS_IN_CALLS = true;
      settings.getCommonSettings(PythonLanguage.getInstance()).ALIGN_MULTILINE_PARAMETERS_IN_CALLS =
          true;
      uiSettings.SHOW_DIRECTORY_FOR_NON_UNIQUE_FILENAMES = true;
      uiSettings.SHOW_MEMORY_INDICATOR = false;
      final String ignoredFilesList = fileTypeManager.getIgnoredFilesList();
      ApplicationManager.getApplication()
          .invokeLater(
              () ->
                  ApplicationManager.getApplication()
                      .runWriteAction(
                          () ->
                              FileTypeManager.getInstance()
                                  .setIgnoredFilesList(ignoredFilesList + ";*$py.class")));
      PyCodeInsightSettings.getInstance().SHOW_IMPORT_POPUP = false;
    }
    final EditorColorsScheme editorColorsScheme =
        EditorColorsManager.getInstance().getScheme(EditorColorsScheme.DEFAULT_SCHEME_NAME);
    editorColorsScheme.setEditorFontSize(14);

    if (!propertiesComponent.isValueSet(DISPLAYED_PROPERTY)) {

      bus.connect()
          .subscribe(
              AppLifecycleListener.TOPIC,
              new AppLifecycleListener() {
                @Override
                public void welcomeScreenDisplayed() {

                  ApplicationManager.getApplication()
                      .invokeLater(
                          () -> {
                            if (!propertiesComponent.isValueSet(DISPLAYED_PROPERTY)) {
                              GeneralSettings.getInstance().setShowTipsOnStartup(false);
                              propertiesComponent.setValue(DISPLAYED_PROPERTY, "true");

                              patchKeymap();
                            }
                          });
                }
              });
    }

    bus.connect()
        .subscribe(
            ProjectManager.TOPIC,
            new ProjectManagerAdapter() {
              @Override
              public void projectOpened(final Project project) {
                if (project.isDefault()) return;
                if (FileChooserUtil.getLastOpenedFile(project) == null) {
                  FileChooserUtil.setLastOpenedFile(project, VfsUtil.getUserHomeDir());
                }

                patchProjectAreaExtensions(project);

                StartupManager.getInstance(project)
                    .runWhenProjectIsInitialized(
                        new DumbAwareRunnable() {
                          @Override
                          public void run() {
                            if (project.isDisposed()) return;
                            updateInspectionsProfile();
                            openProjectStructure();
                          }

                          private void openProjectStructure() {
                            ToolWindowManager.getInstance(project)
                                .invokeLater(
                                    new Runnable() {
                                      int count = 0;

                                      public void run() {
                                        if (project.isDisposed()) return;
                                        if (count++
                                            < 3) { // we need to call this after
                                                   // ToolWindowManagerImpl.registerToolWindowsFromBeans
                                          ToolWindowManager.getInstance(project).invokeLater(this);
                                          return;
                                        }
                                        ToolWindow toolWindow =
                                            ToolWindowManager.getInstance(project)
                                                .getToolWindow("Project");
                                        if (toolWindow != null
                                            && toolWindow.getType() != ToolWindowType.SLIDING) {
                                          toolWindow.activate(null);
                                        }
                                      }
                                    });
                          }

                          private void updateInspectionsProfile() {
                            final String[] codes = new String[] {"W29", "E501"};
                            final VirtualFile baseDir = project.getBaseDir();
                            final PsiDirectory directory =
                                PsiManager.getInstance(project).findDirectory(baseDir);
                            if (directory != null) {
                              InspectionProjectProfileManager.getInstance(project)
                                  .getInspectionProfile()
                                  .modifyToolSettings(
                                      Key.<PyPep8Inspection>create(
                                          PyPep8Inspection.INSPECTION_SHORT_NAME),
                                      directory,
                                      inspection ->
                                          Collections.addAll(inspection.ignoredErrors, codes));
                            }
                          }
                        });
              }
            });
  }
  private void initListeners(@NotNull MessageBus messageBus, @NotNull PsiManager psiManager) {
    messageBus
        .connect()
        .subscribe(
            VirtualFileManager.VFS_CHANGES,
            new BulkFileListener.Adapter() {
              @Override
              public void after(@NotNull List<? extends VFileEvent> events) {
                fileCount.set(0);
                List<VirtualFile> files =
                    ContainerUtil.mapNotNull(
                        events,
                        new Function<VFileEvent, VirtualFile>() {
                          @Override
                          public VirtualFile fun(VFileEvent event) {
                            return event.getFile();
                          }
                        });
                queue(files, "VFS events " + events.size());
              }
            });
    psiManager.addPsiTreeChangeListener(
        new PsiTreeChangeAdapter() {
          @Override
          public void childrenChanged(@NotNull PsiTreeChangeEvent event) {
            PsiFile file = event.getFile();
            VirtualFile virtualFile = PsiUtilCore.getVirtualFile(file);
            if (virtualFile != null) {
              queue(Collections.singletonList(virtualFile), event);
            }
          }

          @Override
          public void propertyChanged(@NotNull PsiTreeChangeEvent event) {
            childrenChanged(event);
          }
        });

    messageBus
        .connect()
        .subscribe(
            DumbService.DUMB_MODE,
            new DumbService.DumbModeListener() {
              @Override
              public void enteredDumbMode() {
                disable();
              }

              @Override
              public void exitDumbMode() {
                enable();
              }
            });
    messageBus
        .connect()
        .subscribe(
            PowerSaveMode.TOPIC,
            new PowerSaveMode.Listener() {
              @Override
              public void powerSaveStateChanged() {
                if (PowerSaveMode.isEnabled()) {
                  enable();
                } else {
                  disable();
                }
              }
            });
    myApplication.addApplicationListener(
        new ApplicationAdapter() {
          @Override
          public void beforeWriteActionStart(@NotNull Object action) {
            disable();
          }

          @Override
          public void writeActionFinished(@NotNull Object action) {
            enable();
          }

          @Override
          public void applicationExiting() {
            disable();
          }
        },
        this);
    VirtualFileManager.getInstance()
        .addVirtualFileManagerListener(
            new VirtualFileManagerListener() {
              @Override
              public void beforeRefreshStart(boolean asynchronous) {
                disable();
              }

              @Override
              public void afterRefreshFinish(boolean asynchronous) {
                enable();
              }
            },
            this);
    HeavyProcessLatch.INSTANCE.addListener(
        new HeavyProcessLatch.HeavyProcessListener() {
          @Override
          public void processStarted() {}

          @Override
          public void processFinished() {
            wakeUp();
          }
        },
        this);
  }
  /** @noinspection UnusedParameters */
  public PyCharmEduInitialConfigurator(
      MessageBus bus,
      CodeInsightSettings codeInsightSettings,
      final PropertiesComponent propertiesComponent,
      FileTypeManager fileTypeManager,
      final ProjectManagerEx projectManager) {
    if (!propertiesComponent.getBoolean(CONFIGURED, false)) {
      propertiesComponent.setValue(CONFIGURED, "true");
      propertiesComponent.setValue("toolwindow.stripes.buttons.info.shown", "true");
      UISettings uiSettings = UISettings.getInstance();
      uiSettings.HIDE_TOOL_STRIPES = false;
      uiSettings.SHOW_MEMORY_INDICATOR = false;
      uiSettings.SHOW_DIRECTORY_FOR_NON_UNIQUE_FILENAMES = true;
      uiSettings.SHOW_MAIN_TOOLBAR = false;
      uiSettings.SHOW_NAVIGATION_BAR = false;
      codeInsightSettings.REFORMAT_ON_PASTE = CodeInsightSettings.NO_REFORMAT;

      Registry.get("ide.new.settings.dialog").setValue(true);

      GeneralSettings.getInstance().setShowTipsOnStartup(false);

      EditorSettingsExternalizable.getInstance().setVirtualSpace(false);
      EditorSettingsExternalizable.getInstance().getOptions().ARE_LINE_NUMBERS_SHOWN = true;
      final CodeStyleSettings settings =
          CodeStyleSettingsManager.getInstance().getCurrentSettings();
      settings.ALIGN_MULTILINE_PARAMETERS_IN_CALLS = true;
      settings.getCommonSettings(PythonLanguage.getInstance()).ALIGN_MULTILINE_PARAMETERS_IN_CALLS =
          true;
      uiSettings.SHOW_DIRECTORY_FOR_NON_UNIQUE_FILENAMES = true;
      uiSettings.SHOW_MEMORY_INDICATOR = false;
      final String ignoredFilesList = fileTypeManager.getIgnoredFilesList();
      ApplicationManager.getApplication()
          .invokeLater(
              new Runnable() {
                @Override
                public void run() {
                  ApplicationManager.getApplication()
                      .runWriteAction(
                          new Runnable() {
                            @Override
                            public void run() {
                              FileTypeManager.getInstance()
                                  .setIgnoredFilesList(ignoredFilesList + ";*$py.class");
                            }
                          });
                }
              });
      PyCodeInsightSettings.getInstance().SHOW_IMPORT_POPUP = false;
    }

    if (!propertiesComponent.isValueSet(DISPLAYED_PROPERTY)) {

      bus.connect()
          .subscribe(
              AppLifecycleListener.TOPIC,
              new AppLifecycleListener.Adapter() {
                @Override
                public void welcomeScreenDisplayed() {

                  ApplicationManager.getApplication()
                      .invokeLater(
                          new Runnable() {
                            @Override
                            public void run() {
                              if (!propertiesComponent.isValueSet(DISPLAYED_PROPERTY)) {
                                GeneralSettings.getInstance().setShowTipsOnStartup(false);
                                propertiesComponent.setValue(DISPLAYED_PROPERTY, "true");

                                patchKeymap();
                              }
                            }
                          });
                }
              });
    }

    bus.connect()
        .subscribe(
            ProjectManager.TOPIC,
            new ProjectManagerAdapter() {
              @Override
              public void projectOpened(final Project project) {
                if (project.isDefault()) return;
                if (FileChooserUtil.getLastOpenedFile(project) == null) {
                  FileChooserUtil.setLastOpenedFile(project, VfsUtil.getUserHomeDir());
                }

                patchProjectAreaExtensions(project);

                StartupManager.getInstance(project)
                    .runWhenProjectIsInitialized(
                        new DumbAwareRunnable() {
                          @Override
                          public void run() {
                            if (project.isDisposed()) return;

                            ToolWindowManager.getInstance(project)
                                .invokeLater(
                                    new Runnable() {
                                      int count = 0;

                                      public void run() {
                                        if (project.isDisposed()) return;
                                        if (count++
                                            < 3) { // we need to call this after
                                                   // ToolWindowManagerImpl.registerToolWindowsFromBeans
                                          ToolWindowManager.getInstance(project).invokeLater(this);
                                          return;
                                        }
                                        ToolWindow toolWindow =
                                            ToolWindowManager.getInstance(project)
                                                .getToolWindow("Project");
                                        if (toolWindow.getType() != ToolWindowType.SLIDING) {
                                          toolWindow.activate(null);
                                        }
                                      }
                                    });
                          }
                        });
              }
            });
  }
  /**
   * invoked by reflection
   *
   * @param dataManager
   * @param applicationInfoEx
   * @param actionManager
   * @param uiSettings
   */
  public WindowManagerImpl(
      DataManager dataManager,
      ApplicationInfoEx applicationInfoEx,
      ActionManagerEx actionManager,
      UISettings uiSettings,
      MessageBus bus) {
    myApplicationInfoEx = applicationInfoEx;
    myDataManager = dataManager;
    myActionManager = actionManager;
    myUiSettings = uiSettings;
    if (myDataManager instanceof DataManagerImpl) {
      ((DataManagerImpl) myDataManager).setWindowManager(this);
    }

    final Application application = ApplicationManager.getApplication();
    if (!application.isUnitTestMode()) {
      Disposer.register(
          application,
          new Disposable() {
            @Override
            public void dispose() {
              disposeRootFrame();
            }
          });
    }

    myCommandProcessor = new CommandProcessor();
    myWindowWatcher = new WindowWatcher();
    final KeyboardFocusManager keyboardFocusManager =
        KeyboardFocusManager.getCurrentKeyboardFocusManager();
    keyboardFocusManager.addPropertyChangeListener(FOCUSED_WINDOW_PROPERTY_NAME, myWindowWatcher);
    if (Patches.SUN_BUG_ID_4218084) {
      keyboardFocusManager.addPropertyChangeListener(
          FOCUSED_WINDOW_PROPERTY_NAME, new SUN_BUG_ID_4218084_Patch());
    }
    myLayout = new DesktopLayout();
    myProject2Frame = new HashMap<Project, IdeFrameImpl>();
    myDialogsToDispose = new HashMap<Project, Set<JDialog>>();
    myFrameExtendedState = Frame.NORMAL;

    // Calculate screen bounds.

    Rectangle screenBounds = new Rectangle();
    if (!application.isHeadlessEnvironment()) {
      final GraphicsEnvironment env = GraphicsEnvironment.getLocalGraphicsEnvironment();
      final GraphicsDevice[] devices = env.getScreenDevices();
      for (final GraphicsDevice device : devices) {
        screenBounds = screenBounds.union(device.getDefaultConfiguration().getBounds());
      }
    }
    myScreenBounds = screenBounds;

    myActivationListener =
        new WindowAdapter() {
          public void windowActivated(WindowEvent e) {
            Window activeWindow = e.getWindow();
            if (activeWindow instanceof IdeFrameImpl) { // must be
              proceedDialogDisposalQueue(((IdeFrameImpl) activeWindow).getProject());
            }
          }
        };

    bus.connect()
        .subscribe(
            AppLifecycleListener.TOPIC,
            new AppLifecycleListener.Adapter() {
              @Override
              public void appClosing() {
                // save fullscreen window states
                if (isFullScreenSupportedInCurrentOS()
                    && GeneralSettings.getInstance().isReopenLastProject()) {
                  Project[] openProjects = ProjectManager.getInstance().getOpenProjects();

                  if (openProjects.length > 0) {
                    WindowManagerEx wm = WindowManagerEx.getInstanceEx();
                    for (Project project : openProjects) {
                      IdeFrameImpl frame = wm.getFrame(project);
                      if (frame != null) {
                        frame.storeFullScreenStateIfNeeded();
                      }
                    }
                  }
                }
              }
            });

    if (UIUtil.hasLeakingAppleListeners()) {
      UIUtil.addAwtListener(
          new AWTEventListener() {
            @Override
            public void eventDispatched(AWTEvent event) {
              if (event.getID() == ContainerEvent.COMPONENT_ADDED) {
                if (((ContainerEvent) event).getChild() instanceof JViewport) {
                  UIUtil.removeLeakingAppleListeners();
                }
              }
            }
          },
          AWTEvent.CONTAINER_EVENT_MASK,
          application);
    }
  }
 public RecentProjectsManagerBase(ProjectManager projectManager, MessageBus messageBus) {
   projectManager.addProjectManagerListener(new MyProjectManagerListener());
   messageBus.connect().subscribe(AppLifecycleListener.TOPIC, new MyAppLifecycleListener());
 }
  /** @noinspection UnusedParameters */
  public ProjectManagerImpl(
      VirtualFileManager virtualFileManager,
      RecentProjectsManagerBase recentProjectsManager,
      ProgressManager progressManager) {
    myProgressManager = progressManager;
    Application app = ApplicationManager.getApplication();
    MessageBus messageBus = app.getMessageBus();
    MessageBusConnection connection = messageBus.connect(app);
    connection.subscribe(
        StateStorage.STORAGE_TOPIC,
        new StateStorage.Listener() {
          @Override
          public void storageFileChanged(
              @NotNull final VirtualFileEvent event, @NotNull final StateStorage storage) {
            VirtualFile file = event.getFile();
            if (!file.isDirectory()
                && !(event.getRequestor() instanceof StateStorage.SaveSession)) {
              saveChangedProjectFile(file, null, storage);
            }
          }
        });
    final ProjectManagerListener busPublisher = messageBus.syncPublisher(TOPIC);

    addProjectManagerListener(
        new ProjectManagerListener() {
          @Override
          public void projectOpened(final Project project) {
            MessageBus messageBus = project.getMessageBus();
            MessageBusConnection connection = messageBus.connect(project);
            connection.subscribe(
                StateStorage.STORAGE_TOPIC,
                new StateStorage.Listener() {
                  @Override
                  public void storageFileChanged(
                      @NotNull final VirtualFileEvent event, @NotNull final StateStorage storage) {
                    VirtualFile file = event.getFile();
                    if (!file.isDirectory()
                        && !(event.getRequestor() instanceof StateStorage.SaveSession)) {
                      saveChangedProjectFile(file, project, storage);
                    }
                  }
                });

            busPublisher.projectOpened(project);
            for (ProjectManagerListener listener : getListeners(project)) {
              listener.projectOpened(project);
            }
          }

          @Override
          public void projectClosed(Project project) {
            busPublisher.projectClosed(project);
            for (ProjectManagerListener listener : getListeners(project)) {
              listener.projectClosed(project);
            }
          }

          @Override
          public boolean canCloseProject(Project project) {
            for (ProjectManagerListener listener : getListeners(project)) {
              if (!listener.canCloseProject(project)) {
                return false;
              }
            }
            return true;
          }

          @Override
          public void projectClosing(Project project) {
            busPublisher.projectClosing(project);
            for (ProjectManagerListener listener : getListeners(project)) {
              listener.projectClosing(project);
            }
          }
        });

    registerExternalProjectFileListener(virtualFileManager);
  }