123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142 |
- //
- // KMPageEditInsertCustomPageWindowController.swift
- // PDF Master
- //
- // Created by tangchao on 2023/1/11.
- //
- import Cocoa
- typealias KMPageEditInsertCustomPageItemClick = (_ index: Int) -> ()
- class KMPageEditInsertCustomPageWindowController: NSWindowController {
-
- @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 selectedPageSize: NSSize = NSZeroSize
-
- var itemClick: KMPageEditInsertCustomPageItemClick!
-
- var typeIndex: Int {
- get {
- self.typeView.selectedIndex
- }
- }
-
- var pageSize: NSSize {
- get {
- self.pageSizeView.getPageSize
- }
- }
-
- var direction: Int {
- get {
- return self.directionView.getDirection()
- }
- }
-
- override func windowDidLoad() {
- super.windowDidLoad()
- self.titleLabel.stringValue = NSLocalizedString("Insert Custom Page", comment: "")
-
- 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")]
-
- self.pageSizeBox.contentView?.addSubview(self.pageSizeView)
- self.pageSizeView.frame = self.pageSizeBox.contentView!.bounds
- self.pageSizeView.autoresizingMask = [.width, .height]
- self.pageSizeView.selectedPageSize = self.selectedPageSize
- self.pageSizeView.itemClick = { [weak self] (index: Int, value: Any) in
- if (index == 1) { /// 当前页
- let radioIndex: Int = value as! Int
- if (radioIndex == 1) { // 当前页
-
- } else if (radioIndex == 2) { /// 标准
-
- } else if (radioIndex == 3) { /// 自定义
-
- }
- } else if (index == 2) { /// 标准[下拉框]
-
- } 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?.addSubview(self.directionView)
- self.directionView.frame = self.directionBox.contentView!.bounds
- self.directionView.autoresizingMask = [.width, .height]
- self.directionView.itemClick = { [weak self] (index: Int, value: Any) in
- if (index == 1) { /// 横向页面
- self?.pageSizeView.changeDirection(isHor: true)
- } else if (index == 2) { /// 纵向页面
- self?.pageSizeView.changeDirection(isHor: false)
- }
- }
-
- cancelButton.title = NSLocalizedString("Cancel", 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)
-
- insertButton.title = NSLocalizedString("Insert", comment: "")
- insertButton.isBordered = false
- insertButton.wantsLayer = true
- insertButton.layer?.cornerRadius = 4
- insertButton.target = self
- insertButton.action = #selector(insertButtonAction)
- insertButton.layer?.backgroundColor = NSColor.black.cgColor
- insertButton.attributedTitle = NSMutableAttributedString(string: insertButton.title, attributes: [NSAttributedString.Key.foregroundColor : NSColor.white])
- }
-
- @objc func cancelButtonAction() {
- guard let callback = self.itemClick else {
- return
- }
-
- callback(1)
- }
-
- @objc func insertButtonAction() {
- guard let callback = self.itemClick else {
- return
- }
-
- callback(2)
- }
-
- }
|