123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643 |
- //
- // KMPDFEditToolbar.swift
- // PDF Reader Pro
- //
- // Created by tangchao on 2023/5/4.
- //
- import Cocoa
- enum KMPageEditType: Int {
- case none = 0
- case pageRange = 1
- case leftRotate
- case rightRotate
- case insert
- case extract
- case replace
- case split
- case reverse
- case copy
- case delete
-
- case zoomOut
- case zoomIn
-
- case paste = 100
-
- // static let none: KMPageEditType = KMPageEditType(rawValue: 0)!
- // static let paste: KMPageEditType = KMPageEditType(rawValue: 100)!
-
- static var insert_files: Int {
- get {
- return self.insert.rawValue + 1000
- }
- }
- static var insert_blank_page: Int {
- get {
- return self.insert.rawValue + 1001
- }
- }
- static var insert_custom_page: Int {
- get {
- return self.insert.rawValue + 1002
- }
- }
-
- static var extract_selected_pages: Int {
- get {
- return self.extract.rawValue + 2000
- }
- }
-
- static var split_selected_pages: Int {
- get {
- return self.split.rawValue + 3000
- }
- }
- }
- class KMPDFEditToolbar: NSView {
- private var toolBar_ = KMToolbarView.init(identifier: "KMPageEditIdentifier")
- var toolBar: KMToolbarView {
- get {
- return self.toolBar_
- }
- }
-
- private var zoomOutButton_: NSButton?
- private var zoomInButton_: NSButton?
-
- open var zoomOutButton: NSButton? {
- get {
- return self.zoomOutButton_
- }
- }
- open var zoomInButton: NSButton? {
- get {
- return self.zoomInButton_
- }
- }
-
- private var pageRangeView_: KMDesignSelect?
- open var pageRangeView: KMDesignSelect? {
- get {
- return self.pageRangeView_
- }
- }
- private var pageRangeViewItems = [KMTools.pageRangeTypeString(pageRange: .all),
- KMTools.pageRangeTypeString(pageRange: .odd),
- KMTools.pageRangeTypeString(pageRange: .even),
- KMTools.pageRangeTypeString(pageRange: .horizontal),
- KMTools.pageRangeTypeString(pageRange: .vertical),
- KMTools.pageRangeTypeString(pageRange: .custom)]
-
- var itemClick: KMItemClickBlock<KMPDFEditToolbar>?
- var pageRangeitemClick: ((KMPageRange)->Void)?
- var pageRangeValueDidChange: KMValueDidChangeBlock?
-
- lazy var insertItemStrings: [String] = {
- return [NSLocalizedString("Blank Page", comment: ""),
- NSLocalizedString("Blank Page - Custom...", comment: ""),
- NSLocalizedString("From PDF", comment: "")]
- }()
-
- private weak var popover: NSPopover?
-
- override init(frame frameRect: NSRect) {
- super.init(frame: frameRect)
-
- self.initDefaultValue()
- self.initSubViews()
- }
-
- required init?(coder: NSCoder) {
- super.init(coder: coder)
-
- self.initDefaultValue()
- self.initSubViews()
- }
-
- public func initDefaultValue() {
-
- }
-
- public func initSubViews() {
- self.addSubview(self.toolBar)
- self.toolBar.frame = self.bounds
- self.toolBar.autoresizingMask = [.width, .height]
- self.toolBar.delegate = self
-
- // let rightItemView = self.rightItemView
- // self.addSubview(rightItemView)
- // rightItemView.frame = NSMakeRect(NSWidth(self.frame)-80, 0, 80, NSHeight(self.frame))
- // rightItemView.autoresizingMask = [.minXMargin, .height]
- }
-
- // MARK: - Publick Methods
-
- public func setPageRangeString(_ string: String) {
- self.pageRangeView?.stringValue = string
- self.pageRangeView?.editable = true
- }
-
- public func getItem(for itemId: String) -> KMToolbarItemView? {
- return self.toolBar.itemForItemIdentifier(itemId)
- }
-
- public func selectItem(for itemId: String) {
- self.getItem(for: itemId)?.isSelected = true
- }
-
- public func unSelectItem(for itemId: String) {
- self.getItem(for: itemId)?.isSelected = false
- }
-
- // MARK: - Actions
-
- @objc private func zoomOutButtonAction() {
- guard let callback = self.itemClick else {
- return
- }
- callback(self, KMPageEditType.zoomOut.rawValue)
- }
-
- @objc private func zoomInButtonAction() {
- guard let callback = self.itemClick else {
- return
- }
- callback(self, KMPageEditType.zoomIn.rawValue)
- }
-
- // MARK: toolBar 菜单事件
-
- @objc func pageRangeMenuAction(sender: KMToolbarClickButton) {
- if let subMenu = (sender.clickObject as? KMToolbarItemView)?.menuFormRepresentation?.submenu {
- subMenu.popUp(positioning: nil, at: sender.frame.origin, in: sender.superview)
- }
- }
-
- @objc private func _pageRangeAction(sender: NSMenuItem) {
- guard let type = KMPageRange(rawValue: sender.tag) else {
- return
- }
- guard let callback = self.pageRangeitemClick else {
- return
- }
- callback(type)
- }
-
- @objc func leftRotateMenuAction(sender: KMToolbarClickButton?) {
- guard let callback = self.itemClick else {
- return
- }
- callback(self, KMPageEditType.leftRotate.rawValue)
- }
-
- @objc func rightRotateMenuAction(sender: KMToolbarClickButton?) {
- guard let callback = self.itemClick else {
- return
- }
- callback(self, KMPageEditType.rightRotate.rawValue)
- }
-
- @objc func insertMenuAction(sender: KMToolbarClickButton) {
- guard let callback = self.itemClick else {
- return
- }
- callback(self, KMPageEditType.insert.rawValue)
-
- if let _popover = self.popover, _popover.isShown {
- self.popover?.close()
- self.popover = nil
- return
- }
-
- let vc: KMHomePopViewController = KMHomePopViewController().initWithPopViewDataArr(self.insertItemStrings)
- let popover: NSPopover = NSPopover.init()
- self.popover = popover
- popover.contentViewController = vc
- popover.animates = true
- popover.behavior = .semitransient
- popover.setValue(true, forKey: "shouldHideAnchor")
- popover.show(relativeTo: CGRect(x: sender.bounds.origin.x, y: 10, width: sender.bounds.size.width, height: sender.bounds.size.height), of: sender, preferredEdge: .maxY)
- vc.downCallback = { [weak self] downEntered, count in
- self?.popover?.close()
- self?.popover = nil
-
- if (!downEntered) {
- return
- }
- guard let index = self?.insertItemStrings.firstIndex(of: count) else {
- return
- }
- if (index == 0) {
- self?.item_insertBlankPage(sender: nil)
- } else if (index == 1) {
- self?.item_insertCustomPage(sender: nil)
- } else if (index == 2) {
- self?.item_insertFile(sender: nil)
- }
- }
- }
-
- @objc func extractMenuAction(sender: KMToolbarClickButton?) {
- // guard let callback = self.itemClick else {
- // return
- // }
- // callback(self, KMPageEditType.insert.rawValue)
-
- if let _popover = self.popover, _popover.isShown {
- self.popover?.close()
- self.popover = nil
- return
- }
-
- let array = [NSLocalizedString("Extract selected pages", comment: ""), NSLocalizedString("Extract", comment: "")]
- let vc: KMHomePopViewController = KMHomePopViewController().initWithPopViewDataArr(array)
- let popover: NSPopover = NSPopover.init()
- self.popover = popover
- popover.contentViewController = vc
- popover.animates = true
- popover.behavior = .semitransient
- popover.setValue(true, forKey: "shouldHideAnchor")
- if let data = sender {
- popover.show(relativeTo: CGRect(x: sender?.bounds.origin.x ?? 0, y: 10, width: sender?.bounds.size.width ?? 0, height: sender?.bounds.size.height ?? 0), of: data, preferredEdge: .maxY)
- }
- vc.downCallback = { [weak self] downEntered, count in
- self?.popover?.close()
- self?.popover = nil
-
- if (!downEntered) {
- return
- }
- guard let index = array.firstIndex(of: count) else {
- return
- }
- if (index == 0) {
- guard let callback = self?.itemClick else {
- return
- }
- callback(self, KMPageEditType.extract_selected_pages)
- } else if (index == 1) {
- guard let callback = self?.itemClick else {
- return
- }
- callback(self, KMPageEditType.extract.rawValue)
- }
- }
- }
-
- @objc private func _extractMenuItemAction(_ sender: NSMenuItem) {
- if (sender.tag == 1) {
- guard let callback = self.itemClick else {
- return
- }
- callback(self, KMPageEditType.extract_selected_pages)
- } else if (sender.tag == 2) {
- guard let callback = self.itemClick else {
- return
- }
- callback(self, KMPageEditType.extract.rawValue)
- }
- FMTrackEventManager.defaultManager.trackEvent(event: "SubTbr_PageEdit", withProperties: ["SubTbr_Btn": "Btn_SubTbr_PageEdit_Extract"])
- }
-
- @objc func replaceMenuAction(sender: KMToolbarClickButton?) {
- guard let callback = self.itemClick else {
- return
- }
- callback(self, KMPageEditType.replace.rawValue)
- }
-
- @objc func splitMenuAction(sender: KMToolbarClickButton) {
- if let subMenu = (sender.clickObject as? KMToolbarItemView)?.menuFormRepresentation?.submenu {
- subMenu.popUp(positioning: nil, at: sender.frame.origin, in: sender.superview)
- }
- }
-
- @objc func reverseMenuAction(sender: KMToolbarClickButton) {
- guard let callback = self.itemClick else {
- return
- }
- callback(self, KMPageEditType.reverse.rawValue)
- }
-
- @objc func copyMenuAction(sender: KMToolbarClickButton) {
- guard let callback = self.itemClick else {
- return
- }
- callback(self, KMPageEditType.copy.rawValue)
- }
-
- @objc func pasteMenuAction(sender: KMToolbarClickButton) {
- guard let callback = self.itemClick else {
- return
- }
- callback(self, KMPageEditType.paste.rawValue)
- }
-
- @objc func deleteMenuAction(sender: KMToolbarClickButton) {
- guard let callback = self.itemClick else {
- return
- }
- callback(self, KMPageEditType.delete.rawValue)
- }
-
- @objc func item_insertFile(sender: NSMenuItem?) {
- guard let callback = self.itemClick else {
- return
- }
- callback(self, KMPageEditType.insert_files)
- FMTrackEventManager.defaultManager.trackEvent(event: "SubTbr_PageEdit", withProperties: ["SubTbr_Btn": "Btn_SubTbr_PageEdit_Insert"])
- }
-
- @objc func item_insertBlankPage(sender: NSMenuItem?) {
- guard let callback = self.itemClick else {
- return
- }
- callback(self, KMPageEditType.insert_blank_page)
- FMTrackEventManager.defaultManager.trackEvent(event: "SubTbr_PageEdit", withProperties: ["SubTbr_Btn": "Btn_SubTbr_PageEdit_Insert"])
- }
-
- @objc func item_insertCustomPage(sender: NSMenuItem?) {
- guard let callback = self.itemClick else {
- return
- }
- callback(self, KMPageEditType.insert_custom_page)
- FMTrackEventManager.defaultManager.trackEvent(event: "SubTbr_PageEdit", withProperties: ["SubTbr_Btn": "Btn_SubTbr_PageEdit_Insert"])
- }
-
- @objc private func _splitAction(sender: NSMenuItem) {
- if (sender.tag == 1) {
- guard let callback = self.itemClick else {
- return
- }
- callback(self, KMPageEditType.split.rawValue)
- return
- }
- guard let callback = self.itemClick else {
- return
- }
- callback(self, KMPageEditType.split_selected_pages)
- FMTrackEventManager.defaultManager.trackEvent(event: "SubTbr_PageEdit", withProperties: ["SubTbr_Btn": "Btn_SubTbr_PageEdit_Split"])
- }
-
- private lazy var rightItemView: NSView = {
- let view = NSView()
-
- let size: CGFloat = 28
- let y: CGFloat = 6
-
- let zoomInButton = NSButton()
- view.addSubview(zoomInButton)
- zoomInButton.frame = NSMakeRect(0, y, size, size)
- zoomInButton.isBordered = false
- zoomInButton.image = NSImage(named: "KMImageNamePageEditZoomIn")
- zoomInButton.target = self
- zoomInButton.action = #selector(zoomInButtonAction)
- self.zoomInButton_ = zoomInButton
-
- let zoomOutButton = NSButton()
- view.addSubview(zoomOutButton)
- zoomOutButton.frame = NSMakeRect(size+7, y, size, size)
- zoomOutButton.isBordered = false
- zoomOutButton.image = NSImage(named: "KMImageNamePageEditZoomOut")
- zoomOutButton.target = self
- zoomOutButton.action = #selector(zoomOutButtonAction)
- self.zoomOutButton_ = zoomOutButton
-
- return view
- }()
- }
- // MARK: - KMNewToolbarDelegate
- extension KMPDFEditToolbar: KMToolbarViewDelegate {
- func toolbarDefaultItemIdentifiers(_ toolbar: KMToolbarView) -> [String] {
- return [KMToolbarPageEditPageRangeItemIdentifier,
- // KMToolbarPageEditLeftRotateItemIdentifier,
- // KMToolbarPageEditRightRotateItemIdentifier,
- KMToolbarDividerItemIdentifier,
- KMToolbarPageEditInsetItemIdentifier,
- KMToolbarPageEditReplaceItemIdentifier,
- KMToolbarPageEditExtractItemIdentifier,
- KMToolbarPageEditSplitItemIdentifier,
- KMToolbarPageEditRotateItemIdentifier,
- KMToolbarPageEditReverseItemIdentifier,
- KMToolbarPageEditCopyItemIdentifier,
- KMToolbarPageEditPasteItemIdentifier,
- KMToolbarPageEditDeleteItemIdentifier]
- }
-
-
- func toolbar(_ toolbar: KMToolbarView, itemFor identifier: String) -> KMToolbarItemView {
- let item: KMToolbarItemView? = KMToolbarCustomItemView(itemIdentifier: identifier)
- if (identifier == KMToolbarPageEditPageRangeItemIdentifier) {
- item?.image = NSImage(named: KMImageNameUXIconSubtoolbarPageRange)
- item?.selectedImage = NSImage(named: "KMImageNameUXIconSubtoolbarPageRangeHighlight")
- item?.alternateImage = NSImage(named: "KMImageNameUXIconSubtoolbarPageRangeHighlight")
- item?.target = self
- item?.btnTag = KMPageEditType.pageRange.rawValue
- item?.titleName = NSLocalizedString("Page Range", comment: "")
- item?.boxImagePosition = .imageExpandLeft
- item?.needExpandAction = true
-
- let menuItem = NSMenuItem.init(title: NSLocalizedString("Page Range", comment: ""), action: #selector(pageRangeMenuAction), target: self)
- let subMenu = NSMenu()
- subMenu.addItem(title: NSLocalizedString("Odd Pages Only", comment: ""), action: #selector(_pageRangeAction), target: self, tag: KMPageRange.odd.rawValue)
- subMenu.addItem(title: NSLocalizedString("Even Pages Only", comment: ""), action: #selector(_pageRangeAction), target: self, tag: KMPageRange.even.rawValue)
- subMenu.addItem(title: NSLocalizedString("Portrait pages", comment: ""), action: #selector(_pageRangeAction), target: self, tag: KMPageRange.vertical.rawValue)
- subMenu.addItem(title: NSLocalizedString("Landscape pages", comment: ""), action: #selector(_pageRangeAction), target: self, tag: KMPageRange.horizontal.rawValue)
- subMenu.addItem(title: NSLocalizedString("All Pages", comment: ""), action: #selector(_pageRangeAction), target: self, tag: KMPageRange.all.rawValue)
- subMenu.addItem(.separator())
- subMenu.addItem(title: NSLocalizedString("Customize", comment: ""), action: #selector(_pageRangeAction), target: self, tag: KMPageRange.custom.rawValue)
- menuItem.submenu = subMenu
- item?.menuFormRepresentation = menuItem
- } else if (identifier == KMToolbarPageEditRotateItemIdentifier) {
- item?.image = NSImage(named: KMImageNameUXIconSubtoolbarPageRotate)
- item?.selectedImage = NSImage(named: "KMImageNameUXIconSubtoolbarPageRotateHighlight")
- item?.alternateImage = NSImage(named: "KMImageNameUXIconSubtoolbarPageRotateHighlight")
- item?.target = self
- item?.btnTag = KMPageEditType.rightRotate.rawValue
- item?.toolTip = NSLocalizedString("Rotate", comment: "")
- item?.titleName = NSLocalizedString("Rotate", comment: "")
- item?.boxImagePosition = .imageLeft
- item?.btnAction = #selector(rightRotateMenuAction)
-
- let menuItem = NSMenuItem.init(title: NSLocalizedString("Rotate", comment: ""), action: #selector(rightRotateMenuAction), target: self)
- item?.menuFormRepresentation = menuItem
- } else if (identifier == KMToolbarPageEditLeftRotateItemIdentifier) {
- item?.image = NSImage(named: "KMImageNameMainToolPageLeftRotate")
- item?.selectedImage = NSImage(named: "KMImageNameMainToolPageLeftRotateHighlight")
- item?.alternateImage = NSImage(named: "KMImageNameMainToolPageLeftRotateHighlight")
- item?.target = self
- item?.btnTag = KMPageEditType.leftRotate.rawValue
- item?.toolTip = NSLocalizedString("Rotate Left", comment: "")
- item?.titleName = NSLocalizedString("", comment: "")
- item?.boxImagePosition = .imageLeft
- item?.btnAction = #selector(leftRotateMenuAction)
-
- let menuItem = NSMenuItem.init(title: NSLocalizedString("Rotate Left", comment: ""), action: #selector(leftRotateMenuAction), target: self)
- item?.menuFormRepresentation = menuItem
- } else if (identifier == KMToolbarPageEditRightRotateItemIdentifier) {
- item?.image = NSImage(named: "KMImageNameMainToolPageRightRotate")
- item?.selectedImage = NSImage(named: "KMImageNameMainToolPageRightRotateHighlight")
- item?.alternateImage = NSImage(named: "KMImageNameMainToolPageRightRotateHighlight")
- item?.target = self
- item?.btnTag = KMPageEditType.rightRotate.rawValue
- item?.toolTip = NSLocalizedString("Rotate Right", comment: "")
- item?.titleName = NSLocalizedString("", comment: "")
- item?.boxImagePosition = .imageLeft
- item?.btnAction = #selector(rightRotateMenuAction)
-
- let menuItem = NSMenuItem.init(title: NSLocalizedString("Rotate Right", comment: ""), action: #selector(rightRotateMenuAction), target: self)
- item?.menuFormRepresentation = menuItem
- } else if (identifier == KMToolbarPageEditInsetItemIdentifier) {
- item?.image = NSImage(named: KMImageNameUXIconSubtoolbarPageInsert)
- item?.selectedImage = NSImage(named: "KMImageNameUXIconSubtoolbarPageInsertHighlight")
- item?.alternateImage = NSImage(named: "KMImageNameUXIconSubtoolbarPageInsertHighlight")
- item?.target = self
- item?.btnTag = KMPageEditType.insert.rawValue
- // item?.toolTip = NSLocalizedString("Inserting pages into an existing PDF", comment: "")
- item?.titleName = NSLocalizedString("Insert", comment: "")
- item?.boxImagePosition = .imageExpandLeft
- // item?.btnAction = #selector(insertMenuAction)
- item?.needExpandAction = true
-
- let menuItem = NSMenuItem.init(title: NSLocalizedString("Insert", comment: ""), action: nil, target: self)
- let subMenu = NSMenu()
- menuItem.submenu = subMenu
- _ = subMenu.addItem(title: self.insertItemStrings[0], action: #selector(item_insertBlankPage) , target: self)
- _ = subMenu.addItem(title: self.insertItemStrings[1], action: #selector(item_insertCustomPage) , target: self)
- _ = subMenu.addItem(title: self.insertItemStrings[2], action: #selector(item_insertFile) , target: self)
- item?.menuFormRepresentation = menuItem
- } else if (identifier == KMToolbarPageEditExtractItemIdentifier) {
- item?.image = NSImage(named: KMImageNameUXIconSubtoolbarPageExtract)
- item?.selectedImage = NSImage(named: "KMImageNameUXIconSubtoolbarPageExtractHighlight")
- item?.alternateImage = NSImage(named: "KMImageNameUXIconSubtoolbarPageExtractHighlight")
- item?.target = self
- item?.btnTag = KMPageEditType.extract.rawValue
- // item?.toolTip = NSLocalizedString("Exctract selected pages", comment: "")
- item?.titleName = NSLocalizedString("Extract", comment: "")
- item?.boxImagePosition = .imageExpandLeft
- // item?.btnAction = #selector(extractMenuAction)
- item?.needExpandAction = true
-
- let menuItem = NSMenuItem.init(title: NSLocalizedString("Extract", comment: ""), action: nil, target: self)
- let subMenu = NSMenu()
- menuItem.submenu = subMenu
- subMenu.addItem(title: NSLocalizedString("Extract selected pages", comment: ""), action: #selector(_extractMenuItemAction) , target: self, tag: 1)
- subMenu.addItem(title: NSLocalizedString("Extract", comment: ""), action: #selector(_extractMenuItemAction) , target: self, tag: 2)
-
- item?.menuFormRepresentation = menuItem
- } else if (identifier == KMToolbarPageEditReplaceItemIdentifier) {
- item?.image = NSImage(named: KMImageNameToolbarReplace)
- item?.selectedImage = NSImage(named: "KMImageNameToolbarReplaceHighlight")
- item?.alternateImage = NSImage(named: "KMImageNameToolbarReplaceHighlight")
- item?.target = self
- item?.btnTag = KMPageEditType.replace.rawValue
- item?.toolTip = NSLocalizedString("Replace", comment: "")
- item?.titleName = NSLocalizedString("Replace", comment: "")
- item?.boxImagePosition = .imageLeft
- item?.btnAction = #selector(replaceMenuAction)
-
- let menuItem = NSMenuItem.init(title: NSLocalizedString("Replace", comment: ""), action: #selector(replaceMenuAction), target: self)
- item?.menuFormRepresentation = menuItem
- } else if (identifier == KMToolbarPageEditSplitItemIdentifier) {
- item?.image = NSImage(named: KMImageNameUXIconSubtoolbarPageSplit)
- item?.selectedImage = NSImage(named: "KMImageNameUXIconSubtoolbarPageSplitHighlight")
- item?.alternateImage = NSImage(named: "KMImageNameUXIconSubtoolbarPageSplitHighlight")
- item?.target = self
- item?.btnTag = KMPageEditType.split.rawValue
- // item?.toolTip = NSLocalizedString("Split and save selected PDF pages as a new separate document", comment: "")
- item?.titleName = NSLocalizedString("Split", comment: "")
- item?.boxImagePosition = .imageExpandLeft
- item?.needExpandAction = true
- // item?.btnAction = #selector(splitMenuAction)
-
- let menuItem = NSMenuItem.init(title: NSLocalizedString("Split", comment: ""), action: nil, target: self)
- let subMenu = NSMenu()
- subMenu.addItem(title: NSLocalizedString("Split selected pages", comment: ""), action: #selector(_splitAction), target: self, tag: 0)
- subMenu.addItem(title: NSLocalizedString("Split", comment: ""), action: #selector(_splitAction), target: self, tag: 1)
- menuItem.submenu = subMenu
- item?.menuFormRepresentation = menuItem
- } else if (identifier == KMToolbarPageEditReverseItemIdentifier) {
- item?.image = NSImage(named: KMImageNameUXIconSubtoolbarPageReverse)
- item?.selectedImage = NSImage(named: "KMImageNameUXIconSubtoolbarPageReverseHighlight")
- item?.alternateImage = NSImage(named: "KMImageNameUXIconSubtoolbarPageReverseHighlight")
- item?.target = self
- item?.btnTag = KMPageEditType.reverse.rawValue
- item?.toolTip = NSLocalizedString("Reverse", comment: "")
- item?.titleName = NSLocalizedString("Reverse", comment: "")
- item?.boxImagePosition = .imageLeft
- item?.btnAction = #selector(reverseMenuAction)
-
- let menuItem = NSMenuItem.init(title: NSLocalizedString("Reverse", comment: ""), action: #selector(reverseMenuAction), target: self)
- item?.menuFormRepresentation = menuItem
- } else if (identifier == KMToolbarPageEditCopyItemIdentifier) {
- item?.image = NSImage(named: KMImageNameUXIconSubtoolbarPageCopy)
- item?.selectedImage = NSImage(named: "KMImageNameUXIconSubtoolbarPageCopyHighlight")
- item?.alternateImage = NSImage(named: "KMImageNameUXIconSubtoolbarPageCopyHighlight")
- item?.target = self
- item?.btnTag = KMPageEditType.delete.rawValue
- item?.toolTip = NSLocalizedString("Copy", comment: "")
- item?.titleName = NSLocalizedString("Copy", comment: "")
- item?.boxImagePosition = .imageLeft
- item?.btnAction = #selector(copyMenuAction)
-
- let menuItem = NSMenuItem.init(title: NSLocalizedString("Copy", comment: ""), action: #selector(copyMenuAction), target: self)
- item?.menuFormRepresentation = menuItem
- } else if (identifier == KMToolbarPageEditPasteItemIdentifier) {
- item?.image = NSImage(named: KMImageNameUXIconSubtoolbarPagePaste)
- item?.selectedImage = NSImage(named: "KMImageNameUXIconSubtoolbarPagePasteHighlight")
- item?.alternateImage = NSImage(named: "KMImageNameUXIconSubtoolbarPagePasteHighlight")
- item?.target = self
- item?.btnTag = KMPageEditType.delete.rawValue
- item?.toolTip = NSLocalizedString("Paste", comment: "")
- item?.titleName = NSLocalizedString("Paste", comment: "")
- item?.boxImagePosition = .imageLeft
- item?.btnAction = #selector(pasteMenuAction)
-
- let menuItem = NSMenuItem.init(title: NSLocalizedString("Paste", comment: ""), action: #selector(pasteMenuAction), target: self)
- item?.menuFormRepresentation = menuItem
- } else if (identifier == KMToolbarPageEditDeleteItemIdentifier) {
- item?.image = NSImage(named: KMImageNameUXIconSubtoolbarPageDelete)
- item?.selectedImage = NSImage(named: "KMImageNameUXIconSubtoolbarPageDeleteHighlight")
- item?.alternateImage = NSImage(named: "KMImageNameUXIconSubtoolbarPageDeleteHighlight")
- item?.target = self
- item?.btnTag = KMPageEditType.delete.rawValue
- item?.toolTip = NSLocalizedString("Delete", comment: "")
- item?.titleName = NSLocalizedString("Delete", comment: "")
- item?.boxImagePosition = .imageLeft
- item?.btnAction = #selector(deleteMenuAction)
-
- let menuItem = NSMenuItem.init(title: NSLocalizedString("Delete", comment: ""), action: #selector(deleteMenuAction), target: self)
- item?.menuFormRepresentation = menuItem
- }
-
- return item!
- }
- }
- // MARK: - KMSelectPopButtonDelegate
- extension KMPDFEditToolbar: KMSelectPopButtonDelegate {
- func km_comboBoxSelectionDidChange(_ obj: KMDesignSelect) {
- guard let callback = self.itemClick else {
- return
- }
- callback(self, KMPageEditType.pageRange.rawValue)
- }
-
- func km_controlTextDidChange(_ obj: KMDesignSelect) {
-
- }
-
- func km_controlTextDidEndEditing(_ obj: KMDesignSelect) {
- guard let callback = self.pageRangeValueDidChange else {
- return
- }
- callback(self.pageRangeView?.stringValue, nil)
- }
- }
|