Differentiate between normal select without undo and deep dive select with undo

This commit is contained in:
Marvin Elsen 2024-11-12 20:21:28 +01:00
parent b22e436f8b
commit 5baccc4b3f
Signed by: marvinelsen
GPG Key ID: 820672408CC318C2
4 changed files with 19 additions and 7 deletions

View File

@ -142,7 +142,7 @@ class Model(
} }
} }
fun selectEntry(entry: DictionaryEntry) { fun deepDive(entry: DictionaryEntry) {
undoManager.execute(object : Command { undoManager.execute(object : Command {
private val previouslySelectedEntry = internalSelectedEntry.value private val previouslySelectedEntry = internalSelectedEntry.value
@ -158,6 +158,11 @@ class Model(
}) })
} }
fun normalSelect(entry: DictionaryEntry) {
undoManager.reset()
select(entry)
}
private fun select(entry: DictionaryEntry) { private fun select(entry: DictionaryEntry) {
internalFinishedFindingCharacters.value = false internalFinishedFindingCharacters.value = false
internalFinishedFindingWordsBeginning.value = false internalFinishedFindingWordsBeginning.value = false

View File

@ -207,7 +207,7 @@ class DetailsController(
selectionModel.selectedItemProperty().addListener { _, _, newEntry -> selectionModel.selectedItemProperty().addListener { _, _, newEntry ->
if (newEntry == null) return@addListener if (newEntry == null) return@addListener
model.selectEntry(newEntry) model.deepDive(newEntry)
} }
} }
progressIndicatorWordsContaining.visibleProperty().bind(model.isFindingWordsContaining) progressIndicatorWordsContaining.visibleProperty().bind(model.isFindingWordsContaining)
@ -225,7 +225,7 @@ class DetailsController(
selectionModel.selectedItemProperty().addListener { _, _, newEntry -> selectionModel.selectedItemProperty().addListener { _, _, newEntry ->
if (newEntry == null) return@addListener if (newEntry == null) return@addListener
model.selectEntry(newEntry) model.deepDive(newEntry)
} }
} }
progressIndicatorWordsBeginning.visibleProperty().bind(model.isFindingWordsBeginning) progressIndicatorWordsBeginning.visibleProperty().bind(model.isFindingWordsBeginning)
@ -243,7 +243,7 @@ class DetailsController(
selectionModel.selectedItemProperty().addListener { _, _, newEntry -> selectionModel.selectedItemProperty().addListener { _, _, newEntry ->
if (newEntry == null) return@addListener if (newEntry == null) return@addListener
model.selectEntry(newEntry) model.deepDive(newEntry)
} }
} }
progressIndicatorCharacters.visibleProperty().bind(model.isFindingCharacters) progressIndicatorCharacters.visibleProperty().bind(model.isFindingCharacters)

View File

@ -49,7 +49,7 @@ class SearchResultsController(
if (newValue == null) { if (newValue == null) {
return@addListener return@addListener
} }
model.selectEntry(newValue) model.normalSelect(newValue)
} }
} }
} }

View File

@ -15,7 +15,7 @@ class UndoManager {
undoStack.push(command).execute() undoStack.push(command).execute()
canUndoProperty.value = undoStack.size > 1 canUndoProperty.value = !undoStack.isEmpty()
canRedoProperty.value = false canRedoProperty.value = false
} }
@ -24,7 +24,7 @@ class UndoManager {
redoStack.push(undoStack.pop()).undo() redoStack.push(undoStack.pop()).undo()
canUndoProperty.value = undoStack.size > 1 canUndoProperty.value = !undoStack.isEmpty()
canRedoProperty.value = true canRedoProperty.value = true
} }
@ -36,4 +36,11 @@ class UndoManager {
canUndoProperty.value = true canUndoProperty.value = true
canRedoProperty.value = !redoStack.isEmpty() canRedoProperty.value = !redoStack.isEmpty()
} }
fun reset() {
undoStack.clear()
redoStack.clear()
canUndoProperty.value = false
canRedoProperty.value = false
}
} }