Skip to content

Commit

Permalink
settings-sync: don't synchronize default project directory and defaul…
Browse files Browse the repository at this point in the history
…t browser settings

Extract the settings which should not be synced from GeneralSettings to a separate component GeneralLocalSettings.

#IDEA-253439 Fixed

GitOrigin-RevId: c4128a8575d62bb95f490f05ce451fc40192aeca
  • Loading branch information
klikh authored and intellij-monorepo-bot committed Jan 12, 2023
1 parent 0e296cd commit a7e6a0d
Show file tree
Hide file tree
Showing 8 changed files with 129 additions and 56 deletions.
81 changes: 81 additions & 0 deletions platform/ide-core/src/com/intellij/ide/GeneralLocalSettings.kt
Original file line number Diff line number Diff line change
@@ -0,0 +1,81 @@
// Copyright 2000-2023 JetBrains s.r.o. and contributors. Use of this source code is governed by the Apache 2.0 license.
package com.intellij.ide

import com.intellij.ide.util.PropertiesComponent
import com.intellij.openapi.application.ApplicationManager
import com.intellij.openapi.components.*
import com.intellij.openapi.util.SystemInfo
import org.jetbrains.annotations.SystemDependent

@Service(Service.Level.APP)
@State(name = "GeneralLocalSettings",
storages = [Storage(value = "ide.general.local.xml", roamingType = RoamingType.DISABLED)])
class GeneralLocalSettings : SimplePersistentStateComponent<GeneralLocalSettings.GeneralLocalState>(GeneralLocalState()) {

class GeneralLocalState : BaseState() {
var defaultProjectDirectory by string("")
var useDefaultBrowser by property(true)
var browserPath by string(null)
}

override fun noStateLoaded() {
migrateFromGeneralSettings()
}

private fun migrateFromGeneralSettings() {
if (!PropertiesComponent.getInstance().getBoolean(MIGRATED_FROM_GENERAL_SETTINGS, false)) {
PropertiesComponent.getInstance().setValue(MIGRATED_FROM_GENERAL_SETTINGS, true)

defaultProjectDirectory = GeneralSettings.getInstance().myDefaultProjectDirectory
useDefaultBrowser = GeneralSettings.getInstance().myUseDefaultBrowser
browserPath = GeneralSettings.getInstance().myBrowserPath

GeneralSettings.getInstance().myDefaultProjectDirectory = ""
GeneralSettings.getInstance().myUseDefaultBrowser = true
GeneralSettings.getInstance().myBrowserPath = ""
}
}

var defaultProjectDirectory: @SystemDependent String
get() = state.defaultProjectDirectory ?: ""
set(value) {
state.defaultProjectDirectory = value
}

var browserPath: String
get() = state.browserPath ?: getDefaultAlternativeBrowserPath()
set(value) {
state.browserPath = value
}

var useDefaultBrowser: Boolean
get() = state.useDefaultBrowser
set(value) {
state.useDefaultBrowser = value
}


companion object {
private const val MIGRATED_FROM_GENERAL_SETTINGS = "migrated.non.roamable.values.from.general.settings"

@JvmStatic
fun getInstance(): GeneralLocalSettings {
return ApplicationManager.getApplication().getService(GeneralLocalSettings::class.java)
}

private fun getDefaultAlternativeBrowserPath(): String {
return if (SystemInfo.isWindows) {
"C:\\Program Files\\Internet Explorer\\IExplore.exe"
}
else if (SystemInfo.isMac) {
"open"
}
else if (SystemInfo.isUnix) {
"/usr/bin/firefox"
}
else {
""
}
}
}
}
44 changes: 16 additions & 28 deletions platform/ide-core/src/com/intellij/ide/GeneralSettings.java
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
// Copyright 2000-2022 JetBrains s.r.o. and contributors. Use of this source code is governed by the Apache 2.0 license.
// Copyright 2000-2023 JetBrains s.r.o. and contributors. Use of this source code is governed by the Apache 2.0 license.
package com.intellij.ide;

import com.intellij.ide.ui.UINumericRange;
Expand All @@ -8,7 +8,6 @@
import com.intellij.openapi.application.ApplicationManager;
import com.intellij.openapi.components.*;
import com.intellij.openapi.util.Disposer;
import com.intellij.openapi.util.SystemInfo;
import com.intellij.util.ObjectUtils;
import com.intellij.util.PlatformUtils;
import com.intellij.util.xmlb.XmlSerializerUtil;
Expand Down Expand Up @@ -43,7 +42,7 @@ public enum ProcessCloseConfirmation {ASK, TERMINATE, DISCONNECT}

private static final String SHOW_TIPS_ON_STARTUP_DEFAULT_VALUE_PROPERTY = "ide.show.tips.on.startup.default.value";

private String myBrowserPath = getDefaultAlternativeBrowserPath();
String myBrowserPath = "";
private boolean myShowTipsOnStartup = Boolean.parseBoolean(System.getProperty(SHOW_TIPS_ON_STARTUP_DEFAULT_VALUE_PROPERTY, "true"));
private boolean myReopenLastProject = true;
private boolean mySupportScreenReaders = ObjectUtils.chooseNotNull(SUPPORT_SCREEN_READERS_OVERRIDDEN, false);
Expand All @@ -53,13 +52,13 @@ public enum ProcessCloseConfirmation {ASK, TERMINATE, DISCONNECT}
private int myInactiveTimeout = 15; // Number of seconds of inactivity after which the IDE automatically saves all files
private boolean myUseSafeWrite = true;
private final PropertyChangeSupport myPropertyChangeSupport = new PropertyChangeSupport(this);
private boolean myUseDefaultBrowser = true;
boolean myUseDefaultBrowser = true;
private boolean mySearchInBackground;
private boolean myConfirmExit = true;
private boolean myShowWelcomeScreen = true;
private int myConfirmOpenNewProject = OPEN_PROJECT_ASK;
private ProcessCloseConfirmation myProcessCloseConfirmation = ProcessCloseConfirmation.ASK;
private String myDefaultProjectDirectory = "";
String myDefaultProjectDirectory = "";

private static final String CONFIGURED_PROPERTY = "GeneralSettings.initiallyConfigured";

Expand Down Expand Up @@ -87,6 +86,10 @@ public void addPropertyChangeListener(@NotNull String propertyName, @NotNull Dis
Disposer.register(parentDisposable, () -> myPropertyChangeSupport.removePropertyChangeListener(propertyName, listener));
}

/**
* @deprecated Use {@link GeneralLocalSettings#getBrowserPath()} instead.
*/
@Deprecated
public String getBrowserPath() {
return myBrowserPath;
}
Expand Down Expand Up @@ -205,14 +208,14 @@ public void loadState(@NotNull GeneralSettings state) {
XmlSerializerUtil.copyBean(state, this);
}

/**
* @deprecated Use {@link GeneralLocalSettings#getUseDefaultBrowser()} instead.
*/
@Deprecated
public boolean isUseDefaultBrowser() {
return myUseDefaultBrowser;
}

public void setUseDefaultBrowser(boolean value) {
myUseDefaultBrowser = value;
}

/**
* @deprecated unused
*/
Expand Down Expand Up @@ -274,27 +277,12 @@ public void setSearchInBackground(final boolean searchInBackground) {
mySearchInBackground = searchInBackground;
}

/**
* @deprecated Use {@link GeneralLocalSettings#getDefaultProjectDirectory()} instead.
*/
@Deprecated
@SystemDependent
public String getDefaultProjectDirectory() {
return myDefaultProjectDirectory;
}

public void setDefaultProjectDirectory(@SystemDependent String defaultProjectDirectory) {
myDefaultProjectDirectory = defaultProjectDirectory;
}

private static @NotNull String getDefaultAlternativeBrowserPath() {
if (SystemInfo.isWindows) {
return "C:\\Program Files\\Internet Explorer\\IExplore.exe";
}
else if (SystemInfo.isMac) {
return "open";
}
else if (SystemInfo.isUnix) {
return "/usr/bin/firefox";
}
else {
return "";
}
}
}
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
// Copyright 2000-2022 JetBrains s.r.o. and contributors. Use of this source code is governed by the Apache 2.0 license.
// Copyright 2000-2023 JetBrains s.r.o. and contributors. Use of this source code is governed by the Apache 2.0 license.
package com.intellij.ide.browsers

import com.intellij.CommonBundle
Expand All @@ -9,7 +9,7 @@ import com.intellij.execution.process.CapturingProcessHandler
import com.intellij.execution.process.ProcessIOExecutorService
import com.intellij.execution.util.ExecUtil
import com.intellij.ide.BrowserUtil
import com.intellij.ide.GeneralSettings
import com.intellij.ide.GeneralLocalSettings
import com.intellij.ide.IdeBundle
import com.intellij.model.SideEffectGuard
import com.intellij.openapi.application.ApplicationManager
Expand Down Expand Up @@ -103,7 +103,7 @@ open class BrowserLauncherAppless : BrowserLauncher() {
}

val settings = generalSettings
if (settings.isUseDefaultBrowser) {
if (settings.useDefaultBrowser) {
openWithDefaultBrowser(url, project)
}
else {
Expand Down Expand Up @@ -227,8 +227,8 @@ open class BrowserLauncherAppless : BrowserLauncher() {

protected open fun getEffectiveBrowser(browser: WebBrowser?): WebBrowser? = browser

private val generalSettings: GeneralSettings
get() = (if (ApplicationManager.getApplication() != null) GeneralSettings.getInstance() else null) ?: GeneralSettings()
private val generalSettings: GeneralLocalSettings
get() = (if (ApplicationManager.getApplication() != null) GeneralLocalSettings.getInstance() else null) ?: GeneralLocalSettings()

private val defaultBrowserCommand: List<String>?
get() = when {
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
// Copyright 2000-2021 JetBrains s.r.o. and contributors. Use of this source code is governed by the Apache 2.0 license that can be found in the LICENSE file.
// Copyright 2000-2023 JetBrains s.r.o. and contributors. Use of this source code is governed by the Apache 2.0 license.
package com.intellij.ide

import com.intellij.application.options.editor.CheckboxDescriptor
Expand All @@ -13,8 +13,7 @@ import com.intellij.openapi.options.ex.ConfigurableWrapper
import com.intellij.openapi.ui.DialogPanel
import com.intellij.ui.IdeUICustomization
import com.intellij.ui.dsl.builder.*
import com.intellij.ui.dsl.builder.panel
import com.intellij.ui.layout.*
import com.intellij.ui.layout.PropertyBinding
import com.intellij.util.PlatformUtils

// @formatter:off
Expand Down Expand Up @@ -96,7 +95,7 @@ class GeneralSettingsConfigurable: BoundCompositeSearchableConfigurable<Searchab
row(IdeUICustomization.getInstance().projectMessage("settings.general.default.directory")) {
textFieldWithBrowseButton(fileChooserDescriptor = FileChooserDescriptorFactory.createSingleFolderDescriptor()
.also { it.putUserData(PathChooserDialog.PREFER_LAST_OVER_EXPLICIT, false) })
.bindText(model::getDefaultProjectDirectory, model::setDefaultProjectDirectory)
.bindText(GeneralLocalSettings.getInstance()::defaultProjectDirectory)
.columns(COLUMNS_MEDIUM)
.comment(IdeBundle.message("settings.general.directory.preselected"), 80)
}
Expand Down
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
// Copyright 2000-2022 JetBrains s.r.o. and contributors. Use of this source code is governed by the Apache 2.0 license.
// Copyright 2000-2023 JetBrains s.r.o. and contributors. Use of this source code is governed by the Apache 2.0 license.
package com.intellij.ide.actions

import com.intellij.icons.AllIcons
import com.intellij.ide.GeneralSettings
import com.intellij.ide.GeneralLocalSettings
import com.intellij.ide.IdeBundle
import com.intellij.ide.highlighter.ProjectFileType
import com.intellij.ide.impl.OpenProjectTask
Expand Down Expand Up @@ -67,8 +67,9 @@ open class OpenFileAction : AnAction(), DumbAware, LightEditCompatible {
val showFiles = project != null || PlatformProjectOpenProcessor.getInstanceIfItExists() != null
val descriptor: FileChooserDescriptor = if (showFiles) ProjectOrFileChooserDescriptor() else ProjectOnlyFileChooserDescriptor()
var toSelect: VirtualFile? = null
if (!GeneralSettings.getInstance().defaultProjectDirectory.isNullOrEmpty()) {
toSelect = VfsUtil.findFileByIoFile(File(GeneralSettings.getInstance().defaultProjectDirectory), true)
val defaultProjectDirectory = GeneralLocalSettings.getInstance().defaultProjectDirectory
if (defaultProjectDirectory.isNotEmpty()) {
toSelect = VfsUtil.findFileByIoFile(File(defaultProjectDirectory), true)
}
descriptor.putUserData(PathChooserDialog.PREFER_LAST_OVER_EXPLICIT, toSelect == null && showFiles)
FileChooser.chooseFiles(descriptor, project, toSelect ?: pathToSelect) { files ->
Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
// Copyright 2000-2021 JetBrains s.r.o. and contributors. Use of this source code is governed by the Apache 2.0 license that can be found in the LICENSE file.
// Copyright 2000-2023 JetBrains s.r.o. and contributors. Use of this source code is governed by the Apache 2.0 license.
package com.intellij.ide.browsers

import com.intellij.ide.GeneralSettings
import com.intellij.ide.GeneralLocalSettings
import com.intellij.ide.IdeBundle
import com.intellij.ide.browsers.BrowserLauncherAppless.Companion.canUseSystemDefaultBrowserPolicy
import com.intellij.openapi.fileChooser.FileChooserDescriptorFactory
Expand Down Expand Up @@ -198,7 +198,6 @@ internal class BrowserSettingsPanel {
val isModified: Boolean
get() {
val browserManager = WebBrowserManager.getInstance()
val generalSettings = GeneralSettings.getInstance()
val defaultBrowserPolicy = defaultBrowser
if (getDefaultBrowserPolicy(browserManager) != defaultBrowserPolicy ||
browserManager.isShowBrowserHover != showBrowserHover.isSelected ||
Expand All @@ -208,15 +207,15 @@ internal class BrowserSettingsPanel {
return true
}
return if (defaultBrowserPolicy == DefaultBrowserPolicy.ALTERNATIVE &&
!Comparing.strEqual(generalSettings.browserPath, alternativeBrowserPathField.text)) {
!Comparing.strEqual(GeneralLocalSettings.getInstance().browserPath, alternativeBrowserPathField.text)) {
true
}
else browsersEditor.isModified
}

fun apply() {
val settings = GeneralSettings.getInstance()
settings.isUseDefaultBrowser = defaultBrowser == DefaultBrowserPolicy.SYSTEM
val settings = GeneralLocalSettings.getInstance()
settings.useDefaultBrowser = defaultBrowser == DefaultBrowserPolicy.SYSTEM
if (alternativeBrowserPathField.isEnabled) {
settings.browserPath = alternativeBrowserPathField.text
}
Expand All @@ -238,11 +237,10 @@ internal class BrowserSettingsPanel {
defaultBrowserPolicyComboBox.selectedItem = effectiveDefaultBrowserPolicy
previewReloadModeComboBox.item = browserManager.getWebPreviewReloadMode()
serverReloadModeComboBox.item = browserManager.getWebServerReloadMode()
val settings = GeneralSettings.getInstance()
showBrowserHover.isSelected = browserManager.isShowBrowserHover
showBrowserHoverXml.isSelected = browserManager.isShowBrowserHoverXml
browsersEditor.reset(browserManager.list)
customPathValue = settings.browserPath
customPathValue = GeneralLocalSettings.getInstance().browserPath
alternativeBrowserPathField.isEnabled = effectiveDefaultBrowserPolicy == DefaultBrowserPolicy.ALTERNATIVE
updateCustomPathTextFieldValue(effectiveDefaultBrowserPolicy)
}
Expand Down
12 changes: 8 additions & 4 deletions platform/platform-impl/src/com/intellij/ide/impl/ProjectUtil.kt
Original file line number Diff line number Diff line change
@@ -1,11 +1,12 @@
// Copyright 2000-2022 JetBrains s.r.o. and contributors. Use of this source code is governed by the Apache 2.0 license.
// Copyright 2000-2023 JetBrains s.r.o. and contributors. Use of this source code is governed by the Apache 2.0 license.
package com.intellij.ide.impl

import com.intellij.CommonBundle
import com.intellij.configurationStore.runInAutoSaveDisabledMode
import com.intellij.configurationStore.saveSettings
import com.intellij.execution.wsl.WslPath.Companion.isWslUncPath
import com.intellij.featureStatistics.fusCollectors.LifecycleUsageTriggerCollector
import com.intellij.ide.GeneralLocalSettings
import com.intellij.ide.GeneralSettings
import com.intellij.ide.IdeBundle
import com.intellij.ide.RecentProjectsManager
Expand All @@ -23,7 +24,10 @@ import com.intellij.openapi.project.ex.ProjectManagerEx
import com.intellij.openapi.startup.StartupManager
import com.intellij.openapi.ui.MessageDialogBuilder.Companion.yesNo
import com.intellij.openapi.ui.Messages
import com.intellij.openapi.util.*
import com.intellij.openapi.util.Disposer
import com.intellij.openapi.util.NlsContexts
import com.intellij.openapi.util.SystemInfoRt
import com.intellij.openapi.util.ThrowableComputable
import com.intellij.openapi.util.io.FileUtil
import com.intellij.openapi.util.io.FileUtilRt
import com.intellij.openapi.util.text.StringUtil
Expand Down Expand Up @@ -485,7 +489,7 @@ object ProjectUtil {

@JvmStatic
fun getBaseDir(): String {
val defaultDirectory = GeneralSettings.getInstance().defaultProjectDirectory
val defaultDirectory = GeneralLocalSettings.getInstance().defaultProjectDirectory
if (!defaultDirectory.isNullOrEmpty()) {
return defaultDirectory.replace('/', File.separatorChar)
}
Expand Down Expand Up @@ -545,7 +549,7 @@ object ProjectUtil {
@JvmStatic
fun getProjectsPath(): @SystemDependent String {
val application = ApplicationManager.getApplication()
val fromSettings = if (application == null || application.isHeadlessEnvironment) null else GeneralSettings.getInstance().defaultProjectDirectory
val fromSettings = if (application == null || application.isHeadlessEnvironment) null else GeneralLocalSettings.getInstance().defaultProjectDirectory
if (!fromSettings.isNullOrEmpty()) {
return PathManager.getAbsolutePath(fromSettings)
}
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
// Copyright 2000-2020 JetBrains s.r.o. Use of this source code is governed by the Apache 2.0 license that can be found in the LICENSE file.
// Copyright 2000-2023 JetBrains s.r.o. and contributors. Use of this source code is governed by the Apache 2.0 license.
package com.intellij.platform

import com.intellij.ide.GeneralLocalSettings
import com.intellij.ide.GeneralSettings
import com.intellij.ide.IdeBundle
import com.intellij.ide.actions.OpenProjectFileChooserDescriptor
Expand Down Expand Up @@ -59,9 +60,10 @@ open class AttachProjectAction : AnAction(ActionsBundle.message("action.AttachPr
LocalFileSystem.getInstance().findFileByNioFile(it)
}
if (preselectedDirectory == null) {
val defaultProjectDirectory = GeneralLocalSettings.getInstance().defaultProjectDirectory
preselectedDirectory =
if (StringUtil.isNotEmpty(GeneralSettings.getInstance().defaultProjectDirectory))
VfsUtil.findFileByIoFile(File(GeneralSettings.getInstance().defaultProjectDirectory), true)
if (StringUtil.isNotEmpty(defaultProjectDirectory))
VfsUtil.findFileByIoFile(File(defaultProjectDirectory), true)
else
VfsUtil.findFileByIoFile(File(SystemProperties.getUserHome()), true)
}
Expand Down

0 comments on commit a7e6a0d

Please sign in to comment.