mirror of
https://github.com/Kilo-Org/kilocode.git
synced 2026-09-24 16:02:55 +08:00
fix(kilo-jetbrains): restore last kilo settings page
This commit is contained in:
+6
-3
@@ -1,7 +1,7 @@
|
||||
package ai.kilocode.client.actions
|
||||
|
||||
import ai.kilocode.client.plugin.KiloBundle
|
||||
import ai.kilocode.client.settings.KiloSettingsConfigurable
|
||||
import ai.kilocode.client.settings.KiloSettingsSelection
|
||||
import ai.kilocode.client.telemetry.Telemetry
|
||||
import com.intellij.openapi.actionSystem.ActionUpdateThread
|
||||
import com.intellij.openapi.actionSystem.AnActionEvent
|
||||
@@ -9,6 +9,7 @@ import com.intellij.openapi.options.Configurable
|
||||
import com.intellij.openapi.options.ConfigurableWithId
|
||||
import com.intellij.openapi.options.ShowSettingsUtil
|
||||
import com.intellij.openapi.project.DumbAwareAction
|
||||
import com.intellij.openapi.project.ProjectManager
|
||||
import java.util.function.Predicate
|
||||
|
||||
class OpenSettingsAction : DumbAwareAction(
|
||||
@@ -18,10 +19,12 @@ class OpenSettingsAction : DumbAwareAction(
|
||||
) {
|
||||
override fun actionPerformed(e: AnActionEvent) {
|
||||
Telemetry.send("Settings Opened", mapOf("surface" to "tool_window"))
|
||||
val project = e.project ?: ProjectManager.getInstance().defaultProject
|
||||
val target = KiloSettingsSelection.target(project)
|
||||
ShowSettingsUtil.getInstance().showSettingsDialog(
|
||||
e.project,
|
||||
project,
|
||||
Predicate { cfg: Configurable ->
|
||||
cfg is ConfigurableWithId && cfg.getId() == KiloSettingsConfigurable.ID
|
||||
cfg is ConfigurableWithId && cfg.getId() == target
|
||||
},
|
||||
null,
|
||||
)
|
||||
|
||||
+21
@@ -0,0 +1,21 @@
|
||||
package ai.kilocode.client.settings
|
||||
|
||||
import ai.kilocode.client.settings.profile.UserProfileConfigurable
|
||||
import com.intellij.ide.util.PropertiesComponent
|
||||
import com.intellij.openapi.project.Project
|
||||
|
||||
internal object KiloSettingsSelection {
|
||||
// IntelliJ persists the selected settings page with SettingsEditor.SELECTED_CONFIGURABLE.
|
||||
const val SELECTED_CONFIGURABLE_KEY = "settings.editor.selected.configurable"
|
||||
|
||||
fun target(project: Project): String {
|
||||
val id = PropertiesComponent.getInstance(project).getValue(SELECTED_CONFIGURABLE_KEY)
|
||||
if (id != null && isKilo(id)) return id
|
||||
return UserProfileConfigurable.ID
|
||||
}
|
||||
|
||||
private fun isKilo(id: String?): Boolean {
|
||||
if (id == KiloSettingsConfigurable.ID) return true
|
||||
return id?.startsWith("${KiloSettingsConfigurable.ID}.") == true
|
||||
}
|
||||
}
|
||||
+43
@@ -0,0 +1,43 @@
|
||||
package ai.kilocode.client.settings
|
||||
|
||||
import ai.kilocode.client.settings.models.ModelsConfigurable
|
||||
import ai.kilocode.client.settings.profile.UserProfileConfigurable
|
||||
import com.intellij.ide.util.PropertiesComponent
|
||||
import com.intellij.testFramework.fixtures.BasePlatformTestCase
|
||||
|
||||
class KiloSettingsSelectionTest : BasePlatformTestCase() {
|
||||
|
||||
override fun tearDown() {
|
||||
try {
|
||||
PropertiesComponent.getInstance(project).unsetValue(KiloSettingsSelection.SELECTED_CONFIGURABLE_KEY)
|
||||
} finally {
|
||||
super.tearDown()
|
||||
}
|
||||
}
|
||||
|
||||
fun `test falls back to profile when no last settings page exists`() {
|
||||
assertEquals(UserProfileConfigurable.ID, KiloSettingsSelection.target(project))
|
||||
}
|
||||
|
||||
fun `test falls back to profile when last page is not kilo`() {
|
||||
select("preferences.lookFeel")
|
||||
|
||||
assertEquals(UserProfileConfigurable.ID, KiloSettingsSelection.target(project))
|
||||
}
|
||||
|
||||
fun `test keeps last kilo root page`() {
|
||||
select(KiloSettingsConfigurable.ID)
|
||||
|
||||
assertEquals(KiloSettingsConfigurable.ID, KiloSettingsSelection.target(project))
|
||||
}
|
||||
|
||||
fun `test keeps last kilo child page`() {
|
||||
select(ModelsConfigurable.ID)
|
||||
|
||||
assertEquals(ModelsConfigurable.ID, KiloSettingsSelection.target(project))
|
||||
}
|
||||
|
||||
private fun select(id: String) {
|
||||
PropertiesComponent.getInstance(project).setValue(KiloSettingsSelection.SELECTED_CONFIGURABLE_KEY, id)
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user