12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455 |
- //
- // KMBookmarkSheetController.swift
- // PDF Reader Pro
- //
- // Created by lizhe on 2024/2/5.
- //
- import Cocoa
- typealias KMBookmarkSheetControllerDoneAction = (_ controller: KMBookmarkSheetController, _ type: KMBookmarkType, _ label: String) -> ()
- typealias KMBookmarkSheetControllerCancelAction = (_ controller: KMBookmarkSheetController, _ type: KMBookmarkType) -> ()
- class KMBookmarkSheetController: NSWindowController {
- @IBOutlet weak var bookmarkSheetView: KMBookmarkSheetView!
-
- var doneAction: KMBookmarkSheetControllerDoneAction?
- var cancelAction: KMBookmarkSheetControllerCancelAction?
-
- var type: KMBookmarkType = .bookmark
- var stringValue: String = "" {
- didSet {
- self.bookmarkSheetView?.bookmarkTextField.stringValue = stringValue
- }
- }
-
- static func showBookmarkSheetController(type: KMBookmarkType) -> KMBookmarkSheetController {
- let controller = KMBookmarkSheetController.init(windowNibName: "KMBookmarkSheetController")
-
- controller.type = type
- NSWindow.currentWindow().beginSheet(controller.window!)
-
- return controller
- }
-
- override func windowDidLoad() {
- self.bookmarkSheetView.type = type
- self.bookmarkSheetView.bookmarkTextField.stringValue = stringValue
- self.bookmarkSheetView.cancelAction = { [unowned self] view, type in
- self.cancelAction?(self, type)
- self.km_quick_endSheet()
- }
-
- self.bookmarkSheetView.doneAction = { [unowned self] view, type, label in
- self.doneAction?(self, type, label)
- self.km_quick_endSheet()
- }
- }
-
- // MARK: Accessors
-
- var selectedFolder: KMBookmark? {
- return bookmarkSheetView.folderPopUp.selectedItem?.representedObject as? KMBookmark
- }
- }
|