123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165 |
- //
- // KMPageEditInsertCustomPageWindowController.swift
- // PDF Master
- //
- // Created by tangchao on 2023/1/11.
- //
- typealias KMPageEditInsertCustomPageItemClick = (_ index: Int) -> ()
- class KMPageEditInsertCustomPageWindowController: KMBaseWindowController {
-
- @IBOutlet weak var titleLabel: NSTextField!
-
- @IBOutlet weak var typeBox: NSBox!
- @IBOutlet weak var pageSizeBox: NSBox!
- @IBOutlet weak var directionBox: NSBox!
-
- var typeView = KMPageEditInsertTypeItemView()
- var pageSizeView = KMPageEditInsertPageSizeItemView()
- var directionView = KMPageEditInsertDirectionItemView()
-
- @IBOutlet weak var cancelButton: NSButton!
- @IBOutlet weak var insertButton: NSButton!
-
- var cancelVC: KMDesignButton?
- var insertVC: KMDesignButton?
-
- var selectedPageSize: NSSize = NSZeroSize
-
- var itemClick: KMPageEditInsertCustomPageItemClick!
-
- convenience init() {
- self.init(windowNibName: "KMPageEditInsertCustomPageWindowController")
- }
-
- var typeIndex: Int {
- get {
- // self.typeView.selectedIndex
- return 1
- }
- }
-
- var pageSize: NSSize {
- get {
- self.pageSizeView.getPageSize
- }
- }
-
- var direction: Int {
- get {
- return self.directionView.getDirection()
- }
- }
-
- override func windowDidLoad() {
- super.windowDidLoad()
- // self.typeBox.contentView?.addSubview(self.typeView)
- // self.typeView.frame = self.typeBox.contentView!.bounds
- // self.typeView.autoresizingMask = [.width, .height]
- // self.typeView.items = [(NSLocalizedString("Blank page", comment: ""), ""),
- // (NSLocalizedString("Line page", comment: ""), "horizontal_line"),
- // (NSLocalizedString("Five line score", comment: ""), "five_line_score"),
- // (NSLocalizedString("Plaid page", comment: ""), "plaid")]
- }
-
- override func initDefaultValue() {
- super.initDefaultValue()
-
- self.titleLabel.stringValue = NSLocalizedString("Insert Custom Page", comment: "")
- self.titleLabel.font = .SFProTextSemiboldFont(16)
- self.titleLabel.textColor = KMAppearance.titleColor()
-
- self.cancelVC?.target = self
- self.cancelVC?.action = #selector(cancelButtonAction)
- self.cancelVC?.stringValue = NSLocalizedString("Cancel", comment: "")
- self.cancelVC?.button(type: .Sec, size: .m)
- self.cancelVC?.button.keyEquivalent = KMKeyEquivalent.esc.string()
-
- self.insertVC?.target = self
- self.insertVC?.action = #selector(insertButtonAction)
- self.insertVC?.stringValue = NSLocalizedString("Insert", comment: "")
- self.insertVC?.button(type: .Cta, size: .m)
- self.insertVC?.button.keyEquivalent = KMKeyEquivalent.enter
- }
-
- override func initSubViews() {
- super.initSubViews()
-
- self.pageSizeBox.contentView = self.pageSizeView
- self.pageSizeView.selectedPageSize = self.selectedPageSize
- self.pageSizeView.itemClick = { [unowned self] index, params in
- if (index == 1) { /// 当前页
- var radioIndex: Int = 0
- if let value = params.first as? Int {
- radioIndex = value
- }
- if (radioIndex == 1) { // 当前页
-
- } else if (radioIndex == 2) { /// 标准
-
- } else if (radioIndex == 3) { /// 自定义
-
- }
- } else if (index == 2) { /// 标准[下拉框]
- let size = self.pageSizeView.getPageSize
- if (size.width > size.height) {
- self.directionView.switchDirection(isHor: true)
- } else {
- self.directionView.switchDirection(isHor: false)
- }
- } else if (index == 3) { /// 自定义[宽度]
- let size = self.pageSizeView.getCustomSize
- if (size.width > size.height) {
- self.directionView.switchDirection(isHor: true)
- } else {
- self.directionView.switchDirection(isHor: false)
- }
- } else if (index == 4) { /// 自定义[高度]
- let size = self.pageSizeView.getCustomSize
- if (size.height > size.width) {
- self.directionView.switchDirection(isHor: false)
- } else {
- self.directionView.switchDirection(isHor: true)
- }
- } else if (index == 5) { /// 自定义[下拉框]
-
- }
- }
-
- self.directionBox.contentView = self.directionView
- self.directionView.itemClick = { [unowned self] index, value in
- if (index == 1) { /// 横向页面
- self.pageSizeView.changeDirection(isHor: true)
- } else if (index == 2) { /// 纵向页面
- self.pageSizeView.changeDirection(isHor: false)
- }
- }
-
- self.cancelVC = KMDesignButton(withType: .Text)
- self.cancelButton.addSubview(self.cancelVC!.view)
- self.cancelVC?.view.frame = self.cancelButton.bounds
- self.cancelVC?.view.autoresizingMask = [.width, .height]
- self.insertVC = KMDesignButton(withType: .Text)
- self.insertButton.addSubview(self.insertVC!.view)
- self.insertVC?.view.frame = self.insertButton.bounds
- self.insertVC?.view.autoresizingMask = [.width, .height]
- }
-
- @objc func cancelButtonAction() {
- guard let callback = self.itemClick else {
- return
- }
-
- callback(1)
- }
-
- @objc func insertButtonAction() {
- guard let callback = self.itemClick else {
- return
- }
-
- callback(2)
- }
-
- }
|