123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442 |
- //
- // KMGuideInfoWindowController.swift
- // PDF Reader Pro Edition
- //
- // Created by Niehaoyu on 2023/12/5.
- //
- import Cocoa
- class KMGuideInfoWindowController: NSWindowController {
- @IBOutlet weak var contendBox: NSBox!
-
- @objc var coverView: KMGuideCoverView!
- @objc var openFileGuidePanel: KMOpenFileGuidePanel!
- @objc var openFileGuideProperty: KMOpenFileGuideProperty!
- @objc var openFileGuideToolbar: KMOpenFileGuideToolbar!
- @objc var openFileFunctionView: KMOpenFileFunctionView!
- @objc var convertGuideView: KMConvertGuideView!
- @objc var customColorGuideView: KMCustomColorGuideView!
- @objc var aiIconGuideView: KMAIIconGuideView!
-
-
- @objc var _type: KMGuideInfoType = .none
- @objc var openPanelRect: CGRect = .zero
- @objc var rightPanelRect: CGRect = .zero
- @objc var _digitalBoxRect: CGRect = .zero
- @objc var compareItemRect: CGRect = .zero
-
- @objc var purchaseHandle: ((_ view: KMGuideInfoWindowController)->Void)?
- @objc var normalGuideFinishHandle: ((_ view: KMGuideInfoWindowController)->Void)?
- @objc var finishHandle: ((_ view: KMGuideInfoWindowController, _ actionType: KMGuideActionType)->Void)?
-
- @objc var openFileToggleHandle: ((_ view: KMGuideInfoWindowController, _ infoType: KMGuideInfoType)->Void)?
- //MARK: Static Method
- @objc static func availableShow(_ type: KMGuideInfoType) -> Bool {
- if type == .openFileNormal {
- if (UserDefaults.standard.object(forKey: kKMGuideInfoOpenFileNormalKey) == nil) {
- return true
- }
- } else if type == .digitalSignGuide {
- if (UserDefaults.standard.object(forKey: kKMGuideInfoDigitalSignKey) == nil) {
- return true
- }
- } else if type == .pdfCompareGuide {
- if (UserDefaults.standard.object(forKey: kKMGuideInfoPDFCompareKey) == nil) {
- return true
- }
- } else if type == .convertGuide {
- if (UserDefaults.standard.object(forKey: kKMGuideInfoFileConvertKey) == nil) {
- return true
- }
- } else if type == .customColor {
- if (UserDefaults.standard.object(forKey: kKMGuideInfoCustomColorKey) == nil) {
- return true
- }
- } else if type == .aiTipIconInfo {
- if (UserDefaults.standard.object(forKey: kKMGuideInfoAITipIconViewKey) == nil) {
- return true
- }
- }
- return false
- }
-
- static func setDidShowFor(_ type: KMGuideInfoType) -> Void {
- if type == .openFileNormal {
- UserDefaults.standard.setValue("Show", forKey: kKMGuideInfoOpenFileNormalKey)
- UserDefaults.standard.synchronize()
- } else if type == .digitalSignGuide {
- UserDefaults.standard.setValue("Show", forKey: kKMGuideInfoDigitalSignKey)
- UserDefaults.standard.synchronize()
- } else if type == .pdfCompareGuide {
- UserDefaults.standard.setValue("Show", forKey: kKMGuideInfoPDFCompareKey)
- UserDefaults.standard.synchronize()
- } else if type == .convertGuide {
- UserDefaults.standard.setValue("Show", forKey: kKMGuideInfoFileConvertKey)
- UserDefaults.standard.synchronize()
- } else if type == .customColor {
- UserDefaults.standard.setValue("Show", forKey: kKMGuideInfoCustomColorKey)
- UserDefaults.standard.synchronize()
- } else if type == .aiTipIconInfo {
- UserDefaults.standard.setValue("Show", forKey: kKMGuideInfoAITipIconViewKey)
- UserDefaults.standard.synchronize()
- }
- }
-
- static var currentWindowController: KMGuideInfoWindowController!
-
- @objc static func currentWC() -> KMGuideInfoWindowController {
- if currentWindowController != nil {
- return currentWindowController
- } else {
- let guideInfoWC: KMGuideInfoWindowController = KMGuideInfoWindowController.init(windowNibName: "KMGuideInfoWindowController")
- currentWindowController = guideInfoWC;
- return guideInfoWC
- }
- }
-
- deinit {
- print("deinit Action")
- }
-
- //MARK: SystemMethod
- override func showWindow(_ sender: Any?) {
- super.showWindow(sender)
-
- self.show()
- }
-
- override func windowDidLoad() {
- super.windowDidLoad()
- // Implement this method to handle any initialization after your window controller's window has been loaded from its nib file.
-
- self.window?.backgroundColor = NSColor.clear
- self.window?.contentView?.wantsLayer = true
- self.window?.contentView?.layer?.backgroundColor = NSColor.clear.cgColor;
- self.window?.isOpaque = false
-
- self.contendBox.fillColor = NSColor.clear
-
- self.coverView = KMGuideCoverView.createFromNib()
- self.coverView.frame = self.contendBox.bounds
- self.contendBox.contentView = self.coverView
-
-
- }
-
- //MARK: Setter
- @objc var type: KMGuideInfoType {
- set {
- _type = newValue;
-
- }
- get {
- return _type;
- }
- }
-
- @objc var digitalBoxRect: CGRect {
- set {
- _digitalBoxRect = newValue;
- }
- get {
- return _digitalBoxRect;
- }
- }
-
- //MARK: Public Method
-
- @objc func show() {
- if self.type == .openFileNormal {
- self.type = .openFileNormalPanel
- }
- self.loadGuideInfoView()
- }
-
- func clearViews() {
- let viewsArr = NSArray.init(array: self.coverView.subviews)
- for view in viewsArr {
- if view is KMOpenFileGuidePanel {
- (view as AnyObject).removeFromSuperview()
- } else if view is KMOpenFileGuideProperty {
- (view as AnyObject).removeFromSuperview()
- } else if view is KMOpenFileGuideToolbar {
- (view as AnyObject).removeFromSuperview()
- } else if view is KMOpenFileFunctionView {
- (view as AnyObject).removeFromSuperview()
- } else if view is KMConvertGuideView {
- (view as AnyObject).removeFromSuperview()
- } else if view is KMCustomColorGuideView {
- (view as AnyObject).removeFromSuperview()
- } else if view is KMAIIconGuideView {
- (view as AnyObject).removeFromSuperview()
- }
- }
- self.coverView.display()
- if self.window != nil {
- var rect = self.window?.frame
- rect?.size.width += 1
- self.window?.setFrame(rect!, display: true)
- }
- }
-
- func loadGuideInfoView() {
- DispatchQueue.main.async {
- self.clearViews()
-
- self.contendBox.contentView = self.coverView
-
- if self.type == .openFileNormalPanel {
- if self.openFileGuidePanel == nil {
- self.openFileGuidePanel = KMOpenFileGuidePanel.createFromNib()
- }
- self.openFileGuidePanel.frame = self.coverView.bounds
- self.openFileGuidePanel.autoresizingMask = [.width, .height]
- self.openFileGuidePanel.clickHandle = {[weak self] view, actionType in
- guard let self = self else { return }
- if actionType == .skip {
- //Skip->数字签名
- //Skip->
- guard let callBack = self.normalGuideFinishHandle else {
- return
- }
- callBack(self)
- if KMGuideInfoWindowController.availableShow(.digitalSignGuide) &&
- (CGRectGetWidth(self.window!.frame) > CGRectGetMinX(self.digitalBoxRect) + 260) &&
- CGRectGetMinX(self.digitalBoxRect) > 450 {
- self.type = .digitalSignGuide
- self.loadGuideInfoView()
- } else {
- guard let callBack = self.finishHandle else {
- return
- }
- callBack(self, .windowNewFinish)
- self.closeAction()
- }
- } else if actionType == .next {
- //Next
- self.type = .openFileNormalProperty
- self.loadGuideInfoView()
- // guard let callBack = self.openFileToggleHandle else {
- // return
- // }
- // callBack(self, .openFileNormalProperty)
- // self.closeAction()
- }
- }
- self.openFileGuidePanel.circleRect = self.openPanelRect
- self.coverView.addSubview(self.openFileGuidePanel)
- self.openFileGuidePanel.updateViewColor()
- KMGuideInfoWindowController.setDidShowFor(.openFileNormal)//记录布局介绍
- } else if self.type == .openFileNormalProperty {
- guard let callBack = self.normalGuideFinishHandle else {
- return
- }
- callBack(self)
- if self.openFileGuideProperty == nil {
- self.openFileGuideProperty = KMOpenFileGuideProperty.createFromNib()
- }
- self.openFileGuideProperty.frame = self.coverView.bounds
- self.openFileGuideProperty.autoresizingMask = [.width, .height]
- self.openFileGuideProperty.clickHandle = {[weak self] view, actionType in
- guard let self = self else { return }
- if actionType == .skip {
- //Skip->数字签名
- //Skip->
- guard let callBack = self.normalGuideFinishHandle else {
- return
- }
- callBack(self)
- if KMGuideInfoWindowController.availableShow(.digitalSignGuide) &&
- (CGRectGetWidth(self.window!.frame) > CGRectGetMinX(self.digitalBoxRect) + 260) &&
- CGRectGetMinX(self.digitalBoxRect) > 450 {
- self.type = .digitalSignGuide
- self.loadGuideInfoView()
- } else {
- guard let callBack = self.finishHandle else {
- return
- }
- callBack(self, .windowNewFinish)
- self.closeAction()
- }
- } else if actionType == .previous {
- //Previous
- self.type = .openFileNormalPanel
- self.loadGuideInfoView()
- guard let callBack = self.normalGuideFinishHandle else {
- return
- }
- callBack(self)
- // guard let callBack = self.openFileToggleHandle else {
- // return
- // }
- // callBack(self, .openFileNormalPanel)
- // self.closeAction()
- } else if actionType == .next {
- //Next
- self.type = .openFileNormalToolbar
- self.loadGuideInfoView()
- // guard let callBack = self.openFileToggleHandle else {
- // return
- // }
- // callBack(self, .openFileNormalToolbar)
- // self.closeAction()
- }
- }
- self.openFileGuideProperty.circleRect = self.rightPanelRect
- self.coverView.addSubview(self.openFileGuideProperty)
- self.openFileGuideProperty.updateViewColor()
- } else if self.type == .openFileNormalToolbar {
- if self.openFileGuideToolbar == nil {
- self.openFileGuideToolbar = KMOpenFileGuideToolbar.createFromNib()
- }
- self.openFileGuideToolbar.frame = self.coverView.bounds
- self.openFileGuideToolbar.autoresizingMask = [.width, .height]
- self.openFileGuideToolbar.clickHandle = {[weak self] view, actionType in
- guard let self = self else { return }
- if actionType == .skip {
- //Skip->数字签名
- //Skip->
- guard let callBack = self.normalGuideFinishHandle else {
- return
- }
- callBack(self)
- if KMGuideInfoWindowController.availableShow(.digitalSignGuide) &&
- (CGRectGetWidth(self.window!.frame) > CGRectGetMinX(self.digitalBoxRect) + 260) &&
- CGRectGetMinX(self.digitalBoxRect) > 450 {
- self.type = .digitalSignGuide
- self.loadGuideInfoView()
- } else {
- guard let callBack = self.finishHandle else {
- return
- }
- callBack(self, .windowNewFinish)
- self.closeAction()
- }
- } else if actionType == .previous {
- //Next
- self.type = .openFileNormalProperty
- self.loadGuideInfoView()
- // guard let callBack = self.openFileToggleHandle else {
- // return
- // }
- // callBack(self, .openFileNormalProperty)
- // self.closeAction()
- } else if actionType == .finish {
- guard let callBack = self.normalGuideFinishHandle else {
- return
- }
- callBack(self)
- if KMGuideInfoWindowController.availableShow(.digitalSignGuide) &&
- (CGRectGetWidth(self.window!.frame) > CGRectGetMinX(self.digitalBoxRect) + 260) &&
- CGRectGetMinX(self.digitalBoxRect) > 450 {
- self.type = .digitalSignGuide
- self.loadGuideInfoView()
- } else {
- guard let callBack = self.finishHandle else {
- return
- }
- callBack(self, .windowNewFinish)
- self.closeAction()
- }
- }
- }
- self.coverView.addSubview(self.openFileGuideToolbar)
- } else if self.type == .digitalSignGuide || self.type == .pdfCompareGuide {
- if self.type == .digitalSignGuide {
- KMGuideInfoWindowController.setDidShowFor(.digitalSignGuide)//记录数字签名介绍
- } else if self.type == .pdfCompareGuide {
- KMGuideInfoWindowController.setDidShowFor(.pdfCompareGuide)//记录文件对比介绍
- }
-
- if self.openFileFunctionView == nil {
- self.openFileFunctionView = KMOpenFileFunctionView.createFromNib()
- }
- self.openFileFunctionView.circleRect = self.digitalBoxRect
- self.openFileFunctionView.frame = self.coverView.bounds
- self.openFileFunctionView.autoresizingMask = [.width, .height]
- self.openFileFunctionView.type = self.type
- self.openFileFunctionView.clickHandle = {[weak self] view, actionType in
- guard let self = self else { return }
- if self.type == .digitalSignGuide {
- guard let callBack = self.finishHandle else {
- return
- }
- callBack(self, .windowDigitalFinish)
- if actionType == .getIt {
- self.closeAction()
- }
- } else if self.type == .pdfCompareGuide {
- if actionType == .getIt {
- self.closeAction()
- }
- }
- }
- self.coverView.addSubview(self.openFileFunctionView)
- self.openFileFunctionView.updateViewColor()
- } else if self.type == .convertGuide {
- if self.convertGuideView == nil {
- self.convertGuideView = KMConvertGuideView.createFromNib()
- }
- self.convertGuideView.frame = self.coverView.bounds
- self.convertGuideView.autoresizingMask = [.width, .height]
- self.convertGuideView.clickHandle = {[weak self] view, actionType in
- guard let self = self else { return }
- if actionType == .skip {
- self.closeAction()
- } else if actionType == .purchase {
- guard let callBack = self.purchaseHandle else {
- return
- }
- callBack(self)
- self.closeAction()
- }
- }
- self.convertGuideView.circleRect = self.digitalBoxRect
- self.coverView.addSubview(self.convertGuideView)
- self.convertGuideView.updateViewColor()
- KMGuideInfoWindowController.setDidShowFor(.convertGuide)//记录转档介绍
- } else if self.type == .customColor {
- if self.customColorGuideView == nil {
- self.customColorGuideView = KMCustomColorGuideView.createFromNib()
- }
- self.customColorGuideView.frame = self.coverView.bounds
- self.customColorGuideView.autoresizingMask = [.width, .height]
- self.customColorGuideView.clickHandle = {[unowned self] view, actionType in
- if actionType == .getIt {
- self.closeAction()
- }
- }
- self.customColorGuideView.circleRect = self.digitalBoxRect
- self.customColorGuideView.updateViewColor()
- self.coverView.addSubview(self.customColorGuideView)
- KMGuideInfoWindowController.setDidShowFor(.customColor)//记录自定义颜色介绍
- } else if self.type == .aiTipIconInfo {
- if self.aiIconGuideView == nil {
- self.aiIconGuideView = KMAIIconGuideView.createFromNib()
- }
- self.aiIconGuideView.frame = self.coverView.bounds
- self.aiIconGuideView.autoresizingMask = [.width, .height]
- self.aiIconGuideView.clickHandle = {[weak self] view, actionType in
- guard let self = self else { return }
- if actionType == .getIt {
- self.closeAction()
- }
- }
- self.aiIconGuideView.updateViewColor()
- self.aiIconGuideView.wantsLayer = true
-
- self.coverView.addSubview(self.aiIconGuideView)
- KMGuideInfoWindowController.setDidShowFor(.aiTipIconInfo)//记录自定义颜色介绍
- }
- }
- }
-
- func closeAction() {
- self.clearViews()
- self.close()
- }
- }
|