KMMainToolbarController.swift 10 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209
  1. //
  2. // KMMainToolbarController.swift
  3. // PDF Reader Pro
  4. //
  5. // Created by lxy on 2022/12/1.
  6. //
  7. import Cocoa
  8. class SKToolbar : NSToolbar {
  9. func allowsSizeMode(sizeMode:NSToolbar.SizeMode) -> Bool {
  10. return true
  11. }
  12. }
  13. @objc protocol KMMainToolbarControllerDelegate {
  14. @objc optional func changeModelAction(mode : CToolMode)
  15. }
  16. class KMMainToolbarController: NSViewController{
  17. @IBOutlet weak var leftControlButton: NSButton!
  18. @IBOutlet weak var pagebox: NSBox!
  19. @IBOutlet weak var beforePageButton: NSButton!
  20. @IBOutlet weak var nextPageButton: NSButton!
  21. @IBOutlet weak var annotationModelButton: NSButton!
  22. @IBOutlet weak var pageModelButton: NSButton!
  23. @IBOutlet weak var conversionModelButton: NSButton!
  24. @IBOutlet weak var scanORCModelButton: NSButton!
  25. @IBOutlet weak var editModelButton: NSButton!
  26. @IBOutlet weak var formModelButton: NSButton!
  27. @IBOutlet weak var signatureModelButton: NSButton!
  28. @IBOutlet weak var toolModelButton: NSButton!
  29. @IBOutlet weak var printModelButton: NSButton!
  30. @IBOutlet weak var shareModelButton: NSButton!
  31. @IBOutlet weak var rightControlButton: NSButton!
  32. @IBOutlet weak var zoomView: NSView!
  33. @IBOutlet weak var mainWindowController : KMBrowserWindowController!
  34. open weak var delegate: KMMainToolbarControllerDelegate?
  35. var toolbarItems : [NSToolbarItem.Identifier : Any] = [:]
  36. private func nibName() -> String {
  37. return "KMMainToolbarController"
  38. }
  39. func setupToolbar() {
  40. _ = self.view
  41. let toolbar : SKToolbar = SKToolbar.init(identifier: "KMDocumentToolbar")
  42. // toolbar.allowsUserCustomization = true
  43. toolbar.autosavesConfiguration = true
  44. toolbar.displayMode = .default
  45. toolbar.delegate = self
  46. self.mainWindowController.window?.toolbar = toolbar
  47. self.mainWindowController.window?.titlebarAppearsTransparent = true
  48. }
  49. //MARK: Action
  50. @IBAction func annotationButtonAction(item:NSMenuItem) {
  51. }
  52. @IBAction func leftControllButtonAction(item:NSMenuItem) {
  53. }
  54. @IBAction func editPDFButtonAction(item:NSMenuItem) {
  55. self.delegate?.changeModelAction?(mode: .editPDFToolMode)
  56. }
  57. }
  58. //MARK: NSToolbarDelegate
  59. extension KMMainToolbarController : NSToolbarDelegate ,NSToolbarItemValidation,NSMenuItemValidation{
  60. func toolbar(_ toolbar: NSToolbar, itemForItemIdentifier itemIdentifier: NSToolbarItem.Identifier, willBeInsertedIntoToolbar flag: Bool) -> NSToolbarItem? {
  61. var item = self.toolbarItems[itemIdentifier] as? KMToolbarItem
  62. if item == nil {
  63. item = KMToolbarItem.init(itemIdentifier: itemIdentifier)
  64. self.toolbarItems[itemIdentifier] = item
  65. if itemIdentifier.rawValue == KMLeftControlToolbarItemIdentifier {
  66. let menuItem = NSMenuItem.init(title: "left", action: #selector(leftControllButtonAction), target: self)
  67. item?.toolTip = NSLocalizedString("left", comment: "")
  68. item?.setViewWithSizes(self.leftControlButton)
  69. item?.menuFormRepresentation = menuItem
  70. } else if itemIdentifier.rawValue == KMDocumentAnnotationToolbarItemIdentifier {
  71. let menuItem = NSMenuItem.init(title: "Annotation", action: #selector(annotationButtonAction), target: self)
  72. item?.toolTip = NSLocalizedString("Annotate PDF with highlight, text box and markup tools", comment: "")
  73. item?.setViewWithSizes(self.annotationModelButton)
  74. item?.menuFormRepresentation = menuItem
  75. } else if itemIdentifier.rawValue == KMDocumentPageToolbarItemIdentifier {
  76. let menuItem = NSMenuItem.init(title: "page", action: #selector(leftControllButtonAction), target: self)
  77. item?.setViewWithSizes(self.pageModelButton)
  78. item?.menuFormRepresentation = menuItem
  79. } else if itemIdentifier.rawValue == KMDocumentConversonToolbarItemIdentifier {
  80. let menuItem = NSMenuItem.init(title: "Converson", action: #selector(leftControllButtonAction), target: self)
  81. item?.setViewWithSizes(self.conversionModelButton)
  82. item?.menuFormRepresentation = menuItem
  83. } else if itemIdentifier.rawValue == KMDocumentScanOCRToolbarItemIdentifier {
  84. let menuItem = NSMenuItem.init(title: "scan", action: #selector(leftControllButtonAction), target: self)
  85. item?.setViewWithSizes(self.scanORCModelButton)
  86. item?.menuFormRepresentation = menuItem
  87. } else if itemIdentifier.rawValue == KMDocumentAIToolsToolbarItemIdentifier {
  88. let menuItem = NSMenuItem.init(title: "AI Tools", action: #selector(leftControllButtonAction), target: self)
  89. item?.setViewWithSizes(self.scanORCModelButton)
  90. item?.menuFormRepresentation = menuItem
  91. } else if itemIdentifier.rawValue == KMDocumentEditToolbarItemIdentifier {
  92. let menuItem = NSMenuItem.init(title: "edit", action: #selector(editPDFButtonAction), target: self)
  93. item?.setViewWithSizes(self.editModelButton)
  94. item?.menuFormRepresentation = menuItem
  95. } else if itemIdentifier.rawValue == KMDocumentFillSginToolbarItemIdentifier {
  96. let menuItem = NSMenuItem.init(title: "fillsign", action: #selector(leftControllButtonAction), target: self)
  97. item?.setViewWithSizes(self.signatureModelButton)
  98. item?.menuFormRepresentation = menuItem
  99. }else if itemIdentifier.rawValue == KMDocumentFormToolbarItemIdentifier {
  100. let menuItem = NSMenuItem.init(title: "form", action: #selector(leftControllButtonAction), target: self)
  101. item?.setViewWithSizes(self.formModelButton)
  102. item?.menuFormRepresentation = menuItem
  103. } else if itemIdentifier.rawValue == KMDocumentToolToolbarItemIdentifier {
  104. let menuItem = NSMenuItem.init(title: "tool", action: #selector(leftControllButtonAction), target: self)
  105. item?.setViewWithSizes(self.toolModelButton)
  106. item?.menuFormRepresentation = menuItem
  107. } else if itemIdentifier.rawValue == KMDocumentPrintToolbarItemIdentifier {
  108. let menuItem = NSMenuItem.init(title: "print", action: #selector(leftControllButtonAction), target: self)
  109. item?.setViewWithSizes(self.printModelButton)
  110. item?.menuFormRepresentation = menuItem
  111. } else if itemIdentifier.rawValue == KMDocumentShareToolbarItemIdentifier {
  112. let menuItem = NSMenuItem.init(title: "share", action: #selector(leftControllButtonAction), target: self)
  113. item?.setViewWithSizes(self.shareModelButton)
  114. item?.menuFormRepresentation = menuItem
  115. } else if itemIdentifier.rawValue == KMRightControlToolbarItemIdentifier {
  116. let menuItem = NSMenuItem.init(title: "right", action: #selector(leftControllButtonAction), target: self)
  117. item?.setViewWithSizes(self.rightControlButton)
  118. item?.menuFormRepresentation = menuItem
  119. }
  120. }
  121. if flag == false {
  122. item?.isEnabled = true
  123. }
  124. return item
  125. }
  126. func toolbarDefaultItemIdentifiers(_ toolbar: NSToolbar) -> [NSToolbarItem.Identifier] {
  127. return [NSToolbarItem.Identifier.space,
  128. NSToolbarItem.Identifier(KMLeftControlToolbarItemIdentifier),
  129. NSToolbarItem.Identifier.flexibleSpace,
  130. NSToolbarItem.Identifier(KMDocumentAnnotationToolbarItemIdentifier),
  131. NSToolbarItem.Identifier(KMDocumentPageToolbarItemIdentifier),
  132. NSToolbarItem.Identifier(KMDocumentConversonToolbarItemIdentifier),
  133. NSToolbarItem.Identifier(KMDocumentScanOCRToolbarItemIdentifier),
  134. NSToolbarItem.Identifier(KMDocumentAIToolsToolbarItemIdentifier),
  135. NSToolbarItem.Identifier(KMDocumentEditToolbarItemIdentifier),
  136. NSToolbarItem.Identifier(KMDocumentFormToolbarItemIdentifier),
  137. NSToolbarItem.Identifier(KMDocumentFillSginToolbarItemIdentifier),
  138. NSToolbarItem.Identifier(KMDocumentToolToolbarItemIdentifier),
  139. NSToolbarItem.Identifier.space,
  140. NSToolbarItem.Identifier.flexibleSpace,
  141. NSToolbarItem.Identifier(KMDocumentPrintToolbarItemIdentifier),
  142. NSToolbarItem.Identifier(KMDocumentShareToolbarItemIdentifier),
  143. NSToolbarItem.Identifier(KMRightControlToolbarItemIdentifier),
  144. NSToolbarItem.Identifier.space]
  145. }
  146. func toolbarAllowedItemIdentifiers(_ toolbar: NSToolbar) -> [NSToolbarItem.Identifier] {
  147. return [NSToolbarItem.Identifier(KMLeftControlToolbarItemIdentifier),
  148. NSToolbarItem.Identifier(KMDocumentAnnotationToolbarItemIdentifier),
  149. NSToolbarItem.Identifier(KMDocumentPageToolbarItemIdentifier),
  150. NSToolbarItem.Identifier(KMDocumentConversonToolbarItemIdentifier),
  151. NSToolbarItem.Identifier(KMDocumentScanOCRToolbarItemIdentifier),
  152. NSToolbarItem.Identifier(KMDocumentAIToolsToolbarItemIdentifier),
  153. NSToolbarItem.Identifier(KMDocumentEditToolbarItemIdentifier),
  154. NSToolbarItem.Identifier(KMDocumentFormToolbarItemIdentifier),
  155. NSToolbarItem.Identifier(KMDocumentFillSginToolbarItemIdentifier),
  156. NSToolbarItem.Identifier(KMDocumentToolToolbarItemIdentifier),
  157. NSToolbarItem.Identifier.space,
  158. NSToolbarItem.Identifier.flexibleSpace,
  159. NSToolbarItem.Identifier(KMDocumentPrintToolbarItemIdentifier),
  160. NSToolbarItem.Identifier(KMDocumentShareToolbarItemIdentifier),
  161. NSToolbarItem.Identifier(KMRightControlToolbarItemIdentifier)]
  162. }
  163. func validateToolbarItem(_ item: NSToolbarItem) -> Bool {
  164. return true
  165. }
  166. func validateMenuItem(_ menuItem: NSMenuItem) -> Bool {
  167. return true
  168. }
  169. }