Skip to content

Commit f34498a

Browse files
authored
Reset defaults by setting value rather than remove (#1385)
Initially reset to defaults was set up by removing the key from the preferences but that didn't work well upstream, changing the value to default instead.
1 parent 5317234 commit f34498a

File tree

2 files changed

+13
-1
lines changed

2 files changed

+13
-1
lines changed

app/src/processing/app/Preferences.kt

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -35,6 +35,9 @@ class ReactiveProperties : Properties() {
3535
operator fun set(key: String, value: String) {
3636
setProperty(key, value)
3737
}
38+
fun remove() {
39+
TODO("Not yet implemented")
40+
}
3841
}
3942

4043
/*

app/src/processing/app/ui/PDEPreferences.kt

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -27,6 +27,7 @@ import androidx.compose.ui.window.application
2727
import com.mikepenz.markdown.compose.Markdown
2828
import com.mikepenz.markdown.m3.markdownColor
2929
import com.mikepenz.markdown.m3.markdownTypography
30+
import processing.app.DEFAULTS_FILE_NAME
3031
import processing.app.LocalPreferences
3132
import processing.app.ReactiveProperties
3233
import processing.app.ui.PDEPreferences.Companion.preferences
@@ -35,6 +36,7 @@ import processing.app.ui.theme.*
3536
import java.awt.Dimension
3637
import java.awt.event.WindowEvent
3738
import java.awt.event.WindowListener
39+
import java.util.*
3840
import javax.swing.SwingUtilities
3941
import javax.swing.WindowConstants
4042

@@ -592,9 +594,16 @@ fun PDEPreferencePane.showPane(groups: PDEPreferenceGroups) {
592594
val prefs = LocalPreferences.current
593595
TextButton(
594596
onClick = {
597+
val defaultsStream =
598+
ClassLoader.getSystemResourceAsStream(DEFAULTS_FILE_NAME) ?: return@TextButton
599+
val defaults = Properties().apply {
600+
defaultsStream.reader(Charsets.UTF_8).use {
601+
load(it)
602+
}
603+
}
595604
groups.forEach { group ->
596605
group.forEach { pref ->
597-
prefs.remove(pref.key)
606+
prefs[pref.key] = defaults.getProperty(pref.key, "")
598607
}
599608
}
600609
}

0 commit comments

Comments
 (0)