Skip to content

Commit 1c9626e

Browse files
committed
setting group hiding
1 parent 90d041b commit 1c9626e

File tree

16 files changed

+217
-202
lines changed

16 files changed

+217
-202
lines changed

src/main/kotlin/com/lambda/config/AutomationConfig.kt

Lines changed: 25 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -102,18 +102,18 @@ open class AutomationConfig(
102102
}
103103

104104
@SettingEditorDsl
105-
internal inline fun <T : Any> KProperty0<T>.edit(edits: FullEditBuilder<T>.(AbstractSetting<T>) -> Unit) {
105+
internal inline fun <T : Any> KProperty0<T>.edit(edits: TypedEditBuilder<T>.(AbstractSetting<T>) -> Unit) {
106106
val setting = delegate as? AbstractSetting<T> ?: throw IllegalStateException("Setting delegate did not match current value's type")
107-
FullEditBuilder(setting, this@AutomationConfig).edits(setting)
107+
TypedEditBuilder(listOf(setting), this@AutomationConfig).edits(setting)
108108
}
109109

110110
@SettingEditorDsl
111-
internal inline fun <T : Any> KProperty0<T>.editWith(
112-
other: KProperty0<*>,
113-
edits: FullEditBuilder<T>.(AbstractSetting<*>) -> Unit
111+
internal inline fun <T : Any, R : Any> KProperty0<T>.editWith(
112+
other: KProperty0<R>,
113+
edits: TypedEditBuilder<T>.(AbstractSetting<R>) -> Unit
114114
) {
115115
val setting = delegate as? AbstractSetting<T> ?: throw IllegalStateException("Setting delegate did not match current value's type")
116-
FullEditBuilder(setting, this@AutomationConfig).edits(other.delegate as AbstractSetting<*>)
116+
TypedEditBuilder(listOf(setting), this@AutomationConfig).edits(other.delegate as AbstractSetting<R>)
117117
}
118118

119119
@SettingEditorDsl
@@ -123,11 +123,11 @@ open class AutomationConfig(
123123
) { BasicEditBuilder(this@AutomationConfig, settings.map { it.delegate } as List<AbstractSetting<*>>).apply(edits) }
124124

125125
@SettingEditorDsl
126-
fun editWith(
126+
internal inline fun <T : Any> editWith(
127127
vararg settings: KProperty0<*>,
128-
other: KProperty0<*>,
129-
edits: BasicEditBuilder.(AbstractSetting<*>) -> Unit
130-
) { BasicEditBuilder(this@AutomationConfig, settings.map { it.delegate } as List<AbstractSetting<*>>).edits(other.delegate as AbstractSetting<*>) }
128+
other: KProperty0<T>,
129+
edits: BasicEditBuilder.(AbstractSetting<T>) -> Unit
130+
) { BasicEditBuilder(this@AutomationConfig, settings.map { it.delegate } as List<AbstractSetting<*>>).edits(other.delegate as AbstractSetting<T>) }
131131

132132
@SettingEditorDsl
133133
internal inline fun <T : Any> editTyped(
@@ -146,6 +146,21 @@ open class AutomationConfig(
146146
fun hide(vararg settings: KProperty0<*>) =
147147
this@AutomationConfig.settings.removeAll(settings.map { it.delegate } as List<AbstractSetting<*>>)
148148

149+
@SettingEditorDsl
150+
fun hideAll(settingGroup: SettingGroup) {
151+
settings.removeAll(settingGroup.settings)
152+
}
153+
154+
@SettingEditorDsl
155+
fun hideAll(vararg settingGroups: SettingGroup) {
156+
settings.removeAll(settingGroups.flatMap { it.settings })
157+
}
158+
159+
@SettingEditorDsl
160+
fun hideAllExcept(settingGroup: SettingGroup, vararg settings: KProperty0<*>) {
161+
this@AutomationConfig.settings.removeIf { it in settingGroup.settings && it !in (settings.toList() as List<AbstractSetting<*>>) }
162+
}
163+
149164
open class BasicEditBuilder(val c: Configurable, open val settings: Collection<AbstractSetting<*>>) {
150165
@SettingEditorDsl
151166
fun visibility(vis: () -> Boolean) =
@@ -177,21 +192,6 @@ open class AutomationConfig(
177192
}
178193
}
179194

180-
class FullEditBuilder<T : Any>(
181-
private val setting: AbstractSetting<T>,
182-
c: Configurable
183-
) : TypedEditBuilder<T>(setOf(setting), c) {
184-
@SettingEditorDsl
185-
fun name(name: String) {
186-
setting.name = name
187-
}
188-
189-
@SettingEditorDsl
190-
fun description(description: String) {
191-
setting.description = description
192-
}
193-
}
194-
195195
enum class InsertMode {
196196
Above,
197197
Below
Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,27 @@
1+
/*
2+
* Copyright 2025 Lambda
3+
*
4+
* This program is free software: you can redistribute it and/or modify
5+
* it under the terms of the GNU General Public License as published by
6+
* the Free Software Foundation, either version 3 of the License, or
7+
* (at your option) any later version.
8+
*
9+
* This program is distributed in the hope that it will be useful,
10+
* but WITHOUT ANY WARRANTY; without even the implied warranty of
11+
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12+
* GNU General Public License for more details.
13+
*
14+
* You should have received a copy of the GNU General Public License
15+
* along with this program. If not, see <http://www.gnu.org/licenses/>.
16+
*/
17+
18+
package com.lambda.config
19+
20+
abstract class SettingGroup() {
21+
val settings = mutableListOf<AbstractSetting<*>>()
22+
23+
fun <T : Any> AbstractSetting<T>.index(): AbstractSetting<T> {
24+
settings.add(this)
25+
return this
26+
}
27+
}

0 commit comments

Comments
 (0)