diff options
Diffstat (limited to 'src/main/kotlin/me/kyren223/trident/data')
| -rw-r--r-- | src/main/kotlin/me/kyren223/trident/data/Settings.kt (renamed from src/main/kotlin/me/kyren223/trident/data/SettingsState.kt) | 30 | ||||
| -rw-r--r-- | src/main/kotlin/me/kyren223/trident/data/SettingsData.kt | 27 | ||||
| -rw-r--r-- | src/main/kotlin/me/kyren223/trident/data/TridentState.kt | 181 |
3 files changed, 32 insertions, 206 deletions
diff --git a/src/main/kotlin/me/kyren223/trident/data/SettingsState.kt b/src/main/kotlin/me/kyren223/trident/data/Settings.kt index 16ec372..27a7d2a 100644 --- a/src/main/kotlin/me/kyren223/trident/data/SettingsState.kt +++ b/src/main/kotlin/me/kyren223/trident/data/Settings.kt @@ -1,15 +1,21 @@ package me.kyren223.trident.data import com.intellij.openapi.application.ApplicationManager -import com.intellij.openapi.components.PersistentStateComponent -import com.intellij.openapi.components.State -import com.intellij.openapi.components.Storage -import com.intellij.util.xmlb.XmlSerializerUtil +import com.intellij.openapi.components.* // 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 SettingsState : PersistentStateComponent<SettingsState?> { +class Settings : SimplePersistentStateComponent<SettingsState>(SettingsState()) { + companion object { + val instance: Settings + get() = ApplicationManager.getApplication().getService(Settings::class.java) + val state: SettingsState + get() = instance.state + } +} +class SettingsState : BaseState() { var width = 800 var height = 400 var fontSize = 20 @@ -17,17 +23,5 @@ class SettingsState : PersistentStateComponent<SettingsState?> { var automaticMapping = false var recursiveMapping = false var rememberLine = 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) - } + var indexCycling = false } diff --git a/src/main/kotlin/me/kyren223/trident/data/SettingsData.kt b/src/main/kotlin/me/kyren223/trident/data/SettingsData.kt index 2c5c467..eed655e 100644 --- a/src/main/kotlin/me/kyren223/trident/data/SettingsData.kt +++ b/src/main/kotlin/me/kyren223/trident/data/SettingsData.kt @@ -16,14 +16,15 @@ class SettingsData { val panel: JPanel - 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 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 enterToSelect = JBCheckBox(null, SettingsState.instance.enterToSelect) - private val rememberLine = JBCheckBox(null, SettingsState.instance.rememberLine) - private val automaticMapping = JBCheckBox(null, SettingsState.instance.automaticMapping) - private val recursiveMapping = JBCheckBox(null, SettingsState.instance.recursiveMapping) + private val enterToSelect = JBCheckBox(null, Settings.state.enterToSelect) + private val rememberLine = JBCheckBox(null, Settings.state.rememberLine) + private val automaticMapping = JBCheckBox(null, Settings.state.automaticMapping) + private val recursiveMapping = JBCheckBox(null, Settings.state.recursiveMapping) + private val indexCycling = JBCheckBox(null, Settings.state.indexCycling) init { panel = FormBuilder.createFormBuilder() @@ -56,6 +57,10 @@ class SettingsData { "and will be selected when the TridentList is opened.")) .addComponent(desc("Note, this does not persist across restarts, it's run-time only.")) + .addLabeledComponent("Index cycling", indexCycling) + .addComponent(desc("If enabled, indexes will be cyclic, " + + "For example if you have 3 files and hotkey to 4, it'll cycle to 1.")) + .addComponentFillVertically(JPanel(), 0) .panel } @@ -121,4 +126,12 @@ class SettingsData { fun setRecursiveMapping(recursiveMapping: Boolean) { this.recursiveMapping.isSelected = recursiveMapping } + + fun getIndexCycling(): Boolean { + return indexCycling.isSelected + } + + fun setIndexCycling(indexCycling: Boolean) { + this.indexCycling.isSelected = indexCycling + } } diff --git a/src/main/kotlin/me/kyren223/trident/data/TridentState.kt b/src/main/kotlin/me/kyren223/trident/data/TridentState.kt deleted file mode 100644 index 54529e9..0000000 --- a/src/main/kotlin/me/kyren223/trident/data/TridentState.kt +++ /dev/null @@ -1,181 +0,0 @@ -package me.kyren223.trident.data - -//object TridentState { -// private const val TRIDENT_LIST_KEY = "TridentList" -// private const val TRIDENT_MAPPINGS_KEY = "TridentMappings" -// -// private var list: MutableMap<String, MutableList<VirtualFile>> = mutableMapOf() -// private var mappings: MutableMap<String, MutableMap<String, String>> = mutableMapOf() -// -// private var quickMenu: QuickMenu? = null -// var quickMenuSelectedIndex: Int? = null -// var quickMenuContent: String = "" -// private var pathMappingsMenu: PathMappingsMenu? = null -// var pathMappingsContent: String = "" -// -//// fun appendFile(project: Project, file: VirtualFile) { -//// if (!file.isValid) return -//// loadProject(project) -//// val files = list[project.name] -//// files!!.add(file) -//// saveProject(project) -//// } -// -//// fun selectFile(project: Project, index: Int): VirtualFile? { -//// if (index < 0) return null -//// loadProject(project) -//// val files = list[project.name] -//// if (files!!.size <= index) return null -//// return files[index] -//// } -// -//// private fun loadProject(project: Project) { -//// if (project.name in list) return -//// val properties = PropertiesComponent.getInstance(project) -//// -//// val pathMappingsList = properties.getList(TRIDENT_MAPPINGS_KEY) -//// var map = mutableMapOf<String, String>() -//// if (pathMappingsList == null) { -//// map["..."] = project.basePath!! -//// } else { -//// for (entry in pathMappingsList) { -//// val split = entry.split("=") -//// if (split.size != 2) continue -//// map[split[0]] = split[1] -//// } -//// } -//// mappings[project.name] = map -//// -//// val list = properties.getList(TRIDENT_LIST_KEY) -//// if (list == null) { -//// this.list[project.name] = mutableListOf() -//// } else { -//// val fs = LocalFileSystem.getInstance() -//// val files = list.stream() -//// .map { fs.findFileByPath(it) } -//// .toList() -//// .filterNotNull() -//// .filter { it.isValid } -//// .toMutableList() -//// this.list[project.name] = files -//// } -//// } -// -//// private fun saveProject(project: Project) { -//// if (project.name !in list) return -//// val files = list[project.name] -//// val properties = PropertiesComponent.getInstance(project) -//// -//// val stringList = files!!.stream() -//// .filter { it.isValid } -//// .map { it.path } -//// .toList() -//// properties.setList(TRIDENT_LIST_KEY, stringList) -//// -//// val pathMappingsString = mappings[project.name]!!.entries -//// .joinToString("\n") { "${it.key}=${it.value}" } -//// .split("\n") -//// properties.setList(TRIDENT_MAPPINGS_KEY, pathMappingsString) -//// } -// -//// fun getIndexOfFile(project: Project, data: VirtualFile?): Int { -//// loadProject(project) -//// val files = list[project.name] -//// if (files == null || data == null) return -1 -//// return files.indexOfFirst { it.path == data.path } -//// } -// -//// fun getFileCount(project: Project): Int { -//// loadProject(project) -//// return list[project.name]!!.size -//// } -// -// fun toggleQuickMenu(project: Project) { -// if (quickMenu != null && quickMenu!!.isShowing) { -// quickMenu!!.doCancelAction() -// return -// } -// -//// loadProject(project) -// val content = TridentList.get(project).joinToString("\n") -// quickMenu = QuickMenu(content) -// val result = quickMenu!!.showAndGet() -// -// if (content != quickMenuContent) { -// retrieveProjectFiles(project, quickMenuContent) -//// saveProject(project) -// } -// -// if (!result) return -// val index = quickMenuSelectedIndex ?: return -// quickMenuSelectedIndex = null -// val file = TridentList.select(project, index) ?: return -// FileEditorManager.getInstance(project).openFile(file, true) -// } -// -// fun quickMenuSelect() { -// if (quickMenu == null || !quickMenu!!.isShowing) return -// quickMenu!!.select() -// } -// -//// private fun getProjectContent(project: Project): String { -//// loadProject(project) -//// val map = mappings[project.name] ?: throw IllegalStateException("Path mappings not found") -//// println("map: $map") -//// var content = list[project.name]!! -//// .joinToString("\n") { it.path } -//// .trim() -//// println("content: $content") -//// for ((key, value) in map) { -//// println("key: $key | value: $value") -//// content = content.replace(value, key) -//// } -//// println("content: $content") -//// return content -//// } -// -//// private fun retrieveProjectFiles(project: Project, content: String) { -//// loadProject(project) -//// val files = content -//// .split("\n") -//// .asSequence() -//// .map { it.trim() } -//// .map { line -> -//// mappings[project.name]!!.entries.fold(line) { acc, (key, value) -> -//// acc.replace(key, value) -//// } -//// } -////// .map { -////// pathMappings[project.name]!!.entries.forEach { (key, value) -> it.replace(key, value) } -////// it -////// } -//// .filter { it.isNotBlank() } -//// .map { LocalFileSystem.getInstance().findFileByPath(it) } -//// .filterNotNull() -//// .filter { it.isValid } -//// .toMutableList() -//// list[project.name] = files -//// } -// -// fun togglePathMappingsMenu(project: Project) { -// if (pathMappingsMenu != null && pathMappingsMenu!!.isShowing) { -// pathMappingsMenu!!.doCancelAction() -// return -// } -// -//// loadProject(project) -// val content = mappings[project.name]!!.entries -// .joinToString("\n") { "${it.key}=${it.value}" } -// pathMappingsMenu = PathMappingsMenu(content) -// pathMappingsMenu!!.showAndGet() -// -// if (content != pathMappingsContent) { -// pathMappingsContent.split("\n").forEach { -// val split = it.split("=") -// if (split.size != 2) return@forEach -// mappings[project.name]!![split[0]] = split[1] -// } -//// saveProject(project) -// } -// } -//}
\ No newline at end of file |
