mirror of
https://gitflic.ru/project/openide/openide.git
synced 2026-09-27 10:03:11 +07:00
Create welcome script in a project with inner venv (PY-40278)
+ Comment about taken approach from another platform class + Report all new/opened projects even if the option is disabled GitOrigin-RevId: 39a0180707e315e82f427250650ed9af12616aa9
This commit is contained in:
committed by
intellij-monorepo-bot
parent
419897f981
commit
72afce383e
+1
-1
@@ -56,7 +56,7 @@ public final class PythonBaseProjectGenerator extends PythonProjectGenerator<PyN
|
||||
// Super should be called according to its contract unless we sync project explicitly (we do not, so we call super)
|
||||
super.configureProject(project, baseDir, settings, module, synchronizer);
|
||||
PySdkExtKt.setPythonSdk(module, settings.getSdk());
|
||||
PyWelcomeGenerator.INSTANCE.welcomeUser(project, baseDir);
|
||||
PyWelcomeGenerator.INSTANCE.welcomeUser(project, baseDir, module);
|
||||
}
|
||||
|
||||
@NotNull
|
||||
|
||||
@@ -24,6 +24,7 @@ import com.intellij.openapi.ui.CheckBoxWithDescription
|
||||
import com.intellij.openapi.util.Disposer
|
||||
import com.intellij.openapi.util.Ref
|
||||
import com.intellij.openapi.util.SystemInfo
|
||||
import com.intellij.openapi.vfs.VfsUtil
|
||||
import com.intellij.openapi.vfs.VirtualFile
|
||||
import com.intellij.openapi.wm.ToolWindowId
|
||||
import com.intellij.openapi.wm.ToolWindowManager.Companion.getInstance
|
||||
@@ -40,6 +41,7 @@ import com.jetbrains.python.newProject.welcome.PyWelcomeCollector.Companion.Proj
|
||||
import com.jetbrains.python.newProject.welcome.PyWelcomeCollector.Companion.ScriptResult
|
||||
import com.jetbrains.python.psi.LanguageLevel
|
||||
import com.jetbrains.python.run.PythonRunConfigurationProducer
|
||||
import com.jetbrains.python.sdk.pythonSdk
|
||||
import org.jetbrains.annotations.CalledInAny
|
||||
import org.jetbrains.concurrency.CancellablePromise
|
||||
import java.awt.event.ItemEvent
|
||||
@@ -55,7 +57,7 @@ internal class PyWelcomeConfigurator : DirectoryProjectConfigurator {
|
||||
}
|
||||
|
||||
StartupManager.getInstance(project).runAfterOpened {
|
||||
PyWelcome.welcomeUser(project, baseDir, false)
|
||||
PyWelcome.welcomeUser(project, baseDir, moduleRef.get(), false)
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -71,8 +73,8 @@ internal object PyWelcomeGenerator {
|
||||
)
|
||||
}
|
||||
|
||||
fun welcomeUser(project: Project, baseDir: VirtualFile) {
|
||||
PyWelcome.welcomeUser(project, baseDir, true)
|
||||
fun welcomeUser(project: Project, baseDir: VirtualFile, module: Module) {
|
||||
PyWelcome.welcomeUser(project, baseDir, module, true)
|
||||
}
|
||||
}
|
||||
|
||||
@@ -80,15 +82,13 @@ private object PyWelcome {
|
||||
private val LOG = Logger.getInstance(PyWelcome::class.java)
|
||||
|
||||
@CalledInAny
|
||||
fun welcomeUser(project: Project, baseDir: VirtualFile, newProject: Boolean) {
|
||||
fun welcomeUser(project: Project, baseDir: VirtualFile, module: Module?, newProject: Boolean) {
|
||||
val enabled = PyWelcomeSettings.instance.createWelcomeScriptForEmptyProject
|
||||
|
||||
if (enabled) {
|
||||
PyWelcomeCollector.logWelcomeProject(project, if (newProject) ProjectType.NEW else ProjectType.OPENED)
|
||||
}
|
||||
PyWelcomeCollector.logWelcomeProject(project, if (newProject) ProjectType.NEW else ProjectType.OPENED)
|
||||
|
||||
if (enabled &&
|
||||
isEmptyProject(baseDir).also { if (!it) PyWelcomeCollector.logWelcomeScript(project, ScriptResult.NOT_EMPTY) }) {
|
||||
isEmptyProject(project, baseDir, module).also { if (!it) PyWelcomeCollector.logWelcomeScript(project, ScriptResult.NOT_EMPTY) }) {
|
||||
prepareFileAndOpen(project, baseDir).onSuccess {
|
||||
if (it != null) {
|
||||
// expand tree after the welcome script is created, otherwise expansion will have no effect on empty tree
|
||||
@@ -102,8 +102,14 @@ private object PyWelcome {
|
||||
}
|
||||
}
|
||||
|
||||
private fun isEmptyProject(baseDir: VirtualFile): Boolean {
|
||||
return baseDir.children.all { ProjectCoreUtil.isProjectOrWorkspaceFile(it) }
|
||||
private fun isEmptyProject(project: Project, baseDir: VirtualFile, module: Module?): Boolean {
|
||||
val sdkBinary = (module?.pythonSdk ?: project.pythonSdk)?.homeDirectory
|
||||
val innerSdk = sdkBinary != null && VfsUtil.isAncestor(baseDir, sdkBinary, true)
|
||||
|
||||
return baseDir.children.all {
|
||||
ProjectCoreUtil.isProjectOrWorkspaceFile(it) ||
|
||||
(innerSdk && it.isDirectory && VfsUtil.isAncestor(it, sdkBinary!!, true))
|
||||
}
|
||||
}
|
||||
|
||||
private fun prepareFileAndOpen(project: Project, baseDir: VirtualFile): CancellablePromise<PsiFile?> {
|
||||
@@ -132,6 +138,8 @@ private object PyWelcome {
|
||||
|
||||
@CalledInAny
|
||||
private fun expandProjectTree(project: Project) {
|
||||
// the approach was taken from com.intellij.platform.PlatformProjectViewOpener
|
||||
|
||||
val toolWindow = getInstance(project).getToolWindow(ToolWindowId.PROJECT_VIEW)
|
||||
if (toolWindow == null) {
|
||||
val listener = ProjectViewListener(project)
|
||||
|
||||
Reference in New Issue
Block a user