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();
|
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
|
* @return whether the current change is marked
|
||||||
* @since 0.0.1
|
* @since 0.0.1
|
||||||
*/
|
*/
|
||||||
boolean isAtMarkedIndex();
|
boolean isAtMarkedChange();
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @return whether a change is present that can be undone
|
* @return whether a change is present that can be undone
|
||||||
|
@ -53,7 +53,12 @@ public final class UnlimitedChangeManager<C extends Change> implements ChangeMan
|
|||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public boolean isAtMarkedIndex() {
|
public void unmark() {
|
||||||
|
markedIndex = -1;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public boolean isAtMarkedChange() {
|
||||||
return markedIndex == index;
|
return markedIndex == index;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -108,12 +108,28 @@ class ChangeManagerTest {
|
|||||||
@Test
|
@Test
|
||||||
@Order(60)
|
@Order(60)
|
||||||
void testMark() {
|
void testMark() {
|
||||||
assertTrue(manager.isAtMarkedIndex());
|
assertTrue(manager.isAtMarkedChange());
|
||||||
manager.addChange(change);
|
manager.addChange(change);
|
||||||
assertFalse(manager.isAtMarkedIndex());
|
assertFalse(manager.isAtMarkedChange());
|
||||||
manager.mark();
|
manager.mark();
|
||||||
assertTrue(manager.isAtMarkedIndex());
|
assertTrue(manager.isAtMarkedChange());
|
||||||
manager.undo();
|
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());
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -24,14 +24,14 @@ public class ChangeManagerWrapper<C extends Change, M extends ChangeManager<C>>
|
|||||||
implements ObservableChangeManager<C> {
|
implements ObservableChangeManager<C> {
|
||||||
|
|
||||||
public static final String LAST_CHANGE = "lastChange";
|
public static final String LAST_CHANGE = "lastChange";
|
||||||
public static final String AT_MARKED_INDEX = "atMarkedIndex";
|
public static final String AT_MARKED_CHANGE = "atMarkedChange";
|
||||||
public static final String UNDO_AVAILABLE = "undoAvailable";
|
public static final String UNDO_AVAILABLE = "undoAvailable";
|
||||||
public static final String REDO_AVAILABLE = "redoAvailable";
|
public static final String REDO_AVAILABLE = "redoAvailable";
|
||||||
|
|
||||||
protected ReadOnlyObjectWrapper<C> lastChange =
|
protected ReadOnlyObjectWrapper<C> lastChange =
|
||||||
new ReadOnlyObjectWrapper<>(this, LAST_CHANGE);
|
new ReadOnlyObjectWrapper<>(this, LAST_CHANGE);
|
||||||
protected ReadOnlyBooleanWrapper atMarkedIndex =
|
protected ReadOnlyBooleanWrapper atMarkedChange =
|
||||||
new ReadOnlyBooleanWrapper(this, AT_MARKED_INDEX);
|
new ReadOnlyBooleanWrapper(this, AT_MARKED_CHANGE);
|
||||||
protected ReadOnlyBooleanWrapper undoAvailable =
|
protected ReadOnlyBooleanWrapper undoAvailable =
|
||||||
new ReadOnlyBooleanWrapper(this, UNDO_AVAILABLE);
|
new ReadOnlyBooleanWrapper(this, UNDO_AVAILABLE);
|
||||||
protected ReadOnlyBooleanWrapper redoAvailable =
|
protected ReadOnlyBooleanWrapper redoAvailable =
|
||||||
@ -76,7 +76,13 @@ public class ChangeManagerWrapper<C extends Change, M extends ChangeManager<C>>
|
|||||||
@Override
|
@Override
|
||||||
public void mark() {
|
public void mark() {
|
||||||
manager.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() {
|
private void updateProperties() {
|
||||||
setLastChange(manager.getLastChange().orElse(null));
|
setLastChange(manager.getLastChange().orElse(null));
|
||||||
setAtMarkedIndex(manager.isAtMarkedIndex());
|
setAtMarkedChange(manager.isAtMarkedChange());
|
||||||
setUndoAvailable(manager.isUndoAvailable());
|
setUndoAvailable(manager.isUndoAvailable());
|
||||||
setRedoAvailable(manager.isRedoAvailable());
|
setRedoAvailable(manager.isRedoAvailable());
|
||||||
}
|
}
|
||||||
@ -101,12 +107,12 @@ public class ChangeManagerWrapper<C extends Change, M extends ChangeManager<C>>
|
|||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public final ReadOnlyBooleanProperty atMarkedIndexProperty() {
|
public final ReadOnlyBooleanProperty atMarkedChangeProperty() {
|
||||||
return atMarkedIndex.getReadOnlyProperty();
|
return atMarkedChange.getReadOnlyProperty();
|
||||||
}
|
}
|
||||||
|
|
||||||
protected final void setAtMarkedIndex(boolean atMarkedIndex) {
|
protected final void setAtMarkedChange(boolean atMarkedChange) {
|
||||||
this.atMarkedIndex.set(atMarkedIndex);
|
this.atMarkedChange.set(atMarkedChange);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
|
@ -24,11 +24,11 @@ public interface ObservableChangeManager<C extends Change> extends ChangeManager
|
|||||||
return Optional.of(lastChangeProperty().get());
|
return Optional.of(lastChangeProperty().get());
|
||||||
}
|
}
|
||||||
|
|
||||||
ReadOnlyBooleanProperty atMarkedIndexProperty();
|
ReadOnlyBooleanProperty atMarkedChangeProperty();
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
default boolean isAtMarkedIndex() {
|
default boolean isAtMarkedChange() {
|
||||||
return atMarkedIndexProperty().get();
|
return atMarkedChangeProperty().get();
|
||||||
}
|
}
|
||||||
|
|
||||||
ReadOnlyBooleanProperty undoAvailableProperty();
|
ReadOnlyBooleanProperty undoAvailableProperty();
|
||||||
|
Reference in New Issue
Block a user