// // KMMainToolbarController.swift // PDF Reader Pro // // Created by lxy on 2022/12/1. // import Cocoa class SKToolbar : NSToolbar { func allowsSizeMode(sizeMode:NSToolbar.SizeMode) -> Bool { return true } } @objc protocol KMMainToolbarControllerDelegate { @objc optional func changeModelAction(mode : CToolMode) } class KMMainToolbarController: NSViewController{ @IBOutlet weak var leftControlButton: NSButton! @IBOutlet weak var pagebox: NSBox! @IBOutlet weak var beforePageButton: NSButton! @IBOutlet weak var nextPageButton: NSButton! @IBOutlet weak var annotationModelButton: NSButton! @IBOutlet weak var pageModelButton: NSButton! @IBOutlet weak var conversionModelButton: NSButton! @IBOutlet weak var scanORCModelButton: NSButton! @IBOutlet weak var editModelButton: NSButton! @IBOutlet weak var formModelButton: NSButton! @IBOutlet weak var signatureModelButton: NSButton! @IBOutlet weak var toolModelButton: NSButton! @IBOutlet weak var printModelButton: NSButton! @IBOutlet weak var shareModelButton: NSButton! @IBOutlet weak var rightControlButton: NSButton! @IBOutlet weak var zoomView: NSView! @IBOutlet weak var mainWindowController : KMBrowserWindowController! open weak var delegate: KMMainToolbarControllerDelegate? var toolbarItems : [NSToolbarItem.Identifier : Any] = [:] private func nibName() -> String { return "KMMainToolbarController" } func setupToolbar() { _ = self.view let toolbar : SKToolbar = SKToolbar.init(identifier: "KMDocumentToolbar") // toolbar.allowsUserCustomization = true toolbar.autosavesConfiguration = true toolbar.displayMode = .default toolbar.delegate = self self.mainWindowController.window?.toolbar = toolbar self.mainWindowController.window?.titlebarAppearsTransparent = true } //MARK: Action @IBAction func annotationButtonAction(item:NSMenuItem) { } @IBAction func leftControllButtonAction(item:NSMenuItem) { } @IBAction func editPDFButtonAction(item:NSMenuItem) { self.delegate?.changeModelAction?(mode: .editPDFToolMode) } } //MARK: NSToolbarDelegate extension KMMainToolbarController : NSToolbarDelegate ,NSToolbarItemValidation,NSMenuItemValidation{ func toolbar(_ toolbar: NSToolbar, itemForItemIdentifier itemIdentifier: NSToolbarItem.Identifier, willBeInsertedIntoToolbar flag: Bool) -> NSToolbarItem? { var item = self.toolbarItems[itemIdentifier] as? KMToolbarItem if item == nil { item = KMToolbarItem.init(itemIdentifier: itemIdentifier) self.toolbarItems[itemIdentifier] = item if itemIdentifier.rawValue == KMLeftControlToolbarItemIdentifier { let menuItem = NSMenuItem.init(title: "left", action: #selector(leftControllButtonAction), target: self) item?.toolTip = NSLocalizedString("left", comment: "") item?.setViewWithSizes(self.leftControlButton) item?.menuFormRepresentation = menuItem } else if itemIdentifier.rawValue == KMDocumentAnnotationToolbarItemIdentifier { let menuItem = NSMenuItem.init(title: "Annotation", action: #selector(annotationButtonAction), target: self) item?.toolTip = NSLocalizedString("Annotate PDF with highlight, text box and markup tools", comment: "") item?.setViewWithSizes(self.annotationModelButton) item?.menuFormRepresentation = menuItem } else if itemIdentifier.rawValue == KMDocumentPageToolbarItemIdentifier { let menuItem = NSMenuItem.init(title: "page", action: #selector(leftControllButtonAction), target: self) item?.setViewWithSizes(self.pageModelButton) item?.menuFormRepresentation = menuItem } else if itemIdentifier.rawValue == KMDocumentConversonToolbarItemIdentifier { let menuItem = NSMenuItem.init(title: "Converson", action: #selector(leftControllButtonAction), target: self) item?.setViewWithSizes(self.conversionModelButton) item?.menuFormRepresentation = menuItem } else if itemIdentifier.rawValue == KMDocumentScanOCRToolbarItemIdentifier { let menuItem = NSMenuItem.init(title: "scan", action: #selector(leftControllButtonAction), target: self) item?.setViewWithSizes(self.scanORCModelButton) item?.menuFormRepresentation = menuItem } else if itemIdentifier.rawValue == KMDocumentAIToolsToolbarItemIdentifier { let menuItem = NSMenuItem.init(title: "AI Tools", action: #selector(leftControllButtonAction), target: self) item?.setViewWithSizes(self.scanORCModelButton) item?.menuFormRepresentation = menuItem } else if itemIdentifier.rawValue == KMDocumentEditToolbarItemIdentifier { let menuItem = NSMenuItem.init(title: "edit", action: #selector(editPDFButtonAction), target: self) item?.setViewWithSizes(self.editModelButton) item?.menuFormRepresentation = menuItem } else if itemIdentifier.rawValue == KMDocumentFillSginToolbarItemIdentifier { let menuItem = NSMenuItem.init(title: "fillsign", action: #selector(leftControllButtonAction), target: self) item?.setViewWithSizes(self.signatureModelButton) item?.menuFormRepresentation = menuItem }else if itemIdentifier.rawValue == KMDocumentFormToolbarItemIdentifier { let menuItem = NSMenuItem.init(title: "form", action: #selector(leftControllButtonAction), target: self) item?.setViewWithSizes(self.formModelButton) item?.menuFormRepresentation = menuItem } else if itemIdentifier.rawValue == KMDocumentToolToolbarItemIdentifier { let menuItem = NSMenuItem.init(title: "tool", action: #selector(leftControllButtonAction), target: self) item?.setViewWithSizes(self.toolModelButton) item?.menuFormRepresentation = menuItem } else if itemIdentifier.rawValue == KMDocumentPrintToolbarItemIdentifier { let menuItem = NSMenuItem.init(title: "print", action: #selector(leftControllButtonAction), target: self) item?.setViewWithSizes(self.printModelButton) item?.menuFormRepresentation = menuItem } else if itemIdentifier.rawValue == KMDocumentShareToolbarItemIdentifier { let menuItem = NSMenuItem.init(title: "share", action: #selector(leftControllButtonAction), target: self) item?.setViewWithSizes(self.shareModelButton) item?.menuFormRepresentation = menuItem } else if itemIdentifier.rawValue == KMRightControlToolbarItemIdentifier { let menuItem = NSMenuItem.init(title: "right", action: #selector(leftControllButtonAction), target: self) item?.setViewWithSizes(self.rightControlButton) item?.menuFormRepresentation = menuItem } } if flag == false { item?.isEnabled = true } return item } func toolbarDefaultItemIdentifiers(_ toolbar: NSToolbar) -> [NSToolbarItem.Identifier] { return [NSToolbarItem.Identifier.space, NSToolbarItem.Identifier(KMLeftControlToolbarItemIdentifier), NSToolbarItem.Identifier.flexibleSpace, NSToolbarItem.Identifier(KMDocumentAnnotationToolbarItemIdentifier), NSToolbarItem.Identifier(KMDocumentPageToolbarItemIdentifier), NSToolbarItem.Identifier(KMDocumentConversonToolbarItemIdentifier), NSToolbarItem.Identifier(KMDocumentScanOCRToolbarItemIdentifier), NSToolbarItem.Identifier(KMDocumentAIToolsToolbarItemIdentifier), NSToolbarItem.Identifier(KMDocumentEditToolbarItemIdentifier), NSToolbarItem.Identifier(KMDocumentFormToolbarItemIdentifier), NSToolbarItem.Identifier(KMDocumentFillSginToolbarItemIdentifier), NSToolbarItem.Identifier(KMDocumentToolToolbarItemIdentifier), NSToolbarItem.Identifier.space, NSToolbarItem.Identifier.flexibleSpace, NSToolbarItem.Identifier(KMDocumentPrintToolbarItemIdentifier), NSToolbarItem.Identifier(KMDocumentShareToolbarItemIdentifier), NSToolbarItem.Identifier(KMRightControlToolbarItemIdentifier), NSToolbarItem.Identifier.space] } func toolbarAllowedItemIdentifiers(_ toolbar: NSToolbar) -> [NSToolbarItem.Identifier] { return [NSToolbarItem.Identifier(KMLeftControlToolbarItemIdentifier), NSToolbarItem.Identifier(KMDocumentAnnotationToolbarItemIdentifier), NSToolbarItem.Identifier(KMDocumentPageToolbarItemIdentifier), NSToolbarItem.Identifier(KMDocumentConversonToolbarItemIdentifier), NSToolbarItem.Identifier(KMDocumentScanOCRToolbarItemIdentifier), NSToolbarItem.Identifier(KMDocumentAIToolsToolbarItemIdentifier), NSToolbarItem.Identifier(KMDocumentEditToolbarItemIdentifier), NSToolbarItem.Identifier(KMDocumentFormToolbarItemIdentifier), NSToolbarItem.Identifier(KMDocumentFillSginToolbarItemIdentifier), NSToolbarItem.Identifier(KMDocumentToolToolbarItemIdentifier), NSToolbarItem.Identifier.space, NSToolbarItem.Identifier.flexibleSpace, NSToolbarItem.Identifier(KMDocumentPrintToolbarItemIdentifier), NSToolbarItem.Identifier(KMDocumentShareToolbarItemIdentifier), NSToolbarItem.Identifier(KMRightControlToolbarItemIdentifier)] } func validateToolbarItem(_ item: NSToolbarItem) -> Bool { return true } func validateMenuItem(_ menuItem: NSMenuItem) -> Bool { return true } }