From 039ff79573989e724b04b3ac0a062341f668bf17 Mon Sep 17 00:00:00 2001 From: Nikolay Chashnikov Date: Wed, 10 Jul 2024 13:03:39 +0200 Subject: [PATCH] [split] don't change the value of 'confirmOpenNewProject' option in remote development sessions (RDCT-1505, GTW-9099) ProjectLifecycleUiCustomization service is introduced to allow always opening projects in a new window without modifying the option. This way we ensure that users won't be able to change the value of this option manually after it set in code in remote dev mode. Also, running the IDE in remote dev mode won't affect settings for monolith (full) IDE. GitOrigin-RevId: 794486d9146a616277933585ab9cc32485414bcc --- .../resources/META-INF/IdeCore.xml | 1 + .../src/com/intellij/ide/GeneralSettings.kt | 8 ++++- .../ProjectLifecycleUiCustomization.kt | 27 ++++++++++++++++ .../ide/GeneralSettingsConfigurable.kt | 31 ++++++++++--------- 4 files changed, 52 insertions(+), 15 deletions(-) create mode 100644 platform/ide-core/src/com/intellij/platform/ide/core/customization/ProjectLifecycleUiCustomization.kt diff --git a/platform/ide-core-impl/resources/META-INF/IdeCore.xml b/platform/ide-core-impl/resources/META-INF/IdeCore.xml index 20080398546b..c862a2e8cf0b 100644 --- a/platform/ide-core-impl/resources/META-INF/IdeCore.xml +++ b/platform/ide-core-impl/resources/META-INF/IdeCore.xml @@ -16,6 +16,7 @@ + diff --git a/platform/ide-core/src/com/intellij/ide/GeneralSettings.kt b/platform/ide-core/src/com/intellij/ide/GeneralSettings.kt index 5c01b32cd620..71902a2923de 100644 --- a/platform/ide-core/src/com/intellij/ide/GeneralSettings.kt +++ b/platform/ide-core/src/com/intellij/ide/GeneralSettings.kt @@ -6,6 +6,7 @@ import com.intellij.ide.util.PropertiesComponent import com.intellij.openapi.application.ApplicationManager import com.intellij.openapi.components.* import com.intellij.platform.ide.core.customization.IdeLifecycleUiCustomization +import com.intellij.platform.ide.core.customization.ProjectLifecycleUiCustomization import com.intellij.util.PlatformUtils import com.intellij.util.xmlb.annotations.OptionTag import kotlinx.coroutines.channels.BufferOverflow @@ -110,7 +111,12 @@ class GeneralSettings : PersistentStateComponent { */ @get:OpenNewProjectOption var confirmOpenNewProject: Int - get() = state.confirmOpenNewProject2 ?: defaultConfirmNewProject() + get() { + return if (ProjectLifecycleUiCustomization.getInstance().alwaysOpenProjectInNewWindow) { + OPEN_PROJECT_NEW_WINDOW + } + else state.confirmOpenNewProject2 ?: defaultConfirmNewProject() + } set(value) { state.confirmOpenNewProject2 = value } diff --git a/platform/ide-core/src/com/intellij/platform/ide/core/customization/ProjectLifecycleUiCustomization.kt b/platform/ide-core/src/com/intellij/platform/ide/core/customization/ProjectLifecycleUiCustomization.kt new file mode 100644 index 000000000000..26b2352d4a7b --- /dev/null +++ b/platform/ide-core/src/com/intellij/platform/ide/core/customization/ProjectLifecycleUiCustomization.kt @@ -0,0 +1,27 @@ +// Copyright 2000-2024 JetBrains s.r.o. and contributors. Use of this source code is governed by the Apache 2.0 license. +package com.intellij.platform.ide.core.customization + +import com.intellij.openapi.components.service +import org.jetbrains.annotations.ApiStatus + +/** + * Override this service to customize UI elements related to project's lifecycle. + * It is supposed to be overriden by parts of the platform used when the IDE is running in different modes, and isn't supposed to be + * overridden in plugins. + */ +@ApiStatus.Internal +open class ProjectLifecycleUiCustomization { + /** + * Returns `false` if the IDE should ask user whether to open a project in new windows or in the same window, and allow a user to choose + * the default choice in Settings. + * Returns `true` if the IDE should always open projects in a new window without asking for confirmation, and shouldn't allow changing + * this. + */ + open val alwaysOpenProjectInNewWindow: Boolean + get() = false + + companion object { + @JvmStatic + fun getInstance(): ProjectLifecycleUiCustomization = service() + } +} diff --git a/platform/platform-impl/src/com/intellij/ide/GeneralSettingsConfigurable.kt b/platform/platform-impl/src/com/intellij/ide/GeneralSettingsConfigurable.kt index 34f69cb74273..9d9e7083e519 100644 --- a/platform/platform-impl/src/com/intellij/ide/GeneralSettingsConfigurable.kt +++ b/platform/platform-impl/src/com/intellij/ide/GeneralSettingsConfigurable.kt @@ -13,6 +13,7 @@ import com.intellij.openapi.options.SearchableConfigurable import com.intellij.openapi.options.ex.ConfigurableWrapper import com.intellij.openapi.ui.DialogPanel import com.intellij.platform.ide.core.customization.IdeLifecycleUiCustomization +import com.intellij.platform.ide.core.customization.ProjectLifecycleUiCustomization import com.intellij.ui.IdeUICustomization import com.intellij.ui.dsl.builder.* import com.intellij.util.PlatformUtils @@ -84,20 +85,22 @@ private class GeneralSettingsConfigurable : row { checkBox(myChkReopenLastProject) } - buttonsGroup { - row(IdeUICustomization.getInstance().projectMessage("label.open.project.in")) { - radioButton(IdeUICustomization.getInstance().projectMessage("radio.button.open.project.in.the.new.window"), - GeneralSettings.OPEN_PROJECT_NEW_WINDOW) - radioButton(IdeUICustomization.getInstance().projectMessage("radio.button.open.project.in.the.same.window"), - GeneralSettings.OPEN_PROJECT_SAME_WINDOW) - radioButton(IdeUICustomization.getInstance().projectMessage("radio.button.confirm.window.to.open.project.in"), - GeneralSettings.OPEN_PROJECT_ASK) - if (PlatformUtils.isDataSpell()) { - radioButton(IdeUICustomization.getInstance().projectMessage("radio.button.attach"), - GeneralSettings.OPEN_PROJECT_SAME_WINDOW_ATTACH) - } - }.layout(RowLayout.INDEPENDENT) - }.bind(getter = { model.confirmOpenNewProject2 ?: GeneralSettings.defaultConfirmNewProject() }, setter = { model.confirmOpenNewProject2 = it }) + if (!ProjectLifecycleUiCustomization.getInstance().alwaysOpenProjectInNewWindow) { + buttonsGroup { + row(IdeUICustomization.getInstance().projectMessage("label.open.project.in")) { + radioButton(IdeUICustomization.getInstance().projectMessage("radio.button.open.project.in.the.new.window"), + GeneralSettings.OPEN_PROJECT_NEW_WINDOW) + radioButton(IdeUICustomization.getInstance().projectMessage("radio.button.open.project.in.the.same.window"), + GeneralSettings.OPEN_PROJECT_SAME_WINDOW) + radioButton(IdeUICustomization.getInstance().projectMessage("radio.button.confirm.window.to.open.project.in"), + GeneralSettings.OPEN_PROJECT_ASK) + if (PlatformUtils.isDataSpell()) { + radioButton(IdeUICustomization.getInstance().projectMessage("radio.button.attach"), + GeneralSettings.OPEN_PROJECT_SAME_WINDOW_ATTACH) + } + }.layout(RowLayout.INDEPENDENT) + }.bind(getter = { model.confirmOpenNewProject2 ?: GeneralSettings.defaultConfirmNewProject() }, setter = { model.confirmOpenNewProject2 = it }) + } row(IdeUICustomization.getInstance().projectMessage("settings.general.default.directory")) { textFieldWithBrowseButton(fileChooserDescriptor = FileChooserDescriptorFactory.createSingleFolderDescriptor()