Skip to content

Commit

Permalink
refactor: make delete button delete the backing filter file
Browse files Browse the repository at this point in the history
  • Loading branch information
Z-Kris committed Aug 1, 2024
1 parent ec3795f commit 4653eb9
Show file tree
Hide file tree
Showing 4 changed files with 11 additions and 0 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ import net.rsprox.shared.filters.PropertyFilter
import net.rsprox.shared.filters.PropertyFilterSet
import net.rsprox.shared.filters.ProtCategory
import java.nio.file.Path
import kotlin.io.path.deleteIfExists
import kotlin.io.path.readText

public class DefaultPropertyFilterSet(
Expand All @@ -28,6 +29,10 @@ public class DefaultPropertyFilterSet(
this.name = name
}

override fun deleteBackingFile() {
path.deleteIfExists()
}

override fun get(filter: PropertyFilter): Boolean {
return filters[filter.name] ?: filter.enabled
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@ public class DefaultPropertyFilterSetStore(
override fun delete(index: Int): PropertyFilterSet? {
if (index == 0) throw IllegalArgumentException("Element at index 0 cannot be deleted.")
val element = filterSets.getOrNull(index) ?: return null
element.deleteBackingFile()
filterSets.removeAt(index)
return element
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,9 @@ public class UnmodifiablePropertyFilterSet : PropertyFilterSet {
override fun setName(name: String) {
}

override fun deleteBackingFile() {
}

override fun get(filter: PropertyFilter): Boolean {
return filter.enabled
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,8 @@ public interface PropertyFilterSet {

public fun setName(name: String)

public fun deleteBackingFile()

public operator fun get(filter: PropertyFilter): Boolean

public operator fun set(
Expand Down

0 comments on commit 4653eb9

Please sign in to comment.