123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416 |
- //
- // 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 prioritizeOutlineCheckbox: ComponentCheckBox!
- @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 weak var panelInteractionLabel: NSTextField!
- @IBOutlet weak var panelInteractionSelect: ComponentSelect!
- @IBOutlet weak var showQuickCheckbox: ComponentCheckBox!
- @IBOutlet weak var showQuickCheckboxWidthConst: 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!
-
-
- 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()
-
- 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 () {
-
- //获取颜色
- var titleLabelColor: NSColor = ComponentLibrary.shared.getComponentColorFromKey("colorText/2")
-
- var subtitleLabelColor: NSColor = ComponentLibrary.shared.getComponentColorFromKey("comp-field/colorText-filled-nor")
-
- //获取字体
- var titleLabelFont: NSFont = ComponentLibrary.shared.getFontFromKey("mac/body-s-medium")
-
- var 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:", comment: "")
- layoutLabel.textColor = subtitleLabelColor
- layoutLabel.font = subtitleLabelFont
-
- zoomLabel.stringValue = KMLocalizedString("Zoom:", comment: "")
- zoomLabel.textColor = subtitleLabelColor
- zoomLabel.font = subtitleLabelFont
-
- leftSideLabel.stringValue = KMLocalizedString("Left Side Panel", comment: "")
- leftSideLabel.textColor = titleLabelColor
- leftSideLabel.font = titleLabelFont
-
- propertyPanelLabel.stringValue = KMLocalizedString("Property Panel", comment: "")
- propertyPanelLabel.textColor = titleLabelColor
- propertyPanelLabel.font = titleLabelFont
-
- panelInteractionLabel.stringValue = KMLocalizedString("Panel Open Interaction:", comment: "")
- panelInteractionLabel.textColor = subtitleLabelColor
- panelInteractionLabel.font = subtitleLabelFont
-
- highlightLabel.stringValue = KMLocalizedString("Highlight", comment: "")
- highlightLabel.textColor = titleLabelColor
- highlightLabel.font = titleLabelFont
-
- }
-
- func setUpLayoutAndZoom() {
-
- layoutSelectView.properties = ComponentSelectProperties(size: .s,
- state: .normal,
- isDisabled: false,
- isError: false,
- leftIcon: false,
- placeholder: nil,
- errorText: nil,
- creatable: false,
- text: KMLocalizedString("Single Page Continuous", comment: ""))
- 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, comment: ""))
- if string == " " {
- itemProperty = ComponentMenuitemProperty.divider()
- }
- menuItemArr.append(itemProperty)
- }
- layoutSelectView.updateMenuItemsArr(menuItemArr)
- layoutSelectView.delegate = self
- }
-
- zoomSelectView.properties = ComponentSelectProperties(size: .s,
- state: .normal,
- isDisabled: false,
- isError: false,
- leftIcon: false,
- placeholder: nil,
- errorText: nil,
- creatable: false,
- text: KMLocalizedString("Adaptation Width", comment: ""))
- 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: "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: "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: "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: "Hide left side panel",
- checkboxType: .normal)
- hideLeftSideRadioWidthConst.constant = hideLeftSideRadio.properties.propertyInfo.viewWidth
-
- prioritizeOutlineCheckbox.properties = ComponentCheckBoxProperty(size: .s,
- state: .normal,
- isDisabled: false,
- showhelp: false,
- text: "Prioritize open the outline list when outlines are available",
- checkboxType: .normal)
- prioritizeOutlineCheckboxWidthConst.constant = prioritizeOutlineCheckbox.properties.propertyInfo.viewWidth
-
- defaultOpenRadio.setTarget(self, action: #selector(leftSidePanelAction(_:)))
- remeberLastRadio.setTarget(self, action: #selector(leftSidePanelAction(_:)))
- hideLeftSideRadio.setTarget(self, action: #selector(leftSidePanelAction(_:)))
- prioritizeOutlineCheckbox.setTarget(self, action: #selector(leftSidePanelAction(_:)))
-
- }
-
- func setUpPropertyPanel() {
- //Property Panel
-
- panelInteractionSelect.properties = ComponentSelectProperties(size: .s,
- state: .normal,
- isDisabled: false,
- isError: false,
- leftIcon: false,
- placeholder: nil,
- errorText: nil,
- creatable: false,
- text: "Automatic")
- if true {
- var menuItemArr: [ComponentMenuitemProperty] = []
- let AutomaticProperty: ComponentMenuitemProperty = ComponentMenuitemProperty(multipleSelect: false, itemSelected: false, isDisabled: false, keyEquivalent: nil, text: "Automatic")
- menuItemArr.append(AutomaticProperty)
-
- let hideProperty: ComponentMenuitemProperty = ComponentMenuitemProperty(multipleSelect: false, itemSelected: false, isDisabled: false, keyEquivalent: nil, text: "Hide Property Panel")
- menuItemArr.append(hideProperty)
-
- panelInteractionSelect.updateMenuItemsArr(menuItemArr)
- panelInteractionSelect.delegate = self
- }
-
- showQuickCheckbox.properties = ComponentCheckBoxProperty(size: .s,
- state: .normal,
- isDisabled: false,
- showhelp: false,
- text: "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: "Highlight Link",
- checkboxType: SettingsManager.sharedInstance.highlightLink ? .selected : .normal)
- highlightLinkBoxWidthConst.constant = highlightLinkCheckbox.properties.propertyInfo.viewWidth
-
- highlightFormCheckbox.properties = ComponentCheckBoxProperty(size: .s,
- state: .normal,
- isDisabled: false,
- showhelp: false,
- text: "Highlight Form Field",
- checkboxType: SettingsManager.sharedInstance.highlightFormField ? .selected : .normal)
- highglightFormboxWidthConst.constant = highlightFormCheckbox.properties.propertyInfo.viewWidth
-
- highlightLinkCheckbox.setTarget(self, action: #selector(highlightAction(_:)))
- highlightFormCheckbox.setTarget(self, action: #selector(highlightAction(_:)))
-
- }
-
- 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
- prioritizeOutlineCheckbox.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 {
- prioritizeOutlineCheckbox.properties.checkboxType = .selected
-
- }
-
- defaultOpenRadio.reloadData()
- remeberLastRadio.reloadData()
- hideLeftSideRadio.reloadData()
- prioritizeOutlineCheckbox.reloadData()
-
- defaultOpenSelectView.selectItemAtIndex(SettingsManager.sharedInstance.defaultOpen.rawValue)
- defaultOpenSelectView.reloadData()
-
- //Property Panel
- panelInteractionSelect.selectItemAtIndex(SettingsManager.sharedInstance.panelOpenType.rawValue)
- panelInteractionSelect.reloadData()
-
- showQuickCheckbox.properties.checkboxType = SettingsManager.sharedInstance.showQuickActionBar ? .selected : .normal
- showQuickCheckbox.reloadData()
- //Highlight
- highlightLinkCheckbox.properties.checkboxType = SettingsManager.sharedInstance.highlightLink ? .selected : .normal
- highlightLinkCheckbox.reloadData()
-
- highlightFormCheckbox.properties.checkboxType = SettingsManager.sharedInstance.highlightFormField ? .selected : .normal
- highlightFormCheckbox.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 == prioritizeOutlineCheckbox {
- SettingsManager.sharedInstance.leftPanelType = .prioritizeOutline
- }
- self.reloadData()
-
- }
-
- @objc func propertyPanelAction(_ sender: NSView) {
- if sender == showQuickCheckbox {
- SettingsManager.sharedInstance.showQuickActionBar = showQuickCheckbox.properties.checkboxType == .selected ? true : false
- }
- self.reloadData()
-
- }
-
- @objc func highlightAction(_ sender: NSView) {
- if sender == highlightLinkCheckbox {
- SettingsManager.sharedInstance.highlightLink = highlightLinkCheckbox.properties.checkboxType == .selected ? true : false
- } else if sender == highlightFormCheckbox {
- SettingsManager.sharedInstance.highlightFormField = highlightFormCheckbox.properties.checkboxType == .selected ? true : false
- }
- self.reloadData()
-
- }
-
-
- }
- 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())!
- }
- } else if view == panelInteractionSelect {
- if panelInteractionSelect.indexOfSelect() >= 0 {
- SettingsManager.sharedInstance.panelOpenType = panelOpenInteractionType(rawValue: panelInteractionSelect.indexOfSelect())!
- }
- }
- SettingsManager.sharedInstance.saveData()
-
- self.reloadData()
- }
-
- }
-
|