123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113 |
- //
- // KMCropSettingWindowController.swift
- // PDF Reader Pro
- //
- // Created by tangchao on 2022/12/30.
- //
- import Cocoa
- typealias KMCropSettingWindowControllerItemClick = (_ index: Int) -> ()
- class KMCropSettingWindowController: NSWindowController {
- @IBOutlet weak var titleLabel: NSTextField!
- @IBOutlet weak var pageRangeBox: NSBox!
- @IBOutlet weak var pageSizeBox: NSBox!
- @IBOutlet weak var applyButton: NSButton!
- @IBOutlet weak var cancelButton: NSButton!
-
- private var pagePageView = KMConvertPageRangeSettingItemView.createFromNib()
- private var pageSizeView = KMCropSettingPageSizeView()
-
- var itemClick: KMCropSettingWindowControllerItemClick!
-
- var pageCount: Int = 0
- var pageRangeIndex: Int = 0
- var pageRangePages: Array<Int> = []
- var pageSize: String = "None"
-
- override func windowDidLoad() {
- super.windowDidLoad()
- self.titleLabel.stringValue = "裁剪设置"
-
- let pageRangeView = self.pagePageView
- pageRangeView?.frame = self.pageRangeBox.contentView!.bounds
- pageRangeView?.autoresizingMask = NSView.AutoresizingMask(rawValue: 18)
- self.pageRangeBox.contentView?.addSubview(pageRangeView!)
- pageRangeView!.pageSizeComboBox.removeAllItems()
- pageRangeView!.pageSizeComboBox.addItems(withObjectValues: ["当前页面","全部页面", "奇数页面", "偶数页面", "自定义页面"])
- pageRangeView!.pageSizeComboBox.selectItem(at: 0)
-
- pageRangeView?.isTextDidEndCallback = true
-
- pageRangeView?.itemClick = { [unowned self] index, _ in
-
- self.pageRangeIndex = index
- }
-
- pageRangeView?.textDidEndEditingCallback = {
- [self] (textString: String) in
- let array = KMPageRangeTools.findSelectPage(pageRangeString: textString, pageCount: self.pageCount)
- if (array.count <= 0) {
- let alert = NSAlert()
- alert.alertStyle = .warning
- alert.messageText = NSLocalizedString("Invalid page range or the page number is out of range. Please try again.", comment: "")
- alert.runModal()
- return
- }
- self.pageRangePages.removeAll()
- for i in array {
- self.pageRangePages.append(i)
- }
- }
-
- let pageSizeView = self.pageSizeView
- pageSizeView.frame = self.pageSizeBox.contentView!.bounds
- pageSizeView.autoresizingMask = NSView.AutoresizingMask(rawValue: 18)
- self.pageSizeBox.contentView?.addSubview(pageSizeView)
- pageSizeView.itemClick = {
- (index: Int, value: Any) in
-
- self.pageSize = value as! String
- }
-
- cancelButton.title = NSLocalizedString("取消", comment: "")
- cancelButton.isBordered = false
- cancelButton.wantsLayer = true
- cancelButton.layer?.borderWidth = 1
- cancelButton.layer?.borderColor = NSColor.black.cgColor
- cancelButton.layer?.cornerRadius = 4
- cancelButton.target = self
- cancelButton.action = #selector(cancelButtonAction)
-
- applyButton.title = NSLocalizedString("应用", comment: "")
- applyButton.isBordered = false
- applyButton.wantsLayer = true
- applyButton.layer?.cornerRadius = 4
- applyButton.target = self
- applyButton.action = #selector(applyButtonAction)
- applyButton.layer?.backgroundColor = NSColor.black.cgColor
- applyButton.attributedTitle = NSMutableAttributedString(string: applyButton.title, attributes: [NSAttributedString.Key.foregroundColor : NSColor.white])
-
- }
-
- @objc func cancelButtonAction() {
- guard let callback = self.itemClick else {
- return
- }
-
- callback(1)
- }
-
- @objc func applyButtonAction() {
- guard let callback = self.itemClick else {
- return
- }
-
- callback(2)
- }
-
- }
|