Skip to content

Commit

Permalink
Do not make domain model deserialization undoable
Browse files Browse the repository at this point in the history
  • Loading branch information
Ninjabrain1 committed Sep 10, 2024
1 parent 2b74e91 commit 0a154af
Show file tree
Hide file tree
Showing 5 changed files with 20 additions and 0 deletions.
1 change: 1 addition & 0 deletions src/main/java/ninjabrainbot/gui/GUI.java
Original file line number Diff line number Diff line change
Expand Up @@ -106,6 +106,7 @@ private void initModel() {
dataState = modelState.dataState;
domainModelImportExportService = new DomainModelImportExportService(domainModel, new TempFileAccessor("NinjabrainBot-save-state.txt"), preferences);
domainModelImportExportService.triggerDeserialization();
domainModel.deleteHistory();
Profiler.stop();
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -50,6 +50,10 @@ public void undoUnderWriteLock() {
public void redoUnderWriteLock() {
}

@Override
public void deleteHistory() {
}

@Override
public boolean isReset() {
return true;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -127,6 +127,11 @@ public void redoUnderWriteLock() {
}
}

@Override
public void deleteHistory() {
domainModelHistory.deleteHistory();
}

@Override
public boolean isReset() {
return fundamentalComponents.stream().allMatch(IFundamentalComponent::isReset);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -51,11 +51,13 @@ private void saveSnapshotAfterCurrentSnapshot(DomainModelSnapshot domainModelSna
}

public DomainModelSnapshot moveToPreviousSnapshotAndGet() {
Assert.isTrue(isInitialized, "The DomainModelHistory has not been initialized.");
currentIndex--;
return snapshots.get(currentIndex);
}

public DomainModelSnapshot moveToNextSnapshotAndGet() {
Assert.isTrue(isInitialized, "The DomainModelHistory has not been initialized.");
currentIndex++;
return snapshots.get(currentIndex);
}
Expand All @@ -68,4 +70,10 @@ public boolean hasNextSnapshot() {
return currentIndex < snapshots.size() - 1;
}

public void deleteHistory() {
DomainModelSnapshot currentSnapshot = snapshots.get(currentIndex);
snapshots.removeIf(snapshot -> snapshot != currentSnapshot);
currentIndex = 0;
Assert.isEqual(snapshots.size(), 1, "The number of snapshots shall be 1 after deleting domain model history.");
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,8 @@ public interface IDomainModel extends IWriteLock {

void redoUnderWriteLock();

void deleteHistory();

boolean isReset();

boolean isExternalSubscriptionRegistrationAllowed();
Expand Down

0 comments on commit 0a154af

Please sign in to comment.