KMBookmarkSheetController.swift 1.8 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455
  1. //
  2. // KMBookmarkSheetController.swift
  3. // PDF Reader Pro
  4. //
  5. // Created by lizhe on 2024/2/5.
  6. //
  7. import Cocoa
  8. typealias KMBookmarkSheetControllerDoneAction = (_ controller: KMBookmarkSheetController, _ type: KMBookmarkType, _ label: String) -> ()
  9. typealias KMBookmarkSheetControllerCancelAction = (_ controller: KMBookmarkSheetController, _ type: KMBookmarkType) -> ()
  10. class KMBookmarkSheetController: NSWindowController {
  11. @IBOutlet weak var bookmarkSheetView: KMBookmarkSheetView!
  12. var doneAction: KMBookmarkSheetControllerDoneAction?
  13. var cancelAction: KMBookmarkSheetControllerCancelAction?
  14. var type: KMBookmarkType = .bookmark
  15. var stringValue: String = "" {
  16. didSet {
  17. self.bookmarkSheetView?.bookmarkTextField.stringValue = stringValue
  18. }
  19. }
  20. static func showBookmarkSheetController(type: KMBookmarkType) -> KMBookmarkSheetController {
  21. let controller = KMBookmarkSheetController.init(windowNibName: "KMBookmarkSheetController")
  22. controller.type = type
  23. NSWindow.currentWindow().beginSheet(controller.window!)
  24. return controller
  25. }
  26. override func windowDidLoad() {
  27. self.bookmarkSheetView.type = type
  28. self.bookmarkSheetView.bookmarkTextField.stringValue = stringValue
  29. self.bookmarkSheetView.cancelAction = { [unowned self] view, type in
  30. self.cancelAction?(self, type)
  31. self.km_quick_endSheet()
  32. }
  33. self.bookmarkSheetView.doneAction = { [unowned self] view, type, label in
  34. self.doneAction?(self, type, label)
  35. self.km_quick_endSheet()
  36. }
  37. }
  38. // MARK: Accessors
  39. var selectedFolder: KMBookmark? {
  40. return bookmarkSheetView.folderPopUp.selectedItem?.representedObject as? KMBookmark
  41. }
  42. }