123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128 |
- //
- // KMPageEditSplitWindowController.swift
- // PDF Master
- //
- // Created by tangchao on 2023/1/12.
- //
- import Cocoa
- class KMPageEditSplitWindowController: KMPageEditSettingBaseWindowController {
-
- var hasPreView: Bool = false
-
- override var model: KMPageEditSettingBaseModel? {
- get {
- return super.model
- }
- set {
- super.model = newValue
- }
- }
-
- override func windowDidLoad() {
- super.windowDidLoad()
-
- if (hasPreView) {
- setWindowSize(NSSize(width: 583, height: 481))
- self.titleLabel.stringValue = NSLocalizedString("Split", comment: "")
- } else {
- setWindowSize(NSSize(width: 480, height: 481))
- self.titleLabel.stringValue = NSLocalizedString("Split Page", comment: "")
- }
-
- funcButton.title = NSLocalizedString("Split", comment: "")
- funcButton.layer?.backgroundColor = NSColor.black.cgColor
- funcButton.attributedTitle = NSMutableAttributedString(string: funcButton.title, attributes: [NSAttributedString.Key.foregroundColor : NSColor.white])
-
- if (hasPreView) {
- let controller = KMPDFInsertPreviewViewController(nibName: "KMPDFInsertPreviewViewController", bundle: nil)
- controller.pdfDocument = CPDFDocument(url: self.model?.documentURL)
- self.contentBox.contentView?.addSubview(controller.view)
- controller.view.frame = NSMakeRect(0, 40, 176+16*2, 300)
- controller.view.autoresizingMask = [.maxYMargin]
-
- let settingView: KMPageEditSplitSettingView = KMPageEditSplitSettingView.createFromNib()!
- self.contentBox.contentView?.addSubview(settingView)
- let settingViewLeft: CGFloat = 176+16+8
- settingView.frame = NSRect(x: settingViewLeft, y: 0, width: NSWidth(self.contentBox.frame)-settingViewLeft, height: NSHeight(self.contentBox.frame))
- settingView.autoresizingMask = [.width, .height]
- self.settingView = settingView
- settingView.oneFileForOnePageStepper.maxValue = Double(self.model!.pageCount)
- settingView.splitMuitiFileStepper.maxValue = Double(self.model!.pageCount)
- settingView.type = (self.model as! KMPageEditSplitSettingModel).type
- if ((self.model as! KMPageEditSplitSettingModel).type == 2) {
- settingView.setPageRangeString((self.model as! KMPageEditSplitSettingModel).pageRangeString)
- }
- settingView.updateName(self.model!.outputFileName)
- } else {
- let settingView: KMPageEditSplitSettingView = KMPageEditSplitSettingView.createFromNib()!
- self.contentBox.contentView?.addSubview(settingView)
- settingView.frame = self.contentBox.contentView!.bounds
- settingView.autoresizingMask = [.width, .height]
- self.settingView = settingView
- settingView.oneFileForOnePageStepper.maxValue = Double(self.model!.pageCount)
- settingView.splitMuitiFileStepper.maxValue = Double(self.model!.pageCount)
- settingView.type = (self.model as! KMPageEditSplitSettingModel).type
- if ((self.model as! KMPageEditSplitSettingModel).type == 2) {
- settingView.setPageRangeString((self.model as! KMPageEditSplitSettingModel).pageRangeString)
- }
- settingView.updateName(self.model!.outputFileName)
- }
- self.settingView!.itemClick = { [weak self] index, value in
- if (index == 1) { /// 类型切换
- (self?.model as! KMPageEditSplitSettingModel).type = value as! Int
- return
- }
- if (index == 2) { /// 平均每几页拆分
- (self?.model as! KMPageEditSplitSettingModel).avgNumberForOneFile = value as! Int
- return
- }
- if (index == 3) { /// 平均拆分几个文件
- (self?.model as! KMPageEditSplitSettingModel).avgSplitNumberFile = value as! Int
- return
- }
- if (index == 4) { /// 页面范围切换
- (self?.model as! KMPageEditSplitSettingModel).pageRangeType = value as! Int
- return
- }
- if (index == 5) { /// 页面范围输入
- (self?.model as! KMPageEditSplitSettingModel).pageRangeString = value as! String
- return
- }
- if (index == 6) { /// 将原始文档名前置
- (self?.model as! KMPageEditSplitSettingModel).origFileNameIsPrefix = value as! Bool
-
- (self?.settingView as! KMPageEditSplitSettingView).updateName((self?.model!.outputFileName)!)
- return
- }
- if (index == 7) { /// 标签
- (self?.model as! KMPageEditSplitSettingModel).hasTag = value as! Bool
-
- (self?.settingView as! KMPageEditSplitSettingView).updateName((self?.model!.outputFileName)!)
- return
- }
- if (index == 8) { /// 分隔符
- (self?.model as! KMPageEditSplitSettingModel).hasSep = value as! Bool
-
- (self?.settingView as! KMPageEditSplitSettingView).updateName((self?.model!.outputFileName)!)
- return
- }
-
- if (index == 9) { /// 分隔符
- (self?.model as! KMPageEditSplitSettingModel).tagString = value as! String
-
- (self?.settingView as! KMPageEditSplitSettingView).updateName((self?.model!.outputFileName)!)
- return
- }
-
- if (index == 10) { /// 分隔符
- (self?.model as! KMPageEditSplitSettingModel).sepString = value as! String
-
- (self?.settingView as! KMPageEditSplitSettingView).updateName((self?.model!.outputFileName)!)
- return
- }
- }
- }
- }
|