From 5baccc4b3f62e65d2201b073372905832a5f6cc3 Mon Sep 17 00:00:00 2001 From: Marvin Elsen Date: Tue, 12 Nov 2024 20:21:28 +0100 Subject: [PATCH] Differentiate between normal select without undo and deep dive select with undo --- src/main/kotlin/com/marvinelsen/willow/Model.kt | 7 ++++++- .../willow/ui/controllers/DetailsController.kt | 6 +++--- .../willow/ui/controllers/SearchResultsController.kt | 2 +- .../com/marvinelsen/willow/ui/undo/UndoManager.kt | 11 +++++++++-- 4 files changed, 19 insertions(+), 7 deletions(-) diff --git a/src/main/kotlin/com/marvinelsen/willow/Model.kt b/src/main/kotlin/com/marvinelsen/willow/Model.kt index 58c625e..81d5d76 100644 --- a/src/main/kotlin/com/marvinelsen/willow/Model.kt +++ b/src/main/kotlin/com/marvinelsen/willow/Model.kt @@ -142,7 +142,7 @@ class Model( } } - fun selectEntry(entry: DictionaryEntry) { + fun deepDive(entry: DictionaryEntry) { undoManager.execute(object : Command { private val previouslySelectedEntry = internalSelectedEntry.value @@ -158,6 +158,11 @@ class Model( }) } + fun normalSelect(entry: DictionaryEntry) { + undoManager.reset() + select(entry) + } + private fun select(entry: DictionaryEntry) { internalFinishedFindingCharacters.value = false internalFinishedFindingWordsBeginning.value = false diff --git a/src/main/kotlin/com/marvinelsen/willow/ui/controllers/DetailsController.kt b/src/main/kotlin/com/marvinelsen/willow/ui/controllers/DetailsController.kt index a4ca4f3..6db45a4 100644 --- a/src/main/kotlin/com/marvinelsen/willow/ui/controllers/DetailsController.kt +++ b/src/main/kotlin/com/marvinelsen/willow/ui/controllers/DetailsController.kt @@ -207,7 +207,7 @@ class DetailsController( selectionModel.selectedItemProperty().addListener { _, _, newEntry -> if (newEntry == null) return@addListener - model.selectEntry(newEntry) + model.deepDive(newEntry) } } progressIndicatorWordsContaining.visibleProperty().bind(model.isFindingWordsContaining) @@ -225,7 +225,7 @@ class DetailsController( selectionModel.selectedItemProperty().addListener { _, _, newEntry -> if (newEntry == null) return@addListener - model.selectEntry(newEntry) + model.deepDive(newEntry) } } progressIndicatorWordsBeginning.visibleProperty().bind(model.isFindingWordsBeginning) @@ -243,7 +243,7 @@ class DetailsController( selectionModel.selectedItemProperty().addListener { _, _, newEntry -> if (newEntry == null) return@addListener - model.selectEntry(newEntry) + model.deepDive(newEntry) } } progressIndicatorCharacters.visibleProperty().bind(model.isFindingCharacters) diff --git a/src/main/kotlin/com/marvinelsen/willow/ui/controllers/SearchResultsController.kt b/src/main/kotlin/com/marvinelsen/willow/ui/controllers/SearchResultsController.kt index 0c7f876..fed9154 100644 --- a/src/main/kotlin/com/marvinelsen/willow/ui/controllers/SearchResultsController.kt +++ b/src/main/kotlin/com/marvinelsen/willow/ui/controllers/SearchResultsController.kt @@ -49,7 +49,7 @@ class SearchResultsController( if (newValue == null) { return@addListener } - model.selectEntry(newValue) + model.normalSelect(newValue) } } } diff --git a/src/main/kotlin/com/marvinelsen/willow/ui/undo/UndoManager.kt b/src/main/kotlin/com/marvinelsen/willow/ui/undo/UndoManager.kt index ab16f64..d64691e 100644 --- a/src/main/kotlin/com/marvinelsen/willow/ui/undo/UndoManager.kt +++ b/src/main/kotlin/com/marvinelsen/willow/ui/undo/UndoManager.kt @@ -15,7 +15,7 @@ class UndoManager { undoStack.push(command).execute() - canUndoProperty.value = undoStack.size > 1 + canUndoProperty.value = !undoStack.isEmpty() canRedoProperty.value = false } @@ -24,7 +24,7 @@ class UndoManager { redoStack.push(undoStack.pop()).undo() - canUndoProperty.value = undoStack.size > 1 + canUndoProperty.value = !undoStack.isEmpty() canRedoProperty.value = true } @@ -36,4 +36,11 @@ class UndoManager { canUndoProperty.value = true canRedoProperty.value = !redoStack.isEmpty() } + + fun reset() { + undoStack.clear() + redoStack.clear() + canUndoProperty.value = false + canRedoProperty.value = false + } }