Skip to content

Commit

Permalink
Version 2.1.2
Browse files Browse the repository at this point in the history
Reverted back to the old settings panel due to the new one not saving properly after a restart.
  • Loading branch information
Kyren223 committed May 14, 2024
1 parent 0f2e71b commit f18b832
Show file tree
Hide file tree
Showing 8 changed files with 42 additions and 38 deletions.
3 changes: 1 addition & 2 deletions build.gradle.kts
Original file line number Diff line number Diff line change
Expand Up @@ -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()
Expand Down
25 changes: 15 additions & 10 deletions src/main/kotlin/me/kyren223/trident/data/Settings.kt
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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)
}
}
18 changes: 9 additions & 9 deletions src/main/kotlin/me/kyren223/trident/data/SettingsData.kt
Original file line number Diff line number Diff line change
Expand Up @@ -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()))
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand All @@ -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
Expand All @@ -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()
Expand All @@ -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)
Expand Down
8 changes: 4 additions & 4 deletions src/main/kotlin/me/kyren223/trident/ui/TridentListMenu.kt
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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()
}
Expand All @@ -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
Expand Down
6 changes: 3 additions & 3 deletions src/main/kotlin/me/kyren223/trident/ui/TridentMappingsMenu.kt
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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()
Expand All @@ -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
Expand Down
10 changes: 5 additions & 5 deletions src/main/kotlin/me/kyren223/trident/utils/TridentUtils.kt
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand All @@ -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
Expand Down Expand Up @@ -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)
Expand Down Expand Up @@ -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) {
Expand Down
2 changes: 1 addition & 1 deletion src/main/resources/META-INF/plugin.xml
Original file line number Diff line number Diff line change
Expand Up @@ -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>
Expand Down

0 comments on commit f18b832

Please sign in to comment.