// // KMFunctionGuideMultiController.swift // PDF Reader Pro Edition // // Created by Niehaoyu on 2023/12/6. // import Cocoa class KMFunctionGuideMultiController: NSViewController { @IBOutlet weak var contendView: NSView! @IBOutlet weak var titleInfoView: NSView! @IBOutlet weak var titleLabel: NSTextField! @IBOutlet weak var typeNameView: NSView! @IBOutlet weak var getStartBox: KMBox! @IBOutlet weak var getStartLabel: NSTextField! @IBOutlet weak var getStartButton: KMButton! @IBOutlet weak var learnButton: HyperLinkButton! @IBOutlet weak var nameHeightConst: NSLayoutConstraint! @IBOutlet weak var descriptionBGView: NSView! @IBOutlet weak var iconImage: NSImageView! @IBOutlet weak var previousButton: KMButton! @IBOutlet weak var nextButton: KMButton! @IBOutlet weak var desLabel: NSTextField! @IBOutlet weak var desSubLabel: NSTextField! let DigitalSignatureKey = "DigitalSignatureKey" let ComparePDFsKey = "ComparePDFsKey" var namesArr = Array() var currentNameKEY = String() var clickHandle: ((_ controller: KMFunctionGuideMultiController)->Void)? deinit { DistributedNotificationCenter.default.removeObserver(self) } override func viewDidLoad() { super.viewDidLoad() // Do view setup here. self.namesArr = [["name":"Digital Signature", "key":DigitalSignatureKey, "imageName":"whatNew_Digital", "description":"Digital signature verify the authenticity and integrity of documents, agreements, or contract, ensuring that the signature cannot be tampered with and provides a higher level of security."]] let dict = self.namesArr.first as! NSDictionary self.currentNameKEY = dict["key"] as! String self.loadTypeNameView() self.reloadNameViewInfo() self.reloadDescriptionInfo() self.descriptionBGView.wantsLayer = true self.titleInfoView.wantsLayer = true self.getStartBox.wantsLayer = true self.getStartBox.layer?.cornerRadius = 4 self.getStartBox.layer?.masksToBounds = true self.titleLabel.stringValue = NSLocalizedString("What‘s New", comment: "") self.getStartLabel.stringValue = NSLocalizedString("Got it", comment: "") self.learnButton.title = NSLocalizedString("Learn More", comment: "") self.learnButton.toolTip = NSLocalizedString("Learn More", comment: "") self.titleLabel.font = NSFont.SFProTextHeavyFont(20) self.getStartLabel.font = NSFont.SFProTextSemiboldFont(14) self.learnButton.font = NSFont.SFProTextSemiboldFont(14) self.desLabel.font = NSFont.SFProTextSemiboldFont(14) self.desSubLabel.font = NSFont.SFProTextRegularFont(14) self.getStartButton.mouseMoveCallback = { [weak self] mouseEntered in if KMAppearance.isDarkMode() { if mouseEntered { self?.getStartBox.fillColor = NSColor(red: 23/255, green: 85/255, blue: 178/255, alpha: 1) } else { self?.getStartBox.fillColor = KMAppearance.KMColor_Interactive_A0() } } else { if mouseEntered { self?.getStartBox.fillColor = NSColor(red: 56/255, green: 100/255, blue: 176/255, alpha: 1) } else { self?.getStartBox.fillColor = NSColor(red: 73/255, green: 130/255, blue: 230/255, alpha: 1) } } } self.learnButton.mouseMoveCallback = { [weak self] mouseEntered in if mouseEntered { self?.learnButton.setTitleColor(KMAppearance.KMColor_Interactive_M1()) } else { self?.learnButton.setTitleColor(KMAppearance.KMColor_Interactive_M0()) } } DistributedNotificationCenter.default().addObserver(self, selector: #selector(themeChange), name: NSNotification.Name(rawValue: "AppleInterfaceThemeChangedNotification"), object: nil) self.updateViewColor() } func loadTypeNameView() { // self.typeNameView.wantsLayer = true // self.typeNameView.layer?.backgroundColor = NSColor.red.cgColor var offsetY: CGFloat = 0 let itemHeight: CGFloat = 32 let viewHeight: CGFloat = itemHeight * CGFloat(self.namesArr.count) self.nameHeightConst.constant = viewHeight for i in 0...self.namesArr.count - 1 { let dict = self.namesArr[i] let nameItem: KMFunctionGuideNameItemView = KMFunctionGuideNameItemView.createFromNib()! nameItem.frame = CGRectMake(0, viewHeight - offsetY - itemHeight, CGRectGetWidth(self.typeNameView.frame), itemHeight) nameItem.infoDict = dict as! NSDictionary nameItem.clickHandle = { view in self.currentNameKEY = view.infoDict["key"] as! String self.reloadNameViewInfo() self.reloadDescriptionInfo() } nameItem.autoresizingMask = [.width, .maxYMargin] self.typeNameView.addSubview(nameItem) offsetY += itemHeight } if self.namesArr.count > 1 { self.previousButton.isHidden = false self.nextButton.isHidden = false } else { self.previousButton.isHidden = true self.nextButton.isHidden = true } } func reloadNameViewInfo() { for view in self.typeNameView.subviews { if view is KMFunctionGuideNameItemView { let itemView = view as! KMFunctionGuideNameItemView if itemView.infoDict["key"] as! String == self.currentNameKEY { itemView.isSelected = true } else { itemView.isSelected = false } } } } func reloadDescriptionInfo() { self.previousButton.isEnabled = true self.nextButton.isEnabled = true for i in 0...self.namesArr.count - 1 { let dict = self.namesArr[i] as! NSDictionary if dict["key"] as! String == self.currentNameKEY { self.desLabel.stringValue = NSLocalizedString(dict["name"] as! String, comment: "") self.desSubLabel.stringValue = NSLocalizedString(dict["description"] as! String, comment: "") self.iconImage.image = NSImage(named: dict["imageName"] as! String) } let keyValue = dict["key"] as! String if i == 0 && keyValue == self.currentNameKEY { self.previousButton.isEnabled = false } else if i == self.namesArr.count - 1 && keyValue == self.currentNameKEY { self.nextButton.isEnabled = false } } } func updateViewColor() { self.getStartBox.fillColor = KMAppearance.KMColor_Interactive_A0() self.getStartLabel.textColor = KMAppearance.KMColor_Layout_W0() self.learnButton.setTitleColor(KMAppearance.KMColor_Interactive_M0()) if KMAppearance.isDarkMode() { self.titleInfoView.layer?.backgroundColor = NSColor(red: 40/255.0, green: 40/255, blue: 40/255, alpha: 1).cgColor self.descriptionBGView.layer?.backgroundColor = NSColor(red: 14/255.0, green: 17/255, blue: 20/255, alpha: 1).cgColor self.titleLabel.textColor = NSColor.white self.desLabel.textColor = NSColor.white self.desSubLabel.textColor = NSColor(red: 200/255, green: 201/255, blue: 204/255, alpha: 1) self.getStartBox.fillColor = NSColor(red: 34/255, green: 122/255, blue: 255/255, alpha: 1) } else { self.titleInfoView.layer?.backgroundColor = NSColor.white.cgColor self.descriptionBGView.layer?.backgroundColor = NSColor(red: 235/255.0, green: 236/255, blue: 240/255, alpha: 1).cgColor self.titleLabel.textColor = NSColor(red: 0, green: 33/255, blue: 67/255, alpha: 1) self.desLabel.textColor = NSColor(red: 14/255, green: 17/255, blue: 20/255, alpha: 1) self.desSubLabel.textColor = NSColor(red: 14/255, green: 17/255, blue: 20/255, alpha: 1) self.getStartBox.fillColor = NSColor(red: 73/255, green: 130/255, blue: 230/255, alpha: 1) } for view in self.typeNameView.subviews { if view is KMFunctionGuideNameItemView { let itemView = view as! KMFunctionGuideNameItemView itemView.updateViewColor() } } } //MARK: IBAction @IBAction func getStartAction(_ sender: Any) { guard let callBack = self.clickHandle else { return } callBack(self) } @IBAction func learnMoreAction(_ sender: Any) { #if VERSION_DMG var url = URL(string:"https://www.pdfreaderpro.com/blog/digital-signature-update-mac-and-windows?utm_source=app_dmg&utm_medium=whatsnew_digitalsign_blog")! NSWorkspace.shared.open(url) #else var url = URL(string:"https://www.pdfreaderpro.com/blog/digital-signature-update-mac-and-windows?utm_source=app_mac&utm_medium=whatsnew_digitalsign_blog")! NSWorkspace.shared.open(url) #endif } @IBAction func previousAction(_ sender: Any) { for i in 0...self.namesArr.count - 1 { let dict = self.namesArr[i] as! NSDictionary if dict["key"] as! String == self.currentNameKEY { if i > 0 { let preDic = self.namesArr[i-1] as! NSDictionary self.currentNameKEY = preDic["key"] as! String break } } } self.reloadNameViewInfo() self.reloadDescriptionInfo() } @IBAction func nextAction(_ sender: Any) { for i in 0...self.namesArr.count - 1 { let dict = self.namesArr[i] as! NSDictionary if dict["key"] as! String == self.currentNameKEY { if i < self.namesArr.count { let nextDic = self.namesArr[i+1] as! NSDictionary self.currentNameKEY = nextDic["key"] as! String break } } } self.reloadNameViewInfo() self.reloadDescriptionInfo() } @objc func themeChange() { DispatchQueue.main.asyncAfter(deadline: DispatchTime.now() + 0.3) { self.updateViewColor() } } }