123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263 |
- //
- // KMNPDFInsertPDFWindowController.swift
- // PDF Reader Pro
- //
- // Created by 丁林圭 on 2024/10/22.
- //
- import Cocoa
- import KMComponentLibrary
- class KMNPDFInsertPDFWindowController: NSWindowController {
- private var parentWindow: NSWindow?
- private var handler: ((String?) -> Void)!
- @IBOutlet var titleLabel: NSTextField!
- @IBOutlet var fileLabel: NSTextField!
- @IBOutlet var fileNameInput: ComponentInputWithAddon!
- @IBOutlet var selectFileInput: ComponentInputAddon!
- @IBOutlet var pageRangeLabel: NSTextField!
- @IBOutlet var pageRangeSelect: ComponentSelect!
-
- @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!
-
- private var orgDocument:CPDFDocument?
- private var insertDocument:CPDFDocument?
- deinit {
- KMPrint("KMSearchReplaceWindowController deinit.")
- }
- override func windowDidLoad() {
- super.windowDidLoad()
- setUpProperty()
- }
-
- // convenience init(_ document: CPDFDocument?) {
- // self.init(windowNibName: "KMNPDFInsertPDFWindowController")
- // orgDocument = document
- // }
- //
- // convenience init(_ filePath: String,password:String?) {
- // self.init(windowNibName: "KMNPDFInsertPDFWindowController")
- // let document = CPDFDocument.init(url: URL(fileURLWithPath: filePath))
- // if password != nil {
- // document?.unlock(withPassword: password as String?)
- // }
- //
- // orgDocument = document
- // }
-
- required init?(coder: NSCoder) {
- fatalError("init(coder:) has not been implemented")
- }
-
- private func setUPPageSelctProperty() {
- pageRangeSelect.properties = ComponentSelectProperties(size: .s,
- state: .normal,
- isDisabled: false,
- isError: false,
- leftIcon: false,
- placeholder: nil,
- errorText: nil,
- creatable: false,
- text: KMLocalizedString("All Pages", comment: ""))
-
- var menuItemString:[String] = [KMLocalizedString("All Pages"),
- KMLocalizedString("Odd Pages Only"),
- KMLocalizedString("Even Pages Only"),
- KMLocalizedString("e.g. 1,3-5,10")]
- if insertDocument?.pageCount ?? 0 <= 1 {
- menuItemString.removeObject(KMLocalizedString("Even Pages Only"))
- }
- var menuItemArr: [ComponentMenuitemProperty] = []
- for language in menuItemString {
- let itemProperty: ComponentMenuitemProperty = ComponentMenuitemProperty(multipleSelect: false,
- itemSelected: false,
- isDisabled: false,
- keyEquivalent: nil,
- text: language)
- menuItemArr.append(itemProperty)
- }
-
- pageRangeSelect.updateMenuItemsArr(menuItemArr)
- pageRangeSelect.delegate = self
- }
-
- 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("Insert File")
- titleLabel.font = ComponentLibrary.shared.getFontFromKey("mac/body-m-medium")
- titleLabel.textColor = ComponentLibrary.shared.getComponentColorFromKey("colorText/1")
-
- fileLabel.stringValue = KMLocalizedString("Form File")
- fileLabel.font = ComponentLibrary.shared.getFontFromKey("mac/body-m-medium")
- fileLabel.textColor = ComponentLibrary.shared.getComponentColorFromKey("colorText/2")
-
- pageRangeLabel.stringValue = KMLocalizedString("Page Range:")
- pageRangeLabel.font = ComponentLibrary.shared.getFontFromKey("mac/body-s-regular")
- pageRangeLabel.textColor = ComponentLibrary.shared.getComponentColorFromKey("comp-field-colorText-filled-nor")
- positionLabel.stringValue = KMLocalizedString("Insertion Position")
- positionLabel.font = ComponentLibrary.shared.getFontFromKey("mac/body-m-medium")
- positionLabel.textColor = ComponentLibrary.shared.getComponentColorFromKey("colorText/2")
-
- 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("First"),
- checkboxType: .normal)
-
- pageRadioButton.properties = ComponentCheckBoxProperty(size: .s,
- state: .normal,
- isDisabled: false,
- showhelp: false,
- text: KMLocalizedString("Page"),
- checkboxType: .normal)
-
- insertButton.properties = ComponentButtonProperty(type: .primary,
- size: .s,
- state: .normal,
- buttonText: KMLocalizedString("Apply"))
- 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.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: 5,
- maxSize: 99,
- text: SettingsManager.sharedInstance.autoSaveMinutes)
- pageNumInput.inputNumberDelegate = self
-
- let inputWithAddonProperty = ComponentInputWithAddonProperty(size: .s,
- isDisabled:false,
- addonType: .text)
- fileNameInput.properties = inputWithAddonProperty
- selectFileInput.properties = ComponentInputAddonProperty(size: .s,
- state: .normal,
- addOnBefore: false,
- onlyRead: false,
- addonType: .imageWithColor,
- iconImage:nil,text: KMLocalizedString("Browse"))
- selectFileInput.setTarget(self, action: #selector(chooseURLAction(_ :)))
-
- pageCountLabel.stringValue = "/" + String(format: "%d", orgDocument?.pageCount ?? 0)
- }
-
- func own_beginSheetModal(for window: NSWindow?, completionHandler handler: ((String?) -> Void)?) {
- if window != nil {
- parentWindow = window
- window!.beginSheet(self.window!) { ModalResponse in
- self.handler?(nil)
- }
- }
- self.handler = handler
- }
-
- //MARK: - Action
- @objc func cancelButtonClicked(_ sender: NSView) {
- parentWindow?.endSheet(self.window!)
- }
-
- @objc func insertButtonClicked(_ sender: NSView) {
-
- parentWindow?.endSheet(self.window!)
- }
-
- @objc func insertPositionAction(_ sender: NSView) {
- if sender == lastRadioButton {
-
- } else if sender == firstRadioButton {
-
- } else if sender == pageRadioButton {
-
- }
- }
-
- @objc func chooseURLAction(_ sender: NSView) {
-
- }
- }
- extension KMNPDFInsertPDFWindowController: ComponentInputNumberDelegate {
- func componentInputNumberDidValueChanged(inputNumber: ComponentInputNumber?) {
- }
- }
- extension KMNPDFInsertPDFWindowController: ComponentSelectDelegate {
- func componentSelectDidSelect(view: ComponentSelect?, menuItemProperty: ComponentMenuitemProperty?) {
- }
- }
|