1
0
mirror of https://github.com/chylex/IntelliJ-Inspection-Lens.git synced 2025-04-22 00:15:45 +02:00

Add button to reset settings to default

This commit is contained in:
chylex 2025-01-15 01:37:15 +01:00
parent 3aeeb32bef
commit 102352a2eb
Signed by: chylex
SSH Key Fingerprint: SHA256:WqM8X/1DDn11LbYM0H5wsqZUjbcKxVsic37L+ERcF4o
2 changed files with 29 additions and 2 deletions
src/main/kotlin/com/chylex/intellij/inspectionlens/settings

View File

@ -10,6 +10,7 @@ import com.intellij.openapi.editor.markup.TextAttributes
import com.intellij.openapi.options.BoundConfigurable
import com.intellij.openapi.options.ConfigurableWithId
import com.intellij.openapi.ui.DialogPanel
import com.intellij.openapi.ui.MessageDialogBuilder
import com.intellij.openapi.util.Disposer
import com.intellij.ui.DisabledTraversalPolicy
import com.intellij.ui.EditorTextFieldCellRenderer.SimpleRendererComponent
@ -75,7 +76,9 @@ class LensApplicationConfigurable : BoundConfigurable("Inspection Lens"), Config
override fun createPanel(): DialogPanel {
val settings = settingsService.state
return panel {
lateinit var panel: DialogPanel
panel = panel {
group("Appearance") {
row {
checkBox("Use editor font").bindSelected(settings::useEditorFont)
@ -84,7 +87,7 @@ class LensApplicationConfigurable : BoundConfigurable("Inspection Lens"), Config
group("Behavior") {
row("Hover mode:") {
val items = LensHoverMode.values().toList()
val items = LensHoverMode.entries
val renderer = SimpleListCellRenderer.create("", LensHoverMode::description)
comboBox(items, renderer).bindItem(settings::lensHoverMode) { settings.lensHoverMode = it ?: LensHoverMode.DEFAULT }
}
@ -105,7 +108,20 @@ class LensApplicationConfigurable : BoundConfigurable("Inspection Lens"), Config
checkBox("Other").bindSelected(settings::showUnknownSeverities)
}
}
group("Actions") {
row {
button("Reset to Default") {
if (MessageDialogBuilder.yesNo("Reset to Default", "Are you sure you want to reset settings to default?").ask(panel)) {
settingsService.resetState()
reset()
}
}
}
}
}
return panel
}
private fun <K, V> Cell<JBCheckBox>.bindSelectedToNotIn(collection: MutableMap<K, V>, key: K, value: V): Cell<JBCheckBox> {

View File

@ -40,6 +40,17 @@ class LensSettingsState : SimplePersistentStateComponent<LensSettingsState.State
update()
}
fun resetState() {
val default = State()
state.hiddenSeverities.apply { clear(); putAll(default.hiddenSeverities) }
state.showUnknownSeverities = default.showUnknownSeverities
state.useEditorFont = default.useEditorFont
state.lensHoverMode = default.lensHoverMode
update()
}
fun update() {
severityFilter = createSeverityFilter()
InspectionLens.scheduleRefresh()