1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093109410951096109710981099110011011102110311041105110611071108110911101111111211131114111511161117111811191120 |
- //
- // KMNPopAnnotationWindowController.swift
- // PDF Reader Pro
- //
- // Created by 丁林圭 on 2024/12/2.
- //
- import Cocoa
- import KMComponentLibrary
- let popOffSet:CGFloat = 8.0
- typealias PaneCallback = (_ isOpenPane: Bool) -> ()
- typealias UpdatePDFViewCallback = () -> ()
- class KMNPopOperationWindow: NSWindow {
- override var canBecomeKey: Bool {
- return true
- }
-
- override var canBecomeMain: Bool {
- return true
- }
- }
- class KMNPopAnnotationWindowController: KMNBaseWindowController {
-
- public var popType:ListViewPopType = .popTypeNone {
- didSet {
- rightOffsetConstraint.constant = 49.0
- operationHeightConstraint.constant = 32.0
- paneBox.isHidden = false
-
- switch popType {
- case .generaAnnotation :
- generaPopView.layoutSubtreeIfNeeded()
- operationWidthConstraint.constant = generaPopView.bounds.width
- self.window?.display() //需刷新约束才会有值,不然会变化
- operationBox.contentView = generaPopView
- congfigGeneraPopUI()
- break
- case .freeTextAnnotation:
- fontPopView.layoutSubtreeIfNeeded()
- operationWidthConstraint.constant = fontPopView.bounds.width
- self.window?.display() //需刷新约束才会有值,不然会变化
- operationBox.contentView = fontPopView
- break
- case .shapeAnnotation:
- var isContainSelfDot = false
- for i in 0..<annotationPopMode.annotations.count {
- if let selfAn = annotationPopMode.annotations[i] as? CSelfSignAnnotation {
- if selfAn.annotationType == .signDot {
- isContainSelfDot = true
- break
- }
- }
- }
-
- var width = 272.0
- if isContainSelfDot == true {
- shapeRightConstraint.constant = 0
- widthZoomOutButton.isHidden = true
- widthZoomInButton.isHidden = true
- width = 200.0
- } else {
- shapeRightConstraint.constant = 72
- widthZoomOutButton.isHidden = false
- widthZoomInButton.isHidden = false
- }
- shapeView.layoutSubtreeIfNeeded()
- // operationWidthConstraint.constant = shapeView.bounds.width //刷新后未更新最后的宽度,暂时写死宽度
- operationWidthConstraint.constant = width
- self.window?.display() //需刷新约束才会有值,不然会变化
- operationBox.contentView = shapeView
-
- congfigShapePopUI()
- break
- case .linkAnnotation:
- if let newLinkAnnotation = annotationPopMode.annotation as? CPDFLinkAnnotation {
- linkAnnotation = newLinkAnnotation
- }
- break
- case .formAnnotation:
- formRightConstraint.constant = 0
- gropNameInput.isHidden = true
- formView.layoutSubtreeIfNeeded()
-
- operationWidthConstraint.constant = formView.bounds.width
- self.window?.display() //需刷新约束才会有值,不然会变化
- operationBox.contentView = formView
- break
- case .formRadioAnnotation:
- formRightConstraint.constant = 110
- gropNameInput.isHidden = false
- formView.layoutSubtreeIfNeeded()
-
- operationWidthConstraint.constant = formView.bounds.width
- self.window?.display() //需刷新约束才会有值,不然会变化
- operationBox.contentView = formView
- break
- case .multpleAnnotation:
- alightView.layoutSubtreeIfNeeded()
- operationWidthConstraint.constant = alightView.bounds.width
- self.window?.display() //需刷新约束才会有值,不然会变化
- operationBox.contentView = alightView
- break
- case .popTypeNone:
- break
-
- }
- }
- }
-
- public var isOpenPane = false {
- didSet {
- if isOpenPane == true {
- paneSelectorItem.properties.state = .pressed
- } else {
- paneSelectorItem.properties.state = .normal
- }
- paneSelectorItem.reloadData()
- }
- }
-
- public var annotationPopMode:KMNAnnotationPopMode = KMNAnnotationPopMode(pdfAnnotations: []) {
- didSet {
- let annotationPopType = annotationPopMode.popType
- popType = annotationPopType
- if annotationPopType == .generaAnnotation {
- let newColor = annotationPopMode.annotationColor()
- annotationColor = newColor
- } else if(annotationPopType == .shapeAnnotation) {
- let newColor = annotationPopMode.annotationColor()
- annotationColor = newColor
- } else if(annotationPopType == .freeTextAnnotation) {
- let newColor = annotationPopMode.annotationFontColor()
- fontColor = newColor
-
- let alignment = annotationPopMode.annotationAlignment()
- fontAlight = alignment
-
- let font = annotationPopMode.annotationFontName()
- compdfFont = font
- } else if annotationPopType == .linkAnnotation {
- if annotationPopMode.annotation != nil {
- linkAnnotation = annotationPopMode.annotation as! CPDFLinkAnnotation
- }
- } else if annotationPopType == .formAnnotation {
- fildNameString = annotationPopMode.annotationFieldName() ?? ""
- } else if annotationPopType == .formRadioAnnotation {
- fildNameString = annotationPopMode.annotationFieldName() ?? ""
- gropNameString = annotationPopMode.annotationGropName() ?? ""
- }
- }
- }
-
- private var annotationColor:NSColor?{
- didSet {
- if popType == .generaAnnotation {
- generaColorGroup.currentColor = annotationColor
- generaColorGroup.refreshUI()
- } else if popType == .shapeAnnotation {
- shapeColorGroup.currentColor = annotationColor
- shapeColorGroup.refreshUI()
- }
- }
- }
-
- private var fontColor:NSColor?{
- didSet {
- fontColorItem.properties?.color = fontColor
- fontColorItem.reloadData()
- }
- }
-
- private var linkAnnotation:CPDFLinkAnnotation = CPDFLinkAnnotation(){
- didSet {
- if let destination = linkAnnotation.destination() {
- linkType = .page
- } else if let annotationURL = linkAnnotation.url(){
- var urlString = annotationURL.fileURL.absoluteString
- if annotationURL.hasPrefix("mailto:") {
- linkType = .email
- } else {
- linkType = .url
- }
- } else {
- linkType = .linkSetting
- }
- }
- }
-
- private var fildNameString:String = ""{
- didSet {
- fildNameInput.properties.text = fildNameString
- fildNameInput.reloadData()
- }
- }
-
- private var gropNameString:String = ""{
- didSet {
- gropNameInput.properties.text = gropNameString
- gropNameInput.reloadData()
- }
- }
-
- private var compdfFont:CPDFFont?{
- didSet {
- if(compdfFont != nil) {
- let styleName = compdfFont!.styleName
- if(styleName?.isEmpty == true) {
- fontNameSelect.properties.text = compdfFont!.familyName
- } else {
- fontNameSelect.properties.text = compdfFont!.familyName + "-" + (compdfFont!.styleName ?? "")
- }
- } else {
- fontNameSelect.properties.text = "-"
- }
- fontNameSelect.reloadData()
- }
- }
-
- private var fontAlight:NSTextAlignment = .left {
- didSet {
- if fontAlight == .center {
- fontAlightButton.properties.icon = NSImage(named: "KMNImageNameListViewPopAlightCenter")
- } else if fontAlight == .right {
- fontAlightButton.properties.icon = NSImage(named: "KMNImageNameListViewPopAlightRight")
- } else {
- fontAlightButton.properties.icon = NSImage(named: "KMNImageNameListViewPopAlightLeft")
- }
- fontAlightButton.reloadData()
- }
- }
-
- private var objectAlignType:ObjectAlignType = .alightLeft {
- didSet {
- let activeAnnotations = annotationPopMode.annotations
- switch objectAlignType {
- case .alightLeft :
- listView?.change(activeAnnotations, alignmentType: .left)
- alightButton.properties.icon = NSImage(named: "KMNImageNameObjectPopAlightLeft")
- break
- case .alightRight:
- listView?.change(activeAnnotations, alignmentType: .right)
- alightButton.properties.icon = NSImage(named: "KMNImageNameObjectPopAlightRight")
- break
- case .alightTop:
- listView?.change(activeAnnotations, alignmentType: .top)
- alightButton.properties.icon = NSImage(named: "KMNImageNameObjectPopAlightTop")
- break
-
- case .alightVer:
- listView?.change(activeAnnotations, alignmentType: .vertical)
- alightButton.properties.icon = NSImage(named: "KMNImageNameObjectPopAlightVer")
- break
- case .alightHor:
- listView?.change(activeAnnotations, alignmentType: .horizontally)
- alightButton.properties.icon = NSImage(named: "KMNImageNameObjectPopAlightHor")
- break
- case .alightBottom:
- listView?.change(activeAnnotations, alignmentType: .bottom)
- alightButton.properties.icon = NSImage(named: "KMNImageNameObjectPopAlightBottom")
- break
- case .averageVer:
- listView?.change(activeAnnotations, alignmentType: .disVertical)
- alightButton.properties.icon = NSImage(named: "KMNImageNameObjecAlignAverageVer")
- break
- case .averageHor:
- listView?.change(activeAnnotations, alignmentType: .disHorizontally)
- alightButton.properties.icon = NSImage(named: "KMNImageNameObjecAlignAverageHor")
- break
- }
- alightButton.reloadData()
- }
- }
-
-
- var paneCallback: PaneCallback?
- var updatePDFViewCallback: UpdatePDFViewCallback?
-
- static let shared: KMNPopAnnotationWindowController = {
- let windowC = KMNPopAnnotationWindowController(windowNibName: "KMNPopAnnotationWindowController")
- return windowC
- }()
-
- var linkType:linkDetailType = .linkSetting {
- didSet {
- if linkType == .linkSetting {
- linkView.layoutSubtreeIfNeeded()
-
- rightOffsetConstraint.constant = 45.0
- operationHeightConstraint.constant = 32.0
- operationWidthConstraint.constant = linkView.bounds.width
- self.window?.display() //需刷新约束才会有值,不然会变化
- operationBox.contentView = linkView
-
- paneBox.isHidden = false
- } else if linkType == .page {
- linkPageDetailView.layoutSubtreeIfNeeded()
- rightOffsetConstraint.constant = 8
- operationWidthConstraint.constant = linkPageDetailView.bounds.width
- operationHeightConstraint.constant = 224
- self.window?.display() //需刷新约束才会有值,不然会变化
- operationBox.contentView = linkPageDetailView
-
- paneBox.isHidden = true
- if let destination = linkAnnotation.destination() {
- reloadPageUrlData()
- refreshPageThum()
- } else {
- paginationView.properties.currentIndex = Int(((listView?.currentPageIndex ?? 0) + 1))
- paginationView.reloadData()
- refreshPageThum()
- }
- } else if linkType == .url {
- linkUrlDetailView.layoutSubtreeIfNeeded()
- rightOffsetConstraint.constant = 8
- operationWidthConstraint.constant = linkUrlDetailView.bounds.width
- operationHeightConstraint.constant = linkUrlDetailView.bounds.height
- self.window?.display() //需刷新约束才会有值,不然会变化
- operationBox.contentView = linkUrlDetailView
-
- paneBox.isHidden = true
-
- urlInput.properties.placeholder = KMNCompanyWebsite
-
- if let annotationURL = linkAnnotation.url(){
- if annotationURL.hasPrefix("mailto:") {
- urlInput.properties.text = ""
- } else {
- urlInput.properties.text = annotationURL
- }
- } else {
- urlInput.properties.text = ""
- }
- urlInput.properties.state = .pressed
- urlInput.beginEditing()
- urlInput.reloadData()
- } else if linkType == .email {
- linkUrlDetailView.layoutSubtreeIfNeeded()
- rightOffsetConstraint.constant = 8
- operationWidthConstraint.constant = linkUrlDetailView.bounds.width
- operationHeightConstraint.constant = linkUrlDetailView.bounds.height
- self.window?.display() //需刷新约束才会有值,不然会变化
- operationBox.contentView = linkUrlDetailView
-
- paneBox.isHidden = true
-
- urlInput.properties.placeholder = KMNCompanyEamil
- if let annotationURL = linkAnnotation.url(){
- if annotationURL.hasPrefix("mailto:") {
- if let range = annotationURL.range(of: "mailto:") {
- let trimmedString = String(annotationURL[range.upperBound...])
- urlInput.properties.text = trimmedString
- }
- } else {
- urlInput.properties.text = ""
- }
- } else {
- urlInput.properties.text = ""
- }
- urlInput.properties.state = .pressed
- urlInput.beginEditing()
- urlInput.reloadData()
- }
- updateFrame(listView: listView ?? CPDFListView())
- }
- }
-
- @IBOutlet weak var contentBox: NSBox!
- @IBOutlet weak var operationBox: NSBox!
- @IBOutlet weak var paneBox: NSBox!
- @IBOutlet weak var lineBox: NSBox!
- @IBOutlet var paneSelectorItem: ComponentCSelector!
- @IBOutlet weak var operationWidthConstraint: NSLayoutConstraint!
- @IBOutlet weak var rightOffsetConstraint: NSLayoutConstraint!
- @IBOutlet weak var operationHeightConstraint: NSLayoutConstraint!
-
- @IBOutlet var generaPopView: NSView!
- @IBOutlet var generaColorGroup: ComponentCColorGroup!
-
- @IBOutlet var fontPopView: NSView!
- @IBOutlet var fontColorItem: ComponentCColorItem!
- @IBOutlet var fontNameSelect: ComponentSelect!
- @IBOutlet var fontSizeZoomOutButton: ComponentButton!
- @IBOutlet var fontSizeZoomInButton: ComponentButton!
- @IBOutlet var fontAlightButton: ComponentButton!
-
- @IBOutlet var shapeView: NSView!
- @IBOutlet var shapeColorGroup: ComponentCColorGroup!
- @IBOutlet var widthZoomOutButton: ComponentButton!
- @IBOutlet var widthZoomInButton: ComponentButton!
- @IBOutlet weak var shapeRightConstraint: NSLayoutConstraint!
- @IBOutlet var linkView: NSView!
- @IBOutlet var pageLinkButton: ComponentButton!
- @IBOutlet var urlLinkButton: ComponentButton!
- @IBOutlet var emailLinkButton: ComponentButton!
- @IBOutlet weak var pageLinkWidthConstraint: NSLayoutConstraint!
- @IBOutlet weak var urlLinkWidthConstraint: NSLayoutConstraint!
- @IBOutlet weak var emailLinkWidthConstraint: NSLayoutConstraint!
-
- @IBOutlet var formView: NSView!
- @IBOutlet var fildNameInput: ComponentInput!
- @IBOutlet var gropNameInput: ComponentInput!
- @IBOutlet var formRightConstraint: NSLayoutConstraint!
-
- @IBOutlet var alightView: NSView!
- @IBOutlet var alightButton: ComponentButton!
-
- @IBOutlet var linkPageDetailView: NSView!
- @IBOutlet var backPageLinkButton: ComponentButton!
- @IBOutlet var paginationView: ComponentPagination!
- @IBOutlet var paginationDesBox: NSBox!
- @IBOutlet var pageThumImageView: NSImageView!
- @IBOutlet var goPageLinkButton: ComponentButton!
- @IBOutlet weak var backPageWidthConstraint: NSLayoutConstraint!
-
- @IBOutlet var linkUrlDetailView: NSView!
- @IBOutlet var backUrlLinkButton: ComponentButton!
- @IBOutlet var goUrlLinkButton: ComponentButton!
- @IBOutlet var urlInput: ComponentInput!
- @IBOutlet weak var backUrlWidthConstraint: NSLayoutConstraint!
-
- private var fontPopover:NSPopover?
- private var ObjectPopover:NSPopover?
-
- weak var listView:CPDFListView? {
- didSet {
- paginationView.properties.totalCount = Int(listView?.document.pageCount ?? 1)
- paginationView.reloadData()
- }
- }
-
- override func windowDidLoad() {
- super.windowDidLoad()
- }
-
- override func initContentView() {
- super.initContentView()
-
- configFormPopUI()
- congfigFontPopUI()
- congfigGeneraPopUI()
- congfigShapePopUI()
-
- paneSelectorItem.properties = ComponentCSelectorProperty(iconImage:NSImage(named: "KMNImageNameListViewPopPane"))
- paneSelectorItem.setTarget(self, action: #selector(paneButtonClicked(_ :)))
-
- fontSizeZoomOutButton.properties = ComponentButtonProperty(type: .text_gray,
- size: .s,
- state: .normal,
- onlyIcon: true,
- icon:NSImage(named: "KMNImageNameListViewPopFontSizeZoomOut"),
- keepPressState: false)
- fontSizeZoomOutButton.setTarget(self, action: #selector(fontSizeZoomOutButtonClicked(_ :)))
-
- fontSizeZoomInButton.properties = ComponentButtonProperty(type: .text_gray,
- size: .s,
- state: .normal,
- onlyIcon: true,
- icon:NSImage(named: "KMNImageNameListViewPopFontSizeZoomIn"),
- keepPressState: false)
- fontSizeZoomInButton.setTarget(self, action: #selector(fontSizeZoomInButtonClicked(_ :)))
-
- fontAlightButton.properties = ComponentButtonProperty(type: .text_gray,
- size: .s,
- state: .normal,
- onlyIcon: true,
- icon:NSImage(named: "KMNImageNameListViewPopAlightLeft"))
- fontAlightButton.setTarget(self, action: #selector(fontAlightButtonClicked(_ :)))
-
- widthZoomOutButton.properties = ComponentButtonProperty(type: .text_gray,
- size: .s,
- state: .normal,
- onlyIcon: true,
- icon:NSImage(named: "KMNImageNameListViewPopWidthZoomOut"),
- keepPressState: false)
- widthZoomOutButton.setTarget(self, action: #selector(widthZoomOutButtonClicked(_ :)))
-
- widthZoomInButton.properties = ComponentButtonProperty(type: .text_gray,
- size: .s,
- state: .normal,
- onlyIcon: true,
- icon:NSImage(named: "KMNImageNameListViewPopWidthZoomIn"),
- keepPressState: false)
- widthZoomInButton.setTarget(self, action: #selector(widthZoomInButtonClicked(_ :)))
-
- pageLinkButton.setTarget(self, action: #selector(pageLinkButtonClicked(_ :)))
- urlLinkButton.setTarget(self, action: #selector(urlLinkButtonClicked(_ :)))
- emailLinkButton.setTarget(self, action: #selector(emailLinkButtonClicked(_ :)))
-
- alightButton.properties = ComponentButtonProperty(type: .text_gray,
- size: .s,
- state: .normal,
- onlyIcon: true,
- icon:NSImage(named: "KMNImageNameObjectPopAlightLeft"))
- alightButton.setTarget(self, action: #selector(alightButtonClicked(_ :)))
-
- goUrlLinkButton.properties = ComponentButtonProperty(type: .text_gray,
- size: .s,
- state: .normal,
- onlyIcon: true,
- icon:NSImage(named: "KMNImageNamePopLinkGO"),keepPressState: false)
- goUrlLinkButton.setTarget(self, action: #selector(linkGoButtonClicked(_ :)))
-
- goPageLinkButton.properties = ComponentButtonProperty(type: .text_gray,
- size: .s,
- state: .normal,
- onlyIcon: true,
- icon:NSImage(named: "KMNImageNamePopLinkGO"),keepPressState: false)
- goPageLinkButton.setTarget(self, action: #selector(linkGoButtonClicked(_ :)))
-
- paginationView.properties = ComponentPaginationProperty(doubleArrow_show: false, currentIndex: 0, totalCount: 1)
- paginationView.delegate = self
-
- let inputFiedProperty: ComponentInputProperty = ComponentInputProperty(size: .s,
- state:.pressed ,
- isError: false,
- showPrefix: false,
- showSuffix: false,
- showClear: false,
- isDisabled: false,
- placeholder: KMNCompanyWebsite,
- text: "")
- urlInput.properties = inputFiedProperty
- urlInput.delegate = self
- }
-
- override func updateUIThemeColor() {
- super.updateUIThemeColor()
-
- lineBox.fillColor = ComponentLibrary.shared.getComponentColorFromKey("colorBorder/divider")
- contentBox.fillColor = ComponentLibrary.shared.getComponentColorFromKey("colorBg/popup")
- contentBox.borderColor = ComponentLibrary.shared.getComponentColorFromKey("colorBorder/3-default")
- paginationDesBox.fillColor = ComponentLibrary.shared.getComponentColorFromKey("colorFill/4")
- paginationDesBox.borderColor = ComponentLibrary.shared.getComponentColorFromKey("colorBorder/4")
- pageThumImageView.wantsLayer = true
- paginationDesBox.layer?.borderColor = ComponentLibrary.shared.getComponentColorFromKey("colorBorder/divider").cgColor
- }
-
- override func updateUILanguage() {
- super.updateUILanguage()
-
- pageLinkButton.properties = ComponentButtonProperty(type: .text_gray,
- size: .s,
- state: .normal,
- onlyIcon: false,
- showLeftIcon:true,
- buttonText:KMLocalizedString("Page"),
- icon:NSImage(named: "KMNImageNameListViewLinkPage"),keepPressState: false)
-
- urlLinkButton.properties = ComponentButtonProperty(type: .text_gray,
- size: .s,
- state: .normal,
- onlyIcon: false,
- showLeftIcon:true,
- buttonText:KMLocalizedString("Web"),
- icon:NSImage(named: "KMNImageNameListViewLinkUrl"),keepPressState: false)
-
- emailLinkButton.properties = ComponentButtonProperty(type: .text_gray,
- size: .s,
- state: .normal,
- onlyIcon: false,
- showLeftIcon:true,
- buttonText:KMLocalizedString("Email"),
- icon:NSImage(named: "KMNImageNameListViewLinkEmail"),keepPressState: false)
-
- pageLinkWidthConstraint.constant = pageLinkButton.properties.propertyInfo.viewWidth
- urlLinkWidthConstraint.constant = urlLinkButton.properties.propertyInfo.viewWidth
- emailLinkWidthConstraint.constant = emailLinkButton.properties.propertyInfo.viewWidth
-
- backUrlLinkButton.properties = ComponentButtonProperty(type: .text_primary,
- size: .s,
- state: .normal,
- onlyIcon: false,
- showLeftIcon: true,
- buttonText: KMLocalizedString("Back"),
- icon:NSImage(named: "KMNImageNamePopLinkBack"),keepPressState: false)
- backUrlLinkButton.setTarget(self, action: #selector(linkBackButtonClicked(_ :)))
- backUrlWidthConstraint.constant = backUrlLinkButton.properties.propertyInfo.viewWidth
- backUrlLinkButton.reloadData()
-
- backPageLinkButton.properties = ComponentButtonProperty(type: .text_primary,
- size: .s,
- onlyIcon: false,
- showLeftIcon:true,
- buttonText: KMLocalizedString("Back"),
- icon:NSImage(named: "KMNImageNamePopLinkBack"),keepPressState: false)
- backPageLinkButton.setTarget(self, action: #selector(linkBackButtonClicked(_ :)))
- backPageWidthConstraint.constant = backPageLinkButton.properties.propertyInfo.viewWidth
-
- }
-
- //MARK: - Public
- public func updateFrame(listView:CPDFListView) {
- let activeAnnotations = annotationPopMode.annotations
- let page = activeAnnotations.first?.page
- let windowFram = listView.window?.frame ?? CGRectZero
-
- if(page != nil) {
- let pageRect = listView.selectionMultipleBounds(with: activeAnnotations)
- let positioningRect = listView.convert(pageRect, from: page!)
- if (CGRectIntersectsRect(positioningRect, listView.frame)) {
- let view: NSView? = nil
- let position = listView.convert(positioningRect, to: view)
- var positionNew = position.origin
-
- positionNew.x += windowFram.origin.x + position.width/2
- positionNew.y += windowFram.origin.y + position.height
-
- var positionRect = self.window?.frame ?? CGRectZero
- positionRect.origin.x = positionNew.x - positionRect.width/2
- positionRect.origin.y = positionNew.y + popOffSet
-
- var listViewWindRect = listView.convert(listView.frame, to: view)
- listViewWindRect.origin.x += windowFram.origin.x
- listViewWindRect.origin.y += windowFram.origin.y
- if CGRectGetMaxY(positionRect) > CGRectGetMaxY(listViewWindRect) {
- positionRect.origin.y = positionNew.y - popOffSet - position.height - positionRect.size.height
- }
-
- if CGRectGetMinX(positionRect) < CGRectGetMinX(listViewWindRect) {
- positionRect.origin.x = CGRectGetMinX(listViewWindRect)
- }
- if CGRectGetMaxX(positionRect) > CGRectGetMaxX(listViewWindRect) {
- positionRect.origin.x = CGRectGetMaxX(listViewWindRect) - positionRect.width
- }
-
- self.window?.setFrame(positionRect, display: true)
-
- updateUILanguage()
- } else {
-
- }
- }
- }
-
- public func closeWindow(listView:CPDFListView?) {
- if self.window?.isVisible == true {
- listView?.window?.removeChildWindow(self.window ?? NSWindow())
- self.window?.close()
- }
-
- if ObjectPopover?.isShown == true {
- ObjectPopover?.close()
- }
-
- if fontPopover?.isShown == true {
- fontPopover?.close()
- }
- }
-
- //MARK: - private
- private func congfigGeneraPopUI() {
- var colors = KMAnnotationPropertiesColorManager.manager.markHighlightColors
- if(annotationPopMode.annotation is CPDFMarkupAnnotation) {
- let markupAnnotation:CPDFMarkupAnnotation = annotationPopMode.annotation as! CPDFMarkupAnnotation
- if markupAnnotation.markupType() == .highlight {
- colors = KMAnnotationPropertiesColorManager.manager.markHighlightColors
- } else {
- colors = KMAnnotationPropertiesColorManager.manager.markOtherColors
- }
- } else if (annotationPopMode.annotation is CPDFInkAnnotation) {
- colors = KMAnnotationPropertiesColorManager.manager.inkColors
- } else if (annotationPopMode.annotation is CPDFTextAnnotation) {
- colors = KMAnnotationPropertiesColorManager.manager.noteColors
- }
-
- let colorAProperty = ComponentCColorProperty(colorType: .color, state: .normal, isCustom: false, color: colors[0])
- let colorBProperty = ComponentCColorProperty(colorType: .color, state: .normal, isCustom: false, color: colors[1])
- let colorCProperty = ComponentCColorProperty(colorType: .color, state: .normal, isCustom: false, color: colors[2])
- let colorDProperty = ComponentCColorProperty(colorType: .color, state: .normal, isCustom: false, color: colors[3])
- let colorEProperty = ComponentCColorProperty(colorType: .color, state: .normal, isCustom: true, color: colors[4])
- generaColorGroup.setUpWithColorPropertys([colorAProperty, colorBProperty, colorCProperty, colorDProperty], customItemProperty: colorEProperty)
- generaColorGroup.delegate = self
- }
-
- private func congfigFontPopUI() {
- fontNameSelect.properties = ComponentSelectProperties(size: .s,
- state: .normal,
- isDisabled: false,
- isError: false,
- leftIcon: false,
- placeholder: nil,
- errorText: nil,
- creatable: false,
- text: NSLocalizedString("", comment: ""))
- fontNameSelect.delegate = self
-
- var menuItemArr: [ComponentMenuitemProperty] = []
- for familyName in CPDFFont.familyNames {
- let fontNames = CPDFFont.fontNames(forFamilyName: familyName)
- let itemProperty: ComponentMenuitemProperty = ComponentMenuitemProperty(multipleSelect: false,
- itemSelected: false,
- isDisabled: false,
- keyEquivalent: nil,
- text: familyName,identifier: "1")
- var subMenuItemArr: [ComponentMenuitemProperty] = []
-
- for fontName in fontNames {
- let subItemProperty: ComponentMenuitemProperty = ComponentMenuitemProperty(multipleSelect: false,
- itemSelected: false,
- isDisabled: false,
- keyEquivalent: nil,
- text: fontName,identifier: "2")
- subMenuItemArr.append(subItemProperty)
- }
-
- itemProperty.subPropertys = subMenuItemArr
- menuItemArr.append(itemProperty)
- }
-
- fontNameSelect.updateMenuItemsArr(menuItemArr)
-
- fontColorItem.properties = ComponentCColorProperty(colorType: .color,
- state: .normal,
- isCustom: true,
- color: NSColor.red)
- fontColorItem.delegate = self
- fontColorItem.reloadData()
- }
-
- private func congfigShapePopUI() {
- var colors = KMAnnotationPropertiesColorManager.manager.inkColors
- let annotation = annotationPopMode.annotation ?? CPDFAnnotation()
- if annotation.isKind(of: CPDFInkAnnotation.self) {
- colors = KMAnnotationPropertiesColorManager.manager.inkColors
- } else if annotation.isKind(of: CPDFCircleAnnotation.self) ||
- annotation.isKind(of: CPDFSquareAnnotation.self) {
- colors = KMAnnotationPropertiesColorManager.manager.inkColors
- } else if annotation.isKind(of: CPDFLineAnnotation.self) {
- if let lineAnnotation:CPDFLineAnnotation = annotation as? CPDFLineAnnotation {
- if lineAnnotation.isMeasure {
- colors = KMAnnotationPropertiesColorManager.manager.measure_Border_Colors
- } else {
- if lineAnnotation.endLineStyle == .none && lineAnnotation.startPoint == .none {
- colors = KMAnnotationPropertiesColorManager.manager.lineColors
- } else {
- colors = KMAnnotationPropertiesColorManager.manager.arrowColors
- }
- }
- }
- } else if (annotation.isKind(of: CPDFPolygonAnnotation.self) ||
- annotation.isKind(of: CPDFPolylineAnnotation.self)) {
- colors = KMAnnotationPropertiesColorManager.manager.measure_Border_Colors
- } else if annotation.isKind(of: CPDFTextAnnotation.self) {
- colors = KMAnnotationPropertiesColorManager.manager.noteColors
- } else if annotation.isKind(of: CSelfSignAnnotation.self) {
- colors = KMAnnotationPropertiesColorManager.manager.fill_tickColors
- }
- let colorAProperty = ComponentCColorProperty(colorType: .color, state: .normal, isCustom: false, color: colors[0])
- let colorBProperty = ComponentCColorProperty(colorType: .color, state: .normal, isCustom: false, color: colors[1])
- let colorCProperty = ComponentCColorProperty(colorType: .color, state: .normal, isCustom: false, color: colors[2])
- let colorDProperty = ComponentCColorProperty(colorType: .color, state: .normal, isCustom: false, color: colors[3])
- let colorEProperty = ComponentCColorProperty(colorType: .color, state: .normal, isCustom: true, color: colors[4])
- shapeColorGroup.setUpWithColorPropertys([colorAProperty, colorBProperty, colorCProperty, colorDProperty], customItemProperty: colorEProperty)
- shapeColorGroup.delegate = self
- }
-
- private func configFormPopUI() {
- let inputFiedProperty: ComponentInputProperty = ComponentInputProperty(size: .s,
- state:.pressed ,
- isError: false,
- showPrefix: false,
- showSuffix: false,
- showClear: false,
- isDisabled: false,
- placeholder: "File Name",
- text: "")
- fildNameInput.properties = inputFiedProperty
- fildNameInput.delegate = self
-
- let inputGropProperty: ComponentInputProperty = ComponentInputProperty(size: .s,
- state:.pressed ,
- isError: false,
- showPrefix: false,
- showSuffix: false,
- showClear: false,
- isDisabled: false,
- placeholder: "Grop Name",
- text: "")
- gropNameInput.properties = inputGropProperty
- gropNameInput.delegate = self
- }
-
- private func reloadPageUrlData() {
- if let destination = linkAnnotation.destination() {
- if let page = destination.page() {
- paginationView.properties.currentIndex = Int(page.pageIndex() + 1)
- paginationView.reloadData()
- return
- }
- }
-
- paginationView.properties.currentIndex = Int(((listView?.currentPageIndex ?? 0) + 1))
- paginationView.reloadData()
- }
-
- private func refreshPageThum() {
- guard let pdfView = listView else {
- return
- }
- let thumbnail = KMNThumbnail.init(document: pdfView.document, currentPageIndex:Int(paginationView.properties.currentIndex - 1))
- thumbnail.generateThumImage {[weak self] image in
- self?.pageThumImageView.image = image
- }
- }
-
- //MARK: - Action
- @objc func paneButtonClicked(_ sender: NSView) {
- isOpenPane = !isOpenPane
- paneCallback?(isOpenPane)
- }
-
- @objc func fontSizeZoomOutButtonClicked(_ sender: NSView) {
- if let freeText = annotationPopMode.annotation as? CPDFFreeTextAnnotation {
- if listView?.isEdit(withCurrentFreeText: freeText) == true {
- listView?.commitEditAnnotationFreeText(freeText)
- }
- if annotationPopMode.zoomOutFontSize() {
- updatePDFViewCallback?()
- }
- }
- }
-
- @objc func fontSizeZoomInButtonClicked(_ sender: NSView) {
- if let freeText = annotationPopMode.annotation as? CPDFFreeTextAnnotation {
- if listView?.isEdit(withCurrentFreeText: freeText) == true {
- listView?.commitEditAnnotationFreeText(freeText)
- }
- if annotationPopMode.zoomInFontSize() {
- updatePDFViewCallback?()
- }
- }
- }
-
- @objc func fontAlightButtonClicked(_ sender: NSView) {
- if fontPopover?.isShown == true {
- fontPopover?.close()
- } else {
- let vc = KMNPopDetailsViewController(nibName: "KMNPopDetailsViewController", bundle: nil)
- let createFilePopover: NSPopover = NSPopover.init()
- createFilePopover.contentViewController = vc
- createFilePopover.delegate = self
- createFilePopover.animates = true
- createFilePopover.behavior = .semitransient
- createFilePopover.setValue(true, forKey: "shouldHideAnchor")
- createFilePopover.show(relativeTo: CGRect(x: sender.bounds.origin.x, y: 20, width: sender.bounds.size.width, height: sender.bounds.size.height), of: sender, preferredEdge: .maxY)
-
- vc.detailPopType = .freeTextAlight
- vc.fontChangeAlighCallback = { [weak self] alight in
- if let freeText = self?.annotationPopMode.annotation as? CPDFFreeTextAnnotation {
- if self?.listView?.isEdit(withCurrentFreeText: freeText) == true {
- self?.listView?.commitEditAnnotationFreeText(freeText)
- }
- }
-
- self?.annotationPopMode.setAnnotationAlignment(annotationAlignment: alight)
- self?.updatePDFViewCallback?()
- self?.fontAlight = alight
- }
- fontPopover = createFilePopover
- vc.fontAlight = fontAlight
- }
- }
-
- @objc func widthZoomOutButtonClicked(_ sender: NSView) {
- if annotationPopMode.zoomOutShapeWidth() {
- updatePDFViewCallback?()
- }
- }
-
- @objc func widthZoomInButtonClicked(_ sender: NSView) {
- if annotationPopMode.zoomInShapeWidth() {
- updatePDFViewCallback?()
- }
- }
-
- @objc func pageLinkButtonClicked(_ sender: NSView) {
- linkType = .page
- }
-
- @objc func urlLinkButtonClicked(_ sender: NSView) {
- linkType = .url
- }
-
- @objc func emailLinkButtonClicked(_ sender: NSView) {
- linkType = .email
- }
-
- @objc func alightButtonClicked(_ sender: NSView) {
- if ObjectPopover?.isShown == true {
- ObjectPopover?.close()
- } else {
- let vc = KMNPopDetailsViewController(nibName: "KMNPopDetailsViewController", bundle: nil)
- let createFilePopover: NSPopover = NSPopover.init()
- createFilePopover.contentViewController = vc
- createFilePopover.delegate = self
- createFilePopover.animates = true
- createFilePopover.behavior = .semitransient
- createFilePopover.setValue(true, forKey: "shouldHideAnchor")
- createFilePopover.show(relativeTo: CGRect(x: sender.bounds.origin.x, y: 20, width: sender.bounds.size.width, height: sender.bounds.size.height), of: sender, preferredEdge: .maxY)
-
- if (annotationPopMode.annotations.count == 2) {
- vc.detailPopType = .freeTextDoubleAlight
- } else if (annotationPopMode.annotations.count > 2) {
- vc.detailPopType = .freeTextMultpleAlight
- }
-
- vc.objectChangeAlighCallback = { [weak self] alight in
- self?.objectAlignType = alight
- self?.updatePDFViewCallback?()
- }
- ObjectPopover = createFilePopover
- vc.objectAlignType = objectAlignType
- }
- }
-
- @objc func linkGoButtonClicked(_ sender: NSView) {
- if linkType == .url {
- guard let webString = linkAnnotation.url() else { return }
- if let data = URL(string: webString) {
- NSWorkspace.shared.open(data)
- }
- } else if linkType == .email {
- guard let emailString = linkAnnotation.url() else {
- let alert = NSAlert()
- alert.alertStyle = .critical
- alert.messageText = NSLocalizedString("Invalid Email. Please try again.", comment: "")
- alert.runModal()
- return
- }
- if KMNTools.isValidateEmail(emailString) {
- let alert = NSAlert()
- alert.alertStyle = .critical
- alert.messageText = NSLocalizedString("Invalid Email. Please try again.", comment: "")
- alert.runModal()
- } else {
- NSWorkspace.shared.open(URL(string: emailString)!)
- }
- } else if linkType == .page {
- if let destination = linkAnnotation.destination() {
- listView?.go(to: destination)
- closeWindow(listView: listView)
- }
- }
- }
-
- @objc func linkBackButtonClicked(_ sender: NSView) {
- linkType = .linkSetting
- }
-
- @objc func fontColorChange(_ sender: Any) {
- if let color = (sender as? NSColorPanel)?.color {
- if let freeText = annotationPopMode.annotation as? CPDFFreeTextAnnotation {
-
- if listView?.isEdit(withCurrentFreeText: freeText) == true {
- listView?.commitEditAnnotationFreeText(freeText)
- }
- }
- annotationPopMode.setAnnotationFontColor(annotationFontColor: color)
- fontColor = color
-
- updatePDFViewCallback?()
- }
- }
- }
- //MARK: - ComponentCColorDelegate
- extension KMNPopAnnotationWindowController: ComponentCColorDelegate {
- func componentCColorDidChooseColor(_ view: NSView, _ color: NSColor?) {
- if(view == generaColorGroup) {
-
- self.annotationPopMode.setAnnotationColor(annotationColor: color)
- updatePDFViewCallback?()
- } else if (view == shapeColorGroup) {
- self.annotationPopMode.setAnnotationColor(annotationColor: color)
- updatePDFViewCallback?()
- } else if (view == fontColorItem) {
- fontColorItem.properties?.state = .normal
- fontColorItem.reloadData()
-
- let colorPanel = NSColorPanel.shared
-
- colorPanel.setTarget(self)
- colorPanel.showsAlpha = false
- colorPanel.setAction(#selector(self.fontColorChange(_:)))
- colorPanel.orderFront(nil)
- }
- }
- }
- //MARK: - ComponentInputDelegate
- extension KMNPopAnnotationWindowController: ComponentInputDelegate {
- func componentInputDidChanged(inputView: ComponentInput) {
- if (inputView == fildNameInput) {
- for i in 0 ..< annotationPopMode.annotations.count {
- let annotation = annotationPopMode.annotations[i]
- if let widgt = annotation as? CPDFWidgetAnnotation {
- widgt.setFieldName(inputView.properties.text)
- }
- }
- updatePDFViewCallback?()
- } else if (inputView == gropNameInput) {
- for i in 0 ..< annotationPopMode.annotations.count {
- let annotation = annotationPopMode.annotations[i]
- if let button = annotation as? CPDFButtonWidgetAnnotation {
- button.setButtonWidgetStateString(inputView.properties.text)
- }
- }
-
- updatePDFViewCallback?()
- } else if (inputView == urlInput) {
- if linkType == .email {
- let emailString = urlInput.properties.text
- if KMNTools.isValidateEmail(emailString) {
- linkAnnotation.setDestination(nil)
-
- let linkUrlPath = KMNTools.judgeEmailURL(emailString)
- linkAnnotation.setURL(linkUrlPath)
- updatePDFViewCallback?()
-
- }
- } else if linkType == .url {
- let webString = urlInput.properties.text
- linkAnnotation.setDestination(nil)
- let linkUrlPath = KMNTools.judgeWebURL(webString)
- linkAnnotation.setURL(linkUrlPath)
- updatePDFViewCallback?()
- }
- }
- }
-
- func componentInputDidEndEditing(inputView: ComponentInput) {
- if (inputView == fildNameInput) {
-
- } else if (inputView == gropNameInput) {
-
- } else if (inputView == urlInput) {
-
-
- }
- }
- }
- //MARK: - ComponentSelectDelegate
- extension KMNPopAnnotationWindowController: ComponentSelectDelegate {
- func componentSelectDidSelect(view: ComponentSelect?, menuItemProperty: ComponentMenuitemProperty?) {
- if(view == fontNameSelect) {
- if menuItemProperty?.identifier == "1" {
- let familyName = fontNameSelect.properties.text ?? "Helvetica"
- let styles = CPDFFont.fontNames(forFamilyName: familyName)
-
- compdfFont = CPDFFont(familyName: familyName, fontStyle: styles.first ?? "")
- annotationPopMode.setAnnotationFont(font: compdfFont ?? CPDFFont.init(familyName: "Helvetica", fontStyle: ""))
- updatePDFViewCallback?()
- } else if menuItemProperty?.identifier == "2"{ //字体样式
- compdfFont = CPDFFont(familyName: compdfFont?.familyName ?? "Helvetica", fontStyle: menuItemProperty?.text ?? "")
- annotationPopMode.setAnnotationFont(font: compdfFont ?? CPDFFont.init(familyName: "Helvetica", fontStyle: ""))
-
- updatePDFViewCallback?()
- }
- }
- }
- }
- //MARK: - ComponentSelectDelegate
- extension KMNPopAnnotationWindowController: NSPopoverDelegate {
- func popoverWillClose(_ notification: Notification) {
- if fontPopover == (notification.object as? NSPopover) {
- if(fontAlightButton.properties.state == .pressed) {
- fontAlightButton.properties.state = .normal
- fontAlightButton.reloadData()
- }
- } else if ObjectPopover == (notification.object as? NSPopover) {
- if(alightButton.properties.state == .pressed) {
- alightButton.properties.state = .normal
- alightButton.reloadData()
- }
- }
-
- }
- }
- //MARK: - ComponentPaginationDelegate
- extension KMNPopAnnotationWindowController: ComponentPaginationDelegate {
- public func componentPaginationDidValueChanged(pagination: ComponentPagination) {
- let pageIndex = pagination.properties.currentIndex
- if let page = listView?.document.page(at: UInt(pageIndex)) {
-
- linkAnnotation.setURL(nil)
- let destination = CPDFDestination(document: listView?.document ?? CPDFDocument(), pageIndex: Int(paginationView.properties.currentIndex - 1))
- linkAnnotation.setDestination(destination)
-
- refreshPageThum()
- reloadPageUrlData()
- updatePDFViewCallback?()
- }
- }
- }
|