123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184 |
- //
- // 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 {
- // KMLightMemberManager.manager.canShowAdvancedView &&
- 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: "")
- // if KMLightMemberManager.manager.purchaseState == .trial {
- // advancedString = NSLocalizedString("Trialling", comment: "")
- // }
- self.advancedLabel.stringValue = advancedString
- }
- } 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.km_init(hex: "#1770F4"))
- self.userInfoButton.font = NSFont.SFProTextSemiboldFont(14.0)
- self.userInfoButton.contentTintColor = NSColor.km_init(hex: "#FFFFFF")
- self.userInfoButton.border(NSColor.km_init(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.km_init(hex: "#1770F4"), 0, 12)
- self.userInfoButton.backgroundColor(NSColor.clear)
- }
- }
- }
-
- func canShowAdvanced() -> Bool {
- #if VERSION_FREE
- return (
- //KMLightMemberManager.manager.isLogin() &&
- (KMLightMemberManager.manager.purchaseState != .subscription &&
- KMLightMemberManager.manager.purchaseState != .trial))
- #else
- return (!KMLightMemberManager.manager.isLogin() ||
- (KMLightMemberManager.manager.purchaseState != .subscription &&
- KMLightMemberManager.manager.purchaseState != .trial))
- #endif
-
- }
-
- func fetchAdvancedViewSize() -> CGSize {
- var advancedString = NSLocalizedString("Upgrade", comment: "")
- // if KMLightMemberManager.manager.purchaseState == .trial {
- // advancedString = NSLocalizedString("Trialling", 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()
- 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)
- }
- }
|