123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204 |
- //
- // 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 headerBGView: NSView!
- @IBOutlet var titleLabel: NSTextField!
-
- @IBOutlet var infoContendView: NSView!
-
- @IBOutlet var emptyView: ComponentEmpty!
-
- var annotations: [CPDFAnnotation] {
- get {
- return self.pdfView?.activeAnnotations as? [CPDFAnnotation] ?? []
- }
- }
-
- var pdfView: CPDFListView?
- var viewManager: KMPDFViewManager?
-
- //Controller
- //Markup
-
- //Edit
- var edit_textController: KMEditPDFTextPropertyViewController?
- var edit_imageController: KMEditImageController?
- var edit_linkController: KMLinkViewController?
-
- //Form
-
- //Fill
-
- //
-
- var contentViewController: NSViewController?
- //MARK: - func
- override func viewDidLoad() {
- super.viewDidLoad()
- // Do view setup here.
-
- setupUI()
-
- setupContentController()
- }
-
- 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")
-
- emptyView.properties = ComponentEmptyProperty(emptyType: .noWatermark, text: KMLocalizedString("No identical attributes"), subText: "")
- }
-
- func updateTitleLabel() {
- if viewManager?.subToolMode == .Edit_text {
- titleLabel.stringValue = KMLocalizedString("Text")
- } else if viewManager?.subToolMode == .Edit_Image {
- titleLabel.stringValue = KMLocalizedString("Image")
- } else if viewManager?.subToolMode == .Edit_Link {
- titleLabel.stringValue = KMLocalizedString("Link")
- } else if viewManager?.subToolMode == .Edit_Crop {
- titleLabel.stringValue = KMLocalizedString("Crop")
- }
- }
-
- func setupContentController() {
- updateTitleLabel()
-
- contentViewController?.view.removeFromSuperview()
- contentViewController = nil
-
- if viewManager?.toolMode == .Edit {
-
- if pdfView?.km_EditingAreas().isEmpty == true {
-
- } else if pdfView?.km_editingImageAreas().isEmpty == true && pdfView?.km_editingTextAreas().isEmpty == false {
- //编辑文字
- if edit_textController == nil {
- edit_textController = KMEditPDFTextPropertyViewController.init()
- }
- edit_textController?.pdfView = self.pdfView
-
- contentViewController = edit_textController
-
- } else if pdfView?.km_editingImageAreas().isEmpty == false && pdfView?.km_editingTextAreas().isEmpty == true {
- //编辑图片
- if edit_imageController == nil {
- edit_imageController = KMEditImageController.init()
- }
- contentViewController = edit_imageController
-
- } else {
- //多选
- }
-
- if viewManager?.subToolMode == .Edit_Link {
- //链接
- if edit_linkController == nil {
- edit_linkController = KMLinkViewController.init()
- }
- edit_linkController?.pdfView = self.pdfView
- contentViewController = edit_linkController
-
- }
- }
-
- if let contendVC = contentViewController {
- contendVC.view.frame = infoContendView.bounds
- contendVC.view.autoresizingMask = [.width, .height]
- infoContendView.addSubview(contendVC.view)
-
- headerBGView.isHidden = false
- emptyView.isHidden = true
- } else {
- headerBGView.isHidden = true
- emptyView.isHidden = false
-
- }
-
- }
-
- func reloadData() {
- if viewManager?.toolMode == .Edit {
-
- //图片&文字
- if pdfView?.km_EditingAreas().isEmpty == true {
-
- } else if pdfView?.km_editingImageAreas().isEmpty == true && pdfView?.km_editingTextAreas().isEmpty == false {
- //编辑文字
- edit_textController?.pdfView = self.pdfView
- edit_textController?.reloadData()
- } else if pdfView?.km_editingImageAreas().isEmpty == false && pdfView?.km_editingTextAreas().isEmpty == true {
- //编辑图片
- edit_imageController?.pdfView = self.pdfView
- edit_imageController?.reloadData()
-
- } else {
- //多选
- }
-
- //Link
- if viewManager?.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()
-
- if linkAnnotations.count == 0 {
- (contentViewController as! KMLinkViewController).view.isHidden = true
- } else {
- (contentViewController as! KMLinkViewController).view.isHidden = false
- }
-
- }
-
- }
-
-
-
- }
-
- public func reloadDataWithPDFView(pdfView: CPDFListView) {
- self.pdfView = pdfView
-
- setupContentController()
-
- reloadData()
-
- }
-
- //重新刷新编辑中内容
- public func reloadEditingAreas() {
- if contentViewController is KMEditPDFTextPropertyViewController {
- (contentViewController as! KMEditPDFTextPropertyViewController).reloadData()
- } else if contentViewController is KMEditImageController {
- (contentViewController as! KMEditImageController).reloadData()
- }
- }
-
- }
|