123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218 |
- //
- // KMMainToolbarController.swift
- // PDF Master
- //
- // 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
- // self.mainWindowController.window?.backgroundColor = NSColor.red
- }
-
- //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 == KMDocumentZoomToolbarItemIdentifier {
- let menuItem = NSMenuItem.init(title: "zoom", action: #selector(annotationButtonAction), target: self)
- // item?.toolTip = NSLocalizedString("Annotate PDF with highlight, text box and markup tools", comment: "")
- item?.setViewWithSizes(self.zoomView)
- 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 == KMDocumentNextPageToolbarItemIdentifier {
- let menuItem = NSMenuItem.init(title: "next", action: #selector(leftControllButtonAction), target: self)
- item?.toolTip = NSLocalizedString("nexts", comment: "")
- item?.setViewWithSizes(self.pagebox)
- 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 == 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(KMDocumentZoomToolbarItemIdentifier),
- NSToolbarItem.Identifier(KMDocumentNextPageToolbarItemIdentifier),
- NSToolbarItem.Identifier.flexibleSpace,
- NSToolbarItem.Identifier(KMDocumentAnnotationToolbarItemIdentifier),
- NSToolbarItem.Identifier(KMDocumentPageToolbarItemIdentifier),
- NSToolbarItem.Identifier(KMDocumentConversonToolbarItemIdentifier),
- NSToolbarItem.Identifier(KMDocumentScanOCRToolbarItemIdentifier),
- 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(KMDocumentZoomToolbarItemIdentifier),
- NSToolbarItem.Identifier(KMDocumentNextPageToolbarItemIdentifier),
- NSToolbarItem.Identifier(KMDocumentAnnotationToolbarItemIdentifier),
- NSToolbarItem.Identifier(KMDocumentPageToolbarItemIdentifier),
- NSToolbarItem.Identifier(KMDocumentConversonToolbarItemIdentifier),
- NSToolbarItem.Identifier(KMDocumentScanOCRToolbarItemIdentifier),
- 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
- }
-
- }
|