mirror of
https://github.com/dscyrescotti/Memola.git
synced 2026-04-18 06:50:03 +02:00
feat: remove erasers in graphic context
This commit is contained in:
@@ -160,7 +160,7 @@ extension GraphicContext {
|
||||
thickness: pen.thickness
|
||||
)
|
||||
eraserStroke.graphicContext = self
|
||||
withPersistence(\.backgroundContext) { [graphicContext = object, _stroke = eraserStroke] context in
|
||||
withPersistence(\.backgroundContext) { [_stroke = eraserStroke] context in
|
||||
let stroke = EraserObject(\.backgroundContext)
|
||||
stroke.bounds = _stroke.bounds
|
||||
stroke.color = _stroke.color
|
||||
@@ -169,8 +169,6 @@ extension GraphicContext {
|
||||
stroke.createdAt = _stroke.createdAt
|
||||
stroke.quads = []
|
||||
stroke.strokes = .init()
|
||||
stroke.graphicContext = graphicContext
|
||||
graphicContext?.erasers.add(stroke)
|
||||
_stroke.object = stroke
|
||||
try context.saveIfNeeded()
|
||||
}
|
||||
|
||||
@@ -65,7 +65,7 @@ final class PenStroke: Stroke, @unchecked Sendable {
|
||||
bounds: object.bounds,
|
||||
color: object.color,
|
||||
style: style,
|
||||
createdAt: object.createdAt,
|
||||
createdAt: object.createdAt, // sometimes crash here
|
||||
thickness: object.thickness
|
||||
)
|
||||
self.object = object
|
||||
|
||||
@@ -85,7 +85,6 @@ struct MemosView: View {
|
||||
|
||||
let graphicContextObject = GraphicContextObject(\.viewContext)
|
||||
graphicContextObject.strokes = []
|
||||
graphicContextObject.erasers = .init()
|
||||
|
||||
memoObject.canvas = canvasObject
|
||||
memoObject.tool = toolObject
|
||||
|
||||
@@ -17,5 +17,4 @@ final class EraserObject: NSManagedObject {
|
||||
@NSManaged var thickness: CGFloat
|
||||
@NSManaged var quads: NSMutableOrderedSet
|
||||
@NSManaged var strokes: NSMutableSet
|
||||
@NSManaged var graphicContext: GraphicContextObject?
|
||||
}
|
||||
|
||||
@@ -12,5 +12,4 @@ import Foundation
|
||||
final class GraphicContextObject: NSManagedObject {
|
||||
@NSManaged var canvas: CanvasObject?
|
||||
@NSManaged var strokes: NSMutableOrderedSet
|
||||
@NSManaged var erasers: NSMutableSet
|
||||
}
|
||||
|
||||
@@ -12,13 +12,11 @@
|
||||
<attribute name="createdAt" attributeType="Date" usesScalarValueType="NO"/>
|
||||
<attribute name="style" attributeType="Integer 16" defaultValueString="0" usesScalarValueType="YES"/>
|
||||
<attribute name="thickness" attributeType="Double" defaultValueString="0.0" usesScalarValueType="YES"/>
|
||||
<relationship name="graphicContext" optional="YES" maxCount="1" deletionRule="Nullify" destinationEntity="GraphicContextObject" inverseName="erasers" inverseEntity="GraphicContextObject"/>
|
||||
<relationship name="quads" toMany="YES" deletionRule="Cascade" ordered="YES" destinationEntity="QuadObject" inverseName="eraser" inverseEntity="QuadObject"/>
|
||||
<relationship name="strokes" toMany="YES" deletionRule="Nullify" destinationEntity="StrokeObject" inverseName="erasers" inverseEntity="StrokeObject"/>
|
||||
</entity>
|
||||
<entity name="GraphicContextObject" representedClassName="GraphicContextObject" syncable="YES">
|
||||
<relationship name="canvas" optional="YES" maxCount="1" deletionRule="Nullify" destinationEntity="CanvasObject" inverseName="graphicContext" inverseEntity="CanvasObject"/>
|
||||
<relationship name="erasers" toMany="YES" deletionRule="Cascade" destinationEntity="EraserObject" inverseName="graphicContext" inverseEntity="EraserObject"/>
|
||||
<relationship name="strokes" toMany="YES" deletionRule="Cascade" ordered="YES" destinationEntity="StrokeObject" inverseName="graphicContext" inverseEntity="StrokeObject"/>
|
||||
</entity>
|
||||
<entity name="MemoObject" representedClassName="MemoObject" syncable="YES">
|
||||
|
||||
Reference in New Issue
Block a user