Browse Source

【偏好设置】批注模块,markup颜色设置项补充

tangchao 1 year ago
parent
commit
4486b5af0f
1 changed files with 163 additions and 68 deletions
  1. 163 68
      PDF Office/PDF Master/Class/Preference/Controller/KMNotesPreferences.swift

+ 163 - 68
PDF Office/PDF Master/Class/Preference/Controller/KMNotesPreferences.swift

@@ -9,20 +9,6 @@ import Cocoa
 
 class KMNotesPreferences: NSViewController {
 
-   /*
-    @interface SKNotesPreferences : NSViewController <SKPreferencePane> {
-        NSArray *labels1;
-        NSArray *colorLabels2;
-        NSArray *colorLabels3;
-        NSArray *lineLabels2;
-        NSArray *colorWells1;
-        NSArray *colorWells2;
-        NSArray *colorWells3;
-    //    NSArray *fontWells;
-        NSArray *lineWells1;
-        NSArray *lineWells2;
-    }
-    */
     @IBOutlet weak var noteLabel: NSTextField!
     
     @IBOutlet weak var textLabel: NSTextField!
@@ -63,7 +49,6 @@ class KMNotesPreferences: NSViewController {
     @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!
@@ -92,12 +77,72 @@ class KMNotesPreferences: NSViewController {
     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.freehandLineWell] {
+        for view in [self.highlightColorWell, self.underlineColorWell, self.strikeThroughColorWell, self.freehandColorWell] {
             if let data = view {
                 controls.append(data)
             }
@@ -129,7 +174,7 @@ class KMNotesPreferences: NSViewController {
         }
         dw += KMAutoSizeLabelFields(colorLabels2, controls, false)
         
-        for view in [self.textLineWell, self.anchoredColorWell, self.lineLineWell, self.lineInteriorColorWell] {
+        for view in [self.textColorWell, self.anchoredColorWell, self.lineColorWell, self.lineInteriorColorWell] {
             if let data = view {
                 controls.append(data)
             }
@@ -176,59 +221,9 @@ class KMNotesPreferences: NSViewController {
         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)
-        
-//        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()
-        
+    private func _initStrings() {
         self.noteLabel.stringValue = NSLocalizedString("Note colors:", comment: "")
         self.textLabel.stringValue = NSLocalizedString("Text:", comment: "")
         self.anchoredLabel.stringValue = NSLocalizedString("Anchored:", comment: "")
@@ -254,6 +249,106 @@ class KMNotesPreferences: NSViewController {
         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
+    }
+    
+    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)
+    }
+    
+    @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
+    }
 }
 
 extension KMNotesPreferences: KMPreferencePane {