Skip to content
This repository has been archived by the owner on Apr 16, 2023. It is now read-only.

Commit

Permalink
Fix deleting a stored pattern not deleting its file
Browse files Browse the repository at this point in the history
  • Loading branch information
chrislo27 committed Jul 22, 2018
1 parent 265b2a9 commit 1f7ecf8
Show file tree
Hide file tree
Showing 2 changed files with 4 additions and 2 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,7 @@ object PatternStorage {
sort()
}

fun persist() {
fun persist(deleteAllOthers: Boolean = false) {
val values = patterns.values.toList()

values.mapNotNull { pattern ->
Expand All @@ -65,6 +65,8 @@ object PatternStorage {
}.also { arrayNode ->
FOLDER.child("list/").apply { mkdirs() }.child("list.json").writeString(JsonHandler.toJson(arrayNode), false, "UTF-8")
}
val filenames = values.mapNotNull(StoredPattern::filename)
FOLDER.list().filter { it.name() !in filenames }.forEach { it.delete() }
}

fun addPattern(pattern: StoredPattern): PatternStorage {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,7 @@ class PatternDeleteScreen(main: RHRE3Application, val editor: Editor, val patter
override fun onLeftClick(xPercent: Float, yPercent: Float) {
super.onLeftClick(xPercent, yPercent)

PatternStorage.deletePattern(pattern).persist()
PatternStorage.deletePattern(pattern).persist(deleteAllOthers = true)
editor.stage.updateSelected()
main.screen = ScreenRegistry["editor"]
}
Expand Down

0 comments on commit 1f7ecf8

Please sign in to comment.