Only save annotations on changes

This commit is contained in:
2026-02-06 16:09:52 +01:00
parent 9a11e42571
commit 58157a2e6e
2 changed files with 53 additions and 29 deletions

View File

@@ -51,6 +51,9 @@ class DrawingController extends ChangeNotifier {
/// Maximum number of history steps to keep
final int maxHistorySteps;
/// Whether there are unsaved changes since last load/clear
bool _hasUnsavedChanges = false;
DrawingController({this.maxHistorySteps = 50});
// ---------------------------------------------------------------------------
@@ -75,6 +78,9 @@ class DrawingController extends ChangeNotifier {
/// Whether redo is available
bool get canRedo => _redoStack.isNotEmpty;
/// Whether there are unsaved changes since last load/clear/markSaved
bool get hasUnsavedChanges => _hasUnsavedChanges;
// ---------------------------------------------------------------------------
// Drawing Operations
// ---------------------------------------------------------------------------
@@ -120,6 +126,7 @@ class DrawingController extends ChangeNotifier {
_redoStack.clear();
_trimHistory();
_currentErasedLines.clear();
_hasUnsavedChanges = true;
notifyListeners(); // Update UI to enable undo button
}
return;
@@ -133,6 +140,7 @@ class DrawingController extends ChangeNotifier {
_undoStack.add(AddLineAction(_currentLine!));
_redoStack.clear();
_trimHistory();
_hasUnsavedChanges = true;
}
_currentLine = null;
@@ -257,6 +265,7 @@ class DrawingController extends ChangeNotifier {
_redoStack.add(action);
}
_hasUnsavedChanges = true;
notifyListeners();
}
@@ -279,6 +288,7 @@ class DrawingController extends ChangeNotifier {
_undoStack.add(action);
}
_hasUnsavedChanges = true;
notifyListeners();
}
@@ -289,6 +299,7 @@ class DrawingController extends ChangeNotifier {
_redoStack.clear();
_currentLine = null;
_currentErasedLines.clear();
_hasUnsavedChanges = false;
notifyListeners();
}
@@ -324,6 +335,7 @@ class DrawingController extends ChangeNotifier {
_redoStack.clear();
_currentLine = null;
_currentErasedLines.clear();
_hasUnsavedChanges = false;
for (final json in jsonList) {
_lines.add(DrawingLine.fromJson(json));
@@ -354,6 +366,11 @@ class DrawingController extends ChangeNotifier {
notifyListeners();
}
/// Marks the current state as saved (resets unsaved changes flag).
void markSaved() {
_hasUnsavedChanges = false;
}
@override
void dispose() {
_lines.clear();