// // KMRightSideController.swift // PDF Reader Pro // // Created by Niehaoyu on 2024/11/12. // import Cocoa import KMComponentLibrary class KMRightSideController: NSViewController { @IBOutlet var contendView: NSView! @IBOutlet var contendLeftDivider: ComponentDivider! @IBOutlet var titleLabel: NSTextField! @IBOutlet var infoContendView: NSView! var annotations: [CPDFAnnotation] = [] { didSet { reloadData() } } var pdfView: CPDFListView? var subToolMode: KMPDFSubToolMode = .None { //二级工具栏 didSet { updateUI() } } var contentViewController: NSViewController? override func viewDidLoad() { super.viewDidLoad() // Do view setup here. setupUI() updateUI() } func setupUI() { contendView.wantsLayer = true contendView.layer?.backgroundColor = ComponentLibrary.shared.getComponentColorFromKey("colorBg/layout-middle").cgColor contendLeftDivider.properties = ComponentDividerProperty(type: .vertical) titleLabel.textColor = ComponentLibrary.shared.getComponentColorFromKey("colorText/2") titleLabel.font = ComponentLibrary.shared.getFontFromKey("mac/body-m-bold") } func updateTitleLabel() { if subToolMode == .Edit_text { titleLabel.stringValue = KMLocalizedString("Text") } else if subToolMode == .Edit_Image { titleLabel.stringValue = KMLocalizedString("Image") } else if subToolMode == .Edit_Link { titleLabel.stringValue = KMLocalizedString("Link") } else if subToolMode == .Edit_Crop { titleLabel.stringValue = KMLocalizedString("Crop") } } func updateUI() { updateTitleLabel() contentViewController?.view.removeFromSuperview() contentViewController = nil if subToolMode == .Edit_Link { let controller = KMLinkViewController.init() controller.view.frame = infoContendView.bounds controller.view.autoresizingMask = [.width, .height] infoContendView.addSubview(controller.view) contentViewController = controller controller.pdfView = self.pdfView } } func reloadData() { if subToolMode == .Edit_Link && contentViewController is KMLinkViewController { if (contentViewController as! KMLinkViewController).pdfView != self.pdfView { (contentViewController as! KMLinkViewController).pdfView = self.pdfView } var linkAnnotations: [CPDFLinkAnnotation] = [] for annotation in self.annotations { if annotation is CPDFLinkAnnotation { linkAnnotations.append(annotation as! CPDFLinkAnnotation) } } (contentViewController as! KMLinkViewController).annotations = linkAnnotations (contentViewController as! KMLinkViewController).reloadData() } } public func reloadDataWithPDFView(pdfView: CPDFListView) { self.pdfView = pdfView var selectedAnnotation : CPDFAnnotation? = nil var activeAnnotations : [CPDFAnnotation] = [] if pdfView.activeAnnotations != nil && pdfView.activeAnnotations.count > 0 { selectedAnnotation = pdfView.activeAnnotations.firstObject as? CPDFAnnotation for annotation in pdfView.activeAnnotations { activeAnnotations.append(annotation as! CPDFAnnotation) } } var isSameAnnotation: Bool = true for tAnnotation in activeAnnotations { if tAnnotation.className != selectedAnnotation?.className { isSameAnnotation = false break } } self.annotations = activeAnnotations // if !isSameAnnotation { // self.annotationProperties.annotations = [] // self.annotationProperties.isEmptyAnnotation = true // return // } else if selectedAnnotation is CPDFTextWidgetAnnotation || selectedAnnotation is CPDFChoiceWidgetAnnotation || selectedAnnotation is CPDFButtonWidgetAnnotation { // if pdfView.toolMode != .formToolMode { // self.annotationProperties.annotations = [] // self.annotationProperties.isEmptyAnnotation = true // return // } // } else if (selectedAnnotation is KMAnnotationFromSignature) && (activeAnnotations.count > 1) { // self.annotationProperties.annotations = [] // self.annotationProperties.isEmptyAnnotation = true // return // } // // let annotationType = pdfView.annotationType // if KMAnnotationPropertiesViewController.height(with: selectedAnnotation) > 0 { // if activeAnnotations.count > 0{ // if self.subViewType != .AnnotationProperts { // self.subViewType = .AnnotationProperts // } // } // self.annotationProperties.annotations = activeAnnotations // self.isHidden = !(activeAnnotations.count > 0) // } else if self.listView.toolMode == .noteToolMode && KMAnnotationPropertiesViewController.height(withAnnotationMode: pdfView.annotationType) > 0 { // self.isHidden = false // if pdfView.activeAnnotation is CPDFLinkAnnotation { // if activeAnnotations.count > 0 { // self.annotationProperties.annotations = activeAnnotations // } else { // self.annotationProperties.annotations = [] // self.annotationProperties.annotationMode = annotationType // } // } else { // self.annotationProperties.annotations = [] // self.annotationProperties.annotationMode = annotationType // } // } else if listView.toolMode == .formToolMode && KMAnnotationPropertiesViewController.height(withAnnotationMode: pdfView.annotationType) > 0 { // self.isHidden = false // self.annotationProperties.annotations = [] // self.annotationProperties.annotationMode = annotationType // } else if listView.toolMode == .selfSignMode && KMAnnotationPropertiesViewController.height(withAnnotationMode: pdfView.annotationType) > 0 { // self.isHidden = false // self.annotationProperties.annotations = [] // self.annotationProperties.kEventTag = self.kEventTag // self.kEventTag = 0 // self.annotationProperties.annotationMode = annotationType // } else if (annotationType == .line || annotationType == .polyLine || annotationType == .polyGon || (annotationType == .square && self.listView.toolMode != .noteToolMode)) && KMAnnotationPropertiesViewController.height(withAnnotationMode: pdfView.annotationType) > 0 { // self.isHidden = false // self.annotationProperties.annotations = [] // self.annotationProperties.measureMode = annotationType // } else { // self.isHidden = true // } // // if (self.isHidden) { // self.annotationProperties.isEmptyAnnotation = self.isHidden // } else { // var isShowEmpty = self.isHidden; // if annotationType == .link && activeAnnotations.count == 0 { // self.isHidden = true // } else if (annotationType == .stamp || annotationType == .signSignature) && isShowEmpty { // let continuousAddStamp = UserDefaults.standard.bool(forKey: "KMContinuousAdditionStamp") // if continuousAddStamp { // isShowEmpty = false // self.annotationProperties.isContinuousAddStamp = true // // UserDefaults.standard.setValue(false, forKey: "KMContinuousAdditionStamp") // UserDefaults.standard.synchronize() // } // } else { // if isShowEmpty { // // } else { // if _subViewType == RightSubViewType.AnnotationProperts { // self.contextBox.contentView = self.annotationProperties.view // } // } // } // self.annotationProperties.isEmptyAnnotation = isShowEmpty // } } }