private void setStorageTypeAndPathToTheBestPossibleState() {
    // all that tricky logic, see the flowchart from the issue description https://youtrack.jetbrains.com/issue/UX-1126

    // 1. If this RC had been shared before Run Configurations dialog was opened - use the state that was used before.
    // This handles the case when user opens shared RC for editing and clicks the 'Save to file' check box two times.
    if (myRCStorageTypeInitial == RCStorageType.DotIdeaFolder) {
      myRCStorageType = RCStorageType.DotIdeaFolder;
      myFolderPathIfStoredInArbitraryFile = null;
      return;
    }

    if (myRCStorageTypeInitial == RCStorageType.ArbitraryFileInProject) {
      myRCStorageType = RCStorageType.ArbitraryFileInProject;
      myFolderPathIfStoredInArbitraryFile = StringUtil.notNullize(myFolderPathIfStoredInArbitraryFileInitial);
      return;
    }

    // 2. For IPR-based projects keep using project.ipr file to store RCs by default
    if (!ProjectKt.isDirectoryBased(myProject)) {
      myRCStorageType = RCStorageType.DotIdeaFolder;
      myFolderPathIfStoredInArbitraryFile = null;
      return;
    }

    // Rider prefers project_base_dir/.run/ folder to .idea/runConfigurations/
    if (!PlatformUtils.isRider()) {
      // 3. If the project is not under VCS, keep using .idea/runConfigurations
      RunConfigurationVcsSupport vcsSupport = myProject.getService(RunConfigurationVcsSupport.class);
      if (!vcsSupport.hasActiveVcss(myProject)) {
        myRCStorageType = RCStorageType.DotIdeaFolder;
        myFolderPathIfStoredInArbitraryFile = null;
        return;
      }

      // 4. If .idea/runConfigurations is not excluded from VCS (e.g. not in .gitignore), then use it
      if (!isDotIdeaStorageVcsIgnored(vcsSupport)) {
        myRCStorageType = RCStorageType.DotIdeaFolder;
        myFolderPathIfStoredInArbitraryFile = null;
        return;
      }
    }

    // notNullize is to make inspections happy. Paths can't be null for non-default project
    VirtualFile baseDir = LocalFileSystem.getInstance().findFileByPath(StringUtil.notNullize(myProject.getBasePath()));
    LOG.assertTrue(baseDir != null);

    // 5. If project base dir is not within project content, use .idea/runConfigurations
    // In Rider baseDir always not in the project content by design after migration to the new workspace model.
    if (!PlatformUtils.isRider() && !ProjectFileIndex.getInstance(myProject).isInContent(baseDir)) {
      myRCStorageType = RCStorageType.DotIdeaFolder;
      myFolderPathIfStoredInArbitraryFile = null;
      return;
    }

    // 6. If there are other RCs stored in arbitrary files (and all in the same folder) - suggest that folder
    Collection<String> otherFolders = getFolderPathsWithinProjectWhereRunConfigurationsStored(myProject);
    if (otherFolders.size() == 1) {
      myRCStorageType = RCStorageType.ArbitraryFileInProject;
      myFolderPathIfStoredInArbitraryFile = otherFolders.iterator().next();
      return;
    }

    // default is .../project_base_dir/.run/ folder
    myRCStorageType = RCStorageType.ArbitraryFileInProject;
    myFolderPathIfStoredInArbitraryFile = baseDir.getPath() + "/.run";
  }
private void setStorageTypeAndPathToTheBestPossibleState()