// // SettingsDisplayView.swift // PDF Reader Pro // // Created by Niehaoyu on 2024/9/26. // import Cocoa import KMComponentLibrary class SettingsDisplayView: BaseXibView { @IBOutlet weak var contendBox: NSBox! @IBOutlet weak var layoutZoomView: NSView! @IBOutlet weak var layoutZoomLabel: NSTextField! @IBOutlet weak var layoutLabel: NSTextField! @IBOutlet weak var layoutSelectView: ComponentSelect! @IBOutlet weak var zoomLabel: NSTextField! @IBOutlet weak var zoomSelectView: ComponentSelect! @IBOutlet weak var leftSideView: NSView! @IBOutlet weak var leftSideLabel: NSTextField! @IBOutlet weak var defaultOpenRadio: ComponentRadio! @IBOutlet weak var defaultOpenSelectView: ComponentSelect! @IBOutlet weak var remeberLastRadio: ComponentRadio! @IBOutlet weak var hideLeftSideRadio: ComponentRadio! @IBOutlet weak var prioritizeOutlineRadio: ComponentRadio! @IBOutlet weak var defaultOpenRadioWidthConst: NSLayoutConstraint! @IBOutlet weak var remeberLastRadioWidthConst: NSLayoutConstraint! @IBOutlet weak var hideLeftSideRadioWidthConst: NSLayoutConstraint! @IBOutlet weak var prioritizeOutlineCheckboxWidthConst: NSLayoutConstraint! @IBOutlet weak var propertyPanelView: NSView! @IBOutlet weak var propertyPanelLabel: NSTextField! @IBOutlet var autoExpandPropertyPanelCheckbox: ComponentCheckBox! @IBOutlet weak var showQuickCheckbox: ComponentCheckBox! @IBOutlet weak var showQuickCheckboxWidthConst: NSLayoutConstraint! @IBOutlet var propertyPanelWidthConst: NSLayoutConstraint! @IBOutlet weak var highlightView: NSView! @IBOutlet weak var highlightLabel: NSTextField! @IBOutlet weak var highlightLinkCheckbox: ComponentCheckBox! @IBOutlet weak var highlightFormCheckbox: ComponentCheckBox! @IBOutlet weak var highlightLinkBoxWidthConst: NSLayoutConstraint! @IBOutlet weak var highglightFormboxWidthConst: NSLayoutConstraint! @IBOutlet var autoScrollView: NSView! @IBOutlet var autoScrolllabel: NSTextField! @IBOutlet var timeLabel: NSTextField! @IBOutlet var autoTimeSlider: ComponentSlider! @IBOutlet var autoTimeSelect: ComponentSelect! @IBOutlet var timeValueLabel: NSTextField! @IBOutlet var jumpSpaceLabel: NSTextField! @IBOutlet var jumpSpaceSlider: ComponentSlider! @IBOutlet var jumpSpaceSelect: ComponentSelect! @IBOutlet var jumpSpaceValueLabel: NSTextField! deinit { NotificationCenter.default.removeObserver(self) } override func draw(_ dirtyRect: NSRect) { super.draw(dirtyRect) // Drawing code here. self.setTitleUI() self.setUpLayoutAndZoom() self.setUpLeftSidePanel() self.setUpPropertyPanel() self.setUpHighlight() setUpAutoScroll() self.reloadData() } public required init?(coder decoder: NSCoder) { super.init(coder: decoder) } override init(frame frameRect: NSRect) { super.init(frame: frameRect) } public override func awakeFromNib() { super.awakeFromNib() } func setTitleUI () { //获取颜色 let titleLabelColor: NSColor = ComponentLibrary.shared.getComponentColorFromKey("colorText/2") let subtitleLabelColor: NSColor = ComponentLibrary.shared.getComponentColorFromKey("comp-field/colorText-filled-nor") //获取字体 let titleLabelFont: NSFont = ComponentLibrary.shared.getFontFromKey("mac/body-s-medium") let subtitleLabelFont: NSFont = ComponentLibrary.shared.getFontFromKey("mac/body-s-regular") //Layout and Zoom layoutZoomLabel.stringValue = KMLocalizedString("Default Layout and Zoom") layoutZoomLabel.textColor = titleLabelColor layoutZoomLabel.font = titleLabelFont layoutLabel.stringValue = KMLocalizedString("Page Layout:") layoutLabel.textColor = subtitleLabelColor layoutLabel.font = subtitleLabelFont zoomLabel.stringValue = KMLocalizedString("Zoom:") zoomLabel.textColor = subtitleLabelColor zoomLabel.font = subtitleLabelFont leftSideLabel.stringValue = KMLocalizedString("Left Side Panel") leftSideLabel.textColor = titleLabelColor leftSideLabel.font = titleLabelFont propertyPanelLabel.stringValue = KMLocalizedString("Property Panel") propertyPanelLabel.textColor = titleLabelColor propertyPanelLabel.font = titleLabelFont highlightLabel.stringValue = KMLocalizedString("Highlight") highlightLabel.textColor = titleLabelColor highlightLabel.font = titleLabelFont autoScrolllabel.stringValue = KMLocalizedString("Auto Scroll Options") autoScrolllabel.textColor = titleLabelColor autoScrolllabel.font = titleLabelFont timeLabel.stringValue = KMLocalizedString("Time Interval:") timeLabel.textColor = subtitleLabelColor timeLabel.font = subtitleLabelFont timeValueLabel.stringValue = KMLocalizedString("sec (1~100)") timeValueLabel.textColor = subtitleLabelColor timeValueLabel.font = subtitleLabelFont jumpSpaceLabel.stringValue = KMLocalizedString("Jump Space:") jumpSpaceLabel.textColor = subtitleLabelColor jumpSpaceLabel.font = subtitleLabelFont jumpSpaceValueLabel.stringValue = KMLocalizedString("px (10~1000)") jumpSpaceValueLabel.textColor = subtitleLabelColor jumpSpaceValueLabel.font = subtitleLabelFont } func setUpLayoutAndZoom() { layoutSelectView.properties = ComponentSelectProperties(size: .s, state: .normal, text: KMLocalizedString("Single Page Continuous")) if true { var menuItemArr: [ComponentMenuitemProperty] = [] for string in ["Single Page", "Single Page Continuous", "Two Page", "Two Page Continuous", "Book Mode", "Book Mode Continuous"] { var itemProperty: ComponentMenuitemProperty = ComponentMenuitemProperty(multipleSelect: false, itemSelected: false, isDisabled: false, keyEquivalent: nil, text: KMLocalizedString(string)) if string == " " { itemProperty = ComponentMenuitemProperty.divider() } menuItemArr.append(itemProperty) } layoutSelectView.updateMenuItemsArr(menuItemArr) layoutSelectView.delegate = self } zoomSelectView.properties = ComponentSelectProperties(size: .s, state: .normal, text: KMLocalizedString("Adaptation Width")) if true { zoomSelectView.updateMenuItemsArr(KMPDFToolbarConfig.scaleZoomItems()) zoomSelectView.delegate = self } } func setUpLeftSidePanel() { //Left Side Panel defaultOpenRadio.properties = ComponentCheckBoxProperty(size: .s, state: .normal, isDisabled: false, showhelp: false, text: KMLocalizedString("Default Open"), checkboxType: .normal) defaultOpenRadioWidthConst.constant = defaultOpenRadio.properties.propertyInfo.viewWidth defaultOpenSelectView.properties = ComponentSelectProperties(size: .s, state: .normal, isDisabled: false, isError: false, leftIcon: false, placeholder: nil, errorText: nil, creatable: false, text: KMLocalizedString("Thumbnail")) if true { var menuItemArr: [ComponentMenuitemProperty] = [] let ThumbnailProperty: ComponentMenuitemProperty = ComponentMenuitemProperty(multipleSelect: false, itemSelected: false, isDisabled: false, keyEquivalent: nil, text: "Thumbnail") menuItemArr.append(ThumbnailProperty) let OutlineProperty: ComponentMenuitemProperty = ComponentMenuitemProperty(multipleSelect: false, itemSelected: false, isDisabled: false, keyEquivalent: nil, text: "Outline") menuItemArr.append(OutlineProperty) let BookmarkProperty: ComponentMenuitemProperty = ComponentMenuitemProperty(multipleSelect: false, itemSelected: false, isDisabled: false, keyEquivalent: nil, text: "Bookmark") menuItemArr.append(BookmarkProperty) let AnnotationProperty: ComponentMenuitemProperty = ComponentMenuitemProperty(multipleSelect: false, itemSelected: false, isDisabled: false, keyEquivalent: nil, text: "Annotation") menuItemArr.append(AnnotationProperty) defaultOpenSelectView.updateMenuItemsArr(menuItemArr) defaultOpenSelectView.delegate = self } remeberLastRadio.properties = ComponentCheckBoxProperty(size: .s, state: .normal, isDisabled: false, showhelp: false, text: KMLocalizedString("Same as the last open"), checkboxType: .normal) remeberLastRadioWidthConst.constant = remeberLastRadio.properties.propertyInfo.viewWidth hideLeftSideRadio.properties = ComponentCheckBoxProperty(size: .s, state: .normal, isDisabled: false, showhelp: false, text: KMLocalizedString("Hide left side panel"), checkboxType: .normal) hideLeftSideRadioWidthConst.constant = hideLeftSideRadio.properties.propertyInfo.viewWidth prioritizeOutlineRadio.properties = ComponentCheckBoxProperty(size: .s, state: .normal, isDisabled: false, showhelp: false, text: KMLocalizedString("Prioritize open the outline list when outlines are available"), checkboxType: .normal) prioritizeOutlineCheckboxWidthConst.constant = prioritizeOutlineRadio.properties.propertyInfo.viewWidth defaultOpenRadio.setTarget(self, action: #selector(leftSidePanelAction(_:))) remeberLastRadio.setTarget(self, action: #selector(leftSidePanelAction(_:))) hideLeftSideRadio.setTarget(self, action: #selector(leftSidePanelAction(_:))) prioritizeOutlineRadio.setTarget(self, action: #selector(leftSidePanelAction(_:))) } func setUpPropertyPanel() { //Property Panel autoExpandPropertyPanelCheckbox.properties = ComponentCheckBoxProperty(size: .s, state: .normal, isDisabled: false, showhelp: false, text: KMLocalizedString("Automatically expand the properties panel"), checkboxType: SettingsManager.sharedInstance.showQuickActionBar ? .selected : .normal) autoExpandPropertyPanelCheckbox.setTarget(self, action: #selector(propertyPanelAction(_:))) propertyPanelWidthConst.constant = autoExpandPropertyPanelCheckbox.properties.propertyInfo.viewWidth showQuickCheckbox.properties = ComponentCheckBoxProperty(size: .s, state: .normal, isDisabled: false, showhelp: false, text: KMLocalizedString("Always show quick action bar"), checkboxType: SettingsManager.sharedInstance.showQuickActionBar ? .selected : .normal) showQuickCheckbox.setTarget(self, action: #selector(propertyPanelAction(_:))) showQuickCheckboxWidthConst.constant = showQuickCheckbox.properties.propertyInfo.viewWidth } func setUpHighlight() { //Highlight highlightLinkCheckbox.properties = ComponentCheckBoxProperty(size: .s, state: .normal, isDisabled: false, showhelp: false, text: KMLocalizedString("Highlight Link"), checkboxType: .normal) highlightLinkBoxWidthConst.constant = highlightLinkCheckbox.properties.propertyInfo.viewWidth highlightFormCheckbox.properties = ComponentCheckBoxProperty(size: .s, state: .normal, isDisabled: false, showhelp: false, text: KMLocalizedString("Highlight Form Field"), checkboxType: .normal) highglightFormboxWidthConst.constant = highlightFormCheckbox.properties.propertyInfo.viewWidth highlightLinkCheckbox.setTarget(self, action: #selector(highlightAction(_:))) highlightFormCheckbox.setTarget(self, action: #selector(highlightAction(_:))) } func setUpAutoScroll() { autoTimeSlider.properties = ComponentSliderProperty(size: .m, percent: 1) autoTimeSlider.delegate = self autoTimeSelect.properties = ComponentSelectProperties(size: .s, state: .normal, text: KMLocalizedString("5")) if true { var menuItemArr: [ComponentMenuitemProperty] = [] for string in ["5", "10", "20", "40", "50", "100"] { var itemProperty: ComponentMenuitemProperty = ComponentMenuitemProperty(multipleSelect: false, itemSelected: false, isDisabled: false, keyEquivalent: nil, text: KMLocalizedString(string)) if string == " " { itemProperty = ComponentMenuitemProperty.divider() } menuItemArr.append(itemProperty) } autoTimeSelect.updateMenuItemsArr(menuItemArr) autoTimeSelect.delegate = self } jumpSpaceSlider.properties = ComponentSliderProperty(size: .m, percent: 1) jumpSpaceSlider.delegate = self jumpSpaceSelect.properties = ComponentSelectProperties(size: .s, state: .normal, text: KMLocalizedString("20")) if true { var menuItemArr: [ComponentMenuitemProperty] = [] for string in ["10", "50", "100", "200", "500", "1000"] { var itemProperty: ComponentMenuitemProperty = ComponentMenuitemProperty(multipleSelect: false, itemSelected: false, isDisabled: false, keyEquivalent: nil, text: KMLocalizedString(string)) if string == " " { itemProperty = ComponentMenuitemProperty.divider() } menuItemArr.append(itemProperty) } jumpSpaceSelect.updateMenuItemsArr(menuItemArr) jumpSpaceSelect.delegate = self } } func reloadData() { //Default Layout and Zoom layoutSelectView.selectItemAtIndex(SettingsManager.sharedInstance.layoutType.rawValue) zoomSelectView.selectItemAtIndex(SettingsManager.sharedInstance.zoomType.rawValue) //Left Side Panel defaultOpenRadio.properties.checkboxType = .normal remeberLastRadio.properties.checkboxType = .normal hideLeftSideRadio.properties.checkboxType = .normal prioritizeOutlineRadio.properties.checkboxType = .normal defaultOpenSelectView.properties.isDisabled = true if SettingsManager.sharedInstance.leftPanelType == .defaultOpen { defaultOpenSelectView.properties.isDisabled = false defaultOpenRadio.properties.checkboxType = .selected } else if SettingsManager.sharedInstance.leftPanelType == .sameAsLastOpen { remeberLastRadio.properties.checkboxType = .selected } else if SettingsManager.sharedInstance.leftPanelType == .hideLeftSide { hideLeftSideRadio.properties.checkboxType = .selected } else if SettingsManager.sharedInstance.leftPanelType == .prioritizeOutline { prioritizeOutlineRadio.properties.checkboxType = .selected } defaultOpenRadio.reloadData() remeberLastRadio.reloadData() hideLeftSideRadio.reloadData() prioritizeOutlineRadio.reloadData() defaultOpenSelectView.selectItemAtIndex(SettingsManager.sharedInstance.defaultOpen.rawValue) defaultOpenSelectView.reloadData() //Property Panel autoExpandPropertyPanelCheckbox.properties.checkboxType = SettingsManager.sharedInstance.autoExpandPropertyPanel ? .selected : .normal autoExpandPropertyPanelCheckbox.reloadData() showQuickCheckbox.properties.checkboxType = SettingsManager.sharedInstance.showQuickActionBar ? .selected : .normal showQuickCheckbox.reloadData() //Highlight highlightLinkCheckbox.properties.checkboxType = CPDFKitConfig.sharedInstance().enableLinkFieldHighlight() ? .selected : .normal highlightLinkCheckbox.reloadData() highlightFormCheckbox.properties.checkboxType = CPDFKitConfig.sharedInstance().enableFormFieldHighlight() ? .selected : .normal highlightFormCheckbox.reloadData() //Auto Scroll let autoScrollTime: CGFloat = SettingsManager.sharedInstance.autoScrollTimeInterval autoTimeSlider.properties.percent = (autoScrollTime - 1) / (100 - 1) autoTimeSlider.reloadData() autoTimeSelect.properties.text = String(format: "%.0f", autoScrollTime, "%") autoTimeSelect.reloadData() let autoScrollJump: CGFloat = SettingsManager.sharedInstance.autoScrollJumpSpace jumpSpaceSlider.properties.percent = (autoScrollJump - 10) / (1000 - 10) jumpSpaceSlider.reloadData() jumpSpaceSelect.properties.text = String(format: "%.0f", autoScrollJump, "%") jumpSpaceSelect.reloadData() } //MARK: - Action @objc func leftSidePanelAction(_ sender: NSView) { if sender == defaultOpenRadio { SettingsManager.sharedInstance.leftPanelType = .defaultOpen } else if sender == remeberLastRadio { SettingsManager.sharedInstance.leftPanelType = .sameAsLastOpen } else if sender == hideLeftSideRadio { SettingsManager.sharedInstance.leftPanelType = .hideLeftSide } else if sender == prioritizeOutlineRadio { SettingsManager.sharedInstance.leftPanelType = .prioritizeOutline } self.reloadData() } @objc func propertyPanelAction(_ sender: NSView) { if sender == showQuickCheckbox { SettingsManager.sharedInstance.showQuickActionBar = showQuickCheckbox.properties.checkboxType == .selected ? true : false } else if sender == autoExpandPropertyPanelCheckbox { SettingsManager.sharedInstance.autoExpandPropertyPanel = autoExpandPropertyPanelCheckbox.properties.checkboxType == .selected ? true : false } self.reloadData() } @objc func highlightAction(_ sender: NSView) { if sender == highlightLinkCheckbox { let value = highlightLinkCheckbox.properties.checkboxType == .selected ? true : false CPDFAnnotation.updateLinkFieldHighlight(nil, linkFieldHighlight: value) NotificationCenter.default.post(name: kPDFViewHighlightLinkUpdateNotiName, object: nil) } else if sender == highlightFormCheckbox { let value = highlightFormCheckbox.properties.checkboxType == .selected ? true : false CPDFAnnotation.updateHighlightFormFiled(nil, highlightFormFiled: value) NotificationCenter.default.post(name: kPDFViewHighlightFormFiledUpdateNotiName, object: nil) } self.reloadData() } } //MARK: - ComponentSelectDelegate extension SettingsDisplayView: ComponentSelectDelegate { func componentSelectDidSelect(view: ComponentSelect?, menuItemProperty: ComponentMenuitemProperty?) { if view == layoutSelectView { if layoutSelectView.indexOfSelect() >= 0 { SettingsManager.sharedInstance.layoutType = pageLayoutType(rawValue: layoutSelectView.indexOfSelect())! } } else if view == zoomSelectView { if zoomSelectView.indexOfSelect() >= 0 { SettingsManager.sharedInstance.zoomType = zoomInfoType(rawValue: zoomSelectView.indexOfSelect())! } } else if view == defaultOpenSelectView { if defaultOpenSelectView.indexOfSelect() >= 0 { SettingsManager.sharedInstance.defaultOpen = defaultOpenType(rawValue: defaultOpenSelectView.indexOfSelect())! } } SettingsManager.sharedInstance.saveData() self.reloadData() } } //MARK: - ComponentSliderDelegate extension SettingsDisplayView: ComponentSliderDelegate { func componentSliderDidUpdate(_ view: ComponentSlider) { let value = view.properties.percent if view == autoTimeSlider { SettingsManager.sharedInstance.autoScrollTimeInterval = 1 + (100 - 1)*value } else if view == jumpSpaceSlider { SettingsManager.sharedInstance.autoScrollJumpSpace = 10 + (1000 - 10)*value } reloadData() } }