Skip to content

Commit

Permalink
added bulk editor actions
Browse files Browse the repository at this point in the history
  • Loading branch information
AlmasB committed Nov 14, 2021
1 parent eb41e26 commit fefdd67
Show file tree
Hide file tree
Showing 2 changed files with 28 additions and 0 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -147,6 +147,15 @@ class DialoguePane(graph: DialogueGraph = DialogueGraph()) : Pane() {

mouseGestures.makeDraggable(selectionRect) {
selectionStart = Point2D(selectionRect.layoutX, selectionRect.layoutY)

performUIAction(BulkAction(
selectedNodeViews.map {
val layoutX = it.properties["startLayoutX"] as Double
val layoutY = it.properties["startLayoutY"] as Double

MoveNodeAction(it.node, this::getNodeView, layoutX, layoutY, it.layoutX, it.layoutY)
}
))
}

selectionRect.layoutXProperty().addListener { _, prevX, layoutX ->
Expand Down Expand Up @@ -218,6 +227,11 @@ class DialoguePane(graph: DialogueGraph = DialogueGraph()) : Pane() {
isSelectingRectangle = false
selectedNodeViews.addAll(selectionRect.getSelectedNodesIn(nodeViews, NodeView::class.java))

selectedNodeViews.forEach {
it.properties["startLayoutX"] = it.layoutX
it.properties["startLayoutY"] = it.layoutY
}

if (selectedNodeViews.isEmpty()) {
selectionRect.isVisible = false
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -28,8 +28,22 @@ interface EditorAction {
// * remove node (and its incident edges)
// * add edge
// * remove edge
// * bulk action
// * TODO: node text editing

class BulkAction(
private val actions: List<EditorAction>
) : EditorAction {

override fun run() {
actions.forEach { it.run() }
}

override fun undo() {
actions.forEach { it.undo() }
}
}

class MoveNodeAction(
private val node: DialogueNode,
private val newNodeViewGetter: (DialogueNode) -> NodeView,
Expand Down

0 comments on commit fefdd67

Please sign in to comment.