Add change manager unmarking
All checks were successful
zdm/undo-redo/pipeline/head This commit looks good
All checks were successful
zdm/undo-redo/pipeline/head This commit looks good
This commit is contained in:
parent
fa5c2419bf
commit
0fc3577750
@ -55,11 +55,18 @@ public interface ChangeManager<C extends Change> {
|
||||
*/
|
||||
void mark();
|
||||
|
||||
/**
|
||||
* Resets the marked index so that no change is marked.
|
||||
*
|
||||
* @since 0.0.1
|
||||
*/
|
||||
void unmark();
|
||||
|
||||
/**
|
||||
* @return whether the current change is marked
|
||||
* @since 0.0.1
|
||||
*/
|
||||
boolean isAtMarkedIndex();
|
||||
boolean isAtMarkedChange();
|
||||
|
||||
/**
|
||||
* @return whether a change is present that can be undone
|
||||
|
@ -53,7 +53,12 @@ public final class UnlimitedChangeManager<C extends Change> implements ChangeMan
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean isAtMarkedIndex() {
|
||||
public void unmark() {
|
||||
markedIndex = -1;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean isAtMarkedChange() {
|
||||
return markedIndex == index;
|
||||
}
|
||||
|
||||
|
@ -108,12 +108,28 @@ class ChangeManagerTest {
|
||||
@Test
|
||||
@Order(60)
|
||||
void testMark() {
|
||||
assertTrue(manager.isAtMarkedIndex());
|
||||
assertTrue(manager.isAtMarkedChange());
|
||||
manager.addChange(change);
|
||||
assertFalse(manager.isAtMarkedIndex());
|
||||
assertFalse(manager.isAtMarkedChange());
|
||||
manager.mark();
|
||||
assertTrue(manager.isAtMarkedIndex());
|
||||
assertTrue(manager.isAtMarkedChange());
|
||||
manager.undo();
|
||||
assertFalse(manager.isAtMarkedIndex());
|
||||
assertFalse(manager.isAtMarkedChange());
|
||||
}
|
||||
|
||||
/**
|
||||
* Tests unmarking a change.
|
||||
*
|
||||
* @since 0.0.1
|
||||
*/
|
||||
@Test
|
||||
@Order(70)
|
||||
void testUnmark() {
|
||||
manager.addChange(change);
|
||||
manager.mark();
|
||||
manager.unmark();
|
||||
assertFalse(manager.isAtMarkedChange());
|
||||
manager.undo();
|
||||
assertTrue(manager.isAtMarkedChange());
|
||||
}
|
||||
}
|
||||
|
@ -23,15 +23,15 @@ import dev.kske.undoredo.core.*;
|
||||
public class ChangeManagerWrapper<C extends Change, M extends ChangeManager<C>>
|
||||
implements ObservableChangeManager<C> {
|
||||
|
||||
public static final String LAST_CHANGE = "lastChange";
|
||||
public static final String AT_MARKED_INDEX = "atMarkedIndex";
|
||||
public static final String UNDO_AVAILABLE = "undoAvailable";
|
||||
public static final String REDO_AVAILABLE = "redoAvailable";
|
||||
public static final String LAST_CHANGE = "lastChange";
|
||||
public static final String AT_MARKED_CHANGE = "atMarkedChange";
|
||||
public static final String UNDO_AVAILABLE = "undoAvailable";
|
||||
public static final String REDO_AVAILABLE = "redoAvailable";
|
||||
|
||||
protected ReadOnlyObjectWrapper<C> lastChange =
|
||||
new ReadOnlyObjectWrapper<>(this, LAST_CHANGE);
|
||||
protected ReadOnlyBooleanWrapper atMarkedIndex =
|
||||
new ReadOnlyBooleanWrapper(this, AT_MARKED_INDEX);
|
||||
protected ReadOnlyBooleanWrapper atMarkedChange =
|
||||
new ReadOnlyBooleanWrapper(this, AT_MARKED_CHANGE);
|
||||
protected ReadOnlyBooleanWrapper undoAvailable =
|
||||
new ReadOnlyBooleanWrapper(this, UNDO_AVAILABLE);
|
||||
protected ReadOnlyBooleanWrapper redoAvailable =
|
||||
@ -76,7 +76,13 @@ public class ChangeManagerWrapper<C extends Change, M extends ChangeManager<C>>
|
||||
@Override
|
||||
public void mark() {
|
||||
manager.mark();
|
||||
setAtMarkedIndex(manager.isAtMarkedIndex());
|
||||
setAtMarkedChange(manager.isAtMarkedChange());
|
||||
}
|
||||
|
||||
@Override
|
||||
public void unmark() {
|
||||
manager.unmark();
|
||||
setAtMarkedChange(manager.isAtMarkedChange());
|
||||
}
|
||||
|
||||
/**
|
||||
@ -86,7 +92,7 @@ public class ChangeManagerWrapper<C extends Change, M extends ChangeManager<C>>
|
||||
*/
|
||||
private void updateProperties() {
|
||||
setLastChange(manager.getLastChange().orElse(null));
|
||||
setAtMarkedIndex(manager.isAtMarkedIndex());
|
||||
setAtMarkedChange(manager.isAtMarkedChange());
|
||||
setUndoAvailable(manager.isUndoAvailable());
|
||||
setRedoAvailable(manager.isRedoAvailable());
|
||||
}
|
||||
@ -101,12 +107,12 @@ public class ChangeManagerWrapper<C extends Change, M extends ChangeManager<C>>
|
||||
}
|
||||
|
||||
@Override
|
||||
public final ReadOnlyBooleanProperty atMarkedIndexProperty() {
|
||||
return atMarkedIndex.getReadOnlyProperty();
|
||||
public final ReadOnlyBooleanProperty atMarkedChangeProperty() {
|
||||
return atMarkedChange.getReadOnlyProperty();
|
||||
}
|
||||
|
||||
protected final void setAtMarkedIndex(boolean atMarkedIndex) {
|
||||
this.atMarkedIndex.set(atMarkedIndex);
|
||||
protected final void setAtMarkedChange(boolean atMarkedChange) {
|
||||
this.atMarkedChange.set(atMarkedChange);
|
||||
}
|
||||
|
||||
@Override
|
||||
|
@ -24,11 +24,11 @@ public interface ObservableChangeManager<C extends Change> extends ChangeManager
|
||||
return Optional.of(lastChangeProperty().get());
|
||||
}
|
||||
|
||||
ReadOnlyBooleanProperty atMarkedIndexProperty();
|
||||
ReadOnlyBooleanProperty atMarkedChangeProperty();
|
||||
|
||||
@Override
|
||||
default boolean isAtMarkedIndex() {
|
||||
return atMarkedIndexProperty().get();
|
||||
default boolean isAtMarkedChange() {
|
||||
return atMarkedChangeProperty().get();
|
||||
}
|
||||
|
||||
ReadOnlyBooleanProperty undoAvailableProperty();
|
||||
|
Reference in New Issue
Block a user