123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869 |
- //
- // KMUserFeekbackHanddler.swift
- // PDF Reader Pro
- //
- // Created by tangchao on 2024/7/17.
- //
- import Cocoa
- class KMUserFeekbackHanddler: NSObject {
- private weak var popover_: NSPopover?
-
- func showUserFbPopView(sender: NSView) {
- if let _ = self.popover_ {
- return
- }
-
- let datas = [NSLocalizedString("Report a Bug", comment: ""), NSLocalizedString("Propose a New Feature", comment: ""), "KMHorizontalLine", NSLocalizedString("Quick Start Guide", comment: "")]
- let vc = KMHomePopViewController(nibName: "KMHomePopViewController", bundle: nil)
- _ = vc.initWithPopViewDataArr(datas)
-
- vc.background = KMAppearance.Layout.bgColor()
- vc.textColor = KMAppearance.Layout.h0Color()
- vc.enterFillColor = KMAppearance.Interactive.s0Color()
-
- vc.downCallback = { [weak self] result, data in
- self?.popover_?.close()
-
- if data == NSLocalizedString("Report a Bug", comment: "") {
- self?.showFeekbackWindow(with: data)
- } else if data == NSLocalizedString("Propose a New Feature", comment: "") {
- self?.showFeekbackWindow(with: data)
- } else if data == NSLocalizedString("Quick Start Guide", comment: "") {
- KMTools.openQuickStartStudy()
- }
- }
- let popover = NSPopover()
- popover.contentViewController = vc
- popover.animates = true
- popover.behavior = .semitransient
- popover.setValue(true, forKey: "shouldHideAnchor")
- popover.delegate = self
- //
- // CGRect sourcesRect = sender.bounds;
- // sourcesRect = [sender convertRect:sourcesRect toView:nil];
- // sourcesRect.origin.y-= 20;
- // sourcesRect.size.height+=20;
- // self.mainWindowC.window.popover = popover;
- // self.mainWindowC.window.sourcesRect = sourcesRect;
-
- popover.show(relativeTo: sender.bounds, of: sender, preferredEdge: .maxX)
- self.popover_ = popover
- }
-
- func showFeekbackWindow(with type: String) {
- let winC = KMUserFeekbackWindowController.shared
- winC.typeString = type
- winC.showWindow(nil)
- }
- }
- extension KMUserFeekbackHanddler: NSPopoverDelegate {
- func popoverWillClose(_ notification: Notification) {
- if let data = self.popover_?.isEqual(to: notification.object), data {
- self.popover_ = nil
- }
- }
- }
|