123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209 |
- //
- // 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
- // }
- }
-
- }
|