KMNPDFInsertClipboardWindowController.swift 9.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195
  1. //
  2. // KMNPDFInsertClipboardWindowController.swift
  3. // PDF Reader Pro
  4. //
  5. // Created by 丁林圭 on 2024/10/23.
  6. //
  7. import Cocoa
  8. import KMComponentLibrary
  9. class KMNPDFInsertClipboardWindowController: KMNBaseWindowController {
  10. private var orgDocument:CPDFDocument?
  11. private var orgPageIndex:Int = 0
  12. @IBOutlet var titleLabel: NSTextField!
  13. @IBOutlet var positionLabel: NSTextField!
  14. @IBOutlet var firstRadioButton: ComponentRadio!
  15. @IBOutlet var lastRadioButton: ComponentRadio!
  16. @IBOutlet var pageRadioButton: ComponentRadio!
  17. @IBOutlet var pageNumInput: ComponentInputNumber!
  18. @IBOutlet var pageCountLabel: NSTextField!
  19. @IBOutlet var positionSelect: ComponentSelect!
  20. @IBOutlet var cancelButton: ComponentButton!
  21. @IBOutlet var insertButton: ComponentButton!
  22. @IBOutlet var cancelWidthButton:NSLayoutConstraint!
  23. @IBOutlet var insertWidthButton:NSLayoutConstraint!
  24. @IBOutlet var pageRadioWidthButton:NSLayoutConstraint!
  25. convenience init(_ document: CPDFDocument?, currentPageIndex: Int) {
  26. self.init(windowNibName: "KMNPDFInsertClipboardWindowController")
  27. orgDocument = document
  28. orgPageIndex = currentPageIndex
  29. }
  30. convenience init(_ filePath: String,password:String?) {
  31. self.init(windowNibName: "KMNPDFInsertClipboardWindowController")
  32. let document = CPDFDocument.init(url: URL(fileURLWithPath: filePath))
  33. if password != nil {
  34. document?.unlock(withPassword: password as String?)
  35. }
  36. orgDocument = document
  37. }
  38. override func windowDidLoad() {
  39. super.windowDidLoad()
  40. setUpProperty()
  41. positionSelect.selectItemAtIndex(0)
  42. pageRadioButton.properties.checkboxType = .selected
  43. pageRadioButton.reloadData()
  44. pageNumInput.properties.text = String((orgPageIndex+1))
  45. pageNumInput.reloadData()
  46. pageCountLabel.stringValue = "/" + String(format: "%d", orgDocument?.pageCount ?? 0)
  47. }
  48. private func setUpPositionSelctProperty() {
  49. positionSelect.properties = ComponentSelectProperties(size: .s,
  50. state: .normal,
  51. isDisabled: false,
  52. isError: false,
  53. leftIcon: false,
  54. placeholder: nil,
  55. errorText: nil,
  56. creatable: false,
  57. text: KMLocalizedString("After", comment: ""))
  58. var menuItemArr: [ComponentMenuitemProperty] = []
  59. for language in [KMLocalizedString("After"),KMLocalizedString("Before")] {
  60. let itemProperty: ComponentMenuitemProperty = ComponentMenuitemProperty(multipleSelect: false,
  61. itemSelected: false,
  62. isDisabled: false,
  63. keyEquivalent: nil,
  64. text: language)
  65. menuItemArr.append(itemProperty)
  66. }
  67. positionSelect.updateMenuItemsArr(menuItemArr)
  68. positionSelect.delegate = self
  69. }
  70. private func setUpProperty() {
  71. titleLabel.stringValue = KMLocalizedString("From Clipboard")
  72. titleLabel.font = ComponentLibrary.shared.getFontFromKey("mac/body-m-medium")
  73. titleLabel.textColor = ComponentLibrary.shared.getComponentColorFromKey("colorText/1")
  74. positionLabel.stringValue = KMLocalizedString("Where to insert?")
  75. positionLabel.font = ComponentLibrary.shared.getFontFromKey("mac/body-m-medium")
  76. positionLabel.textColor = ComponentLibrary.shared.getComponentColorFromKey("colorText/2")
  77. insertButton.properties = ComponentButtonProperty(type: .primary,
  78. size: .s,
  79. state: .normal,
  80. buttonText: KMLocalizedString("Insert"))
  81. insertButton.setTarget(self, action: #selector(insertButtonClicked(_ :)))
  82. insertWidthButton.constant = insertButton.properties.propertyInfo.viewWidth
  83. cancelButton.properties = ComponentButtonProperty(type: .default_tertiary,
  84. size: .s,
  85. state: .normal,
  86. buttonText: KMLocalizedString("Cancel"))
  87. cancelButton.setTarget(self, action: #selector(cancelButtonClicked(_ :)))
  88. cancelWidthButton.constant = cancelButton.properties.propertyInfo.viewWidth
  89. firstRadioButton.properties = ComponentCheckBoxProperty(size: .s,
  90. state: .normal,
  91. isDisabled: false,
  92. showhelp: false,
  93. text: KMLocalizedString("First"),
  94. checkboxType: .normal)
  95. lastRadioButton.properties = ComponentCheckBoxProperty(size: .s,
  96. state: .normal,
  97. isDisabled: false,
  98. showhelp: false,
  99. text: KMLocalizedString("Last"),
  100. checkboxType: .normal)
  101. pageRadioButton.properties = ComponentCheckBoxProperty(size: .s,
  102. state: .normal,
  103. isDisabled: false,
  104. showhelp: false,
  105. text: KMLocalizedString("Page"),
  106. checkboxType: .normal)
  107. firstRadioButton.setTarget(self, action: #selector(insertPositionAction(_:)))
  108. lastRadioButton.setTarget(self, action: #selector(insertPositionAction(_:)))
  109. pageRadioButton.setTarget(self, action: #selector(insertPositionAction(_:)))
  110. pageNumInput.properties = ComponentInputNumberProperty(alignment: .left,
  111. size: .s,
  112. state: .normal,
  113. isError: false,
  114. showErrorInfo: false,
  115. isDisabled: true,
  116. showPrefix: false,
  117. showSuffix: false,
  118. minSize: 1,
  119. maxSize: Int(orgDocument?.pageCount ?? 1),
  120. text: SettingsManager.sharedInstance.autoSaveMinutes)
  121. pageNumInput.inputNumberDelegate = self
  122. pageCountLabel.stringValue = "/" + String(format: "%d", orgDocument?.pageCount ?? 0)
  123. setUpPositionSelctProperty()
  124. pageRadioWidthButton.constant = pageRadioButton.properties.propertyInfo.viewWidth
  125. cancelWidthButton.constant = cancelButton.properties.propertyInfo.viewWidth
  126. insertWidthButton.constant = insertButton.properties.propertyInfo.viewWidth
  127. }
  128. //MARK: - Action
  129. @objc func cancelButtonClicked(_ sender: NSView) {
  130. own_closeEndSheet()
  131. }
  132. @objc func insertButtonClicked(_ sender: NSView) {
  133. own_closeEndSheet()
  134. }
  135. @objc func insertPositionAction(_ sender: NSView) {
  136. if sender == lastRadioButton {
  137. } else if sender == firstRadioButton {
  138. } else if sender == pageRadioButton {
  139. }
  140. }
  141. }
  142. extension KMNPDFInsertClipboardWindowController: ComponentInputNumberDelegate {
  143. func componentInputNumberDidValueChanged(inputNumber: ComponentInputNumber?) {
  144. if(inputNumber == pageNumInput) {
  145. }
  146. }
  147. }
  148. extension KMNPDFInsertClipboardWindowController: ComponentSelectDelegate {
  149. func componentSelectDidSelect(view: ComponentSelect?, menuItemProperty: ComponentMenuitemProperty?) {
  150. if(view == positionSelect) {
  151. }
  152. }
  153. }