Skip to content

Commit f19a321

Browse files
villanellex2intellij-monorepo-bot
authored andcommitted
IJPL-212811 added a method isNewlyCreatedProject and fixed creation of two instances of the project for DataGrip
GitOrigin-RevId: 7ec9472d862180ac02d9b03914db13f40c2f9a48
1 parent 3db7350 commit f19a321

File tree

3 files changed

+23
-21
lines changed

3 files changed

+23
-21
lines changed

platform/platform-impl/src/com/intellij/ide/impl/ProjectUtil.kt

Lines changed: 13 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,6 @@ import com.intellij.openapi.project.ex.ProjectManagerEx
2727
import com.intellij.openapi.startup.StartupManager
2828
import com.intellij.openapi.ui.MessageDialogBuilder
2929
import com.intellij.openapi.ui.Messages
30-
import com.intellij.openapi.util.Disposer
3130
import com.intellij.openapi.util.SystemInfoRt
3231
import com.intellij.openapi.util.io.FileUtil
3332
import com.intellij.openapi.util.io.FileUtilRt
@@ -654,31 +653,25 @@ object ProjectUtil {
654653
false
655654
}
656655

657-
var projectFile: Path? = null
658-
if (created) {
659-
val options = OpenProjectTask {
660-
isNewProject = true
661-
runConfigurators = true
662-
projectName = name
663-
}
664-
665-
val project = projectManager.newProjectAsync(file = file, options = options)
666-
runInAutoSaveDisabledMode {
667-
saveSettings(componentManager = project, forceSavingAllSettings = true)
668-
}
669-
edtWriteAction {
670-
Disposer.dispose(project)
671-
}
672-
projectFile = file
656+
if (!created) {
657+
return null
673658
}
674659

675-
if (projectFile == null) {
676-
return null
660+
val newProject = projectManager.newProjectAsync(file = file, options = OpenProjectTask {
661+
isNewProject = true
662+
isProjectCreatedWithWizard = true
663+
runConfigurators = true
664+
projectName = name
665+
})
666+
667+
runInAutoSaveDisabledMode {
668+
saveSettings(componentManager = newProject, forceSavingAllSettings = true)
677669
}
678670

679-
return projectManager.openProjectAsync(projectIdentityFile = projectFile, options = OpenProjectTask {
671+
return projectManager.openProjectAsync(projectIdentityFile = file, options = OpenProjectTask {
680672
runConfigurators = true
681673
isProjectCreatedWithWizard = true
674+
project = newProject
682675
})
683676
}
684677

platform/platform-impl/src/com/intellij/openapi/project/impl/ProjectManagerImpl.kt

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -73,6 +73,7 @@ import com.intellij.openapi.wm.WindowManager
7373
import com.intellij.openapi.wm.ex.WelcomeScreenProjectProvider
7474
import com.intellij.openapi.wm.ex.WindowManagerEx
7575
import com.intellij.openapi.wm.impl.welcomeScreen.WelcomeFrame
76+
import com.intellij.platform.PROJECT_NEWLY_CREATED
7677
import com.intellij.platform.PROJECT_NEWLY_OPENED
7778
import com.intellij.platform.PlatformProjectOpenProcessor
7879
import com.intellij.platform.attachToProjectAsync
@@ -657,7 +658,8 @@ open class ProjectManagerImpl : ProjectManagerEx(), Disposable {
657658
projectName = options.projectName,
658659
beforeInit = options.beforeInit,
659660
useDefaultProjectAsTemplate = options.useDefaultProjectAsTemplate,
660-
preloadServices = options.preloadServices
661+
preloadServices = options.preloadServices,
662+
markAsNewlyCreated = options.isProjectCreatedWithWizard,
661663
)
662664
else -> prepareProject(
663665
projectIdentityFile = projectIdentityFile,
@@ -838,6 +840,7 @@ open class ProjectManagerImpl : ProjectManagerEx(), Disposable {
838840
options.beforeInit,
839841
options.useDefaultProjectAsTemplate,
840842
options.preloadServices,
843+
options.isProjectCreatedWithWizard,
841844
markAsNew = false
842845
).also { project ->
843846
TrustedProjects.setProjectTrusted(project, true)
@@ -885,6 +888,7 @@ open class ProjectManagerImpl : ProjectManagerEx(), Disposable {
885888
beforeInit: ((Project) -> Unit)?,
886889
useDefaultProjectAsTemplate: Boolean,
887890
preloadServices: Boolean,
891+
markAsNewlyCreated: Boolean,
888892
markAsNew: Boolean = true,
889893
): Project {
890894
return coroutineScope {
@@ -915,6 +919,7 @@ open class ProjectManagerImpl : ProjectManagerEx(), Disposable {
915919

916920
val project = instantiateProject(identityFle = identityFle, projectName = projectName, beforeInit = beforeInit)
917921
project.putUserData(PROJECT_NEWLY_OPENED, markAsNew)
922+
project.putUserData(PROJECT_NEWLY_CREATED, markAsNewlyCreated)
918923
val template = templateAsync?.await()
919924
initProject(file = identityFle, project = project, preloadServices = preloadServices, template = template)
920925
project

platform/platform-impl/src/com/intellij/platform/PlatformProjectOpenProcessor.kt

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -54,6 +54,7 @@ private val PROJECT_CONFIGURED_BY_PLATFORM_PROCESSOR: Key<Boolean> = Key.create(
5454
val PROJECT_LOADED_FROM_CACHE_BUT_HAS_NO_MODULES: Key<Boolean> = Key.create("PROJECT_LOADED_FROM_CACHE_BUT_HAS_NO_MODULES")
5555

5656
internal val PROJECT_NEWLY_OPENED: Key<Boolean> = Key.create("PROJECT_NEWLY_OPENED")
57+
internal val PROJECT_NEWLY_CREATED: Key<Boolean> = Key.create("PROJECT_NEWLY_CREATED")
5758

5859
@Internal
5960
fun isConfiguredByPlatformProcessor(project: Project): Boolean = project.getUserData(PROJECT_CONFIGURED_BY_PLATFORM_PROCESSOR) == true
@@ -89,6 +90,9 @@ class PlatformProjectOpenProcessor : ProjectOpenProcessor(), CommandLineProjectO
8990

9091
fun isNewProject(project: Project): Boolean = project.getUserData(PROJECT_NEWLY_OPENED) == true
9192

93+
@Internal
94+
fun isNewlyCreatedProject(project: Project): Boolean = project.getUserData(PROJECT_NEWLY_CREATED) == true
95+
9296
fun isTempProject(project: Project): Boolean = project.service<OpenProjectSettingsService>().state.isLocatedInTempDirectory
9397

9498
@JvmStatic

0 commit comments

Comments
 (0)