123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189 |
- //
- // KMBatchWindowController.swift
- // PDF Master
- //
- // Created by lizhe on 2023/1/12.
- //
- import Cocoa
- class KMBatchWindowController: NSWindowController {
- @IBOutlet weak var batchPrecessingView: KMBatchProcessingView!
- @IBOutlet weak var batchCollectionView: KMBatchCollectionView!
- @IBOutlet weak var batchHandleView: NSView!
- @IBOutlet weak var settingView: KMBatchSettingView!
- @IBOutlet weak var titleLabel: NSTextField!
-
- var batchData: [KMBatchProcessingTableViewModel]?
- var inputType: DataNavigationViewButtonActionType? {
- didSet {
- var type: KMBatchCollectionViewType = .convertPDF
- switch inputType {
- case .BatchRemove:
- type = .batchRemove
- case .Background:
- type = .background
- case .Watermark:
- type = .watermark
- case .Compression:
- type = .compress
- case .Security:
- type = .security
- case.HeaderAndFooter:
- type = .headerAndFooter
- case .BatesCode:
- type = .batesNumber
- default:
- type = .convertPDF
- }
- self.type = type
- }
- }
-
- var inputSubType: Any?
-
- var type: KMBatchCollectionViewType = .convertPDF {
- didSet {
- self.reloadData()
- }
- }
-
- deinit {
- KMPrint("KMImageToPDFWindowController 释放")
- }
-
- override func windowDidLoad() {
- super.windowDidLoad()
- // Implement this method to handle any initialization after your window controller's window has been loaded from its nib file.
- self.window?.title = NSLocalizedString("Batch", comment: "")
- self.setup()
- self.reloadData()
- }
-
-
- func setup() {
- self.window?.contentView?.wantsLayer = true
- self.window?.contentView?.layer?.backgroundColor = NSColor.white.cgColor
-
- self.titleLabel.font = NSFont.SFProTextRegularFont(16.0)
- self.titleLabel.textColor = NSColor.km_init(hex: "#252629")
-
- self.batchCollectionView.delegate = self
- self.batchPrecessingView.delegate = self
-
- self.settingView.type = .convertPDF
- }
-
- func reloadData() {
- self.batchPrecessingView.inputType = self.inputType
- self.batchCollectionView.inputType = self.type
- self.settingView.type = self.type
- self.settingView.subType = self.inputSubType
- }
-
- //MARK: 打开文件
- static func openFiles(window: NSWindow) {
- if KMBatchWindowController.isSampleController() {
- KMPrint("存在相同文件")
- if let controller: KMBatchWindowController = self.fetchSampleController() {
- controller.inputType = .Batch
- controller.showWindow(window)
- }
- } else {
- KMBatchProcessingView.openfiles(window: window) { openPanel in
- openPanel.title = "选择图片"
- openPanel.canChooseDirectories = false
- openPanel.canChooseFiles = true
- openPanel.allowsMultipleSelection = true
- openPanel.allowedFileTypes = KMOCRModel.supportedTypes()
- } completion: { (panel ,data) in
- if data.count != 0 {
- let batchWindowController: KMBatchWindowController = KMBatchWindowController.init(windowNibName: "KMBatchWindowController")
- batchWindowController.showWindow(window)
- batchWindowController.batchPrecessingView.inputData = data
- batchWindowController.inputType = .Batch
- }
- }
- }
- }
-
- //MARK: 打开文件
- static func openFile(_ url: URL?, _ type: DataNavigationViewButtonActionType, _ subType: Any = "") {
- if KMBatchWindowController.isSampleController() {
- if let controller: KMBatchWindowController = self.fetchSampleController() {
- KMPrint("存在相同文件")
- controller.inputSubType = subType
- controller.inputType = type
- controller.showWindow(NSApp.mainWindow)
- }
- } else {
- let batchWindowController: KMBatchWindowController = KMBatchWindowController.init(windowNibName: "KMBatchWindowController")
- batchWindowController.showWindow(NSApp.mainWindow)
- if url != nil {
- batchWindowController.batchPrecessingView.inputData = [url!]
- }
-
- batchWindowController.inputSubType = subType
- batchWindowController.inputType = type
- }
- }
-
- static func isSampleController() -> Bool {
- for window in NSApp.windows {
- let controller = window.windowController
- if controller is KMBatchWindowController {
- return true
- }
- }
- return false
- }
-
- static func fetchSampleController() -> KMBatchWindowController? {
- for window in NSApp.windows {
- let controller = window.windowController
- if controller is KMBatchWindowController {
- return controller as! KMBatchWindowController
- }
- }
-
- return nil
- }
- }
- extension KMBatchWindowController: KMBatchProcessingViewDelegate {
- func reloadData(data: [KMBatchProcessingTableViewModel]) {
- self.batchData = data
- self.settingView.filesData = self.batchData
- }
- }
- extension KMBatchWindowController: KMBatchCollectionViewDelegate {
- func didSelect(index: IndexPath, data: KMBatchCollectionViewModel) {
- KMPrint(data.type.rawValue)
- let dataType: KMBatchCollectionViewType = data.type
- self.settingView.type = dataType
-
- var type: DataNavigationViewButtonActionType = self.inputType ?? .ConvertPDF
- switch dataType {
- case .batchRemove:
- type = .BatchRemove
- case .background:
- type = .Background
- case .watermark:
- type = .Watermark
- case .compress:
- type = .Compression
- case .security:
- type = .Security
- case.headerAndFooter:
- type = .HeaderAndFooter
- case .batesNumber:
- type = .BatesCode
- default:
- type = .ConvertPDF
- }
- self.batchPrecessingView.inputType = type
- }
- }
|