PY-75909: Expand project view right after new project creation.

Platform expands project view automatically once `generateProject` returns but only if it isn't empty. As we generate things in background (see `.launch`) nothing is expanded.

So we expand it explicitly 2 times: when SDK is generated and when project is generated. At least one of these actions must create files which is required to expand the tree.

This code can't be tested because there is no project view tree in a headless mode.


(cherry picked from commit 2390d09619639e8ff8d8906a4e0a284cf24da5ba)

KT-MR-18605

GitOrigin-RevId: 115034e348c029ea751072caacf4220d121bc220
This commit is contained in:
Ilya.Kazakevich
2024-10-22 21:09:42 +02:00
committed by intellij-monorepo-bot
parent 01cb90eb84
commit 98ea3d54fe

View File

@@ -2,6 +2,7 @@
package com.jetbrains.python.newProjectWizard
import com.intellij.facet.ui.ValidationResult
import com.intellij.ide.projectView.impl.AbstractProjectViewPane
import com.intellij.openapi.application.EDT
import com.intellij.openapi.components.Service
import com.intellij.openapi.components.service
@@ -51,10 +52,19 @@ abstract class PyV3ProjectBaseGenerator<TYPE_SPECIFIC_SETTINGS : PyV3ProjectType
}
throw it
}
// Project view must be expanded (PY-75909) but it can't be unless it contains some files.
// Either base settings (which create venv) might generate some or type specific settings (like Django) may.
// So we expand it right after SDK generation, but if there are no files yet, we do it again after project generation
ensureProjectViewExpanded(project)
typeSpecificSettings.generateProject(module, baseDir, sdk)
ensureProjectViewExpanded(project)
}
}
private suspend fun ensureProjectViewExpanded(project: Project): Unit = withContext(Dispatchers.EDT) {
AbstractProjectViewPane.EP.getExtensions(project).firstNotNullOf { pane -> pane.tree }.expandRow(0)
}
override fun createPeer(): ProjectGeneratorPeer<PyV3BaseProjectSettings> =
PyV3GeneratorPeer(baseSettings, typeSpecificUI?.let { Pair(it, typeSpecificSettings) }, allowedInterpreterTypes)