Browse Source

【属性面板】属性面板调色板视图逻辑补充

wanjun 1 year ago
parent
commit
539504be7e

+ 8 - 0
PDF Office/PDF Master.xcodeproj/project.pbxproj

@@ -1054,6 +1054,9 @@
 		9FDD0FBA295D5230000C4DAD /* KMToolbarController.xib in Resources */ = {isa = PBXBuildFile; fileRef = 9FDD0FB6295D5230000C4DAD /* KMToolbarController.xib */; };
 		9FDD0FBB295D5230000C4DAD /* KMToolbarController.xib in Resources */ = {isa = PBXBuildFile; fileRef = 9FDD0FB6295D5230000C4DAD /* KMToolbarController.xib */; };
 		9FDD0FBC295D5230000C4DAD /* KMToolbarController.xib in Resources */ = {isa = PBXBuildFile; fileRef = 9FDD0FB6295D5230000C4DAD /* KMToolbarController.xib */; };
+		9FE0BBDE2B0E009F00CD1CAC /* KMColorPickerView.swift in Sources */ = {isa = PBXBuildFile; fileRef = 9FE0BBDD2B0E009F00CD1CAC /* KMColorPickerView.swift */; };
+		9FE0BBDF2B0E009F00CD1CAC /* KMColorPickerView.swift in Sources */ = {isa = PBXBuildFile; fileRef = 9FE0BBDD2B0E009F00CD1CAC /* KMColorPickerView.swift */; };
+		9FE0BBE02B0E009F00CD1CAC /* KMColorPickerView.swift in Sources */ = {isa = PBXBuildFile; fileRef = 9FE0BBDD2B0E009F00CD1CAC /* KMColorPickerView.swift */; };
 		9FF816DD2AFA5B8E0087EFC5 /* KMAnnotationTableViewController.swift in Sources */ = {isa = PBXBuildFile; fileRef = 9FF816DC2AFA5B8E0087EFC5 /* KMAnnotationTableViewController.swift */; };
 		9FF816DE2AFA5B8E0087EFC5 /* KMAnnotationTableViewController.swift in Sources */ = {isa = PBXBuildFile; fileRef = 9FF816DC2AFA5B8E0087EFC5 /* KMAnnotationTableViewController.swift */; };
 		9FF816DF2AFA5B8E0087EFC5 /* KMAnnotationTableViewController.swift in Sources */ = {isa = PBXBuildFile; fileRef = 9FF816DC2AFA5B8E0087EFC5 /* KMAnnotationTableViewController.swift */; };
@@ -4449,6 +4452,7 @@
 		9FDD0FB129534FEA000C4DAD /* KMGlobal.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = KMGlobal.swift; sourceTree = "<group>"; };
 		9FDD0FB5295D5230000C4DAD /* KMToolbarController.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = KMToolbarController.swift; sourceTree = "<group>"; };
 		9FDD0FB6295D5230000C4DAD /* KMToolbarController.xib */ = {isa = PBXFileReference; lastKnownFileType = file.xib; path = KMToolbarController.xib; sourceTree = "<group>"; };
+		9FE0BBDD2B0E009F00CD1CAC /* KMColorPickerView.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = KMColorPickerView.swift; sourceTree = "<group>"; };
 		9FF816DC2AFA5B8E0087EFC5 /* KMAnnotationTableViewController.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = KMAnnotationTableViewController.swift; sourceTree = "<group>"; };
 		9FF816E02AFA5BA80087EFC5 /* KMAnnotationTableViewController.xib */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = file.xib; path = KMAnnotationTableViewController.xib; sourceTree = "<group>"; };
 		9FF816E52AFA5D650087EFC5 /* KMTableAnnotation.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = KMTableAnnotation.swift; sourceTree = "<group>"; };
@@ -6003,6 +6007,7 @@
 				89E4E73C2964160F002DBA6F /* KMAnnotationLinkViewController.xib */,
 				9FF816DC2AFA5B8E0087EFC5 /* KMAnnotationTableViewController.swift */,
 				9FF816E02AFA5BA80087EFC5 /* KMAnnotationTableViewController.xib */,
+				9FE0BBDD2B0E009F00CD1CAC /* KMColorPickerView.swift */,
 				9F0CB44C29667FC700007028 /* ViewController */,
 			);
 			path = AnnotationProperty;
@@ -12394,6 +12399,7 @@
 				AD88109229A7612000178CA1 /* KMRegisterModel.swift in Sources */,
 				BB1BFF812AEA139F003EB179 /* KMLongerButton.swift in Sources */,
 				BBC8A7642B05C93900FA9377 /* KMThumbnailTableView.swift in Sources */,
+				9FE0BBDE2B0E009F00CD1CAC /* KMColorPickerView.swift in Sources */,
 				ADBC2D1F299CDA29006280C8 /* NSView+Layer.swift in Sources */,
 				ADAFDA3E2AE8F32400F084BC /* KMAdvertisementManager.swift in Sources */,
 				BBC8A76D2B05EDDF00FA9377 /* KMThumbnail.swift in Sources */,
@@ -13574,6 +13580,7 @@
 				BBF2455E2AE78FF900037D08 /* KMBatchWindow.swift in Sources */,
 				BBC4F9FB2AEB9E200098A1A8 /* KMBatchTableCellView.swift in Sources */,
 				BB146FEE299DC0D100784A6A /* GTLRBatchResult.m in Sources */,
+				9FE0BBDF2B0E009F00CD1CAC /* KMColorPickerView.swift in Sources */,
 				BB4F7E752B0C42160077EC8C /* KMPopupMenuObject.swift in Sources */,
 				ADE8BC3C29F9458700570F89 /* KMRecommondManager.m in Sources */,
 				BB897272294DB6BE0045787C /* KMWatermarkAdjectivePlainView.swift in Sources */,
@@ -14062,6 +14069,7 @@
 				9FDD0F8E2952FCE0000C4DAD /* KMGlobalParser.swift in Sources */,
 				BBC348352955A118008D2CD1 /* KMCreateBackgroundController.swift in Sources */,
 				89E4E757296427E5002DBA6F /* NSImage_SKExtensions.m in Sources */,
+				9FE0BBE02B0E009F00CD1CAC /* KMColorPickerView.swift in Sources */,
 				ADD1B6EE2946C04C00C3FFF7 /* KMPrintChoosePageSizePamphletView.swift in Sources */,
 				9F0CB4DB2986553600007028 /* KMDesignToken+VerticalPadding.swift in Sources */,
 				BB6DD816293486FA001F0544 /* KMSecureEncryptPasswordCellView.swift in Sources */,

+ 4 - 4
PDF Office/PDF Master/Class/PDFWindowController/Side/RightSide/AnnotationProperty/KMAnnotationPropertiesViewController.xib

@@ -1,8 +1,8 @@
 <?xml version="1.0" encoding="UTF-8"?>
-<document type="com.apple.InterfaceBuilder3.Cocoa.XIB" version="3.0" toolsVersion="21507" targetRuntime="MacOSX.Cocoa" propertyAccessControl="none" useAutolayout="YES" customObjectInstantitationMethod="direct">
+<document type="com.apple.InterfaceBuilder3.Cocoa.XIB" version="3.0" toolsVersion="22154" targetRuntime="MacOSX.Cocoa" propertyAccessControl="none" useAutolayout="YES" customObjectInstantitationMethod="direct">
     <dependencies>
         <deployment identifier="macosx"/>
-        <plugIn identifier="com.apple.InterfaceBuilder.CocoaPlugin" version="21507"/>
+        <plugIn identifier="com.apple.InterfaceBuilder.CocoaPlugin" version="22154"/>
         <capability name="documents saved in the Xcode 8 format" minToolsVersion="8.0"/>
     </dependencies>
     <objects>
@@ -27,7 +27,7 @@
                 <customView translatesAutoresizingMaskIntoConstraints="NO" id="rxw-ZM-edB">
                     <rect key="frame" x="0.0" y="529" width="284" height="40"/>
                     <subviews>
-                        <textField horizontalHuggingPriority="251" verticalHuggingPriority="750" translatesAutoresizingMaskIntoConstraints="NO" id="Mws-8l-JHx">
+                        <textField focusRingType="none" horizontalHuggingPriority="251" verticalHuggingPriority="750" translatesAutoresizingMaskIntoConstraints="NO" id="Mws-8l-JHx">
                             <rect key="frame" x="14" y="13" width="256" height="15"/>
                             <textFieldCell key="cell" scrollable="YES" lineBreakMode="clipping" sendsActionOnEndEditing="YES" alignment="left" id="mBB-CB-9jR">
                                 <font key="font" metaFont="systemBold" size="12"/>
@@ -46,7 +46,7 @@
                 <customView translatesAutoresizingMaskIntoConstraints="NO" id="B80-hQ-s7Z">
                     <rect key="frame" x="52" y="174" width="180" height="182"/>
                     <subviews>
-                        <textField horizontalHuggingPriority="251" verticalHuggingPriority="750" translatesAutoresizingMaskIntoConstraints="NO" id="UXe-E2-gz1">
+                        <textField focusRingType="none" horizontalHuggingPriority="251" verticalHuggingPriority="750" translatesAutoresizingMaskIntoConstraints="NO" id="UXe-E2-gz1">
                             <rect key="frame" x="-2" y="0.0" width="184" height="34"/>
                             <constraints>
                                 <constraint firstAttribute="width" constant="180" id="kUd-2I-6Is"/>

+ 490 - 0
PDF Office/PDF Master/Class/PDFWindowController/Side/RightSide/AnnotationProperty/KMColorPickerView.swift

@@ -0,0 +1,490 @@
+//
+//  KMColorPickerView.swift
+//  PDF Master
+//
+//  Created by wanjun on 2023/11/22.
+//
+
+import Cocoa
+
+enum KMPropertiesColors: Int {
+    case markupHighlightColors
+    case markupOtherColors
+    case lineColors
+    case lineFillColors
+    case inkColors
+    case inkFillColors
+    case freeTextColors
+    case freeTextFillColors
+    case anchoredNoteColors
+    case fromColors
+    case fromFillColors
+    case selfSignColors
+    case editText
+    case otherColors
+}
+
+class KMColorPickerView: NSControl {
+
+    var color: NSColor?
+    private(set) var colors: [NSColor] = []
+    private(set) var firstButton: NSButton = NSButton()
+    var _annotationType: KMPropertiesColors = .markupHighlightColors
+    var isFillColor: Bool = false
+    var isFreeText: Bool = false
+    var isCallColorPanelAction: Bool = false
+    var annotationTypeString: String = ""
+    var noContentString: Bool = false
+    var hideColorPanelAlpha: Bool = false
+    var isVerticalMode: Bool = false
+    
+    var buttons: [NSButton] = []
+    var customColorButton: NSButton =  NSButton()
+    var customColorLayer: CALayer = CALayer()
+    var customColor: NSColor?
+    var updatingColor: Bool = false
+    var secterindex: Int = 0
+    var titleLabel: NSTextField = NSTextField()
+    
+    // MARK: Init Methods
+    
+    deinit {
+        NSColorPanel.shared.setTarget(nil)
+        NSColorPanel.shared.setAction(nil)
+    }
+    
+    override var intrinsicContentSize: NSSize {
+        return NSMakeSize(40*6, 30)
+    }
+    
+    // MARK: Get、Set
+    
+    var annotationType: KMPropertiesColors {
+        set {
+            _annotationType = newValue
+            
+            switch newValue {
+            case .markupHighlightColors:
+                colors = KMAnnotationPropertiesColorManager.manager.markHighlightColors
+            case .markupOtherColors:
+                colors = KMAnnotationPropertiesColorManager.manager.markOtherColors
+            case .lineColors:
+                colors = KMAnnotationPropertiesColorManager.manager.lineColors
+            case .lineFillColors:
+                colors = KMAnnotationPropertiesColorManager.manager.fillLineColors
+            case .inkColors:
+                colors = KMAnnotationPropertiesColorManager.manager.inkColors
+            case .inkFillColors:
+                colors = KMAnnotationPropertiesColorManager.manager.inkFillColors
+            case .freeTextColors:
+                colors = KMAnnotationPropertiesColorManager.manager.freeTextColors
+            case .freeTextFillColors:
+                colors = KMAnnotationPropertiesColorManager.manager.freeFillTextColors
+            case .anchoredNoteColors:
+                colors = KMAnnotationPropertiesColorManager.manager.anchoredNoteColors
+            case .fromColors:
+                colors = KMAnnotationPropertiesColorManager.manager.fromColors
+            case .fromFillColors:
+                colors = KMAnnotationPropertiesColorManager.manager.fromFillColors
+            case .selfSignColors, .editText:
+                colors = KMAnnotationPropertiesColorManager.manager.selfSignColors
+            case .otherColors:
+                colors = KMAnnotationPropertiesColorManager.manager.otherColors
+            }
+        }
+        get {
+            return _annotationType
+        }
+    }
+
+    func setColor(_ newValue: NSColor) -> Void {
+        self.color = newValue
+        
+        for i in 0..<buttons.count {
+            let button = buttons[i]
+            button.layer?.borderColor = .clear
+            button.layer?.borderWidth = 0.0
+        }
+        var ischangeColor = isChangeColor(color)
+        var isSelected = false
+        for i in 0..<buttons.count {
+            let button = buttons[i]
+            
+            if self.color != nil {
+                if isTheSameColor(self.color!, anotherColor: self.colors[i]) {
+                    isSelected = true
+                    button.layer?.borderColor = KMAppearance.Interactive.a0Color().cgColor
+                    button.layer?.borderWidth = 2.0
+                    break
+                }
+            }
+        }
+
+        if isSelected {
+            customColorButton.layer?.borderWidth = 0.0
+            
+            if customColor == nil {
+                customColor = self.color
+            }
+        } else {
+            customColorButton.layer?.borderWidth = 2.0
+            customColor = self.color
+            customColorButton.layer?.borderColor = KMAppearance.Interactive.a0Color().cgColor
+        }
+
+        customColorLayer.backgroundColor = customColor?.cgColor
+    }
+    
+    // MARK: Private Method
+    
+    private func setColors(_ newValue: [NSColor]) -> Void {
+        self.colors = newValue
+        
+        while let lastSubview = self.subviews.last {
+            lastSubview.removeFromSuperview()
+        }
+
+        var width: CGFloat = 30.0
+        let space: CGFloat = 9.0
+        var posX: CGFloat = 0
+        var buttons: [NSButton] = []
+
+        for i in 0..<min(self.colors.count, 4) {
+            let color = self.colors[i]
+            let button = NSButton()
+            button.tag = i
+
+            if self.isVerticalMode {
+                button.frame = NSMakeRect(0, self.frame.height - posX - width, width, width)
+            } else {
+                button.frame = NSMakeRect(posX, 0, width, width)
+            }
+
+            button.title = ""
+            button.isBordered = false
+            button.wantsLayer = true
+            button.layer?.cornerRadius = button.frame.size.width / 2.0
+            button.target = self
+            button.action = #selector(buttonAction(_:))
+            self.addSubview(button)
+
+            if i == 0 {
+                self.firstButton = button
+            }
+
+            let menu = NSMenu(title: "")
+            var item: NSMenuItem?
+
+            if i == 0 && (self.annotationType == .lineColors || self.annotationType == .lineFillColors || self.annotationType == .inkFillColors || self.annotationType == .freeTextFillColors || self.annotationType == .fromFillColors) {
+                // Do nothing for this case
+            } else {
+                item = menu.addItem(withTitle: NSLocalizedString("Change Color...", comment: ""), action: #selector(menuItemChangeColorAction(_:)), keyEquivalent: "")
+                item?.representedObject = i as NSNumber
+            }
+
+            item = menu.addItem(withTitle: NSLocalizedString("Restore Default Colors", comment: ""), action: #selector(menuItemRestoreColorAction(_:)), keyEquivalent: "")
+            item?.representedObject = i as NSNumber
+            button.menu = menu
+            buttons.append(button)
+            posX += width + space
+
+            let layer = CAShapeLayer()
+            layer.frame = NSMakeRect(3, 3, width - 6, width - 6)
+            layer.cornerRadius = layer.frame.size.width / 2.0
+            layer.backgroundColor = color.cgColor
+            layer.borderWidth = 1.0
+            layer.borderColor = KMAppearance.Interactive.s0Color().cgColor
+
+            var red: CGFloat = 0, green: CGFloat = 0, blue: CGFloat = 0, alpha: CGFloat = 0
+            color.usingColorSpace(NSColorSpace.deviceRGB)?.getRed(&red, green: &green, blue: &blue, alpha: &alpha)
+
+            if alpha < 0.000000001 {
+                let x = (layer.frame.size.width - sqrt(pow(layer.frame.size.width, 2) / 2)) / 2
+                let path = CGMutablePath()
+                path.move(to: CGPoint(x: x, y: layer.frame.size.height - x))
+                path.addLine(to: CGPoint(x: layer.frame.size.width - x, y: x))
+                layer.path = path
+                layer.strokeColor = NSColor.red.cgColor
+                layer.lineWidth = 2.0
+
+                if #available(macOS 10.14, *) {
+                    if let appearanceName = NSApp.effectiveAppearance.bestMatch(from: [.aqua, .darkAqua]), appearanceName == .darkAqua {
+                        layer.backgroundColor = NSColor(red: 255.0/255.0, green: 255.0/255.0, blue: 255.0/255.0, alpha: 1).cgColor
+                    }
+                }
+                path.closeSubpath()
+            }
+            button.layer?.addSublayer(layer)
+        }
+
+        self.buttons = buttons
+
+        if self.noContentString {
+            self.titleLabel = NSTextField(frame: CGRect(x: 0, y: width + 9, width: self.frame.size.width, height: 18))
+            self.titleLabel.stringValue = self.annotationTypeString 
+            self.titleLabel.textColor = KMAppearance.Layout.h1Color()
+            self.titleLabel.isBezeled = false
+            self.titleLabel.drawsBackground = false
+            self.titleLabel.isEditable = false
+            self.titleLabel.isSelectable = false
+            self.titleLabel.font = NSFont.systemFont(ofSize: 13.0)
+            self.addSubview(self.titleLabel)
+        }
+
+        let customColorBox = NSBox(frame: CGRect(x: posX, y: 0, width: (width * 2 + space), height: width + 2))
+        if self.isVerticalMode {
+            customColorBox.frame = CGRect(x: 0, y: self.frame.height - posX - (width * 2 + space), width: width + 2, height: (width * 2 + space))
+        }
+
+        customColorBox.boxType = .custom
+        customColorBox.borderWidth = 1.0
+        customColorBox.borderColor = KMAppearance.Interactive.s0Color()
+        customColorBox.fillColor = KMAppearance.Layout.l1Color()
+        customColorBox.contentViewMargins = NSSize(width: 0, height: 0)
+        customColorBox.wantsLayer = true
+        customColorBox.cornerRadius = width / 2
+        self.addSubview(customColorBox)
+
+        self.customColorButton = NSButton()
+        if self.isVerticalMode {
+            self.customColorButton.frame = NSMakeRect(0, customColorBox.frame.height - width - 4, width, width)
+        } else {
+            self.customColorButton.frame = NSMakeRect(0, 0, width, width)
+        }
+        self.customColorButton.title = ""
+        self.customColorButton.isBordered = false
+        self.customColorButton.wantsLayer = true
+        self.customColorButton.layer?.cornerRadius = self.customColorButton.frame.size.width / 2.0
+        self.customColorButton.target = self
+        self.customColorButton.action = #selector(customColorButtonAction(_:))
+        customColorBox.addSubview(self.customColorButton)
+
+        self.customColorLayer = CALayer()
+        self.customColorLayer.frame = NSMakeRect(3, 3, width - 6, width - 6)
+        self.customColorLayer.cornerRadius = self.customColorLayer.frame.size.width / 2.0
+        self.customColorLayer.borderWidth = 1.0
+        self.customColorLayer.borderColor = KMAppearance.Interactive.s0Color().cgColor
+        self.customColorButton.layer?.addSublayer(self.customColorLayer)
+
+        let colorbutton = NSButton()
+        if self.isVerticalMode {
+            colorbutton.frame = NSMakeRect(2, 4, width - 4, width - 4)
+        } else {
+            colorbutton.frame = NSMakeRect(width + space, 2, width - 4, width - 4)
+        }
+        colorbutton.title = ""
+        colorbutton.isBordered = false
+        colorbutton.wantsLayer = true
+        colorbutton.layer?.cornerRadius = colorbutton.frame.size.width / 2.0
+        colorbutton.image = NSImage(named: "view_color")
+        colorbutton.imageScaling = .scaleProportionallyDown
+        colorbutton.target = self
+        colorbutton.action = #selector(colorButtonAction(_:))
+        customColorBox.addSubview(colorbutton)
+
+        self.setColor(color!)
+    }
+    
+    // MARK: Public Method
+    
+    func isChangeColor(_ color: NSColor?) -> Bool {
+        var hue: CGFloat = 0.0
+        var sa: CGFloat = 0.0
+        var bri: CGFloat = 0.0
+        var alpha: CGFloat = 0.0
+
+        if let color = color {
+            color.usingColorSpaceName(NSColorSpaceName.calibratedRGB)?.getHue(&hue, saturation: &sa, brightness: &bri, alpha: &alpha)
+        }
+
+        if (sa < 0.06 && bri > 0.25) || alpha < 0.15 {
+            return true
+        } else {
+            return false
+        }
+    }
+    
+    func isTheSameColor(_ color1: NSColor, anotherColor color2: NSColor) -> Bool {
+        let component = color1.cgColor.components
+        let component1 = color2.cgColor.components
+        
+        guard let comp = component, let comp1 = component1 else {
+            // Handle the case where one or both colors don't have components
+            return false
+        }
+        
+        if !compareSize(comp[0], comp1[0]) {
+            return false
+        }
+        
+        if !compareSize(comp[1], comp1[1]) {
+            return false
+        }
+        
+        if !compareSize(comp[2], comp1[2]) {
+            return false
+        }
+        
+        if !compareSize(comp[3], comp1[3]) {
+            return false
+        }
+        
+        return true
+    }
+    
+    func compareSize(_ floa1: CGFloat, _ floa2: CGFloat) -> Bool {
+        let t1 = String(format: "%.3f", floa1).stringToCGFloat()
+        let t2 = String(format: "%.3f", floa2).stringToCGFloat()
+        
+        if Int32(fabs(t1 - t2)) > Int32(1e-6) {
+            return false
+        }
+        
+        return true
+    }
+    
+    // MARK: Button Action
+    
+    @objc func buttonAction(_ button: NSButton) {
+        NSColorPanel.shared.setTarget(nil)
+        updatingColor = true
+        let color = colors[button.tag]
+        self.color = color
+        target?.perform(self.action, with: self)
+        updatingColor = false
+    }
+
+    @objc func customColorButtonAction(_ sender: Any) {
+        self.color = customColor!
+        target?.perform(self.action, with: self)
+    }
+    
+    @objc func colorButtonAction(_ sender: Any) {
+        if isCallColorPanelAction {
+            NSColorPanel.shared.setTarget(self)
+            NSColorPanel.shared.setAction(#selector(colorPanelAction(_:)))
+        }
+        
+        if hideColorPanelAlpha {
+            NSColorPanel.shared.showsAlpha = false
+        } else {
+            NSColorPanel.shared.showsAlpha = true
+        }
+        
+        if let accessoryView = NSColorPanel.shared.accessoryView as? NSButton {
+            if isFreeText {
+                accessoryView.state = isFillColor ? .off : .on
+            } else {
+                accessoryView.state = isFillColor ? .on : .off
+            }
+        }
+        
+        if isFillColor {
+            NSColorPanel.shared.orderFront(nil)
+        } else {
+            if isFreeText {
+                // NSFontPanel.shared.orderFront(nil)
+                NSColorPanel.shared.orderFront(nil)
+            } else {
+                NSColorPanel.shared.orderFront(nil)
+            }
+        }
+    }
+    
+    @objc func colorPanelAction(_ sender: Any) {
+        self.color = NSColorPanel.shared.color
+        self.target?.perform(self.action, with: self)
+    }
+
+    @objc func menuItemChangeColorAction(_ sender: NSMenuItem) {
+        if let indexNumber = sender.representedObject as? NSNumber {
+            self.secterindex = indexNumber.intValue
+            NSColorPanel.shared.setTarget(self)
+            NSColorPanel.shared.setAction(#selector(menuItemPanelAction(_:)))
+            if let accessoryView = NSColorPanel.shared.accessoryView as? NSButton {
+                if self.isFreeText {
+                    accessoryView.state = self.isFillColor ? .off : .on
+                } else {
+                    accessoryView.state = self.isFillColor ? .on : .off
+                }
+            }
+            NSColorPanel.shared.orderFront(nil)
+        }
+    }
+    
+    @objc func menuItemPanelAction(_ sender: Any) {
+        self.color = NSColorPanel.shared.color
+        self.target?.perform(self.action, with: self)
+        
+        var tColors = self.colors
+        tColors[self.secterindex] = self.color!
+        self.colors = tColors
+        
+        self.saveColors()
+    }
+    
+    @objc func menuItemRestoreColorAction(_ sender: NSMenuItem) {
+        switch annotationType {
+        case .markupHighlightColors:
+            colors = KMAnnotationPropertiesColorManager.manager.markHighlightColors
+        case .markupOtherColors:
+            colors = KMAnnotationPropertiesColorManager.manager.markOtherColors
+        case .lineColors:
+            colors = KMAnnotationPropertiesColorManager.manager.lineColors
+        case .lineFillColors:
+            colors = KMAnnotationPropertiesColorManager.manager.fillLineColors
+        case .inkColors:
+            colors = KMAnnotationPropertiesColorManager.manager.inkColors
+        case .inkFillColors:
+            colors = KMAnnotationPropertiesColorManager.manager.inkFillColors
+        case .freeTextColors:
+            colors = KMAnnotationPropertiesColorManager.manager.freeTextColors
+        case .freeTextFillColors:
+            colors = KMAnnotationPropertiesColorManager.manager.freeFillTextColors
+        case .anchoredNoteColors:
+            colors = KMAnnotationPropertiesColorManager.manager.anchoredNoteColors
+        case .fromColors:
+            colors = KMAnnotationPropertiesColorManager.manager.fromColors
+        case .fromFillColors:
+            colors = KMAnnotationPropertiesColorManager.manager.fromFillColors
+        case .selfSignColors, .editText:
+            colors = KMAnnotationPropertiesColorManager.manager.selfSignColors
+        case .otherColors:
+            colors = KMAnnotationPropertiesColorManager.manager.otherColors
+        default:
+            break
+        }
+        saveColors()
+    }
+    
+    func saveColors() {
+        switch annotationType {
+        case .markupHighlightColors:
+            KMAnnotationPropertiesColorManager.manager.markHighlightColors = colors
+        case .markupOtherColors:
+            KMAnnotationPropertiesColorManager.manager.markOtherColors = colors
+        case .lineColors:
+            KMAnnotationPropertiesColorManager.manager.lineColors = colors
+        case .lineFillColors:
+            KMAnnotationPropertiesColorManager.manager.fillLineColors = colors
+        case .inkColors:
+            KMAnnotationPropertiesColorManager.manager.inkColors = colors
+        case .inkFillColors:
+            KMAnnotationPropertiesColorManager.manager.inkFillColors = colors
+        case .freeTextColors:
+            KMAnnotationPropertiesColorManager.manager.freeTextColors = colors
+        case .freeTextFillColors:
+            KMAnnotationPropertiesColorManager.manager.freeFillTextColors = colors
+        case .anchoredNoteColors:
+            KMAnnotationPropertiesColorManager.manager.anchoredNoteColors = colors
+        case .fromColors:
+            KMAnnotationPropertiesColorManager.manager.fromColors = colors
+        case .fromFillColors:
+            KMAnnotationPropertiesColorManager.manager.fromFillColors = colors
+        case .selfSignColors, .editText: // Handling both cases for .selfSignColors and .editText
+            KMAnnotationPropertiesColorManager.manager.selfSignColors = colors
+        case .otherColors:
+            KMAnnotationPropertiesColorManager.manager.otherColors = colors
+        }
+    }
+}

+ 1 - 1
PDF Office/PDF Master/Class/PDFWindowController/Side/RightSide/AnnotationProperty/KMColorPickerViewController.m

@@ -483,7 +483,7 @@
 
 -(void)menuItemRestoreColorAction:(NSMenuItem *)sender
 {
-    self.colors = [[KMAnnotationPropertiesColorManager manager] defaultColorsWithType:_annotationType];
+//    self.colors = [[KMAnnotationPropertiesColorManager manager] defaultColorsWithType:_annotationType];
     [self saveColors];
 }
 

+ 10 - 10
PDF Office/PDF Master/Class/PDFWindowController/Side/RightSide/AnnotationProperty/KMColorPickerViewController.xib

@@ -1,8 +1,8 @@
 <?xml version="1.0" encoding="UTF-8"?>
-<document type="com.apple.InterfaceBuilder3.Cocoa.XIB" version="3.0" toolsVersion="21507" targetRuntime="MacOSX.Cocoa" propertyAccessControl="none" useAutolayout="YES" customObjectInstantitationMethod="direct">
+<document type="com.apple.InterfaceBuilder3.Cocoa.XIB" version="3.0" toolsVersion="22154" targetRuntime="MacOSX.Cocoa" propertyAccessControl="none" useAutolayout="YES" customObjectInstantitationMethod="direct">
     <dependencies>
         <deployment identifier="macosx"/>
-        <plugIn identifier="com.apple.InterfaceBuilder.CocoaPlugin" version="21507"/>
+        <plugIn identifier="com.apple.InterfaceBuilder.CocoaPlugin" version="22154"/>
         <capability name="documents saved in the Xcode 8 format" minToolsVersion="8.0"/>
     </dependencies>
     <objects>
@@ -41,25 +41,25 @@
                         <subviews>
                             <button verticalHuggingPriority="750" translatesAutoresizingMaskIntoConstraints="NO" id="wuk-T5-Ulr">
                                 <rect key="frame" x="2" y="3" width="24" height="24"/>
-                                <constraints>
-                                    <constraint firstAttribute="height" constant="24" id="3h0-pX-ir5"/>
-                                    <constraint firstAttribute="width" constant="24" id="Xw7-N5-QS3"/>
-                                </constraints>
                                 <buttonCell key="cell" type="bevel" bezelStyle="rounded" alignment="center" imageScaling="proportionallyDown" inset="2" id="xvB-xo-9Gw">
                                     <behavior key="behavior" pushIn="YES" lightByBackground="YES" lightByGray="YES"/>
                                     <font key="font" metaFont="system"/>
                                 </buttonCell>
+                                <constraints>
+                                    <constraint firstAttribute="height" constant="24" id="3h0-pX-ir5"/>
+                                    <constraint firstAttribute="width" constant="24" id="Xw7-N5-QS3"/>
+                                </constraints>
                             </button>
                             <button verticalHuggingPriority="750" translatesAutoresizingMaskIntoConstraints="NO" id="Zp8-gJ-tf6">
                                 <rect key="frame" x="35" y="3" width="24" height="24"/>
-                                <constraints>
-                                    <constraint firstAttribute="height" constant="24" id="U2X-hN-GPj"/>
-                                    <constraint firstAttribute="width" constant="24" id="WkX-ql-XEO"/>
-                                </constraints>
                                 <buttonCell key="cell" type="bevel" bezelStyle="rounded" image="NSColorPanel" imagePosition="only" alignment="center" imageScaling="proportionallyDown" inset="2" id="Y5e-Wx-idd">
                                     <behavior key="behavior" pushIn="YES" lightByBackground="YES" lightByGray="YES"/>
                                     <font key="font" metaFont="system"/>
                                 </buttonCell>
+                                <constraints>
+                                    <constraint firstAttribute="height" constant="24" id="U2X-hN-GPj"/>
+                                    <constraint firstAttribute="width" constant="24" id="WkX-ql-XEO"/>
+                                </constraints>
                             </button>
                         </subviews>
                         <constraints>

+ 1 - 1
PDF Office/PDF Master/Class/PDFWindowController/Side/RightSide/AnnotationProperty/KMGeneralAnnotationViewController.xib

@@ -2940,7 +2940,7 @@ AAAAAAABd9w
 </mutableData>
         </image>
         <namedColor name="KMControlBackgroundColor">
-            <color red="0.32899999618530273" green="0.32400000095367432" blue="0.4779999852180481" alpha="0.33000001311302185" colorSpace="custom" customColorSpace="sRGB"/>
+            <color red="0.96470588235294119" green="0.96470588235294119" blue="0.96470588235294119" alpha="1" colorSpace="custom" customColorSpace="sRGB"/>
         </namedColor>
         <namedColor name="KMGrayFColor">
             <color red="0.32899999618530273" green="0.32400000095367432" blue="0.4779999852180481" alpha="0.33000001311302185" colorSpace="custom" customColorSpace="sRGB"/>