// // KMToolbarRightView.swift // PDF Reader Pro // // Created by wanjun on 2022/12/9. // import Cocoa @objc protocol KMToolbarRightViewDelegate { @objc func pdfRightSegmentedControlAction(_ sender: KMSegmentedBox?) @objc func userInfoButtonAction(_ sender: NSButton) @objc func homeRefreshButtonAction(_ sender: NSButton?) @objc func homeUploadButtonAction(_ sender: NSButton) @objc func homeMenuSortAction(_ sender: NSPopUpButton) @objc func homeMenuFilterAction(_ sender: NSPopUpButton) } @objcMembers class KMToolbarRightView: NSView { open var delete: KMToolbarRightViewDelegate? @IBOutlet weak var homeRefreshButton: NSButton! @IBOutlet weak var homeUploadButton: NSButton! @IBOutlet weak var userInfoButton: NSButton! @IBOutlet weak var sortPopUpButton: NSPopUpButton! @IBOutlet weak var filterPopUpButton: NSPopUpButton! @IBOutlet weak var homeRightSearchField: NSSearchField! @IBOutlet weak var pdfRightSegmentedBox: KMSegmentedBox! @IBOutlet weak var rightSegmentControlConstraint: NSLayoutConstraint! @IBOutlet weak var advancedContentView: NSView! @IBOutlet weak var advancedLabel: NSTextField! @IBOutlet weak var trailPositionView: NSView! @IBOutlet weak var trailPositionWidthConst: NSLayoutConstraint! @IBOutlet weak var filterPopUpButtonWidth: NSLayoutConstraint! @IBOutlet weak var filterPopUpButtonLeft: NSLayoutConstraint! @IBOutlet weak var advancedViewRightConstraint: NSLayoutConstraint! deinit { self.removeNotification() } override func draw(_ dirtyRect: NSRect) { super.draw(dirtyRect) // Drawing code here. } override func awakeFromNib() { super.awakeFromNib() self.updateView() self.addNotification() } @objc func updateView() -> Void { if canShowAdvanced() { if self.advancedLabel != nil { self.advancedContentView.isHidden = false self.advancedViewRightConstraint.constant = 8.0 self.advancedLabel.font = NSFont.SFProTextRegularFont(12.0) self.advancedLabel.textColor = NSColor.km_init(hex: "#FFFFFF") var advancedString = NSLocalizedString("Upgrade", comment: "") self.advancedLabel.stringValue = advancedString } } else { if self.advancedContentView != nil { self.advancedContentView.isHidden = true self.advancedViewRightConstraint.constant = -163.0 } } if self.userInfoButton != nil { } } func canShowAdvanced() -> Bool { return false } func fetchAdvancedViewSize() -> CGSize { var advancedString = NSLocalizedString("Upgrade", comment: "") let paragraphStyle = NSMutableParagraphStyle() paragraphStyle.lineHeightMultiple = 1.32 paragraphStyle.alignment = .right let attributes = [NSAttributedString.Key.paragraphStyle: paragraphStyle, NSAttributedString.Key.font : NSFont.SFProTextRegularFont(12.0)] let title: NSString = advancedString as NSString let size = title.boundingRect(with: CGSize(width: 300, height: 24) , attributes: attributes).size let resultSize = CGSize(width: size.width + 8 + 16 + 8 + 8, height: size.height) if self.rightSegmentControlConstraint != nil { self.rightSegmentControlConstraint.constant = resultSize.width } return resultSize } func fetchAdvancedViewSize_update_rightSegmentControlConstraint() { if self.rightSegmentControlConstraint != nil { self.rightSegmentControlConstraint.constant = 89.0 } } func addNotification() { self.removeNotification() } func updateAdvancedContentView() { self.updateView() self.delete?.homeRefreshButtonAction(nil) } func removeNotification() { NotificationCenter.default.removeObserver(self) } // MARK: Dark&Light // MARK: Action @IBAction func advancedButtonAction(_ sender: Any) { self.delete?.pdfRightSegmentedControlAction(nil) } @IBAction func homeRefreshButtonAction(_ sender: Any) { } @IBAction func homeUploadButtonAction(_ sender: Any) { } @IBAction func homeMenuSortAction(_ sender: Any) { } @IBAction func homeMenuFilterAction(_ sender: Any) { } @IBAction func userInfoButtonAction(_ sender: Any) { self.delete?.userInfoButtonAction(sender as! NSButton) } }