123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195 |
- //
- // KMNPDFInsertClipboardWindowController.swift
- // PDF Reader Pro
- //
- // Created by 丁林圭 on 2024/10/23.
- //
- import Cocoa
- import KMComponentLibrary
- class KMNPDFInsertClipboardWindowController: KMNBaseWindowController {
- private var orgDocument:CPDFDocument?
- private var orgPageIndex:Int = 0
-
- @IBOutlet var titleLabel: NSTextField!
- @IBOutlet var positionLabel: NSTextField!
- @IBOutlet var firstRadioButton: ComponentRadio!
- @IBOutlet var lastRadioButton: ComponentRadio!
- @IBOutlet var pageRadioButton: ComponentRadio!
- @IBOutlet var pageNumInput: ComponentInputNumber!
- @IBOutlet var pageCountLabel: NSTextField!
- @IBOutlet var positionSelect: ComponentSelect!
- @IBOutlet var cancelButton: ComponentButton!
- @IBOutlet var insertButton: ComponentButton!
- @IBOutlet var cancelWidthButton:NSLayoutConstraint!
- @IBOutlet var insertWidthButton:NSLayoutConstraint!
- @IBOutlet var pageRadioWidthButton:NSLayoutConstraint!
- convenience init(_ document: CPDFDocument?, currentPageIndex: Int) {
- self.init(windowNibName: "KMNPDFInsertClipboardWindowController")
- orgDocument = document
- orgPageIndex = currentPageIndex
- }
- convenience init(_ filePath: String,password:String?) {
- self.init(windowNibName: "KMNPDFInsertClipboardWindowController")
- let document = CPDFDocument.init(url: URL(fileURLWithPath: filePath))
- if password != nil {
- document?.unlock(withPassword: password as String?)
- }
- orgDocument = document
- }
- override func windowDidLoad() {
- super.windowDidLoad()
- setUpProperty()
- positionSelect.selectItemAtIndex(0)
-
- pageRadioButton.properties.checkboxType = .selected
- pageRadioButton.reloadData()
-
- pageNumInput.properties.text = String((orgPageIndex+1))
- pageNumInput.reloadData()
-
- pageCountLabel.stringValue = "/" + String(format: "%d", orgDocument?.pageCount ?? 0)
- }
-
- private func setUpPositionSelctProperty() {
- positionSelect.properties = ComponentSelectProperties(size: .s,
- state: .normal,
- isDisabled: false,
- isError: false,
- leftIcon: false,
- placeholder: nil,
- errorText: nil,
- creatable: false,
- text: KMLocalizedString("After", comment: ""))
-
- var menuItemArr: [ComponentMenuitemProperty] = []
- for language in [KMLocalizedString("After"),KMLocalizedString("Before")] {
- let itemProperty: ComponentMenuitemProperty = ComponentMenuitemProperty(multipleSelect: false,
- itemSelected: false,
- isDisabled: false,
- keyEquivalent: nil,
- text: language)
- menuItemArr.append(itemProperty)
- }
-
- positionSelect.updateMenuItemsArr(menuItemArr)
- positionSelect.delegate = self
- }
-
- private func setUpProperty() {
- titleLabel.stringValue = KMLocalizedString("From Clipboard")
- titleLabel.font = ComponentLibrary.shared.getFontFromKey("mac/body-m-medium")
- titleLabel.textColor = ComponentLibrary.shared.getComponentColorFromKey("colorText/1")
-
- positionLabel.stringValue = KMLocalizedString("Where to insert?")
- positionLabel.font = ComponentLibrary.shared.getFontFromKey("mac/body-m-medium")
- positionLabel.textColor = ComponentLibrary.shared.getComponentColorFromKey("colorText/2")
-
- insertButton.properties = ComponentButtonProperty(type: .primary,
- size: .s,
- state: .normal,
- buttonText: KMLocalizedString("Insert"))
- insertButton.setTarget(self, action: #selector(insertButtonClicked(_ :)))
- insertWidthButton.constant = insertButton.properties.propertyInfo.viewWidth
-
- cancelButton.properties = ComponentButtonProperty(type: .default_tertiary,
- size: .s,
- state: .normal,
- buttonText: KMLocalizedString("Cancel"))
- cancelButton.setTarget(self, action: #selector(cancelButtonClicked(_ :)))
- cancelWidthButton.constant = cancelButton.properties.propertyInfo.viewWidth
-
- firstRadioButton.properties = ComponentCheckBoxProperty(size: .s,
- state: .normal,
- isDisabled: false,
- showhelp: false,
- text: KMLocalizedString("First"),
- checkboxType: .normal)
- lastRadioButton.properties = ComponentCheckBoxProperty(size: .s,
- state: .normal,
- isDisabled: false,
- showhelp: false,
- text: KMLocalizedString("Last"),
- checkboxType: .normal)
-
- pageRadioButton.properties = ComponentCheckBoxProperty(size: .s,
- state: .normal,
- isDisabled: false,
- showhelp: false,
- text: KMLocalizedString("Page"),
- checkboxType: .normal)
-
- firstRadioButton.setTarget(self, action: #selector(insertPositionAction(_:)))
- lastRadioButton.setTarget(self, action: #selector(insertPositionAction(_:)))
- pageRadioButton.setTarget(self, action: #selector(insertPositionAction(_:)))
- pageNumInput.properties = ComponentInputNumberProperty(alignment: .left,
- size: .s,
- state: .normal,
- isError: false,
- showErrorInfo: false,
- isDisabled: true,
- showPrefix: false,
- showSuffix: false,
- minSize: 1,
- maxSize: Int(orgDocument?.pageCount ?? 1),
- text: SettingsManager.sharedInstance.autoSaveMinutes)
- pageNumInput.inputNumberDelegate = self
-
- pageCountLabel.stringValue = "/" + String(format: "%d", orgDocument?.pageCount ?? 0)
-
- setUpPositionSelctProperty()
-
- pageRadioWidthButton.constant = pageRadioButton.properties.propertyInfo.viewWidth
- cancelWidthButton.constant = cancelButton.properties.propertyInfo.viewWidth
- insertWidthButton.constant = insertButton.properties.propertyInfo.viewWidth
- }
-
- //MARK: - Action
- @objc func cancelButtonClicked(_ sender: NSView) {
- own_closeEndSheet()
- }
-
- @objc func insertButtonClicked(_ sender: NSView) {
- own_closeEndSheet()
- }
-
- @objc func insertPositionAction(_ sender: NSView) {
- if sender == lastRadioButton {
-
- } else if sender == firstRadioButton {
-
- } else if sender == pageRadioButton {
-
- }
- }
- }
- extension KMNPDFInsertClipboardWindowController: ComponentInputNumberDelegate {
- func componentInputNumberDidValueChanged(inputNumber: ComponentInputNumber?) {
- if(inputNumber == pageNumInput) {
-
- }
- }
- }
- extension KMNPDFInsertClipboardWindowController: ComponentSelectDelegate {
- func componentSelectDidSelect(view: ComponentSelect?, menuItemProperty: ComponentMenuitemProperty?) {
- if(view == positionSelect) {
-
- }
- }
- }
|