12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788 |
- //
- // KMCreatPDFView.swift
- // PDF Reader Pro
- //
- // Created by lizhe on 2023/10/23.
- //
- import Cocoa
- typealias KMCreatPDFViewOpenPDFAction = (_ view: KMCreatPDFView, _ sender: KMBox) -> Void
- typealias KMCreatPDFViewCreatAction = (_ view: KMCreatPDFView, _ sender: KMBox) -> Void
- class KMCreatPDFView: KMBaseXibView {
- @IBOutlet weak var openBox: KMBox!
- @IBOutlet weak var openLabel: NSTextField!
- @IBOutlet weak var creatBox: KMBox!
- @IBOutlet weak var creatLabel: NSTextField!
-
- var openPDFAction: KMCreatPDFViewOpenPDFAction?
- var creatPDFAction: KMCreatPDFViewCreatAction?
-
-
- override func draw(_ dirtyRect: NSRect) {
- super.draw(dirtyRect)
- // Drawing code here.
- }
-
- override func setup() {
- self.openLabel.stringValue = NSLocalizedString("Open File", comment: "")
- self.openLabel.textColor = KMAppearance.Layout.w0Color()
- self.creatLabel.stringValue = NSLocalizedString("Create PDF", comment: "")
- self.creatLabel.textColor = KMAppearance.Layout.m_1Color()
-
- self.openBox.fillColor = KMAppearance.Interactive.m0Color()
- self.openBox.toolTip = NSLocalizedString("Open PDF", comment: "")
- self.openBox.downCallback = { [unowned self] downEntered, mouseBox, event in
- if (downEntered) {
- self.openBox.fillColor = KMAppearance.Interactive.m_1Color()
- self.openPDFButtonAction()
- } else {
- self.openBox.fillColor = KMAppearance.Interactive.m0Color()
- }
- };
-
- self.openBox.moveCallback = { [unowned self] mouseEntered, mouseBox in
- if (mouseEntered) {
- self.openBox.fillColor = KMAppearance.Interactive.m1Color()
- } else {
- self.openBox.fillColor = KMAppearance.Interactive.m0Color()
- }
- };
-
- self.creatBox.toolTip = NSLocalizedString("Create PDF", comment: "")
- self.creatBox.fillColor = KMAppearance.Layout.l0Color()
- self.creatBox.borderWidth = 1.0;
- self.creatBox.borderColor = KMAppearance.Interactive.m0Color()
- self.creatBox.downCallback = { [unowned self] downEntered, mouseBox, event in
- if (downEntered) {
- self.creatBox.fillColor = KMAppearance.Status.preColor()
- self.createPDFButtonAction()
- } else {
- self.creatBox.fillColor = KMAppearance.Layout.l0Color()
- }
- };
-
- self.creatBox.moveCallback = { [unowned self] mouseEntered, mouseBox in
- if (mouseEntered) {
- self.creatBox.fillColor = KMAppearance.Status.hovColor()
- } else {
- self.creatBox.fillColor = KMAppearance.Layout.l0Color()
- }
- };
- }
-
- @objc func openPDFButtonAction() {
- guard let callBack = openPDFAction else { return }
-
- callBack(self, self.openBox)
- }
-
- @objc func createPDFButtonAction() {
- guard let callBack = creatPDFAction else { return }
-
- callBack(self, self.creatBox)
- }
-
- }
|