mirror of
https://gitflic.ru/project/openide/openide.git
synced 2025-12-16 22:51:17 +07:00
(IDEA-347002) Settings Import: introduce a recent project limit
#IDEA-347002 Fixed GitOrigin-RevId: f0f723d27341a73077c30cadade360044eaee013
This commit is contained in:
committed by
intellij-monorepo-bot
parent
1dd34e4bb0
commit
aa033b1f0f
@@ -1,7 +1,8 @@
|
||||
// Copyright 2000-2023 JetBrains s.r.o. and contributors. Use of this source code is governed by the Apache 2.0 license.
|
||||
// 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.ide.startup.importSettings.models
|
||||
|
||||
import com.intellij.ide.RecentProjectMetaInfo
|
||||
import com.intellij.util.PlatformUtils
|
||||
|
||||
open class Settings(
|
||||
val preferences: SettingsPreferences = SettingsPreferences(),
|
||||
@@ -13,12 +14,28 @@ open class Settings(
|
||||
* Original plugin id ⇒ feature or plugin info.
|
||||
*/
|
||||
val plugins: MutableMap<String, FeatureInfo> = mutableMapOf(),
|
||||
/**
|
||||
* Don't forget to set info.projectOpenTimestamp
|
||||
*/
|
||||
val recentProjects: MutableList<RecentPathInfo> = mutableListOf()
|
||||
) {
|
||||
val notes = mutableMapOf<String, Any>()
|
||||
|
||||
private val recentProjectLimit =
|
||||
if (PlatformUtils.isWebStorm()) 5
|
||||
else 10
|
||||
|
||||
private val recentProjectList = mutableListOf<RecentPathInfo>()
|
||||
val recentProjects: List<RecentPathInfo> = recentProjectList
|
||||
|
||||
/**
|
||||
* NOTE: Remember to set info.projectOpenTimestamp.
|
||||
*
|
||||
* @return true if there is still space for new projects, false otherwise.
|
||||
*/
|
||||
fun addRecentProjectIfNeeded(info: () -> RecentPathInfo?): Boolean {
|
||||
if (recentProjects.size < recentProjectLimit) {
|
||||
info()?.let(recentProjectList::add)
|
||||
}
|
||||
|
||||
return recentProjects.size < recentProjectLimit
|
||||
}
|
||||
}
|
||||
|
||||
data class RecentPathInfo(
|
||||
|
||||
@@ -42,14 +42,11 @@ class StateDatabaseParser(private val settings: Settings) {
|
||||
?: error("Unexpected JSON data; expected: ${JsonNodeType.OBJECT}")
|
||||
|
||||
val paths = (root["entries"] as ArrayNode).mapNotNull { it["folderUri"]?.textValue() }
|
||||
|
||||
paths.forEach { uri ->
|
||||
logger.runAndLogException {
|
||||
val res = StorageParser.parsePath(URI(uri))
|
||||
if (res != null) {
|
||||
settings.recentProjects.add(res)
|
||||
}
|
||||
}
|
||||
for (uri in paths) {
|
||||
val shouldBreak = logger.runAndLogException {
|
||||
!settings.addRecentProjectIfNeeded { StorageParser.parsePath(URI(uri)) }
|
||||
} ?: false
|
||||
if (shouldBreak) break
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -33,13 +33,13 @@ class StorageParser(private val settings: Settings) {
|
||||
}
|
||||
|
||||
val path = when (uri.scheme) {
|
||||
"file" -> Path.of(uri)
|
||||
"vscode-remote" -> fromWslPath(uri.schemeSpecificPart)
|
||||
else -> {
|
||||
logger.warn("Unknown scheme: ${uri.scheme}")
|
||||
null
|
||||
}
|
||||
} ?: return null
|
||||
"file" -> Path.of(uri)
|
||||
"vscode-remote" -> fromWslPath(uri.schemeSpecificPart)
|
||||
else -> {
|
||||
logger.warn("Unknown scheme: ${uri.scheme}")
|
||||
null
|
||||
}
|
||||
} ?: return null
|
||||
|
||||
val modifiedTime = path.toFile().listFiles()?.maxByOrNull { it.lastModified() }?.lastModified()
|
||||
|
||||
@@ -106,17 +106,11 @@ class StorageParser(private val settings: Settings) {
|
||||
}
|
||||
|
||||
val workspaces = if (!workspacesNew.isNullOrEmpty()) workspacesNew else workspacesOld ?: return
|
||||
|
||||
workspaces.forEach { uri ->
|
||||
try {
|
||||
val res = parsePath(URI(uri))
|
||||
if (res != null) {
|
||||
settings.recentProjects.add(res)
|
||||
}
|
||||
}
|
||||
catch (t: Throwable) {
|
||||
logger.warn(t)
|
||||
}
|
||||
for (uri in workspaces) {
|
||||
val shouldBreak = logger.runAndLogException {
|
||||
!settings.addRecentProjectIfNeeded { parsePath(URI(uri)) }
|
||||
} ?: false
|
||||
if (shouldBreak) break
|
||||
}
|
||||
}
|
||||
catch (t: Throwable) {
|
||||
|
||||
@@ -54,7 +54,7 @@ class RecentProjectsParser(private val settings: Settings) {
|
||||
}
|
||||
}
|
||||
|
||||
settings.recentProjects.add(RecentPathInfo(path.invariantSeparatorsPathString, rpmi))
|
||||
settings.addRecentProjectIfNeeded { RecentPathInfo(path.invariantSeparatorsPathString, rpmi) }
|
||||
}
|
||||
catch (t: Throwable) {
|
||||
logger.warn(t)
|
||||
|
||||
@@ -1,4 +1,4 @@
|
||||
// Copyright 2000-2023 JetBrains s.r.o. and contributors. Use of this source code is governed by the Apache 2.0 license.
|
||||
// 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.ide.startup.importSettings.providers.vswin.parsers
|
||||
|
||||
import com.intellij.ide.startup.importSettings.db.KnownColorSchemes
|
||||
@@ -32,7 +32,9 @@ class VSParser(private val hive: VSHive) {
|
||||
// plugins.add(KnownPlugins.XAMLStyler)
|
||||
//}
|
||||
|
||||
recentProjects.addAll(regParser.recentProjects)
|
||||
for (path in regParser.recentProjects) {
|
||||
if (!addRecentProjectIfNeeded { path }) break
|
||||
}
|
||||
|
||||
if (laf == null) {
|
||||
logger.info("Got null for laf, trying registry method")
|
||||
|
||||
Reference in New Issue
Block a user