|
@@ -6,11 +6,23 @@
|
|
|
//
|
|
|
|
|
|
import Cocoa
|
|
|
+import KMComponentLibrary
|
|
|
|
|
|
class KMBatchBackgroundView: KMBatchSettingItemView {
|
|
|
@IBOutlet weak var applyButton: NSButton!
|
|
|
@IBOutlet weak var itemContentView: NSView!
|
|
|
|
|
|
+ var propertyController: KMBackgroundPropertyController = KMBackgroundPropertyController.init()
|
|
|
+ var templatesController: KMBGTemplateController = KMBGTemplateController()
|
|
|
+
|
|
|
+ var saveTemplateMessage: ComponentMessage = ComponentMessage()
|
|
|
+
|
|
|
+ var pdfDocument: CPDFDocument?
|
|
|
+
|
|
|
+ var backgroundModel: KMBackgroundModel?
|
|
|
+
|
|
|
+ var editSubType: KMPDFEditSubModeType = .none
|
|
|
+
|
|
|
override func setup() {
|
|
|
super.setup()
|
|
|
|
|
@@ -20,6 +32,21 @@ class KMBatchBackgroundView: KMBatchSettingItemView {
|
|
|
self.applyButton.stringValue = NSLocalizedString("Compress", comment: "")
|
|
|
self.applyButton.font = NSFont.SFProTextRegularFont(14.0)
|
|
|
self.applyButton.layer?.backgroundColor = NSColor.km_init(hex: "#BDDFFD").cgColor
|
|
|
+
|
|
|
+ propertyController.view.frame = itemContentView.bounds
|
|
|
+ propertyController.view.autoresizingMask = [.width, .height]
|
|
|
+ propertyController.delegate = self
|
|
|
+ propertyController.view.isHidden = true
|
|
|
+ propertyController.isInBatchMode = true
|
|
|
+ itemContentView.addSubview(propertyController.view)
|
|
|
+
|
|
|
+ templatesController.view.frame = itemContentView.bounds
|
|
|
+ templatesController.view.autoresizingMask = [.width, .height]
|
|
|
+ templatesController.delegate = self
|
|
|
+ templatesController.view.isHidden = true
|
|
|
+ itemContentView.addSubview(templatesController.view)
|
|
|
+
|
|
|
+ setupProperty()
|
|
|
}
|
|
|
|
|
|
override func reloadData() {
|
|
@@ -31,13 +58,159 @@ class KMBatchBackgroundView: KMBatchSettingItemView {
|
|
|
self.applyButton.layer?.backgroundColor = NSColor.km_init(hex: "#BDDFFD").cgColor
|
|
|
self.applyButton.isEnabled = false
|
|
|
}
|
|
|
+
|
|
|
+ if editSubType == .template {
|
|
|
+ templatesController.reloadData()
|
|
|
+
|
|
|
+ backgroundModel = templatesController.selectedBackground
|
|
|
+ } else if editSubType == .add {
|
|
|
+ propertyController.editSubType = editSubType
|
|
|
+ propertyController.backgroundData = KMBackgroundManager.defaultManager.defaultModel
|
|
|
+ propertyController.reloadData()
|
|
|
+
|
|
|
+ backgroundModel = propertyController.backgroundData
|
|
|
+ } else if editSubType == .edit {
|
|
|
+ propertyController.editSubType = editSubType
|
|
|
+ propertyController.reloadData()
|
|
|
+
|
|
|
+ backgroundModel = propertyController.backgroundData
|
|
|
+ }
|
|
|
+
|
|
|
+ updatePDFDocumentBackground()
|
|
|
+ }
|
|
|
+
|
|
|
+ func setupProperty() {
|
|
|
+ saveTemplateMessage.properties = ComponentMessageProperty(messageType: .success, title: KMLocalizedString("Saved Template"))
|
|
|
+
|
|
|
+ }
|
|
|
+
|
|
|
+ func resetUI() {
|
|
|
+ propertyController.view.isHidden = true
|
|
|
+ templatesController.view.isHidden = true
|
|
|
+
|
|
|
+ if editSubType == .template {
|
|
|
+ templatesController.view.isHidden = false
|
|
|
+
|
|
|
+ } else if editSubType == .add {
|
|
|
+ propertyController.view.isHidden = false
|
|
|
+ propertyController.editSubType = editSubType
|
|
|
+
|
|
|
+ } else if editSubType == .edit {
|
|
|
+ propertyController.view.isHidden = false
|
|
|
+ propertyController.editSubType = editSubType
|
|
|
+
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+ func updatePDFDocumentBackground() {
|
|
|
+
|
|
|
+ }
|
|
|
+
|
|
|
+ override func mouseUp(with event: NSEvent) {
|
|
|
+ super.mouseUp(with: event)
|
|
|
+
|
|
|
+
|
|
|
+ }
|
|
|
+
|
|
|
+}
|
|
|
+
|
|
|
+//MARK: - KMBackgroundPropertyControllerDelegate
|
|
|
+extension KMBatchBackgroundView: KMBackgroundPropertyControllerDelegate {
|
|
|
+ func backgroundPropertyControllerDidUpdate(_ controller: KMBackgroundPropertyController) {
|
|
|
+ backgroundModel = controller.backgroundData
|
|
|
+
|
|
|
+ updatePDFDocumentBackground()
|
|
|
+
|
|
|
+ }
|
|
|
+
|
|
|
+ func backgroundPropertyControllerDidChangetoTemplate(_ controller: KMBackgroundPropertyController) {
|
|
|
+ editSubType = .template
|
|
|
+ resetUI()
|
|
|
+
|
|
|
+ backgroundModel = templatesController.selectedBackground
|
|
|
+ reloadData()
|
|
|
+ }
|
|
|
+
|
|
|
+ func backgroundPropertyControllerSaveTemplateSuccess(_ controller: KMBackgroundPropertyController, _ data: KMBackgroundModel) {
|
|
|
+ saveTemplateMessage.frame = CGRectMake((CGRectGetWidth(self.frame) - saveTemplateMessage.properties.propertyInfo.viewWidth)/2,
|
|
|
+ CGRectGetHeight(self.frame) - saveTemplateMessage.properties.propertyInfo.viewHeight - 8,
|
|
|
+ saveTemplateMessage.properties.propertyInfo.viewWidth,
|
|
|
+ saveTemplateMessage.properties.propertyInfo.viewHeight)
|
|
|
+ saveTemplateMessage.reloadData()
|
|
|
+ saveTemplateMessage.show(inView: self, autoHideSeconde: 2)
|
|
|
+
|
|
|
+ editSubType = .template
|
|
|
+ resetUI()
|
|
|
+
|
|
|
+ templatesController.selectedBackground = data
|
|
|
+
|
|
|
+ reloadData()
|
|
|
+
|
|
|
+ KMBackgroundManager.defaultManager.defaultModel = KMBackgroundModel()
|
|
|
+ }
|
|
|
+
|
|
|
+ func backgroundPropertyControllerCancelTemplateEdit(_ controller: KMBackgroundPropertyController) {
|
|
|
+ editSubType = .template
|
|
|
+ resetUI()
|
|
|
+
|
|
|
+ templatesController.selectedBackground = controller.backgroundData
|
|
|
+
|
|
|
+ reloadData()
|
|
|
+
|
|
|
+ }
|
|
|
+
|
|
|
+ func backgroundPropertyControllerFinishTemplateEdit(_ controller: KMBackgroundPropertyController) {
|
|
|
+ editSubType = .template
|
|
|
+ resetUI()
|
|
|
+
|
|
|
+ templatesController.selectedBackground = controller.backgroundData
|
|
|
+
|
|
|
+ reloadData()
|
|
|
+ }
|
|
|
+}
|
|
|
+
|
|
|
+//MARK: - KMBGTemplateControllerDelegate
|
|
|
+extension KMBatchBackgroundView: KMBGTemplateControllerDelegate {
|
|
|
+ func templateControllerDidSelectedChanged(_ controller: KMBGTemplateController) {
|
|
|
+ backgroundModel = controller.selectedBackground
|
|
|
+
|
|
|
+ updatePDFDocumentBackground()
|
|
|
+
|
|
|
+ }
|
|
|
+
|
|
|
+ func templateControllerDidAddData(_ controller: KMBGTemplateController) {
|
|
|
+ editSubType = .add
|
|
|
+ resetUI()
|
|
|
+
|
|
|
+ propertyController.backgroundData = KMBackgroundManager.defaultManager.defaultModel
|
|
|
+
|
|
|
+ templatesController.selectedBackground = nil
|
|
|
+ templatesController.reloadData()
|
|
|
+
|
|
|
+ reloadData()
|
|
|
+
|
|
|
+ }
|
|
|
+
|
|
|
+ func templateControllerDidEditData(_ controller: KMBGTemplateController, _ data: KMBackgroundModel) {
|
|
|
+ editSubType = .edit
|
|
|
+ resetUI()
|
|
|
+
|
|
|
+ propertyController.originalDataDict = KMBackgroundManager.defaultManager.parseModelToDict(model: data)
|
|
|
+ propertyController.backgroundData = data
|
|
|
+
|
|
|
+ templatesController.selectedBackground = nil
|
|
|
+ templatesController.reloadData()
|
|
|
+
|
|
|
+ reloadData()
|
|
|
}
|
|
|
}
|
|
|
|
|
|
+protocol KMBatchBackgroundViewAction: KMBatchBackgroundView {
|
|
|
+
|
|
|
+}
|
|
|
|
|
|
-protocol KMBatchBackgroundViewAction: KMBatchBackgroundView {}
|
|
|
extension KMBatchBackgroundView: KMBatchBackgroundViewAction {
|
|
|
@IBAction func applyButtonAction(_ sender: NSButton) {
|
|
|
-
|
|
|
+
|
|
|
}
|
|
|
}
|