|
|
|
@ -139,6 +139,10 @@ public class OrderedDictionary<ValueType>: NSObject {
|
|
|
|
|
return OrderedDictionary(keyValueMap: keyValueMap, orderedKeys: orderedKeys)
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public func value(forKey key: KeyType) -> ValueType? {
|
|
|
|
|
return keyValueMap[key]
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public func append(key: KeyType, value: ValueType) {
|
|
|
|
|
if keyValueMap[key] != nil {
|
|
|
|
|
owsFailDebug("Unexpected duplicate key in key map: \(key)")
|
|
|
|
@ -239,6 +243,11 @@ public class ImageEditorContents: NSObject {
|
|
|
|
|
return ImageEditorContents(itemMap: itemMap.clone())
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
@objc
|
|
|
|
|
public func item(forId itemId: String) -> ImageEditorItem? {
|
|
|
|
|
return itemMap.value(forKey: itemId)
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
@objc
|
|
|
|
|
public func append(item: ImageEditorItem) {
|
|
|
|
|
Logger.verbose("\(item.itemId)")
|
|
|
|
@ -300,6 +309,7 @@ private class ImageEditorOperation: NSObject {
|
|
|
|
|
@objc
|
|
|
|
|
public protocol ImageEditorModelDelegate: class {
|
|
|
|
|
func imageEditorModelDidChange()
|
|
|
|
|
func imageEditorModelDidChange(changedItemIds: [String])
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// MARK: -
|
|
|
|
@ -360,6 +370,11 @@ public class ImageEditorModel: NSObject {
|
|
|
|
|
return contents.items()
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
@objc
|
|
|
|
|
public func item(forId itemId: String) -> ImageEditorItem? {
|
|
|
|
|
return contents.item(forId: itemId)
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
@objc
|
|
|
|
|
public func canUndo() -> Bool {
|
|
|
|
|
return !undoStack.isEmpty
|
|
|
|
@ -382,6 +397,7 @@ public class ImageEditorModel: NSObject {
|
|
|
|
|
|
|
|
|
|
self.contents = undoOperation.contents
|
|
|
|
|
|
|
|
|
|
// We could diff here and yield a more narrow change event.
|
|
|
|
|
delegate?.imageEditorModelDidChange()
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
@ -397,6 +413,7 @@ public class ImageEditorModel: NSObject {
|
|
|
|
|
|
|
|
|
|
self.contents = redoOperation.contents
|
|
|
|
|
|
|
|
|
|
// We could diff here and yield a more narrow change event.
|
|
|
|
|
delegate?.imageEditorModelDidChange()
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
@ -404,7 +421,7 @@ public class ImageEditorModel: NSObject {
|
|
|
|
|
public func append(item: ImageEditorItem) {
|
|
|
|
|
performAction({ (newContents) in
|
|
|
|
|
newContents.append(item: item)
|
|
|
|
|
})
|
|
|
|
|
}, changedItemIds: [item.itemId])
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
@objc
|
|
|
|
@ -420,10 +437,11 @@ public class ImageEditorModel: NSObject {
|
|
|
|
|
public func remove(item: ImageEditorItem) {
|
|
|
|
|
performAction({ (newContents) in
|
|
|
|
|
newContents.remove(item: item)
|
|
|
|
|
})
|
|
|
|
|
}, changedItemIds: [item.itemId])
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
private func performAction(_ action: (ImageEditorContents) -> Void,
|
|
|
|
|
changedItemIds: [String],
|
|
|
|
|
suppressUndo: Bool = false) {
|
|
|
|
|
if !suppressUndo {
|
|
|
|
|
let undoOperation = ImageEditorOperation(contents: contents)
|
|
|
|
@ -435,6 +453,6 @@ public class ImageEditorModel: NSObject {
|
|
|
|
|
action(newContents)
|
|
|
|
|
contents = newContents
|
|
|
|
|
|
|
|
|
|
delegate?.imageEditorModelDidChange()
|
|
|
|
|
delegate?.imageEditorModelDidChange(changedItemIds: changedItemIds)
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|