// // KMToolbarRightView.swift // PDF Master // // 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 KMLightMemberManager.manager.canShowAdvancedView && !KMLightMemberManager.manager.isLogin() { if self.advancedLabel != nil { self.advancedContentView.isHidden = false self.advancedViewRightConstraint.constant = 4.0 self.advancedLabel.font = NSFont.SFProTextRegular(12.0) self.advancedLabel.textColor = NSColor(hex: "#FFFFFF") self.advancedLabel.stringValue = NSLocalizedString("Enjoy Advanced Features", comment: "") } if self.rightSegmentControlConstraint != nil { let size = self.fetchAdvancedViewSize() self.rightSegmentControlConstraint.constant = size.width + 20 } } else { if self.advancedContentView != nil { self.advancedContentView.isHidden = true self.advancedViewRightConstraint.constant = -163.0 } } if self.userInfoButton != nil { if KMLightMemberManager.manager.info.email.count != 0 { self.userInfoButton.backgroundColor(NSColor(hex: "#1770F4")) self.userInfoButton.font = NSFont.SFProTextSemibold(14.0) self.userInfoButton.contentTintColor = NSColor(hex: "#FFFFFF") self.userInfoButton.border(NSColor(hex: "#1770F4"), 1, 12) self.userInfoButton.title = KMLightMemberManager.manager.info.email.substring(to: 1) self.userInfoButton.image = nil } else { self.userInfoButton.image = NSImage(named: "Icon_other_avatar_false") self.userInfoButton.title = "" self.userInfoButton.border(NSColor(hex: "#1770F4"), 0, 12) self.userInfoButton.backgroundColor(NSColor.clear) } } } func fetchAdvancedViewSize() -> CGSize { let paragraphStyle = NSMutableParagraphStyle() paragraphStyle.lineHeightMultiple = 1.32 paragraphStyle.alignment = .right let attributes = [NSAttributedString.Key.paragraphStyle: paragraphStyle, NSAttributedString.Key.font : NSFont.SFProTextRegular(12.0)] let title: NSString = NSLocalizedString("Enjoy Advanced Features", comment: "") as NSString let size = title.boundingRect(with: CGSize(width: 300, height: 24) , attributes: attributes).size return size } func addNotification() { self.removeNotification() NotificationCenter.default.addObserver(self, selector: #selector(updateAdvancedContentView), name: NSNotification.Name(rawValue: ADVANCED_NOTIFICATION), object: nil) NotificationCenter.default.addObserver(self, selector: #selector(updateAdvancedContentView), name: NSNotification.Name(rawValue: USER_INFO_CHANGE_NOTIFICATION), object: nil) NotificationCenter.default.addObserver(self, selector: #selector(updateAdvancedContentView), name: NSNotification.Name(rawValue: USER_LOGINSTATE_NOTIFICATION), object: nil) } 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) } }