12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364 |
- //
- // KMBookmarkSheetView.swift
- // PDF Reader Pro
- //
- // Created by lizhe on 2024/2/6.
- //
- import Cocoa
- typealias KMBookmarkSheetViewDoneAction = (_ view: KMBookmarkSheetView, _ type: KMBookmarkType, _ label: String) -> ()
- typealias KMBookmarkSheetViewCancelAction = (_ view: KMBookmarkSheetView, _ type: KMBookmarkType) -> ()
- class KMBookmarkSheetView: KMBaseXibView {
- @IBOutlet weak var folderPopUp: NSPopUpButton!
- @IBOutlet weak var bookmarkTextField: NSTextField!
- @IBOutlet weak var bookmarkLabel: NSTextField!
- @IBOutlet weak var addToLabel: NSTextField!
- @IBOutlet weak var cancelButton: NSButton!
- @IBOutlet weak var okButton: NSButton!
-
- var type: KMBookmarkType = .bookmark
-
- var doneAction: KMBookmarkSheetViewDoneAction?
- var cancelAction: KMBookmarkSheetViewCancelAction?
-
- override func draw(_ dirtyRect: NSRect) {
- super.draw(dirtyRect)
- // Drawing code here.
- }
-
- override func setup() {
- let root = KMBookmarkManager.manager.rootBookmark
- self.folderPopUp.removeAllItems()
- addMenuItems(forBookmarks: [root], level: 0, toMenu: self.folderPopUp.menu!)
- self.folderPopUp.selectItem(at: 0)
-
- self.bookmarkLabel.stringValue = NSLocalizedString("Bookmarks", comment: "")
- self.addToLabel.stringValue = NSLocalizedString("Add to", comment:"")
- self.cancelButton.title = NSLocalizedString("Cancel", comment:"")
- self.okButton.title = NSLocalizedString("OK", comment:"")
- }
-
- func addMenuItems(forBookmarks bookmarks: [KMBookmark], level: Int, toMenu menu: NSMenu) {
- for bm in bookmarks {
- if bm.bookmarkType == .folder {
- let label = bm.label
- let item = menu.addItem(withTitle: label, action: nil, keyEquivalent: "")
- item.setImageAndSize(bm.icon)
- item.indentationLevel = level
- item.representedObject = bm
- addMenuItems(forBookmarks: bm.children, level: level + 1, toMenu: menu)
- }
- }
- }
-
- @IBAction func cancelButtonAction(_ sender: Any) {
- self.cancelAction?(self, type)
- }
-
- @IBAction func doneButtonAction(_ sender: Any) {
- self.doneAction?(self, type, bookmarkTextField.stringValue)
- }
- }
|