summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorKyren223 <ulmliad223@gmail.com>2024-05-14 19:10:19 +0300
committerKyren223 <ulmliad223@gmail.com>2024-05-14 19:10:19 +0300
commitf18b83288869613c2119ed3c51fd1b94c6a313ef (patch)
tree2df6cb7bce7123580adf4e3be55d5ae67d0e0f77
parent0f2e71ba3e40ba5994fa723b2d4e3792a6b5165b (diff)
Version 2.1.2
Reverted back to the old settings panel due to the new one not saving properly after a restart.
-rw-r--r--build.gradle.kts3
-rw-r--r--src/main/kotlin/me/kyren223/trident/data/Settings.kt25
-rw-r--r--src/main/kotlin/me/kyren223/trident/data/SettingsData.kt18
-rw-r--r--src/main/kotlin/me/kyren223/trident/ui/SettingsConfigurable.kt8
-rw-r--r--src/main/kotlin/me/kyren223/trident/ui/TridentListMenu.kt8
-rw-r--r--src/main/kotlin/me/kyren223/trident/ui/TridentMappingsMenu.kt6
-rw-r--r--src/main/kotlin/me/kyren223/trident/utils/TridentUtils.kt10
-rw-r--r--src/main/resources/META-INF/plugin.xml2
8 files changed, 42 insertions, 38 deletions
diff --git a/build.gradle.kts b/build.gradle.kts
index 521f020..d427f07 100644
--- a/build.gradle.kts
+++ b/build.gradle.kts
@@ -3,9 +3,8 @@ plugins {
id("org.jetbrains.kotlin.jvm") version "1.9.21"
id("org.jetbrains.intellij") version "1.17.3"
}
-
group = "me.kyren223"
-version = "2.1.1"
+version = "2.1.2"
repositories {
mavenCentral()
diff --git a/src/main/kotlin/me/kyren223/trident/data/Settings.kt b/src/main/kotlin/me/kyren223/trident/data/Settings.kt
index a1a400b..e97737c 100644
--- a/src/main/kotlin/me/kyren223/trident/data/Settings.kt
+++ b/src/main/kotlin/me/kyren223/trident/data/Settings.kt
@@ -2,20 +2,12 @@ package me.kyren223.trident.data
import com.intellij.openapi.application.ApplicationManager
import com.intellij.openapi.components.*
+import com.intellij.util.xmlb.XmlSerializerUtil
// Copyright 2000-2022 JetBrains s.r.o. and other contributors. Use of this source code is governed by the Apache 2.0 license that can be found in the LICENSE file.
@Service
@State(name = "me.kyren223.trident.data.SettingsState", storages = [Storage("SdkSettingsPlugin.xml")])
-class Settings : SimplePersistentStateComponent<SettingsState>(SettingsState()) {
- companion object {
- private val instance: Settings
- get() = ApplicationManager.getApplication().getService(Settings::class.java)
- val state: SettingsState
- get() = instance.state
- }
-}
-
-class SettingsState : BaseState() {
+class SettingsState : PersistentStateComponent<SettingsState?> {
var width = 800
var height = 400
var fontSize = 20
@@ -25,4 +17,17 @@ class SettingsState : BaseState() {
var recursiveMapping = false
var rememberLine = false
var indexCycling = false
+
+ override fun getState(): SettingsState {
+ return this
+ }
+
+ override fun loadState(state: SettingsState) {
+ XmlSerializerUtil.copyBean(state, this)
+ }
+
+ companion object {
+ val instance: SettingsState
+ get() = ApplicationManager.getApplication().getService(SettingsState::class.java)
+ }
}
diff --git a/src/main/kotlin/me/kyren223/trident/data/SettingsData.kt b/src/main/kotlin/me/kyren223/trident/data/SettingsData.kt
index b4c48f7..26cb1d1 100644
--- a/src/main/kotlin/me/kyren223/trident/data/SettingsData.kt
+++ b/src/main/kotlin/me/kyren223/trident/data/SettingsData.kt
@@ -17,20 +17,20 @@ class SettingsData {
val panel: JPanel
- private val width = JBIntSpinner(Settings.state.width, minValue, maxValue, step)
- private val height = JBIntSpinner(Settings.state.height, minValue, maxValue, step)
- private val fontSize = JBIntSpinner(Settings.state.fontSize, minValue, maxValue, step)
+ private val width = JBIntSpinner(SettingsState.instance.width, minValue, maxValue, step)
+ private val height = JBIntSpinner(SettingsState.instance.height, minValue, maxValue, step)
+ private val fontSize = JBIntSpinner(SettingsState.instance.fontSize, minValue, maxValue, step)
- private val enterToSelect = JBCheckBox(null, Settings.state.enterToSelect)
- private val rememberLine = JBCheckBox(null, Settings.state.rememberLine)
+ private val enterToSelect = JBCheckBox(null, SettingsState.instance.enterToSelect)
+ private val rememberLine = JBCheckBox(null, SettingsState.instance.rememberLine)
private val automaticMapping = ComboBox(AutomaticMapping.entries.toTypedArray())
private val automaticReplacing = ComboBox(AutomaticReplacing.entries.toTypedArray())
- private val recursiveMapping = JBCheckBox(null, Settings.state.recursiveMapping)
- private val indexCycling = JBCheckBox(null, Settings.state.indexCycling)
+ private val recursiveMapping = JBCheckBox(null, SettingsState.instance.recursiveMapping)
+ private val indexCycling = JBCheckBox(null, SettingsState.instance.indexCycling)
init {
- automaticMapping.selectedItem = Settings.state.automaticMapping
- automaticReplacing.selectedItem = Settings.state.automaticReplacing
+ automaticMapping.selectedItem = SettingsState.instance.automaticMapping
+ automaticReplacing.selectedItem = SettingsState.instance.automaticReplacing
panel = FormBuilder.createFormBuilder()
.addComponent(JBLabel("Popup settings").withFont(JBFont.h4()))
diff --git a/src/main/kotlin/me/kyren223/trident/ui/SettingsConfigurable.kt b/src/main/kotlin/me/kyren223/trident/ui/SettingsConfigurable.kt
index c0d1247..f6979b1 100644
--- a/src/main/kotlin/me/kyren223/trident/ui/SettingsConfigurable.kt
+++ b/src/main/kotlin/me/kyren223/trident/ui/SettingsConfigurable.kt
@@ -4,7 +4,7 @@ package me.kyren223.trident.ui
import com.intellij.openapi.options.Configurable
import com.intellij.openapi.util.NlsContexts.ConfigurableName
import me.kyren223.trident.data.SettingsData
-import me.kyren223.trident.data.Settings
+import me.kyren223.trident.data.SettingsState
import javax.swing.JComponent
class SettingsConfigurable : Configurable {
@@ -21,7 +21,7 @@ class SettingsConfigurable : Configurable {
}
override fun isModified(): Boolean {
- val settings = Settings.state
+ val settings = SettingsState.instance
if (settings.width != this.settings!!.getWidth()) return true
if (settings.height != this.settings!!.getHeight()) return true
if (settings.fontSize != this.settings!!.getFontSize()) return true
@@ -35,7 +35,7 @@ class SettingsConfigurable : Configurable {
}
override fun apply() {
- val settings = Settings.state
+ val settings = SettingsState.instance
settings.width = this.settings!!.getWidth()
settings.height = this.settings!!.getHeight()
settings.fontSize = this.settings!!.getFontSize()
@@ -48,7 +48,7 @@ class SettingsConfigurable : Configurable {
}
override fun reset() {
- val settings = Settings.state
+ val settings = SettingsState.instance
if (this.settings == null) this.settings = SettingsData()
this.settings!!.setWidth(settings.width)
this.settings!!.setHeight(settings.height)
diff --git a/src/main/kotlin/me/kyren223/trident/ui/TridentListMenu.kt b/src/main/kotlin/me/kyren223/trident/ui/TridentListMenu.kt
index af04b7c..75e059a 100644
--- a/src/main/kotlin/me/kyren223/trident/ui/TridentListMenu.kt
+++ b/src/main/kotlin/me/kyren223/trident/ui/TridentListMenu.kt
@@ -8,7 +8,7 @@ import com.intellij.openapi.ui.DialogWrapper
import com.intellij.ui.EditorTextField
import com.maddyhome.idea.vim.newapi.vim
import com.maddyhome.idea.vim.state.mode.Mode
-import me.kyren223.trident.data.Settings
+import me.kyren223.trident.data.SettingsState
import me.kyren223.trident.utils.TridentList
import me.kyren223.trident.utils.injectEnterToSelectMapping
import me.kyren223.trident.utils.setEditorMode
@@ -22,7 +22,7 @@ class TridentListMenu(private val content: String) : DialogWrapper(true) {
init {
this.title = "Trident List"
- val settings = Settings.state
+ val settings = SettingsState.instance
setSize(settings.width, settings.height)
super.init()
}
@@ -31,9 +31,9 @@ class TridentListMenu(private val content: String) : DialogWrapper(true) {
editor = EditorTextField(this.content)
editor.setOneLineMode(false)
editor.addSettingsProvider {
- it.setFontSize(Settings.state.fontSize)
+ it.setFontSize(SettingsState.instance.fontSize)
it.isInsertMode = false
- val lineNumber = if (Settings.state.rememberLine) line else 0
+ val lineNumber = if (SettingsState.instance.rememberLine) line else 0
it.caretModel.moveToLogicalPosition(LogicalPosition(lineNumber, 0))
it.settings.isLineNumbersShown = true
it.settings.lineNumerationType = EditorSettings.LineNumerationType.ABSOLUTE
diff --git a/src/main/kotlin/me/kyren223/trident/ui/TridentMappingsMenu.kt b/src/main/kotlin/me/kyren223/trident/ui/TridentMappingsMenu.kt
index 4a6d859..79f1df8 100644
--- a/src/main/kotlin/me/kyren223/trident/ui/TridentMappingsMenu.kt
+++ b/src/main/kotlin/me/kyren223/trident/ui/TridentMappingsMenu.kt
@@ -7,7 +7,7 @@ import com.intellij.openapi.ui.DialogWrapper
import com.intellij.ui.EditorTextField
import com.maddyhome.idea.vim.newapi.vim
import com.maddyhome.idea.vim.state.mode.Mode
-import me.kyren223.trident.data.Settings
+import me.kyren223.trident.data.SettingsState
import me.kyren223.trident.utils.TridentMappings
import me.kyren223.trident.utils.setEditorMode
import java.awt.event.FocusEvent
@@ -18,7 +18,7 @@ class TridentMappingsMenu(private val content: String) : DialogWrapper(true) {
private lateinit var editor: EditorTextField
init {
- val settings = Settings.state
+ val settings = SettingsState.instance.state
this.title = "Trident Mappings"
setSize(settings.width, settings.height)
super.init()
@@ -28,7 +28,7 @@ class TridentMappingsMenu(private val content: String) : DialogWrapper(true) {
editor = EditorTextField(this.content)
editor.setOneLineMode(false)
editor.addSettingsProvider {
- it.setFontSize(Settings.state.fontSize)
+ it.setFontSize(SettingsState.instance.fontSize)
it.isInsertMode = false
it.caretModel.moveToLogicalPosition(LogicalPosition(0, 0))
it.settings.isLineNumbersShown = true
diff --git a/src/main/kotlin/me/kyren223/trident/utils/TridentUtils.kt b/src/main/kotlin/me/kyren223/trident/utils/TridentUtils.kt
index 910fe34..96ab454 100644
--- a/src/main/kotlin/me/kyren223/trident/utils/TridentUtils.kt
+++ b/src/main/kotlin/me/kyren223/trident/utils/TridentUtils.kt
@@ -7,7 +7,7 @@ import com.intellij.openapi.vfs.LocalFileSystem
import com.intellij.openapi.vfs.VirtualFile
import me.kyren223.trident.data.AutomaticMapping
import me.kyren223.trident.data.AutomaticReplacing
-import me.kyren223.trident.data.Settings
+import me.kyren223.trident.data.SettingsState
object TridentList {
private const val PROPERTIES_KEY = "TridentList"
@@ -20,8 +20,8 @@ object TridentList {
}
private fun getModifiedPath(project: Project, path: String): String {
- val automaticMapping = Settings.state.automaticMapping
- val automaticReplacing = Settings.state.automaticReplacing
+ val automaticMapping = SettingsState.instance.automaticMapping
+ val automaticReplacing = SettingsState.instance.automaticReplacing
val mappings = TridentMappings.get(project)
val hasReplacement = automaticReplacing != AutomaticReplacing.Disabled
@@ -113,7 +113,7 @@ object TridentList {
}
fun select(project: Project, index: Int): VirtualFile? {
- val cycle = Settings.state.indexCycling
+ val cycle = SettingsState.instance.indexCycling
val count = getFiles(project).size
val i = if (cycle) ((index % count) + count) % count else index
val files = getFiles(project)
@@ -172,7 +172,7 @@ object TridentMappings {
}
fun expand(project: Project, path: String): String {
- val recursive = Settings.state.recursiveMapping
+ val recursive = SettingsState.instance.recursiveMapping
val mappings = get(project).toList().sortedByDescending { it.first.length }
var expandedPath = path
while (true) {
diff --git a/src/main/resources/META-INF/plugin.xml b/src/main/resources/META-INF/plugin.xml
index 484fa98..e52e798 100644
--- a/src/main/resources/META-INF/plugin.xml
+++ b/src/main/resources/META-INF/plugin.xml
@@ -40,7 +40,7 @@
instance="me.kyren223.trident.ui.SettingsConfigurable"
id="me.kyren223.trident.ui.SettingsConfigurable"
displayName="Trident Settings"/>
- <applicationService serviceImplementation="me.kyren223.trident.data.Settings"/>
+ <applicationService serviceImplementation="me.kyren223.trident.data.SettingsState"/>
</extensions>
<actions>