[Editor] Enable clearing undo/redo stack on map settings update
This commit is contained in:
@@ -80,6 +80,18 @@ class DefaultUndoRedoService : UndoRedoService {
|
||||
}
|
||||
}
|
||||
|
||||
override fun clear() {
|
||||
log.debug("Clearing [undo] and [redo] stacks")
|
||||
undo.clear()
|
||||
redo.clear()
|
||||
}
|
||||
|
||||
override fun clear(context: UndoableContext) {
|
||||
log.debug("Clearing [undo] and [redo] stacks (ctx: ${toHexString(context.hashCode())})")
|
||||
undo.removeIf { it.second == context }
|
||||
redo.removeIf { it.second == context }
|
||||
}
|
||||
|
||||
override val lastUndoable: Undoable?
|
||||
get() = undo.first?.first
|
||||
|
||||
|
||||
@@ -7,10 +7,12 @@ interface UndoRedoService {
|
||||
fun push(undoable: Undoable)
|
||||
fun undo()
|
||||
fun redo()
|
||||
fun clear()
|
||||
|
||||
fun push(undoable: Undoable, context: UndoableContext)
|
||||
fun undo(context: UndoableContext)
|
||||
fun redo(context: UndoableContext)
|
||||
fun clear(context: UndoableContext)
|
||||
|
||||
val lastUndoable: Undoable?
|
||||
val lastRedoable: Undoable?
|
||||
|
||||
@@ -40,7 +40,7 @@ class MapCanvas(val map: GameMapVM, private val editorStateVM: EditorStateVM, pr
|
||||
}
|
||||
|
||||
private fun renderUnderlyingLayers(gc: GraphicsContext) {
|
||||
for(layer in map.layers.dropLast( map.layers.size - editorStateVM.selectedLayer)) {
|
||||
for(layer in map.layers.dropLast(if(editorStateVM.selectedLayer < 0) 0 else map.layers.size - editorStateVM.selectedLayer)) {
|
||||
dispatchLayerRender(gc, layer)
|
||||
}
|
||||
}
|
||||
|
||||
@@ -7,4 +7,6 @@ interface Layer {
|
||||
val nameProperty: StringProperty
|
||||
|
||||
fun resize(rows: Int, columns: Int)
|
||||
|
||||
fun clone(): Layer
|
||||
}
|
||||
@@ -19,4 +19,8 @@ class TileLayer(name: String, rows: Int, columns: Int) : Layer {
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
override fun clone() = TileLayer(name, 0, 0).apply {
|
||||
layer = this@TileLayer.layer
|
||||
}
|
||||
}
|
||||
@@ -1,10 +1,15 @@
|
||||
package com.bartlomiejpluta.base.editor.map.view
|
||||
|
||||
import com.bartlomiejpluta.base.editor.command.context.UndoableScope
|
||||
import com.bartlomiejpluta.base.editor.command.service.UndoRedoService
|
||||
import com.bartlomiejpluta.base.editor.map.viewmodel.GameMapVM
|
||||
import org.kordamp.ikonli.javafx.FontIcon
|
||||
import tornadofx.*
|
||||
|
||||
class MapSettingsFragment : Fragment("Map Settings") {
|
||||
override val scope = super.scope as UndoableScope
|
||||
private val undoRedoService: UndoRedoService by di()
|
||||
|
||||
private val mapVM = find<GameMapVM>()
|
||||
|
||||
var result: Boolean = false
|
||||
@@ -49,6 +54,8 @@ class MapSettingsFragment : Fragment("Map Settings") {
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
label("Warning: Submitting the form will clear related undo/redo stacks!")
|
||||
}
|
||||
|
||||
buttonbar {
|
||||
@@ -56,9 +63,12 @@ class MapSettingsFragment : Fragment("Map Settings") {
|
||||
shortcut("Enter")
|
||||
|
||||
action {
|
||||
mapVM.commit {
|
||||
result = true
|
||||
close()
|
||||
if(mapVM.valid.value) {
|
||||
mapVM.commit {
|
||||
result = true
|
||||
undoRedoService.clear(scope)
|
||||
close()
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user