summaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authorKyren223 <ulmliad223@gmail.com>2024-02-13 14:07:55 +0200
committerKyren223 <ulmliad223@gmail.com>2024-02-13 14:07:55 +0200
commit6f6bd6a028f48a1685370049406986425f889a50 (patch)
tree0dcb9ccf43b21b754b80cd8b519003b022e21832 /src
parent923453baa759f7d7e2f6fb4e1d1610fe5b773789 (diff)
Added a settings menu
Changed project from java to kotlin
Diffstat (limited to 'src')
-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
-rw-r--r--src/main/resources/META-INF/HarpoonForJB-IdeaVim.xml2
-rw-r--r--src/main/resources/META-INF/plugin.xml11
6 files changed, 133 insertions, 7 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 {
-}
diff --git a/src/main/resources/META-INF/HarpoonForJB-IdeaVim.xml b/src/main/resources/META-INF/HarpoonForJB-IdeaVim.xml
new file mode 100644
index 0000000..164f46c
--- /dev/null
+++ b/src/main/resources/META-INF/HarpoonForJB-IdeaVim.xml
@@ -0,0 +1,2 @@
+<idea-plugin>
+</idea-plugin>
diff --git a/src/main/resources/META-INF/plugin.xml b/src/main/resources/META-INF/plugin.xml
index 2aca8f6..7469358 100644
--- a/src/main/resources/META-INF/plugin.xml
+++ b/src/main/resources/META-INF/plugin.xml
@@ -1,7 +1,7 @@
<!-- Plugin Configuration File. Read more: https://plugins.jetbrains.com/docs/intellij/plugin-configuration-file.html -->
<idea-plugin>
<!-- Unique identifier of the plugin. It should be FQN. It cannot be changed between the plugin versions. -->
- <id>me.kyren223.HarpoonForJB</id>
+ <id>me.kyren223.harpoonforjb</id>
<!-- Public plugin name should be written in Title Case.
Guidelines: https://plugins.jetbrains.com/docs/marketplace/plugin-overview-page.html#plugin-name -->
@@ -27,10 +27,15 @@
<!-- Product and plugin compatibility requirements.
Read more: https://plugins.jetbrains.com/docs/intellij/plugin-compatibility.html -->
<depends>com.intellij.modules.platform</depends>
-
+ <depends optional="true" config-file="HarpoonForJB-IdeaVim.xml">IdeaVIM</depends>
<!-- Extension points defined by the plugin.
Read more: https://plugins.jetbrains.com/docs/intellij/plugin-extension-points.html -->
<extensions defaultExtensionNs="com.intellij">
-
+ <applicationConfigurable
+ parentId="tools"
+ instance="me.kyren223.harpoonforjb.AppSettingsConfigurable"
+ id="me.kyren223.harpoonforjb.AppSettingsConfigurable"
+ displayName="HarpoonForJB Settings"/>
+ <applicationService serviceImplementation="me.kyren223.harpoonforjb.AppSettingsState"/>
</extensions>
</idea-plugin> \ No newline at end of file