1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093109410951096109710981099110011011102110311041105110611071108110911101111111211131114111511161117111811191120112111221123112411251126112711281129113011311132113311341135113611371138113911401141114211431144114511461147114811491150115111521153115411551156115711581159116011611162116311641165116611671168116911701171117211731174117511761177117811791180118111821183118411851186118711881189119011911192119311941195119611971198119912001201120212031204120512061207120812091210121112121213121412151216121712181219122012211222122312241225122612271228122912301231123212331234123512361237123812391240124112421243124412451246124712481249125012511252125312541255125612571258125912601261126212631264126512661267126812691270127112721273127412751276127712781279128012811282128312841285128612871288128912901291129212931294129512961297 |
- //
- // KMPDFToolbarController.swift
- // PDF Reader Pro
- //
- // Created by Niehaoyu on 2024/10/8.
- //
- import Cocoa
- import KMComponentLibrary
- @objc protocol KMPDFToolbarControllerDelegate: AnyObject {
-
- //ViewTools视图工具发生变化时调用
- @objc optional func kmPDFToolbarControllerDidViewToolsChanged(_ controller: KMPDFToolbarController)
-
- //一级工具栏状态发生变化时调用
- @objc optional func kmPDFToolbarControllerDidToolModeChanged(_ controller: KMPDFToolbarController)
-
- //非一级工具栏按钮点击调用
- @objc optional func kmPDFToolbarControllerDidToolbarItemClicked(_ controller: KMPDFToolbarController, _ itemIdentifier: String)
-
- //结束页面编辑
- @objc optional func kmPDFToolbarControllerDidExitPageEditMode(_ controller: KMPDFToolbarController)
-
- //ComponentSelect中文字编辑回调
- @objc optional func kmPDFToolbarControllerDidSelectTextDidBeginEditing(_ controller: KMPDFToolbarController, _ view: ComponentSelect)
- @objc optional func kmPDFToolbarControllerDidSelectTextDidChange(_ controller: KMPDFToolbarController, _ view: ComponentSelect)
- @objc optional func kmPDFToolbarControllerDidSelectTextDidEndEditing(_ controller: KMPDFToolbarController, _ view: ComponentSelect)
-
-
- }
- class KMPDFToolbarController: NSViewController {
-
- @IBOutlet var contendBox: NSBox!
-
- @IBOutlet var mainToolbarContendView: NSView!
-
- @IBOutlet var leftToolsView: NSView!
- @IBOutlet var leftViewButton: ComponentButton!
- @IBOutlet var pageButton: ComponentButton!
- @IBOutlet var toolsView: ComponentDropdownTool!
- @IBOutlet var dividerView: ComponentDivider!
- @IBOutlet var selectZoom: ComponentSelectZoom!
-
- @IBOutlet var tabsContendView: NSView!
- @IBOutlet var tabsScrollView: NSScrollView!
-
- @IBOutlet var tabsMoreButton: ComponentButton!
-
- @IBOutlet var rightToolsView: NSView!
-
- @IBOutlet var secondContendView: NSView!
-
- @IBOutlet var tabsLeftConst: NSLayoutConstraint!
- @IBOutlet var tabsRightConst: NSLayoutConstraint!
-
- @IBOutlet var rightViewWidthConst: NSLayoutConstraint!
-
- var scrollDocumentView: NSView = NSView.init()
-
- var tabsView: ComponentTabs!
-
- //MARK: -自定义工具栏
- private var customRightGroupView: ComponentGroup!
- private var customRightItems: [ComponentMenuitemProperty] = []
- private var undoRedo_Menuitem_Property = ComponentMenuitemProperty(type: .normal, multipleSelect: true, itemSelected: false, text: KMLocalizedString("Undo / Redo"), identifier: "undoRedo_Menuitem_PropertyKey")
- private var save_Menuitem_Property = ComponentMenuitemProperty(type: .normal, multipleSelect: true, itemSelected: false, text: KMLocalizedString("Save"), identifier: "save_Menuitem_PropertyKey")
-
- private var fileInfo_Menuitem_Property = ComponentMenuitemProperty(type: .normal, multipleSelect: true, itemSelected: false, text: KMLocalizedString("File Info"), identifier: "fileInfo_Menuitem_PropertyKey")
- private var batch_Menuitem_Property = ComponentMenuitemProperty(type: .normal, multipleSelect: true, itemSelected: false, text: KMLocalizedString("Batch"), identifier: "batch_Menuitem_PropertyKey")
- private var tts_Menuitem_Property = ComponentMenuitemProperty(type: .normal, multipleSelect: true, itemSelected: false, text: KMLocalizedString("TTS"), identifier: "tts_Menuitem_PropertyKey")
- private var ppt_Menuitem_Property = ComponentMenuitemProperty(type: .normal, multipleSelect: true, itemSelected: false, text: KMLocalizedString("Slide Show"), identifier: "ppt_Menuitem_PropertyKey")
- private var print_Menuitem_Property = ComponentMenuitemProperty(type: .normal, multipleSelect: true, itemSelected: false, text: KMLocalizedString("Print"), identifier: "print_Menuitem_PropertyKey")
- private var share_Menuitem_Property = ComponentMenuitemProperty(type: .normal, multipleSelect: true, itemSelected: false, text: KMLocalizedString("Share"), identifier: "share_Menuitem_PropertyKey")
-
- //MARK: -更多Tabs
- private var moreTabsItems: [ComponentMenuitemProperty] = []
- private var markup_Menuitem_Property = ComponentMenuitemProperty(type: .normal, itemSelected: false, text: KMLocalizedString("Markup"), identifier: "markup_Menuitem_PropertyKey")
- private var edit_Menuitem_Property = ComponentMenuitemProperty(type: .normal, itemSelected: false, text: KMLocalizedString("Edit"), identifier: "markup_Menuitem_PropertyKey")
- private var form_Menuitem_Property = ComponentMenuitemProperty(type: .normal, itemSelected: false, text: KMLocalizedString("Form"), identifier: "markup_Menuitem_PropertyKey")
- private var fill_Menuitem_Property = ComponentMenuitemProperty(type: .normal, itemSelected: false, text: KMLocalizedString("Fill"), identifier: "markup_Menuitem_PropertyKey")
- private var convert_Menuitem_Property = ComponentMenuitemProperty(type: .normal, itemSelected: false, text: KMLocalizedString("Convert"), identifier: "markup_Menuitem_PropertyKey")
- private var protect_Menuitem_Property = ComponentMenuitemProperty(type: .normal, itemSelected: false, text: KMLocalizedString("Protect"), identifier: "markup_Menuitem_PropertyKey")
- private var tools_Menuitem_Property = ComponentMenuitemProperty(type: .normal, itemSelected: false, text: KMLocalizedString("Tools"), identifier: "markup_Menuitem_PropertyKey")
-
- var pdfView: CPDFListView?
- var viewManager: KMPDFViewManager?
- var toolbarManager: KMPDFToolbarManager?
-
- //MARK: -View
- var secondToolBar: KMPDFSecToolbarController = KMPDFSecToolbarController.init()
-
- var redactToolbar: KMRedactToolbarController = KMRedactToolbarController.init()
-
- weak open var delegate: KMPDFToolbarControllerDelegate?
-
- override func viewWillLayout() {
- super.viewWillLayout()
-
- refreshTabsScrollViewUI()
- }
-
- override func viewDidLayout() {
- super.viewDidLayout()
-
- refreshTabsScrollViewUI()
-
- refreshTabsScrollViewVisiableRect()
- }
-
- override func viewDidAppear() {
- super.viewDidAppear()
-
- refreshTabsScrollViewUI()
-
- }
-
- override func viewDidLoad() {
- super.viewDidLoad()
- // Do view setup here.
-
- contendBox.fillColor = ComponentLibrary.shared.getComponentColorFromKey("colorBg/layout-middle")
-
- leftToolsView.wantsLayer = true
- leftToolsView.layer?.backgroundColor = contendBox.fillColor.cgColor
-
- rightToolsView.wantsLayer = true
- rightToolsView.layer?.backgroundColor = contendBox.fillColor.cgColor
-
- tabsContendView.wantsLayer = true
- tabsContendView.layer?.backgroundColor = contendBox.fillColor.cgColor
-
- tabsMoreButton.superview?.wantsLayer = true
- tabsMoreButton.superview?.layer?.backgroundColor = contendBox.fillColor.cgColor
-
- tabsView = ComponentTabs.init()
- tabsView.frame = CGRectMake(0, 0, 446, 40)
-
- scrollDocumentView.wantsLayer = true
- tabsScrollView.documentView = scrollDocumentView
-
- setUpData()
-
- NotificationCenter.default.addObserver(self, selector: #selector(imageColorChangedNoti), name: toolbarImageColorChangedNotificationName, object: nil)
- }
-
- func setUpData() {
- setUpProperty()
-
- setUpRightViews()
-
- setupSecondToolbar()
-
- reloadData()
- }
-
- func setUpProperty() {
- guard let toolbarManager = self.toolbarManager else {
- return
- }
- leftViewButton.properties = toolbarManager.viewProperty
- leftViewButton.setTarget(self, action: #selector(buttonClicked(_:)))
-
- pageButton.properties = toolbarManager.pageProperty
- pageButton.setTarget(self, action: #selector(buttonClicked(_:)))
-
- dividerView.properties = ComponentDividerProperty(type: .vertical, dash: false)
-
- toolsView.properties = toolbarManager.toolsProperty
- toolsView.delegate = self
-
- selectZoom.properties = toolbarManager.selectZoomProperty
- selectZoom.delegate = self
-
- tabsView.updateItemProperty([toolbarManager.markupMode_Property,
- toolbarManager.editMode_Property,
- toolbarManager.formMode_Property,
- toolbarManager.fillMode_Property,
- toolbarManager.convertMode_Property,
- toolbarManager.protectMode_Property,
- toolbarManager.toolsMode_Property])
- tabsView.delegate = self
-
- scrollDocumentView.frame = CGRectMake(0, 0, tabsView.viewWidth, 28)
-
- tabsView.frame = scrollDocumentView.bounds
- tabsView.autoresizingMask = [.width, .height]
-
- scrollDocumentView.addSubview(tabsView)
-
- tabsMoreButton.properties = ComponentButtonProperty(type: .text_gray,
- size: .xs,
- onlyIcon: true,
- icon: NSImage(named: "toolbar_more"))
- tabsMoreButton.setTarget(self, action: #selector(tabsMoreButtonClicked(_:)))
-
- customRightItems = [undoRedo_Menuitem_Property,
- save_Menuitem_Property,
- fileInfo_Menuitem_Property,
- batch_Menuitem_Property,
- tts_Menuitem_Property,
- ppt_Menuitem_Property,
- print_Menuitem_Property,
- share_Menuitem_Property]
-
- moreTabsItems = [markup_Menuitem_Property,
- edit_Menuitem_Property,
- form_Menuitem_Property,
- fill_Menuitem_Property,
- convert_Menuitem_Property,
- protect_Menuitem_Property,
- tools_Menuitem_Property]
-
- }
-
- //MARK: - 刷新一级工具栏
- func reloadToolbarTabsView() {
- guard let toolbarManager = self.toolbarManager, let viewManager = self.viewManager else {
- return
- }
- toolbarManager.markupMode_Property.state = viewManager.toolMode == .Markup ? .pressed : .normal
- toolbarManager.editMode_Property.state = viewManager.toolMode == .Edit ? .pressed : .normal
- toolbarManager.formMode_Property.state = viewManager.toolMode == .Form ? .pressed : .normal
- toolbarManager.fillMode_Property.state = viewManager.toolMode == .Fill ? .pressed : .normal
- toolbarManager.convertMode_Property.state = viewManager.toolMode == .Convert ? .pressed : .normal
- toolbarManager.protectMode_Property.state = viewManager.toolMode == .Protect ? .pressed : .normal
- toolbarManager.toolsMode_Property.state = viewManager.toolMode == .Tools ? .pressed : .normal
-
- tabsView.refreshItems()
-
- }
-
- func reloadLeftIconView() {
- guard let toolbarManager = self.toolbarManager, let viewManager = self.viewManager else {
- return
- }
- toolbarManager.viewProperty.state = viewManager.showDisplayView ? .pressed : .normal
- toolbarManager.viewProperty.isDisabled = false
- if viewManager.isPageEditMode {
- toolbarManager.viewProperty.isDisabled = true
- }
- leftViewButton.reloadData()
-
- }
-
- func reloadPageEditView() {
- guard let toolbarManager = self.toolbarManager, let viewManager = self.viewManager else {
- return
- }
- toolbarManager.pageProperty.state = viewManager.isPageEditMode ? .pressed : .normal
- pageButton.reloadData()
-
- }
-
- func reloadSelectZoomView() {
- guard let toolbarManager = self.toolbarManager, let viewManager = self.viewManager else {
- return
- }
- toolbarManager.selectZoomProperty.isDisabled = false
- if viewManager.isPageEditMode {
- toolbarManager.selectZoomProperty.isDisabled = true
- }
- if let pdfview = self.pdfView {
- toolbarManager.selectZoomProperty.text = (NSString(format: "%.0f", pdfview.scaleFactor * 100) as String) + "%"
- }
-
- selectZoom.reloadData()
-
- }
-
- func refreshTabsScrollViewUI() {
- let pointX: CGFloat = (CGRectGetWidth(view.frame) - tabsView.viewWidth)/2
-
- var xValue: CGFloat = 0
-
- if pointX-12-264 > 10 {
- xValue = pointX - 12 - 264
- tabsLeftConst.constant = xValue
-
- tabsMoreButton.superview?.isHidden = true
- } else {
- xValue = 10
- let rightXValue = CGRectGetWidth(view.frame) - tabsView.viewWidth - 12 - 264 - rightViewWidthConst.constant - 12 - xValue
-
- if rightXValue < 10 {
- tabsMoreButton.superview?.isHidden = false
- tabsRightConst.constant = 44
- } else {
- tabsMoreButton.superview?.isHidden = true
- tabsRightConst.constant = rightXValue
- }
- }
- }
-
- func refreshTabsScrollViewVisiableRect() {
- guard let toolbarManager = self.toolbarManager, let viewManager = self.viewManager else {
- return
- }
- if tabsView.viewWidth > CGRectGetWidth(tabsContendView.frame)-21 {
- if viewManager.toolMode != .None {
- var pointx: CGFloat = 0
- print(tabsScrollView.documentVisibleRect)
- let _manager = toolbarManager
-
- if viewManager.toolMode == .Markup {
- pointx = 0
- } else if viewManager.toolMode == .Edit {
- pointx = _manager.markupMode_Property.propertyInfo.viewWidth
- } else if viewManager.toolMode == .Form {
- pointx = _manager.markupMode_Property.propertyInfo.viewWidth + _manager.editMode_Property.propertyInfo.viewWidth
- } else if viewManager.toolMode == .Fill {
- pointx = _manager.markupMode_Property.propertyInfo.viewWidth + _manager.editMode_Property.propertyInfo.viewWidth + _manager.formMode_Property.propertyInfo.viewWidth
- } else if viewManager.toolMode == .Convert {
- pointx = _manager.markupMode_Property.propertyInfo.viewWidth + _manager.editMode_Property.propertyInfo.viewWidth + _manager.formMode_Property.propertyInfo.viewWidth + _manager.editMode_Property.propertyInfo.viewWidth
- } else if viewManager.toolMode == .Protect {
- pointx = _manager.markupMode_Property.propertyInfo.viewWidth + _manager.editMode_Property.propertyInfo.viewWidth + _manager.formMode_Property.propertyInfo.viewWidth + _manager.editMode_Property.propertyInfo.viewWidth + _manager.convertMode_Property.propertyInfo.viewWidth
- } else if viewManager.toolMode == .Tools {
- pointx = _manager.markupMode_Property.propertyInfo.viewWidth + _manager.editMode_Property.propertyInfo.viewWidth + _manager.formMode_Property.propertyInfo.viewWidth + _manager.editMode_Property.propertyInfo.viewWidth + _manager.convertMode_Property.propertyInfo.viewWidth + _manager.protectMode_Property.propertyInfo.viewWidth
- }
- if tabsScrollView.documentVisibleRect.origin.x > pointx {
- tabsScrollView.scroll(tabsScrollView.contentView, to: CGPoint(x: pointx, y: 0))
- }
- }
- }
- }
-
- //MARK: -右侧工具模块
- func setUpRightViews() {
- let subviews = rightToolsView.subviews
- for view in subviews {
- view.removeFromSuperview()
- }
-
- var itemXvalue: CGFloat = 4
- guard let _manager = self.toolbarManager, let _ = self.viewManager else {
- return
- }
-
- var propertys: [Any] = []
-
- var adddividerA: Bool = false
- var adddividerB: Bool = false
-
- for property in _manager.validRightPropertys {
- if property == _manager.undoProperty ||
- property == _manager.redoProperty ||
- property == _manager.saveProperty {
- adddividerA = true
-
- } else if property == _manager.fileInfo_Property ||
- property == _manager.batchProperty ||
- property == _manager.ttsProperty ||
- property == _manager.pptProperty ||
- property == _manager.printProperty ||
- property == _manager.shareProperty {
- adddividerB = true
- }
- }
-
- for property in _manager.validRightPropertys {
- if adddividerA == true {
- if property == _manager.fileInfo_Property ||
- property == _manager.batchProperty ||
- property == _manager.ttsProperty ||
- property == _manager.pptProperty ||
- property == _manager.printProperty ||
- property == _manager.shareProperty {
-
- propertys.append(ComponentDividerProperty(type: .vertical, dash: false))
- adddividerA = false
- }
- }
- propertys.append(property)
- }
- if adddividerB == true {
- if propertys.last is ComponentDividerProperty {
-
- } else {
- propertys.append(ComponentDividerProperty(type: .vertical, dash: false))
- }
- }
- propertys.append(_manager.rightViewProperty)
-
- for property in propertys {
- if property is ComponentButtonProperty {
- let buttonProperty = (property as! ComponentButtonProperty)
- let button = ComponentButton.init()
- button.properties = buttonProperty
- if buttonProperty.onlyIcon {
- button.frame = CGRectMake(itemXvalue, 0, 28, 28)
- } else {
- button.frame = CGRectMake(itemXvalue, 0, button.properties.propertyInfo.viewWidth, 28)
- }
- button.setTarget(self, action: #selector(buttonClicked(_:)))
- rightToolsView.addSubview(button)
-
- itemXvalue += CGRectGetWidth(button.frame)
- itemXvalue += 12
-
- } else if property is ComponentDividerProperty {
- let divider = ComponentDivider.init()
- divider.frame = CGRectMake(itemXvalue, CGRectGetHeight(rightToolsView.frame)/2-8, 1, 16)
- divider.properties = (property as! ComponentDividerProperty)
- rightToolsView.addSubview(divider)
-
- itemXvalue += 1
- itemXvalue += 12
-
- } else if property is ComponentDropdownToolProperty {
- let dropdownTool = ComponentDropdownTool.init()
- dropdownTool.properties = property as! ComponentDropdownToolProperty
- dropdownTool.frame = CGRectMake(itemXvalue, 0, 28, 28)
- dropdownTool.delegate = self
- rightToolsView.addSubview(dropdownTool)
-
- itemXvalue += CGRectGetWidth(dropdownTool.frame)
- itemXvalue += 12
-
- }
- }
- itemXvalue -= 12
-
- rightViewWidthConst.constant = itemXvalue
-
- }
-
- func reloadRightToolsView() {
- let subviews = rightToolsView.subviews
- for view in subviews {
- if view is ComponentButton {
- let button = view as! ComponentButton
- if button.properties.identifier == KMPDFToolbar_rightView_Identifier {
- if viewManager?.showRightSide == true {
- if button.properties.state != .pressed {
- button.properties.state = .pressed
- button.reloadData()
- }
- } else {
- if button.properties.state != .normal {
- button.properties.state = .normal
- button.reloadData()
- }
- }
- button.reloadData()
-
- }
- } else if view is ComponentDropdownTool {
-
- }
- }
-
- }
-
- //MARK: - 二级工具栏
- func setupSecondToolbar() {
- secondToolBar.view.frame = secondContendView.bounds
- secondToolBar.delegate = self
- secondToolBar.view.autoresizingMask = [.width, .height]
- secondToolBar.viewManager = viewManager
- secondContendView.addSubview(secondToolBar.view)
-
- }
-
- func reloadSecondToolbar(forceRefresh refresh: Bool = false) {
- guard let _manager = self.toolbarManager, let viewManager = self.viewManager else {
- return
- }
- if viewManager.isPageEditMode {
- secondToolBar.reloadMainPropertys(_manager.getSubToolbarItems(isPageEditMode: true))
- secondToolBar.reloadRightPropertys([_manager.page_Reduce_Property, _manager.page_Increase_Property])
- } else {
- let propertys = _manager.getSubToolbarItems(viewManager.toolMode)
- if let firstProperty = propertys.first {
- if secondToolBar.propertys.contains(firstProperty) == false {
- secondToolBar.reloadMainPropertys(propertys)
- } else {
- //同一种类型
- if refresh {
- //特殊情况下同一级点击刷新所有item
- secondToolBar.reloadMainPropertys(propertys)
- }
- }
- } else {
- secondToolBar.reloadMainPropertys(propertys)
- }
- secondToolBar.reloadRightPropertys([])
- }
- }
-
- //只刷新Item状态
- func refreshSecondToolbarItemsState() {
-
- toolbarManager?.eyeProperty.state = pdfView?.hideNotes == true ? .pressed : .normal
-
- secondToolBar.reloadMainview()
-
- secondToolBar.reloadRightview()
- }
-
- //MARK: - 取消二级工具栏按钮选中状态
- func cancelSelectedSecondToolbarItems(_ toolMode: KMPDFToolsMode) {
- guard let _manager = self.toolbarManager, let _ = self.viewManager else {
- return
- }
-
- let propertys = _manager.getSubToolbarItems(toolMode)
- for property in propertys {
- if property is ComponentButtonProperty {
- (property as! ComponentButtonProperty).state = .normal
- } else if property is ComponentDropdownToolProperty {
- (property as! ComponentDropdownToolProperty).state = .normal
- } else if property is ComponentSelectProperties {
- (property as! ComponentSelectProperties).state = .normal
- }
- }
- }
-
- //MARK: - PDF界面选中注释发生变化时调用
- func pdfViewActiveAnnotationsChanged() {
- if self.viewManager?.toolMode == .Form {
- let annotations = self.pdfView?.activeAnnotations ?? []
-
- if annotations.count < 2 {
- toolbarManager?.form_alignment_left_Property.isDisabled = true
- toolbarManager?.form_alignment_Hori_Property.isDisabled = true
- toolbarManager?.form_alignment_Right_Property.isDisabled = true
- toolbarManager?.form_alignment_Top_Property.isDisabled = true
- toolbarManager?.form_alignment_Vert_Property.isDisabled = true
- toolbarManager?.form_alignment_Bottom_Property.isDisabled = true
- toolbarManager?.form_alignment_Distribute_Vert_Property.isDisabled = true
- toolbarManager?.form_alignment_Distribute_Hori_Property.isDisabled = true
- } else if annotations.count < 3 {
- toolbarManager?.form_alignment_left_Property.isDisabled = false
- toolbarManager?.form_alignment_Hori_Property.isDisabled = false
- toolbarManager?.form_alignment_Right_Property.isDisabled = false
- toolbarManager?.form_alignment_Top_Property.isDisabled = false
- toolbarManager?.form_alignment_Vert_Property.isDisabled = false
- toolbarManager?.form_alignment_Bottom_Property.isDisabled = false
- toolbarManager?.form_alignment_Distribute_Vert_Property.isDisabled = true
- toolbarManager?.form_alignment_Distribute_Hori_Property.isDisabled = true
- } else {
- toolbarManager?.form_alignment_left_Property.isDisabled = false
- toolbarManager?.form_alignment_Hori_Property.isDisabled = false
- toolbarManager?.form_alignment_Right_Property.isDisabled = false
- toolbarManager?.form_alignment_Top_Property.isDisabled = false
- toolbarManager?.form_alignment_Vert_Property.isDisabled = false
- toolbarManager?.form_alignment_Bottom_Property.isDisabled = false
- toolbarManager?.form_alignment_Distribute_Vert_Property.isDisabled = false
- toolbarManager?.form_alignment_Distribute_Hori_Property.isDisabled = false
- }
- }
- }
-
- //MARK: - Action点击
- public func clickWithIdentify(_ identify: String) {
- guard let toolbarManager = self.toolbarManager, let viewManager = self.viewManager else {
- return
- }
-
- if identify == KMPDFToolbar_PageEdit_Identifier {
- //MARK: -页面编辑
- pageButton.properties.state = viewManager.isPageEditMode ? .pressed : .normal
- pageButton.reloadData()
-
- viewManager.toolMode = .None
-
- delegate?.kmPDFToolbarControllerDidToolbarItemClicked?(self, pageButton.properties.identifier)
-
- reloadData()
-
- } else if identify == KMPDFToolbar_Markup_Identifier {
- componentTabsDidSelected(tabsView, toolbarManager.markupMode_Property)
-
- } else if identify == KMPDFToolbar_edit_link_Identifier {
- viewManager.toolMode = .Edit
- viewManager.subToolMode = .Edit_Link
-
- toolbarManager.edit_text_Property.state = .normal
- toolbarManager.edit_image_Property.state = .normal
- toolbarManager.edit_link_Property.state = .pressed
-
- refreshSecondToolbarItemsState()
- kmPDFSecToolbarControllerDidItemClicked(secondToolBar, toolbarManager.edit_link_Property)
-
- } else if identify == KMPDFToolbar_edit_text_Identifier {
- viewManager.toolMode = .Edit
- viewManager.subToolMode = .Edit_text
-
- toolbarManager.edit_text_Property.state = .pressed
- toolbarManager.edit_image_Property.state = .normal
- toolbarManager.edit_link_Property.state = .normal
-
- refreshSecondToolbarItemsState()
- kmPDFSecToolbarControllerDidItemClicked(secondToolBar, toolbarManager.edit_text_Property)
-
- } else if identify == KMPDFToolbar_edit_image_Identifier {
- viewManager.toolMode = .Edit
- viewManager.subToolMode = .Edit_Image
-
- toolbarManager.edit_text_Property.state = .normal
- toolbarManager.edit_image_Property.state = .pressed
- toolbarManager.edit_link_Property.state = .normal
-
- refreshSecondToolbarItemsState()
-
- kmPDFSecToolbarControllerDidItemClicked(secondToolBar, toolbarManager.edit_image_Property)
- }
- }
-
- //MARK: - 查找
- func findViewWith(_ identify: String) -> NSView? {
- //左侧
-
- //中间
-
- //右侧
- if true {
- let views = rightToolsView.subviews
- for view in views {
- if view is ComponentButton {
- if (view as! ComponentButton).properties.identifier == identify {
- return view
- }
- } else if view is ComponentDropdownTool {
- if (view as! ComponentDropdownTool).properties.identifier == identify {
- return view
- }
- for item in (view as! ComponentDropdownTool).properties.menuItemArr ?? [] {
- if item.identifier == identify {
- return view
- }
- }
- }
- }
- }
-
- return nil
- }
-
- //MARK: - reloadData
- func reloadData() {
- reloadLeftIconView()
-
- reloadPageEditView()
-
- reloadToolsView()
-
- reloadSelectZoomView()
-
- reloadToolbarTabsView()
-
- reloadRightToolsView()
-
- reloadSecondToolbar()
-
- refreshSecondToolbarItemsState()
-
- updateRightMenuItemSelectedState()
-
- reloadRedactToolbar()
- }
-
- //MARK: - 刷新tools工具
- func reloadToolsView() {
- toolbarManager?.reloadToolsData()
- toolbarManager?.tools_selectProperty.itemSelected = false
- toolbarManager?.tools_scrollProperty.itemSelected = false
- toolbarManager?.tools_contentProperty.itemSelected = false
- toolbarManager?.tools_magnifyProperty.itemSelected = false
- toolbarManager?.tools_areaProperty.itemSelected = false
- if viewManager?.viewToolsType == .Select {
- toolbarManager?.tools_selectProperty.itemSelected = true
- } else if viewManager?.viewToolsType == .Scroll {
- toolbarManager?.tools_scrollProperty.itemSelected = true
- } else if viewManager?.viewToolsType == .Content_Selection {
- toolbarManager?.tools_contentProperty.itemSelected = true
- } else if viewManager?.viewToolsType == .Magnify {
- toolbarManager?.tools_magnifyProperty.itemSelected = true
- } else if viewManager?.viewToolsType == .AreaZoom {
- toolbarManager?.tools_areaProperty.itemSelected = true
- }
-
- toolsView.reloadData()
- }
-
- //MARK: - Action
- @objc func buttonClicked(_ sender: ComponentButton) {
- guard let toolbarManager = self.toolbarManager, let viewManager = self.viewManager else {
- return
- }
- if sender.properties == toolbarManager.viewProperty {
- //MARK: -View
- viewManager.showDisplayView = !viewManager.showDisplayView
-
- sender.properties.state = viewManager.showDisplayView ? .pressed : .normal
- sender.reloadData()
-
- } else if sender.properties == toolbarManager.pageProperty {
- //MARK: -页面编辑
- viewManager.isPageEditMode = !viewManager.isPageEditMode
-
- sender.properties.state = viewManager.isPageEditMode ? .pressed : .normal
- sender.reloadData()
-
- if viewManager.toolMode != .None {
- cancelSelectedSecondToolbarItems(viewManager.toolMode)
-
- viewManager.toolMode = .None
- }
- } else if sender.properties == toolbarManager.rightViewProperty {
- //MARK: -属性栏
- viewManager.showRightSide = !viewManager.showRightSide
-
- }
-
- delegate?.kmPDFToolbarControllerDidToolbarItemClicked?(self, sender.properties.identifier)
-
- reloadData()
- }
-
- @objc func tabsMoreButtonClicked(_ sender: ComponentButton) {
- guard let point = sender.superview?.convert(sender.frame.origin, to: view.window?.contentView) else { return }
-
- for item in moreTabsItems {
- item.state = .normal
- item.itemSelected = false
- }
- showGroupView(moreTabsItems, point)
-
- customRightGroupView.clickedAutoHide = true
- }
-
- //MARK: - 自定义工具栏
- func updateRightMenuItemSelectedState() {
-
- undoRedo_Menuitem_Property.itemSelected = false
- save_Menuitem_Property.itemSelected = false
- fileInfo_Menuitem_Property.itemSelected = false
- batch_Menuitem_Property.itemSelected = false
- tts_Menuitem_Property.itemSelected = false
- ppt_Menuitem_Property.itemSelected = false
- print_Menuitem_Property.itemSelected = false
- share_Menuitem_Property.itemSelected = false
-
- guard let toolbarManager = self.toolbarManager, let _ = self.viewManager else {
- return
- }
- for property in toolbarManager.validRightPropertys {
- if property == toolbarManager.undoProperty ||
- property == toolbarManager.redoProperty {
- undoRedo_Menuitem_Property.itemSelected = true
- } else if property == toolbarManager.saveProperty {
- save_Menuitem_Property.itemSelected = true
- } else if property == toolbarManager.fileInfo_Property {
- fileInfo_Menuitem_Property.itemSelected = true
- } else if property == toolbarManager.batchProperty {
- batch_Menuitem_Property.itemSelected = true
- } else if property == toolbarManager.ttsProperty {
- tts_Menuitem_Property.itemSelected = true
- } else if property == toolbarManager.pptProperty {
- ppt_Menuitem_Property.itemSelected = true
- } else if property == toolbarManager.printProperty {
- print_Menuitem_Property.itemSelected = true
- } else if property == toolbarManager.shareProperty {
- share_Menuitem_Property.itemSelected = true
- }
- }
-
- }
-
- func showPageTurnMenuWithPoint(_ point: CGPoint) {
- if (customRightGroupView?.superview) != nil {
- return
- }
-
- updateRightMenuItemSelectedState()
-
- let items: [ComponentMenuitemProperty] = [ComponentMenuitemProperty.header(KMLocalizedString("Show Right Tools")), undoRedo_Menuitem_Property, save_Menuitem_Property, ComponentMenuitemProperty.divider(),
- fileInfo_Menuitem_Property, batch_Menuitem_Property, tts_Menuitem_Property, ppt_Menuitem_Property, print_Menuitem_Property, share_Menuitem_Property]
-
- showGroupView(items, point)
- customRightGroupView.clickedAutoHide = false
-
- refreshRightMenuState()
- }
-
- func showGroupView(_ items: [ComponentMenuitemProperty], _ point: NSPoint) {
-
- var viewHeight: CGFloat = 8.0
- for item in items {
- item.state = .normal
- if item.type == .normal {
- viewHeight += 36
- } else if item.type == .divider {
- viewHeight += 8
- } else if item.type == .header {
- viewHeight += 36
- }
- }
-
- if customRightGroupView == nil {
- customRightGroupView = ComponentGroup.createFromNib(in: ComponentLibrary.shared.componentBundle())
- }
- customRightGroupView.clickedAutoHide = false
- customRightGroupView?.frame = CGRectMake(0, 0, 160, viewHeight)
- customRightGroupView?.reloadData()
- customRightGroupView.groupDelegate = self
- customRightGroupView.showWithPoint(CGPoint(x: point.x, y: point.y-viewHeight), relativeTo: self.contendBox)
- customRightGroupView?.updateGroupInfo(items)
-
- }
-
- func hideGroupView() {
- customRightGroupView?.removeGroupView()
-
- }
-
- func refreshRightMenuState() {
-
- let totalItems = customRightItems
-
- var selectedCount = 0
- for item in totalItems {
- if item.itemSelected == true {
- selectedCount += 1
- }
- }
-
- var maxCount = 6
- if undoRedo_Menuitem_Property.itemSelected == true {
- maxCount = 5
- }
- if selectedCount == maxCount {
- for item in totalItems {
- if item.itemSelected == false {
- item.isDisabled = true
- }
- }
- } else {
- for item in totalItems {
- item.isDisabled = false
- }
- }
-
- if selectedCount == 5 && undoRedo_Menuitem_Property.itemSelected == false {
- //特殊情况,UndoRedo占两个空位
- undoRedo_Menuitem_Property.isDisabled = true
- }
-
- for item in totalItems {
- NotificationCenter.default.post(name: Notification.Name(rawValue: ComponentMenuItemUpdatedKey), object: item.identifier)
- }
-
- }
-
- //MARK: - Redact
- func reloadRedactToolbar() {
- if viewManager?.subToolMode == .Redact {
- redactToolbar.view.frame = contendBox.bounds
- redactToolbar.view.autoresizingMask = [.width, .height]
- contendBox.addSubview(redactToolbar.view)
- redactToolbar.delegate = self
- redactToolbar.reloadData()
- } else {
- redactToolbar.view.removeFromSuperview()
- }
- }
-
- //MARK: - Noti
- @objc func imageColorChangedNoti() {
- toolbarManager?.refreshMarkupColorImages()
-
- secondToolBar.reloadMainview()
- }
-
- //MARK: - MouseEvent
- override func rightMouseUp(with event: NSEvent) {
- super.rightMouseUp(with: event)
-
- var clickEnabled = true
- let windowPoint = event.locationInWindow
-
- if tabsMoreButton.superview?.isHidden == false {
- if CGRectContainsPoint(tabsMoreButton.frame, mainToolbarContendView.convert(windowPoint, from: nil)) {
- clickEnabled = false
- }
- }
-
- if clickEnabled {
- showPageTurnMenuWithPoint(windowPoint)
- }
-
- }
-
- }
- //MARK: - ComponentDropdownToolDelegate:工具模式
- extension KMPDFToolbarController: ComponentDropdownToolDelegate {
- func componentDropdownToolDidClicked(_ view: ComponentDropdownTool, menuItem: ComponentMenuitemProperty?) {
- guard let toolbarManager = self.toolbarManager, let viewManager = self.viewManager else {
- return
- }
-
- for item in toolbarManager.toolsProperty.menuItemArr ?? [] {
- item.itemSelected = false
- item.state = .normal
- }
-
- menuItem?.itemSelected = true
-
- var itemIdentifier = menuItem?.identifier ?? ""
-
- if toolbarManager.getSubToolItemIdentifys(KMPDFToolbar_View_Identifier).contains(itemIdentifier) {
- //MARK: 工具模式
- if menuItem == toolbarManager.tools_selectProperty {
- viewManager.viewToolsType = .Select
- } else if menuItem == toolbarManager.tools_scrollProperty {
- viewManager.viewToolsType = .Scroll
- } else if menuItem == toolbarManager.tools_contentProperty {
- viewManager.viewToolsType = .Content_Selection
- } else if menuItem == toolbarManager.tools_magnifyProperty {
- viewManager.viewToolsType = .Magnify
- } else if menuItem == toolbarManager.tools_areaProperty {
- viewManager.viewToolsType = .AreaZoom
- }
- if viewManager.viewToolsType != .Select {
- viewManager.toolMode = .None
-
- reloadToolbarTabsView()
- }
- reloadToolsView()
-
- delegate?.kmPDFToolbarControllerDidViewToolsChanged?(self)
- } else if menuItem == toolbarManager.share_PDF_Property ||
- menuItem == toolbarManager.share_Flatted_Property ||
- menuItem == toolbarManager.share_Original_Property {
- //MARK: -分享
- if let id = menuItem?.identifier {
- delegate?.kmPDFToolbarControllerDidToolbarItemClicked?(self, id)
- }
-
- } else {
-
- }
-
- }
- }
- //MARK: - ComponentSelectZoomDelegate:缩放比例
- extension KMPDFToolbarController: ComponentSelectZoomDelegate {
- func componentSelectZoomDidReduce(view: ComponentSelectZoom) {
- let zoomSting = view.properties.text
- var scale = CGFloat((NSString(string: zoomSting)).floatValue / 100.0)
- switch scale {
- case 0...0.25:
- scale = 0
- case 0.25...3:
- scale -= 0.25
- case 3.1...10:
- scale -= 0.4
- case 10.1...100:
- scale -= 1
- default:
- scale -= 1
- }
- pdfView?.scaleFactor = scale
-
- }
-
- func componentSelectZoomDidSelect(view: ComponentSelectZoom?, menuItemProperty: ComponentMenuitemProperty?) {
- if menuItemProperty?.identifier == KMPDFToolbar_Zoom_AdapWidth_Identifier {
- pdfView?.autoScales = true
- } else if menuItemProperty?.identifier == KMPDFToolbar_Zoom_AdapPage_Identifier {
- let pageHeight = pdfView?.currentPage()!.size.height
- let pdfviewHeight = pdfView?.bounds.size.height
- pdfView?.scaleFactor = pdfviewHeight!/pageHeight!
- pdfView?.autoScales = false
- } else if menuItemProperty?.identifier == KMPDFToolbar_Zoom_ActualSize_Identifier {
- if pdfView?.scaleFactor != 1.0 {
- pdfView?.scaleFactor = 1.0
- pdfView?.autoScales = false
- }
- } else if menuItemProperty?.identifier == KMPDFToolbar_Zoom_10_Identifier {
- pdfView?.scaleFactor = 0.1
-
- } else if menuItemProperty?.identifier == KMPDFToolbar_Zoom_25_Identifier {
- pdfView?.scaleFactor = 0.25
-
- } else if menuItemProperty?.identifier == KMPDFToolbar_Zoom_50_Identifier {
- pdfView?.scaleFactor = 0.5
-
- } else if menuItemProperty?.identifier == KMPDFToolbar_Zoom_75_Identifier {
- pdfView?.scaleFactor = 0.75
-
- } else if menuItemProperty?.identifier == KMPDFToolbar_Zoom_100_Identifier {
- pdfView?.scaleFactor = 1.0
-
- } else if menuItemProperty?.identifier == KMPDFToolbar_Zoom_150_Identifier {
- pdfView?.scaleFactor = 1.5
-
- } else if menuItemProperty?.identifier == KMPDFToolbar_Zoom_200_Identifier {
- pdfView?.scaleFactor = 2.0
-
- } else if menuItemProperty?.identifier == KMPDFToolbar_Zoom_400_Identifier {
- pdfView?.scaleFactor = 4.0
-
- } else if menuItemProperty?.identifier == KMPDFToolbar_Zoom_800_Identifier {
- pdfView?.scaleFactor = 8.0
-
- }
- }
-
- func componentSelectZoomDidAdd(view: ComponentSelectZoom) {
- let zoomSting = view.properties.text
- var scale = CGFloat((NSString(string: zoomSting)).floatValue / 100.0)
- switch scale {
- case 0...0.25:
- scale += 0.25
- case 0.25...3:
- scale += 0.25
- case 3.1...10:
- scale += 0.4
- case 10.1...100:
- scale += 1
- default:
- scale += 1
- }
- pdfView?.scaleFactor = scale
- }
-
- }
- //MARK: - ComponentTabsDelegate:一级工具栏
- extension KMPDFToolbarController: ComponentTabsDelegate {
- func componentTabsDidSelected(_ view: ComponentTabs, _ property: ComponentTabsProperty) {
- guard let toolbarManager = self.toolbarManager, let _manager = self.viewManager else {
- return
- }
-
- if _manager.viewToolsType != .Select {
- _manager.viewToolsType = .Select
-
- delegate?.kmPDFToolbarControllerDidViewToolsChanged?(self)
- }
-
- if _manager.isPageEditMode == true {
- delegate?.kmPDFToolbarControllerDidExitPageEditMode?(self)
-
- _manager.isPageEditMode = false
- }
-
- cancelSelectedSecondToolbarItems(_manager.toolMode)
- if property == toolbarManager.markupMode_Property {
- if _manager.toolMode == .Markup {
- _manager.toolMode = .None
-
- property.state = .normal
- view.refreshItems()
- } else {
- _manager.toolMode = .Markup
- }
- _manager.subToolMode = .None
- } else if property == toolbarManager.editMode_Property {
- if _manager.toolMode == .Edit {
- _manager.toolMode = .None
-
- property.state = .normal
- view.refreshItems()
- } else {
- _manager.toolMode = .Edit
- }
- _manager.subToolMode = .None
- } else if property == toolbarManager.formMode_Property {
- if _manager.toolMode == .Form {
- _manager.toolMode = .None
-
- property.state = .normal
- view.refreshItems()
- } else {
- _manager.toolMode = .Form
- }
- _manager.subToolMode = .None
-
- pdfViewActiveAnnotationsChanged()
-
- } else if property == toolbarManager.fillMode_Property {
- if _manager.toolMode == .Fill {
- _manager.toolMode = .None
-
- property.state = .normal
- view.refreshItems()
- } else {
- _manager.toolMode = .Fill
- }
- _manager.subToolMode = .None
- } else if property == toolbarManager.convertMode_Property {
- if _manager.toolMode == .Convert {
- _manager.toolMode = .None
-
- property.state = .normal
- view.refreshItems()
- } else {
- _manager.toolMode = .Convert
- }
- _manager.subToolMode = .None
- } else if property == toolbarManager.protectMode_Property {
- if _manager.toolMode == .Protect {
- _manager.toolMode = .None
-
- property.state = .normal
- view.refreshItems()
- } else {
- _manager.toolMode = .Protect
- }
- _manager.subToolMode = .None
- } else if property == toolbarManager.toolsMode_Property {
- if _manager.toolMode == .Tools {
- _manager.toolMode = .None
-
- property.state = .normal
- view.refreshItems()
- } else {
- _manager.toolMode = .Tools
- }
- _manager.subToolMode = .None
- }
-
- refreshTabsScrollViewVisiableRect()
-
- delegate?.kmPDFToolbarControllerDidToolModeChanged?(self)
-
- reloadData()
- }
- }
- //MARK: - KMPDFSecToolbarControllerDelegate:二级工具栏
- extension KMPDFToolbarController: KMPDFSecToolbarControllerDelegate {
- func kmPDFSecToolbarControllerDidItemClicked(_ controller: KMPDFSecToolbarController, _ property: Any) {
- if let value = property as? ComponentButtonProperty {
- delegate?.kmPDFToolbarControllerDidToolbarItemClicked?(self, value.identifier)
- reloadData()
- } else if let value = property as? ComponentMenuitemProperty {
- delegate?.kmPDFToolbarControllerDidToolbarItemClicked?(self, value.identifier)
- reloadData()
- } else if let value = property as? ComponentDropdownToolProperty {
- if value.identifier == KMPDFToolbar_edit_Watermark_Identifier ||
- value.identifier == KMPDFToolbar_edit_BG_Identifier ||
- value.identifier == KMPDFToolbar_edit_HF_Identifier ||
- value.identifier == KMPDFToolbar_edit_Bates_Identifier {
- if viewManager?.subToolMode != .None {
- viewManager?.subToolMode = .None
- }
- delegate?.kmPDFToolbarControllerDidToolbarItemClicked?(self, value.identifier)
- }
- }
- }
-
- func kmPDFSecToolbarControllerDidSelectTextDidBeginEditing(_ controller: KMPDFSecToolbarController, _ view: ComponentSelect) {
- delegate?.kmPDFToolbarControllerDidSelectTextDidBeginEditing?(self, view)
- }
-
- func kmPDFSecToolbarControllerDidSelectTextDidChange(_ controller: KMPDFSecToolbarController, _ view: ComponentSelect) {
- delegate?.kmPDFToolbarControllerDidSelectTextDidChange?(self, view)
- }
-
- func kmPDFSecToolbarControllerDidSelectTextDidEndEditing(_ controller: KMPDFSecToolbarController, _ view: ComponentSelect) {
- delegate?.kmPDFToolbarControllerDidSelectTextDidEndEditing?(self, view)
- }
- }
- //MARK: - ComponentGroupDelegate:右侧工具栏
- extension KMPDFToolbarController: ComponentGroupDelegate {
- func componentGroupDidDismiss(group: ComponentGroup?) {
- tabsMoreButton.properties.state = .normal
- tabsMoreButton.reloadData()
-
- }
-
- func componentGroupDidSelect(group: ComponentGroup?, menuItemProperty: ComponentMenuitemProperty?) {
-
- guard let property = menuItemProperty else {
- return
- }
-
- guard let toolbarManager = self.toolbarManager, let viewManager = self.viewManager else {
- return
- }
-
- if customRightItems.contains(property) {
- var validItems:[NSObject] = []
-
- if undoRedo_Menuitem_Property.itemSelected {
- validItems.append(toolbarManager.undoProperty)
- validItems.append(toolbarManager.redoProperty)
- }
- if save_Menuitem_Property.itemSelected {
- validItems.append(toolbarManager.saveProperty)
- }
- if fileInfo_Menuitem_Property.itemSelected {
- validItems.append(toolbarManager.fileInfo_Property)
- }
- if batch_Menuitem_Property.itemSelected {
- validItems.append(toolbarManager.batchProperty)
- }
- if tts_Menuitem_Property.itemSelected {
- validItems.append(toolbarManager.ttsProperty)
- }
- if ppt_Menuitem_Property.itemSelected {
- validItems.append(toolbarManager.pptProperty)
- }
- if print_Menuitem_Property.itemSelected {
- validItems.append(toolbarManager.printProperty)
- }
- if share_Menuitem_Property.itemSelected {
- validItems.append(toolbarManager.shareProperty)
- }
-
- let sortArray = toolbarManager.totalRightPropertys
-
- let sortedArray = validItems.sorted {
- guard let indexA = sortArray.firstIndex(of: $0 as NSObject),
- let indexB = sortArray.firstIndex(of: $1 as NSObject) else {
- return false
- }
- return indexA < indexB
- }
-
- toolbarManager.validRightPropertys = sortedArray
-
- setUpRightViews()
-
- refreshRightMenuState()
-
- } else if moreTabsItems.contains(property) {
- viewManager.viewToolsType = .Select
-
- if viewManager.isPageEditMode == true {
- delegate?.kmPDFToolbarControllerDidExitPageEditMode?(self)
- viewManager.isPageEditMode = false
- }
-
- if property == markup_Menuitem_Property {
- viewManager.toolMode = .Markup
- } else if property == edit_Menuitem_Property {
- viewManager.toolMode = .Edit
- } else if property == form_Menuitem_Property {
- viewManager.toolMode = .Form
- } else if property == fill_Menuitem_Property {
- viewManager.toolMode = .Fill
- } else if property == toolbarManager.convertMode_Property {
- viewManager.toolMode = .Convert
- } else if property == protect_Menuitem_Property {
- viewManager.toolMode = .Protect
- } else if property == tools_Menuitem_Property {
- viewManager.toolMode = .Tools
- }
- tabsView.refreshItems()
-
- delegate?.kmPDFToolbarControllerDidToolbarItemClicked?(self, property.identifier)
-
- reloadData()
-
- }
-
-
- }
- }
- //MARK: - KMRedactToolbarControllerDelegate标记密文
- extension KMPDFToolbarController: KMRedactToolbarControllerDelegate {
- func redactToolbarControllerDidButtonClick(controller: KMRedactToolbarController, buttonIndex: Int) {
- if buttonIndex == 1 {
- delegate?.kmPDFToolbarControllerDidToolbarItemClicked?(self, KMPDFToolbar_protect_redact_Property_Identifier)
-
- } else if buttonIndex == 2 {
- viewManager?.subToolMode = .None
- cancelSelectedSecondToolbarItems(.Protect)
- delegate?.kmPDFToolbarControllerDidToolbarItemClicked?(self, KMPDFToolbar_protect_redact_Apply_Identifier)
-
- } else if buttonIndex == 3 {
- viewManager?.subToolMode = .None
- cancelSelectedSecondToolbarItems(.Protect)
- delegate?.kmPDFToolbarControllerDidToolbarItemClicked?(self, KMPDFToolbar_protect_redact_Exit_Identifier)
-
- }
-
- reloadData()
-
-
- }
- }
|