mirror of
https://github.com/dscyrescotti/Memola.git
synced 2026-06-30 18:11:44 +02:00
feat: update undo and redo
This commit is contained in:
@@ -42,15 +42,27 @@ class GraphicContext: NSManagedObject {
|
|||||||
func undoGraphic() {
|
func undoGraphic() {
|
||||||
guard let stroke = strokes.lastObject as? Stroke else { return }
|
guard let stroke = strokes.lastObject as? Stroke else { return }
|
||||||
strokes.remove(stroke)
|
strokes.remove(stroke)
|
||||||
|
stroke.graphicContext = nil
|
||||||
previousStroke = nil
|
previousStroke = nil
|
||||||
|
do {
|
||||||
|
try Persistence.shared.viewContext.save()
|
||||||
|
} catch {
|
||||||
|
NSLog("[Memola] - \(error.localizedDescription)")
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
func redoGraphic(for event: HistoryEvent) {
|
func redoGraphic(for event: HistoryEvent) {
|
||||||
switch event {
|
switch event {
|
||||||
case .stroke(let stroke):
|
case .stroke(let stroke):
|
||||||
strokes.add(stroke)
|
strokes.add(stroke)
|
||||||
|
stroke.graphicContext = self
|
||||||
previousStroke = nil
|
previousStroke = nil
|
||||||
}
|
}
|
||||||
|
do {
|
||||||
|
try Persistence.shared.viewContext.save()
|
||||||
|
} catch {
|
||||||
|
NSLog("[Memola] - \(error.localizedDescription)")
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -109,8 +121,15 @@ extension GraphicContext {
|
|||||||
}
|
}
|
||||||
|
|
||||||
func cancelStroke() {
|
func cancelStroke() {
|
||||||
if let stroke = strokes.lastObject {
|
if let stroke = strokes.lastObject as? Stroke {
|
||||||
strokes.remove(stroke)
|
do {
|
||||||
|
let viewContext = Persistence.shared.viewContext
|
||||||
|
strokes.remove(stroke)
|
||||||
|
viewContext.delete(stroke)
|
||||||
|
try viewContext.save()
|
||||||
|
} catch {
|
||||||
|
NSLog("[Memola] - \(error.localizedDescription)")
|
||||||
|
}
|
||||||
}
|
}
|
||||||
currentStroke = nil
|
currentStroke = nil
|
||||||
currentPoint = nil
|
currentPoint = nil
|
||||||
|
|||||||
@@ -88,6 +88,7 @@ struct MemoView: View {
|
|||||||
}
|
}
|
||||||
|
|
||||||
func closeMemo() {
|
func closeMemo() {
|
||||||
|
history.resetRedo()
|
||||||
if managedObjectContext.hasChanges {
|
if managedObjectContext.hasChanges {
|
||||||
do {
|
do {
|
||||||
try managedObjectContext.save()
|
try managedObjectContext.save()
|
||||||
|
|||||||
@@ -23,7 +23,7 @@
|
|||||||
<attribute name="color" attributeType="Transformable" valueTransformerName="NSSecureUnarchiveFromDataTransformer" customClassName="[CGFloat]"/>
|
<attribute name="color" attributeType="Transformable" valueTransformerName="NSSecureUnarchiveFromDataTransformer" customClassName="[CGFloat]"/>
|
||||||
<attribute name="createdAt" attributeType="Date" usesScalarValueType="NO"/>
|
<attribute name="createdAt" attributeType="Date" usesScalarValueType="NO"/>
|
||||||
<attribute name="id" attributeType="UUID" usesScalarValueType="NO"/>
|
<attribute name="id" attributeType="UUID" usesScalarValueType="NO"/>
|
||||||
<attribute name="strokeQuads" optional="YES" attributeType="Transformable" valueTransformerName="QuadValueTransformer" customClassName="[StrokeQuad]"/>
|
<attribute name="strokeQuads" attributeType="Transformable" valueTransformerName="QuadValueTransformer" customClassName="[StrokeQuad]"/>
|
||||||
<attribute name="style" attributeType="Integer 16" defaultValueString="0" usesScalarValueType="YES"/>
|
<attribute name="style" attributeType="Integer 16" defaultValueString="0" usesScalarValueType="YES"/>
|
||||||
<attribute name="thickness" attributeType="Double" defaultValueString="0.0" usesScalarValueType="YES"/>
|
<attribute name="thickness" attributeType="Double" defaultValueString="0.0" usesScalarValueType="YES"/>
|
||||||
<relationship name="graphicContext" optional="YES" maxCount="1" deletionRule="Nullify" destinationEntity="GraphicContext" inverseName="strokes" inverseEntity="GraphicContext"/>
|
<relationship name="graphicContext" optional="YES" maxCount="1" deletionRule="Nullify" destinationEntity="GraphicContext" inverseName="strokes" inverseEntity="GraphicContext"/>
|
||||||
|
|||||||
Reference in New Issue
Block a user