summaryrefslogtreecommitdiff
path: root/src/main/kotlin/me/kyren223/harpoonforjb
diff options
context:
space:
mode:
Diffstat (limited to 'src/main/kotlin/me/kyren223/harpoonforjb')
-rw-r--r--src/main/kotlin/me/kyren223/harpoonforjb/AppSettingsConfigurable.kt47
-rw-r--r--src/main/kotlin/me/kyren223/harpoonforjb/AppSettingsState.kt29
-rw-r--r--src/main/kotlin/me/kyren223/harpoonforjb/SettingsData.kt47
-rw-r--r--src/main/kotlin/me/kyren223/harpoonforjb/State.java4
4 files changed, 123 insertions, 4 deletions
diff --git a/src/main/kotlin/me/kyren223/harpoonforjb/AppSettingsConfigurable.kt b/src/main/kotlin/me/kyren223/harpoonforjb/AppSettingsConfigurable.kt
new file mode 100644
index 0000000..5d50bb9
--- /dev/null
+++ b/src/main/kotlin/me/kyren223/harpoonforjb/AppSettingsConfigurable.kt
@@ -0,0 +1,47 @@
+// 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.
+package me.kyren223.harpoonforjb
+
+import com.intellij.openapi.options.Configurable
+import com.intellij.openapi.util.NlsContexts.ConfigurableName
+import javax.swing.JComponent
+
+class AppSettingsConfigurable : Configurable {
+ private var settings: SettingsData? = null
+ override fun getDisplayName(): @ConfigurableName String {
+ return "HarpoonForJB Settings"
+ }
+
+ override fun createComponent(): JComponent {
+ settings = SettingsData()
+ return settings!!.panel
+ }
+
+ override fun isModified(): Boolean {
+ val settings = AppSettingsState.instance
+ if (settings.harpoonWidth != this.settings!!.getHarpoonWidth()) return true
+ if (settings.harpoonHeight != this.settings!!.getHarpoonHeight()) return true
+ if (settings.harpoonFontSize != this.settings!!.getHarpoonFontSize()) return true
+ return false
+ }
+
+ override fun apply() {
+ val settings = AppSettingsState.instance
+ settings.harpoonWidth = this.settings!!.getHarpoonWidth()
+ settings.harpoonHeight = this.settings!!.getHarpoonHeight()
+ settings.harpoonFontSize = this.settings!!.getHarpoonFontSize()
+ }
+
+ override fun reset() {
+ val settings = AppSettingsState.instance
+ if (this.settings == null) {
+ this.settings = SettingsData()
+ }
+ this.settings!!.setHarpoonWidth(settings.harpoonWidth)
+ this.settings!!.setHarpoonHeight(settings.harpoonHeight)
+ this.settings!!.setHarpoonFontSize(settings.harpoonFontSize)
+ }
+
+ override fun disposeUIResources() {
+ settings = null
+ }
+}
diff --git a/src/main/kotlin/me/kyren223/harpoonforjb/AppSettingsState.kt b/src/main/kotlin/me/kyren223/harpoonforjb/AppSettingsState.kt
new file mode 100644
index 0000000..5699d53
--- /dev/null
+++ b/src/main/kotlin/me/kyren223/harpoonforjb/AppSettingsState.kt
@@ -0,0 +1,29 @@
+package me.kyren223.harpoonforjb
+
+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
+
+// 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.
+@State(name = "me.kyren223.harpoonforjb.AppSettingsState", storages = [Storage("SdkSettingsPlugin.xml")])
+class AppSettingsState : PersistentStateComponent<AppSettingsState?> {
+
+ var harpoonWidth = 800
+ var harpoonHeight = 400
+ var harpoonFontSize = 20
+
+ override fun getState(): AppSettingsState {
+ return this
+ }
+
+ override fun loadState(state: AppSettingsState) {
+ XmlSerializerUtil.copyBean(state, this)
+ }
+
+ companion object {
+ val instance: AppSettingsState
+ get() = ApplicationManager.getApplication().getService(AppSettingsState::class.java)
+ }
+}
diff --git a/src/main/kotlin/me/kyren223/harpoonforjb/SettingsData.kt b/src/main/kotlin/me/kyren223/harpoonforjb/SettingsData.kt
new file mode 100644
index 0000000..3749661
--- /dev/null
+++ b/src/main/kotlin/me/kyren223/harpoonforjb/SettingsData.kt
@@ -0,0 +1,47 @@
+package me.kyren223.harpoonforjb
+
+import com.intellij.ui.JBIntSpinner
+import com.intellij.ui.components.JBLabel
+import com.intellij.util.ui.FormBuilder
+import javax.swing.JPanel
+
+class SettingsData {
+
+ val panel: JPanel
+ private val harpoonWidth: JBIntSpinner = JBIntSpinner(800, 1, 5000, 10)
+ private val harpoonHeight: JBIntSpinner = JBIntSpinner(400, 1, 5000, 10)
+ private val harpoonFontSize: JBIntSpinner = JBIntSpinner(20, 1, 100)
+
+ init {
+ panel = FormBuilder.createFormBuilder()
+ .addLabeledComponent(JBLabel("Harpoon width"), harpoonWidth, 1, false)
+ .addLabeledComponent(JBLabel("Harpoon height"), harpoonHeight, 1, false)
+ .addLabeledComponent(JBLabel("Harpoon font size"), harpoonFontSize, 1, false)
+ .addComponentFillVertically(JPanel(), 0)
+ .panel
+ }
+
+ fun getHarpoonWidth(): Int {
+ return harpoonWidth.number
+ }
+
+ fun getHarpoonHeight(): Int {
+ return harpoonHeight.number
+ }
+
+ fun getHarpoonFontSize(): Int {
+ return harpoonFontSize.number
+ }
+
+ fun setHarpoonWidth(width: Int) {
+ harpoonWidth.number = width
+ }
+
+ fun setHarpoonHeight(height: Int) {
+ harpoonHeight.number = height
+ }
+
+ fun setHarpoonFontSize(fontSize: Int) {
+ harpoonFontSize.number = fontSize
+ }
+}
diff --git a/src/main/kotlin/me/kyren223/harpoonforjb/State.java b/src/main/kotlin/me/kyren223/harpoonforjb/State.java
deleted file mode 100644
index 3996786..0000000
--- a/src/main/kotlin/me/kyren223/harpoonforjb/State.java
+++ /dev/null
@@ -1,4 +0,0 @@
-package me.kyren223.harpoonforjb;
-
-public class State {
-}