// // 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", "Preference pane label") } } override func loadView() { super.loadView() self._initLayoutUI() // NSUserDefaultsController *sudc = [NSUserDefaultsController sharedUserDefaultsController]; // SKLineWell *lineWell = [lineWells1 objectAtIndex:0]; // [lineWell bind:SKLineWellLineWidthKey toObject:sudc withKeyPath:VALUES_KEY_PATH(SKStringConstants.freeTextNoteLineWidthKey) options:nil]; // [lineWell bind:SKLineWellStyleKey toObject:sudc withKeyPath:VALUES_KEY_PATH(SKStringConstants.freeTextNoteLineStyleKey) options:nil]; // [lineWell bind:SKLineWellDashPatternKey toObject:sudc withKeyPath:VALUES_KEY_PATH(SKStringConstants.freeTextNoteDashPatternKey) options:nil]; // [lineWell setDisplayStyle:SKLineWellDisplayStyleRectangle]; self.textLineWell.lineWidth = 0 // // lineWell = [lineWells2 objectAtIndex:0]; // [lineWell bind:SKLineWellLineWidthKey toObject:sudc withKeyPath:VALUES_KEY_PATH(SKStringConstants.circleNoteLineWidthKey) options:nil]; // [lineWell bind:SKLineWellStyleKey toObject:sudc withKeyPath:VALUES_KEY_PATH(SKStringConstants.circleNoteLineStyleKey) options:nil]; // [lineWell bind:SKLineWellDashPatternKey toObject:sudc withKeyPath:VALUES_KEY_PATH(SKStringConstants.circleNoteDashPatternKey) options:nil]; // [lineWell setDisplayStyle:SKLineWellDisplayStyleOval]; self.circleLineWell.displayStyle = .oval self.circleLineWell.lineWidth = 2 // // lineWell = [lineWells2 objectAtIndex:1]; // [lineWell bind:SKLineWellLineWidthKey toObject:sudc withKeyPath:VALUES_KEY_PATH(SKStringConstants.squareNoteLineWidthKey) options:nil]; // [lineWell bind:SKLineWellStyleKey toObject:sudc withKeyPath:VALUES_KEY_PATH(SKStringConstants.squareNoteLineStyleKey) options:nil]; // [lineWell bind:SKLineWellDashPatternKey toObject:sudc withKeyPath:VALUES_KEY_PATH(SKStringConstants.squareNoteDashPatternKey) options:nil]; // [lineWell setDisplayStyle:SKLineWellDisplayStyleRectangle]; self.rectLineWell.displayStyle = .rectangle self.rectLineWell.lineWidth = 2 // // lineWell = [lineWells1 objectAtIndex:1]; // [lineWell bind:SKLineWellLineWidthKey toObject:sudc withKeyPath:VALUES_KEY_PATH(SKStringConstants.lineNoteLineWidthKey) options:nil]; // [lineWell bind:SKLineWellStyleKey toObject:sudc withKeyPath:VALUES_KEY_PATH(SKStringConstants.lineNoteLineStyleKey) options:nil]; // [lineWell bind:SKLineWellDashPatternKey toObject:sudc withKeyPath:VALUES_KEY_PATH(SKStringConstants.lineNoteDashPatternKey) options:nil]; // [lineWell bind:SKLineWellStartLineStyleKey toObject:sudc withKeyPath:VALUES_KEY_PATH(SKStringConstants.lineNoteStartLineStyleKey) options:nil]; // [lineWell bind:SKLineWellEndLineStyleKey toObject:sudc withKeyPath:VALUES_KEY_PATH(SKStringConstants.lineNoteEndLineStyleKey) options:nil]; self.lineLineWell.displayStyle = .line self.lineLineWell.lineWidth = 2 self.lineLineWell.endLineStyle = .openArrow // // lineWell = [lineWells1 objectAtIndex:2]; // [lineWell bind:SKLineWellLineWidthKey toObject:sudc withKeyPath:VALUES_KEY_PATH(SKStringConstants.inkNoteLineWidthKey) options:nil]; // [lineWell bind:SKLineWellStyleKey toObject:sudc withKeyPath:VALUES_KEY_PATH(SKStringConstants.inkNoteLineStyleKey) options:nil]; // [lineWell bind:SKLineWellDashPatternKey toObject:sudc withKeyPath:VALUES_KEY_PATH(SKStringConstants.inkNoteDashPatternKey) options:nil]; // [lineWell setDisplayStyle:SKLineWellDisplayStyleSimpleLine]; self.freehandLineWell.displayStyle = .simpleLine self.freehandLineWell.lineWidth = 2 // 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 // SKFreeTextNoteFontNameKey // SKFreeTextNoteFontSizeKey // SKFreeTextNoteAlignmentKey // SKAnchoredNoteFontNameKey // SKAnchoredNoteFontSizeKey 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 } 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) } @objc func textColorWellAction(_ sender: NSColorWell) { KMPreference.shared.markupTextColor = sender.color } @objc func anchoredColorWellAction(_ sender: NSColorWell) { KMPreference.shared.markupNoteColor = sender.color } @objc func lineColorWellAction(_ sender: NSColorWell) { KMPreference.shared.markupLineColor = sender.color } @objc func lineInteriorColorWellAction(_ sender: NSColorWell) { // KMPreference.shared.markupLineColor = sender.color } @objc func circleColorWellAction(_ sender: NSColorWell) { KMPreference.shared.markupCircleBorderColor = sender.color } @objc func circleInteriorColorWellAction(_ sender: NSColorWell) { KMPreference.shared.markupCircleFillColor = sender.color } @objc func rectColorWellAction(_ sender: NSColorWell) { KMPreference.shared.markupRectangleBorderColor = sender.color } @objc func rectInteriorColorWellAction(_ sender: NSColorWell) { KMPreference.shared.markupRectangleFillColor = sender.color } @objc func highlightColorWellAction(_ sender: NSColorWell) { KMPreference.shared.markupHighlightColor = sender.color } @objc func underlineColorWellAction(_ sender: NSColorWell) { KMPreference.shared.markupUnderlineColor = sender.color } @objc func strikeThroughColorWellAction(_ sender: NSColorWell) { KMPreference.shared.markupStrikthroughColor = sender.color } @objc func freehandColorWellAction(_ sender: NSColorWell) { KMPreference.shared.markupPenColor = sender.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) } } extension KMNotesPreferences: KMPreferencePane { func defaultsDidRevert() { } }