// // KMNotesPreferences.swift // PDF Reader Pro // // Created by tangchao on 2023/11/6. // import Cocoa class KMNotesPreferences: NSViewController { @IBOutlet weak var noteLabel: NSTextField! @IBOutlet weak var textLabel: NSTextField! @IBOutlet weak var textColorWell: NSColorWell! @IBOutlet weak var anchoredLabel: NSTextField! @IBOutlet weak var anchoredColorWell: NSColorWell! @IBOutlet weak var lineLabel: NSTextField! @IBOutlet weak var lineColorWell: NSColorWell! @IBOutlet weak var lineInteriorLabel: NSTextField! @IBOutlet weak var lineInteriorColorWell: NSColorWell! @IBOutlet weak var circleLabel: NSTextField! @IBOutlet weak var circleColorWell: NSColorWell! @IBOutlet weak var circleInteriorLabel: NSTextField! @IBOutlet weak var circleInteriorColorWell: NSColorWell! @IBOutlet weak var rectLabel: NSTextField! @IBOutlet weak var rectColorWell: NSColorWell! @IBOutlet weak var rectInteriorLabel: NSTextField! @IBOutlet weak var rectInteriorColorWell: NSColorWell! @IBOutlet weak var highlightLabel: NSTextField! @IBOutlet weak var highlightColorWell: NSColorWell! @IBOutlet weak var underlineLabel: NSTextField! @IBOutlet weak var underlineColorWell: NSColorWell! @IBOutlet weak var strikeThroughLabel: NSTextField! @IBOutlet weak var strikeThroughColorWell: NSColorWell! @IBOutlet weak var freehandLabel: NSTextField! @IBOutlet weak var freehandColorWell: NSColorWell! @IBOutlet weak var fontLabel: NSTextField! @IBOutlet weak var textFontLabel: NSTextField! @IBOutlet var fontWell1: KMFontWell! @IBOutlet var fontWell2: KMFontWell! @IBOutlet weak var anchoredFontLabel: NSTextField! @IBOutlet weak var alignmentSegmentControl: NSSegmentedControl! @IBOutlet weak var lineAndBorderLabel: NSTextField! @IBOutlet weak var lbTextLabel: NSTextField! @IBOutlet weak var textLineWell: KMLineWell! @IBOutlet weak var ibLineLabel: NSTextField! @IBOutlet weak var lineLineWell: KMLineWell! @IBOutlet weak var ibFreehandLabel: NSTextField! @IBOutlet weak var freehandLineWell: KMLineWell! @IBOutlet weak var ibCircleLabel: NSTextField! @IBOutlet weak var circleLineWell: KMLineWell! @IBOutlet weak var ibRectLabel: NSTextField! @IBOutlet weak var rectLineWell: KMLineWell! override var nibName: NSNib.Name? { return "NotesPreferences" } override var title: String? { set { super.title = newValue } get { return KMLocalizedString("Annotate") } } override func loadView() { super.loadView() self._initLayoutUI() // let fontWell = self.fontWell1 // NSDictionary *options = [NSDictionary dictionaryWithObjectsAndKeys:NSUnarchiveFromDataTransformerName, NSValueTransformerNameBindingOption, nil]; // [fontWell setHasTextColor:YES]; // [fontWell bind:@"textColor" toObject:sudc withKeyPath:VALUES_KEY_PATH(SKStringConstants.freeTextNoteFontColorKey) options:options]; } override func viewDidLoad() { super.viewDidLoad() self._initStrings() self._initValues() self._initActions() } private func _initLayoutUI() { var controls: [NSControl] = [] var dw: CGFloat = 0 var dw1: CGFloat = 0 var dw2: CGFloat = 0 for view in [self.highlightColorWell, self.underlineColorWell, self.strikeThroughColorWell, self.freehandColorWell] { if let data = view { controls.append(data) } } var colorLabels3: [NSTextField] = [] for view in [self.highlightLabel, self.underlineLabel, self.strikeThroughLabel, self.freehandLabel] { if let data = view { colorLabels3.append(data) } } dw = KMAutoSizeLabelFields(colorLabels3, controls, false) for view in [self.circleColorWell, self.circleInteriorColorWell, self.rectColorWell, self.rectInteriorColorWell] { if let data = view { controls.append(data) } } for view in [self.highlightLabel, self.underlineLabel, self.strikeThroughLabel, self.freehandLabel] { if let data = view { controls.append(data) } } var colorLabels2: [NSTextField] = [] for view in [self.circleLabel, self.circleInteriorLabel, self.rectLabel, self.rectInteriorLabel] { if let data = view { colorLabels2.append(data) } } dw += KMAutoSizeLabelFields(colorLabels2, controls, false) for view in [self.textColorWell, self.anchoredColorWell, self.lineColorWell, self.lineInteriorColorWell] { if let data = view { controls.append(data) } } for view in [self.circleLabel, self.circleInteriorLabel, self.rectLabel, self.rectInteriorLabel] { if let data = view { controls.append(data) } } for view in [self.fontWell1, self.fontWell2] { if let data = view { controls.append(data) } } for view in [self.textLineWell, self.lineLineWell, self.freehandLineWell] { if let data = view { controls.append(data) } } var labels1: [NSTextField] = [] for view in [self.textLabel, self.anchoredLabel, self.lineLabel, self.lineInteriorLabel, self.textFontLabel, self.anchoredFontLabel, self.lbTextLabel, self.ibLineLabel, self.ibFreehandLabel] { if let data = view { labels1.append(data) } } dw1 = KMAutoSizeLabelFields(labels1, controls, false) dw += dw1 var lineLabels2: [NSTextField] = [] for view in [self.ibCircleLabel, self.ibRectLabel] { if let data = view { lineLabels2.append(data) } } var lineWells2: [NSControl] = [] for view in [self.circleLineWell, self.rectLineWell] { if let data = view { lineWells2.append(data) } } dw2 = KMAutoSizeLabelFields(lineLabels2, lineWells2, false) KMShiftAndResizeViews([self.fontWell1, self.fontWell2], dx: 0.0, dw: dw - dw1) KMShiftAndResizeViews([self.ibCircleLabel, self.ibRectLabel, self.circleLineWell, self.rectLineWell], dx: dw - dw2, dw: 0.0) KMShiftAndResizeView(self.view, dx: 0.0, dw: dw) } private func _initStrings() { self.noteLabel.stringValue = NSLocalizedString("Note colors:", comment: "") self.textLabel.stringValue = NSLocalizedString("Text:", comment: "") self.anchoredLabel.stringValue = NSLocalizedString("Anchored:", comment: "") self.lineLabel.stringValue = NSLocalizedString("Line:", comment: "") self.lineInteriorLabel.stringValue = NSLocalizedString("Line interior:", comment: "") self.circleLabel.stringValue = NSLocalizedString("Circle:", comment: "") self.circleInteriorLabel.stringValue = NSLocalizedString("Circle interior:", comment: "") self.rectLabel.stringValue = NSLocalizedString("Rect:", comment: "") self.rectInteriorLabel.stringValue = NSLocalizedString("Rect interior:", comment: "") self.highlightLabel.stringValue = NSLocalizedString("Highlight:", comment: "") self.underlineLabel.stringValue = NSLocalizedString("Underline:", comment: "") self.strikeThroughLabel.stringValue = NSLocalizedString("Strikethrough:", comment: "") self.freehandLabel.stringValue = NSLocalizedString("Freehand:", comment: "") self.fontLabel.stringValue = NSLocalizedString("Note fonts:", comment: "") self.textFontLabel.stringValue = NSLocalizedString("Text:", comment: "") self.anchoredFontLabel.stringValue = NSLocalizedString("Anchored:", comment: "") self.lineAndBorderLabel.stringValue = NSLocalizedString("Note lines and borders:", comment: "") self.lbTextLabel.stringValue = NSLocalizedString("Text:", comment: "") self.ibLineLabel.stringValue = NSLocalizedString("Line:", comment: "") self.ibFreehandLabel.stringValue = NSLocalizedString("Freehand:", comment: "") self.ibCircleLabel.stringValue = NSLocalizedString("Circle:", comment: "") self.ibRectLabel.stringValue = NSLocalizedString("Rect:", comment: "") } private func _initValues() { self.textColorWell.color = KMPreference.shared.markupTextColor self.anchoredColorWell.color = KMPreference.shared.markupNoteColor self.lineColorWell.color = KMPreference.shared.markupLineColor // self.lineInteriorColorWell.color = KMPreference.shared.markupLineColor self.circleColorWell.color = KMPreference.shared.markupCircleBorderColor self.circleInteriorColorWell.color = KMPreference.shared.markupCircleFillColor self.rectColorWell.color = KMPreference.shared.markupRectangleBorderColor self.rectInteriorColorWell.color = KMPreference.shared.markupRectangleFillColor self.highlightColorWell.color = KMPreference.shared.markupHighlightColor self.underlineColorWell.color = KMPreference.shared.markupUnderlineColor self.strikeThroughColorWell.color = KMPreference.shared.markupStrikthroughColor self.freehandColorWell.color = KMPreference.shared.markupPenColor let textFontName = KMPreference.shared.markupFontTextString let textFontSize = KMPreference.shared.markupTextFontSize let textFont = NSFont(name: textFontName, size: textFontSize.cgFloat) self.fontWell1.font = textFont let noteFontName = KMPreference.shared.markupFontNoteString let noteFontSize = KMPreference.shared.markupNoteFontSize let noteFont = NSFont(name: noteFontName, size: noteFontSize.cgFloat) self.fontWell2.font = noteFont let alignment = KMPreference.shared.markupFontTextAligment if alignment == .left { self.alignmentSegmentControl.selectedSegment = 0 } else if alignment == .center { self.alignmentSegmentControl.selectedSegment = 1 } else if alignment == .right { self.alignmentSegmentControl.selectedSegment = 2 } self.textLineWell.displayStyle = .rectangle self.textLineWell.lineWidth = KMPreference.shared.freeTextNoteLineWidth.cgFloat self.textLineWell.style = CPDFBorderStyle(rawValue: KMPreference.shared.freeTextNoteLineStyle) ?? .solid self.textLineWell.dashPattern = KMPreference.shared.freeTextNoteDashPattern as NSArray self.lineLineWell.displayStyle = .line self.lineLineWell.lineWidth = KMPreference.shared.lineNoteLineWidth.cgFloat self.lineLineWell.style = CPDFBorderStyle(rawValue: KMPreference.shared.lineNoteLineStyle) ?? .solid self.lineLineWell.dashPattern = KMPreference.shared.lineNoteDashPattern as NSArray self.lineLineWell.startLineStyle = CPDFLineStyle(rawValue: KMPreference.shared.lineNoteStartLineStyle) ?? .none self.lineLineWell.endLineStyle = CPDFLineStyle(rawValue: KMPreference.shared.lineNoteEndLineStyle) ?? .none self.freehandLineWell.displayStyle = .simpleLine self.freehandLineWell.lineWidth = KMPreference.shared.inkNoteLineWidth.cgFloat self.freehandLineWell.style = CPDFBorderStyle(rawValue: KMPreference.shared.inkNoteLineStyle) ?? .solid self.freehandLineWell.dashPattern = KMPreference.shared.inkNoteDashPattern as NSArray self.circleLineWell.displayStyle = .oval self.circleLineWell.lineWidth = KMPreference.shared.circleNoteLineWidth.cgFloat self.circleLineWell.style = CPDFBorderStyle(rawValue: KMPreference.shared.circleNoteLineStyle) ?? .solid self.circleLineWell.dashPattern = KMPreference.shared.circleNoteDashPattern as NSArray self.rectLineWell.displayStyle = .rectangle self.rectLineWell.lineWidth = KMPreference.shared.squareNoteLineWidth.cgFloat self.rectLineWell.style = CPDFBorderStyle(rawValue: KMPreference.shared.squareNoteLineStyle) ?? .solid self.rectLineWell.dashPattern = KMPreference.shared.squareNoteDashPattern as NSArray } private func _initActions() { self.textColorWell.target = self self.textColorWell.action = #selector(textColorWellAction) self.anchoredColorWell.target = self self.anchoredColorWell.action = #selector(anchoredColorWellAction) self.lineColorWell.target = self self.lineColorWell.action = #selector(lineColorWellAction) self.lineInteriorColorWell.target = self self.lineInteriorColorWell.action = #selector(lineInteriorColorWellAction) self.circleColorWell.target = self self.circleColorWell.action = #selector(circleColorWellAction) self.circleInteriorColorWell.target = self self.circleInteriorColorWell.action = #selector(circleInteriorColorWellAction) self.rectColorWell.target = self self.rectColorWell.action = #selector(rectColorWellAction) self.rectInteriorColorWell.target = self self.rectInteriorColorWell.action = #selector(rectInteriorColorWellAction) self.highlightColorWell.target = self self.highlightColorWell.action = #selector(highlightColorWellAction) self.underlineColorWell.target = self self.underlineColorWell.action = #selector(underlineColorWellAction) self.strikeThroughColorWell.target = self self.strikeThroughColorWell.action = #selector(strikeThroughColorWellAction) self.freehandColorWell.target = self self.freehandColorWell.action = #selector(freehandColorWellAction) self.fontWell1.target = self self.fontWell1.action = #selector(textFontWellAction) self.fontWell2.target = self self.fontWell2.action = #selector(anchoredFontWellAction) self.alignmentSegmentControl.target = self self.alignmentSegmentControl.action = #selector(alignmentSegmentAction) self.textLineWell.target = self self.textLineWell.action = #selector(textLineWellAction) self.lineLineWell.target = self self.lineLineWell.action = #selector(lineLineWellAction) self.freehandLineWell.target = self self.freehandLineWell.action = #selector(freehandLineWellAction) self.circleLineWell.target = self self.circleLineWell.action = #selector(circleLineWellAction) self.rectLineWell.target = self self.rectLineWell.action = #selector(rectLineWellAction) } @objc func textColorWellAction(_ sender: NSColorWell) { KMPreference.shared.markupTextColor = sender.color } @objc func anchoredColorWellAction(_ sender: NSColorWell) { if let color = sender.color.usingColorSpaceName(NSColorSpaceName.calibratedRGB) { KMPreference.shared.markupNoteColor = color } } @objc func lineColorWellAction(_ sender: NSColorWell) { if let color = sender.color.usingColorSpaceName(NSColorSpaceName.calibratedRGB) { KMPreference.shared.markupLineColor = color } } @objc func lineInteriorColorWellAction(_ sender: NSColorWell) { // KMPreference.shared.markupLineColor = sender.color } @objc func circleColorWellAction(_ sender: NSColorWell) { if let color = sender.color.usingColorSpaceName(NSColorSpaceName.calibratedRGB) { KMPreference.shared.markupCircleBorderColor = color } } @objc func circleInteriorColorWellAction(_ sender: NSColorWell) { if let color = sender.color.usingColorSpaceName(NSColorSpaceName.calibratedRGB) { KMPreference.shared.markupCircleFillColor = color } } @objc func rectColorWellAction(_ sender: NSColorWell) { if let color = sender.color.usingColorSpaceName(NSColorSpaceName.calibratedRGB) { KMPreference.shared.markupRectangleBorderColor = color } } @objc func rectInteriorColorWellAction(_ sender: NSColorWell) { if let color = sender.color.usingColorSpaceName(NSColorSpaceName.calibratedRGB) { KMPreference.shared.markupRectangleFillColor = color } } @objc func highlightColorWellAction(_ sender: NSColorWell) { if let color = sender.color.usingColorSpaceName(NSColorSpaceName.calibratedRGB) { KMPreference.shared.markupHighlightColor = color } } @objc func underlineColorWellAction(_ sender: NSColorWell) { if let color = sender.color.usingColorSpaceName(NSColorSpaceName.calibratedRGB) { KMPreference.shared.markupUnderlineColor = color } } @objc func strikeThroughColorWellAction(_ sender: NSColorWell) { if let color = sender.color.usingColorSpaceName(NSColorSpaceName.calibratedRGB) { KMPreference.shared.markupStrikthroughColor = color } } @objc func freehandColorWellAction(_ sender: NSColorWell) { if let color = sender.color.usingColorSpaceName(NSColorSpaceName.calibratedRGB) { KMPreference.shared.markupPenColor = color } } // MARK: - Font @objc func textFontWellAction(_ sender: KMFontWell) { // KMPrint("\(sender.fontName),\(sender.fontSize)") KMPreference.shared.markupFontTextString = sender.fontName ?? "" KMPreference.shared.markupTextFontSize = Float(sender.fontSize) } @objc func anchoredFontWellAction(_ sender: KMFontWell) { KMPreference.shared.markupFontNoteString = sender.fontName ?? "" KMPreference.shared.markupNoteFontSize = Float(sender.fontSize) } @objc func alignmentSegmentAction(_ sender: NSSegmentedControl) { if sender.selectedSegment == 0 { KMPreference.shared.markupFontTextAligment = .left } else if sender.selectedSegment == 1 { KMPreference.shared.markupFontTextAligment = .center } else if sender.selectedSegment == 2 { KMPreference.shared.markupFontTextAligment = .right } } // MARK: - LineWell @objc func textLineWellAction(_ sender: KMLineWell) { let action = KMLineInspector.shared.currentLineChangeAction if action == .lineWidth { KMPreference.shared.freeTextNoteLineWidth = Float(sender.lineWidth) } else if action == .style { KMPreference.shared.freeTextNoteLineStyle = sender.style.rawValue } else if action == .dashPattern { KMPreference.shared.freeTextNoteDashPattern = sender.dashPattern as? [CGFloat] ?? [] } } @objc func lineLineWellAction(_ sender: KMLineWell) { let action = KMLineInspector.shared.currentLineChangeAction if action == .lineWidth { KMPreference.shared.lineNoteLineWidth = Float(sender.lineWidth) } else if action == .style { KMPreference.shared.lineNoteLineStyle = sender.style.rawValue } else if action == .dashPattern { KMPreference.shared.lineNoteDashPattern = sender.dashPattern as? [CGFloat] ?? [] } else if action == .startLineStyle { KMPreference.shared.lineNoteStartLineStyle = sender.startLineStyle.rawValue } else if action == .endLineStyle { KMPreference.shared.lineNoteEndLineStyle = sender.endLineStyle.rawValue } } @objc func freehandLineWellAction(_ sender: KMLineWell) { let action = KMLineInspector.shared.currentLineChangeAction if action == .lineWidth { KMPreference.shared.inkNoteLineWidth = Float(sender.lineWidth) } else if action == .style { KMPreference.shared.inkNoteLineStyle = sender.style.rawValue } else if action == .dashPattern { KMPreference.shared.inkNoteDashPattern = sender.dashPattern as? [CGFloat] ?? [] } } @objc func circleLineWellAction(_ sender: KMLineWell) { // KMPreference.shared.beginGrouping() // KMPreference.shared.circleNoteLineWidth = Float(sender.lineWidth) // KMPreference.shared.circleNoteLineStyle = sender.style.rawValue // KMPreference.shared.circleNoteDashPattern = sender.dashPattern as? [CGFloat] ?? [] // KMPreference.shared.endGrouping() let action = KMLineInspector.shared.currentLineChangeAction if action == .lineWidth { KMPreference.shared.circleNoteLineWidth = Float(sender.lineWidth) } else if action == .style { KMPreference.shared.circleNoteLineStyle = sender.style.rawValue } else if action == .dashPattern { KMPreference.shared.circleNoteDashPattern = sender.dashPattern as? [CGFloat] ?? [] } } @objc func rectLineWellAction(_ sender: KMLineWell) { let action = KMLineInspector.shared.currentLineChangeAction if action == .lineWidth { KMPreference.shared.squareNoteLineWidth = Float(sender.lineWidth) } else if action == .style { KMPreference.shared.squareNoteLineStyle = sender.style.rawValue } else if action == .dashPattern { KMPreference.shared.squareNoteDashPattern = sender.dashPattern as? [CGFloat] ?? [] } } } extension KMNotesPreferences: KMPreferencePane { func defaultsDidRevert() { } func reloadData() { self._initValues() } }