123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405 |
- //
- // 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 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];
- 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
- 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
- }
-
- }
-
- 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)
- }
-
- @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)
- }
-
- @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
- }
- }
- }
- extension KMNotesPreferences: KMPreferencePane {
- func defaultsDidRevert() {
-
- }
- }
|