KMBatesPropertyController.swift 27 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593
  1. //
  2. // KMBatesPropertyController.swift
  3. // PDF Reader Pro
  4. //
  5. // Created by Niehaoyu on 2024/11/8.
  6. //
  7. import Cocoa
  8. import KMComponentLibrary
  9. @objc protocol KMBatesPropertyControllerDelegate: AnyObject {
  10. //水印数据有更新
  11. @objc optional func batesPropertyControllerDidUpdate(_ controller: KMBatesPropertyController)
  12. //切换到模板界面
  13. @objc optional func batesPropertyControllerDidChangetoTemplate(_ controller: KMBatesPropertyController)
  14. //成功保存到模板
  15. @objc optional func batesPropertyControllerSaveTemplateSuccess(_ controller: KMBatesPropertyController, _ data: KMBatesModel)
  16. //取消修改模板信息
  17. @objc optional func batesPropertyControllerCancelTemplateEdit(_ controller: KMBatesPropertyController)
  18. @objc optional func batesPropertyControllerFinishTemplateEdit(_ controller: KMBatesPropertyController)
  19. }
  20. class KMBatesPropertyController: NSViewController {
  21. @IBOutlet var contendView: NSView!
  22. @IBOutlet var titleLabel: NSTextField!
  23. @IBOutlet var templateButton: ComponentButton!
  24. @IBOutlet var leftTopButton: ComponentButton!
  25. //Font
  26. @IBOutlet var fontBGView: NSView!
  27. @IBOutlet var fontLabel: NSTextField!
  28. @IBOutlet var fontNameSelect: ComponentSelect!
  29. @IBOutlet var fontSizeSelect: ComponentSelect!
  30. @IBOutlet var fontColorView: ComponentCColorCustom!
  31. //Margin
  32. @IBOutlet var marginBGView: NSView!
  33. @IBOutlet var marginLabel: NSTextField!
  34. @IBOutlet var marginLeftInput: ComponentInputNumber!
  35. @IBOutlet var marginTopInput: ComponentInputNumber!
  36. @IBOutlet var marginRightInput: ComponentInputNumber!
  37. @IBOutlet var marginBottomInput: ComponentInputNumber!
  38. //Display
  39. @IBOutlet var displayBGView: NSView!
  40. @IBOutlet var displayLabel: NSTextField!
  41. @IBOutlet var prefixLabel: NSTextField!
  42. @IBOutlet var prefixInput: ComponentInput!
  43. @IBOutlet var suffixLabel: NSTextField!
  44. @IBOutlet var suffixInput: ComponentInput!
  45. @IBOutlet var digitsLabel: NSTextField!
  46. @IBOutlet var digitsInputNumber: ComponentInputNumber!
  47. @IBOutlet var startPageLabel: NSTextField!
  48. @IBOutlet var startPageSelect: ComponentSelect!
  49. //Layout&Content
  50. @IBOutlet var layoutBGView: NSView!
  51. @IBOutlet var layoutLabel: NSTextField!
  52. @IBOutlet var layoutInsertButton: ComponentButton!
  53. @IBOutlet var layoutPosition: ComponentCPosition!
  54. @IBOutlet var layoutTextarea: ComponentTextarea!
  55. //Save
  56. @IBOutlet var saveTemplateBGView: NSView!
  57. @IBOutlet var saveButton: ComponentButton!
  58. var groupView: ComponentGroup!
  59. private var familyNames = CPDFFont.familyNames
  60. var positionSelRow: Int = 1
  61. var positionSelColumn: Int = 0
  62. var batesModel: KMBatesModel = KMBatesModel()
  63. var totalPDFCount: Int = 1
  64. var originalDataDict: Dictionary<String, Any>?
  65. var editSubType: KMPDFEditSubModeType = .none
  66. weak open var delegate: KMBatesPropertyControllerDelegate?
  67. override func viewDidLoad() {
  68. super.viewDidLoad()
  69. // Do view setup here.
  70. setupProperty()
  71. }
  72. func setupProperty() {
  73. contendView.wantsLayer = true
  74. contendView.layer?.backgroundColor = ComponentLibrary.shared.getComponentColorFromKey("colorBg/layout-middle").cgColor
  75. titleLabel.textColor = ComponentLibrary.shared.getComponentColorFromKey("colorText/2")
  76. titleLabel.font = ComponentLibrary.shared.getFontFromKey("mac/body-m-bold")
  77. titleLabel.stringValue = KMLocalizedString("Add Bates Numbers")
  78. templateButton.properties = ComponentButtonProperty(type: .text_gray, size: .xxs, onlyIcon: true, icon: NSImage(named: "icon_wm_template"), keepPressState: false)
  79. templateButton.setTarget(self, action: #selector(componentButtonClicked(_:)))
  80. leftTopButton.properties = ComponentButtonProperty(type: .text_gray, size: .xxs, onlyIcon: true, icon: NSImage(named: "watermark_arrowLeft"), keepPressState: false)
  81. leftTopButton.setTarget(self, action: #selector(leftTopButtonClicked(_:)))
  82. //Font
  83. fontLabel.stringValue = KMLocalizedString("Font")
  84. fontLabel.textColor = ComponentLibrary.shared.getComponentColorFromKey("colorText/2")
  85. fontLabel.font = ComponentLibrary.shared.getFontFromKey("mac/body-s-medium")
  86. fontNameSelect.properties = ComponentSelectProperties(size: .s,
  87. state: .normal,
  88. text: "")
  89. var menuItemArr: [ComponentMenuitemProperty] = []
  90. for string in familyNames {
  91. let item = ComponentMenuitemProperty(type: .normal, text: string, identifier: string)
  92. menuItemArr.append(item)
  93. }
  94. fontNameSelect.updateMenuItemsArr(menuItemArr)
  95. fontNameSelect.delegate = self
  96. fontSizeSelect.properties = ComponentSelectProperties(size: .s,
  97. state: .normal,
  98. creatable: true,
  99. text: "12 pt",
  100. regexString: "0123456789 pt")
  101. if true {
  102. var sizeItemArr: [ComponentMenuitemProperty] = []
  103. for string in KMHeaderFooterManager.getFontSize() {
  104. let item = ComponentMenuitemProperty(type: .normal, text: string, identifier: string)
  105. sizeItemArr.append(item)
  106. }
  107. fontSizeSelect.updateMenuItemsArr(sizeItemArr)
  108. }
  109. fontSizeSelect.delegate = self
  110. fontColorView.properties = ComponentCColorProperty(colorType: .colorPanel, state: .normal, isCustom: true, color: NSColor.black)
  111. //Margin
  112. marginLabel.stringValue = KMLocalizedString("Margin (mm)")
  113. marginLabel.textColor = ComponentLibrary.shared.getComponentColorFromKey("colorText/2")
  114. marginLabel.font = ComponentLibrary.shared.getFontFromKey("mac/body-s-medium")
  115. marginLeftInput.properties = ComponentInputNumberProperty(alignment: .left,
  116. size: .s,
  117. minSize: 0,
  118. maxSize: 1000,
  119. text: "0")
  120. marginLeftInput.delegate = self
  121. marginTopInput.properties = ComponentInputNumberProperty(alignment: .left,
  122. size: .s,
  123. minSize: 0,
  124. maxSize: 1000,
  125. text: "0")
  126. marginTopInput.delegate = self
  127. marginRightInput.properties = ComponentInputNumberProperty(alignment: .left,
  128. size: .s,
  129. minSize: 0,
  130. maxSize: 1000,
  131. text: "0")
  132. marginRightInput.delegate = self
  133. marginBottomInput.properties = ComponentInputNumberProperty(alignment: .left,
  134. size: .s,
  135. minSize: 0,
  136. maxSize: 1000,
  137. text: "0")
  138. marginBottomInput.delegate = self
  139. //Display
  140. displayLabel.stringValue = KMLocalizedString("Display")
  141. displayLabel.textColor = ComponentLibrary.shared.getComponentColorFromKey("colorText/2")
  142. displayLabel.font = ComponentLibrary.shared.getFontFromKey("mac/body-s-medium")
  143. prefixLabel.stringValue = KMLocalizedString("Prefix: ")
  144. prefixLabel.textColor = ComponentLibrary.shared.getComponentColorFromKey("comp-field/colorText-filled-nor")
  145. prefixLabel.font = ComponentLibrary.shared.getFontFromKey("mac/body-s-regular")
  146. prefixInput.properties = ComponentInputProperty(size: .s, text: "")
  147. prefixInput.delegate = self
  148. suffixLabel.stringValue = KMLocalizedString("Suffix: ")
  149. suffixLabel.textColor = ComponentLibrary.shared.getComponentColorFromKey("comp-field/colorText-filled-nor")
  150. suffixLabel.font = ComponentLibrary.shared.getFontFromKey("mac/body-s-regular")
  151. suffixInput.properties = ComponentInputProperty(size: .s, text: "")
  152. suffixInput.delegate = self
  153. digitsLabel.stringValue = KMLocalizedString("Numbers of Digits: ")
  154. digitsLabel.textColor = ComponentLibrary.shared.getComponentColorFromKey("comp-field/colorText-filled-nor")
  155. digitsLabel.font = ComponentLibrary.shared.getFontFromKey("mac/body-s-regular")
  156. digitsInputNumber.properties = ComponentInputNumberProperty(alignment: .left, size: .s, minSize: 0, maxSize: 99, valueType: .intType)
  157. digitsInputNumber.delegate = self
  158. startPageLabel.stringValue = KMLocalizedString("Start Page:")
  159. startPageLabel.textColor = ComponentLibrary.shared.getComponentColorFromKey("comp-field/colorText-filled-nor")
  160. startPageLabel.font = ComponentLibrary.shared.getFontFromKey("mac/body-s-regular")
  161. startPageSelect.properties = ComponentSelectProperties(size: .s,
  162. state: .normal,
  163. creatable: false,
  164. text: "1")
  165. startPageSelect.delegate = self
  166. //Layout&Content
  167. layoutLabel.stringValue = KMLocalizedString("Layout & Content")
  168. layoutLabel.textColor = ComponentLibrary.shared.getComponentColorFromKey("colorText/2")
  169. layoutLabel.font = ComponentLibrary.shared.getFontFromKey("mac/body-s-medium")
  170. layoutInsertButton.properties = ComponentButtonProperty(type: .text_gray, size: .xxs, onlyIcon: true, icon: NSImage(named: "watermark_template_add"), keepPressState: false)
  171. layoutInsertButton.setTarget(self, action: #selector(componentButtonClicked(_:)))
  172. layoutPosition.properties = ComponentCPositionProperty(rowCount: 2, columnCount: 3, dash: true)
  173. layoutPosition.delegate = self
  174. layoutTextarea.properties = ComponentTextareaProperty(totalCount: -1)
  175. layoutTextarea.delegate = self
  176. //Save
  177. saveTemplateBGView.wantsLayer = true
  178. saveTemplateBGView.layer?.backgroundColor = ComponentLibrary.shared.getComponentColorFromKey("colorBg/layout-middle").cgColor
  179. saveButton.properties = ComponentButtonProperty(type: .default_tertiary, size: .m, showLeftIcon: true, buttonText: KMLocalizedString("Save as Template"), icon: NSImage(named: "icon_wm_template_save"), keepPressState: false)
  180. saveButton.setTarget(self, action: #selector(componentButtonClicked(_:)))
  181. }
  182. func clearData() {
  183. positionSelRow = 1
  184. positionSelColumn = 0
  185. totalPDFCount = 1
  186. }
  187. func reloadData() {
  188. titleLabel.stringValue = KMLocalizedString("Add Bates")
  189. leftTopButton.isHidden = true
  190. saveTemplateBGView.isHidden = false
  191. templateButton.properties.icon = NSImage(named: "icon_wm_template")
  192. if editSubType == .edit {
  193. titleLabel.stringValue = KMLocalizedString("Edit Bates")
  194. leftTopButton.isHidden = false
  195. saveTemplateBGView.isHidden = true
  196. templateButton.properties.icon = NSImage(named: "edit_save")
  197. }
  198. templateButton.reloadData()
  199. //Font
  200. if let index = familyNames.firstIndex(of: batesModel.fontName){
  201. fontNameSelect.selectItemAtIndex(index)
  202. }
  203. fontNameSelect.properties.text = batesModel.fontName
  204. fontNameSelect.reloadData()
  205. let fontSizeStr = String(format: "%.0f", batesModel.fontsize)
  206. if let index = KMHeaderFooterManager.getFontSize().firstIndex(of: fontSizeStr) {
  207. fontSizeSelect.selectItemAtIndex(index)
  208. }
  209. fontSizeSelect.properties.text = String(format: "%.0f", batesModel.fontsize) + " pt"
  210. fontSizeSelect.reloadData()
  211. fontColorView.properties?.color = batesModel.color
  212. fontColorView.reloadData()
  213. //Margin
  214. marginLeftInput.properties.text = String(format: "%d", batesModel.leftMargin)
  215. marginLeftInput.reloadData()
  216. marginTopInput.properties.text = String(format: "%d", batesModel.topMargin)
  217. marginTopInput.reloadData()
  218. marginRightInput.properties.text = String(format: "%d", batesModel.rightMargin)
  219. marginRightInput.reloadData()
  220. marginBottomInput.properties.text = String(format: "%d", batesModel.bottomMargin)
  221. marginBottomInput.reloadData()
  222. //Display
  223. prefixInput.properties.text = batesModel.prefixString
  224. suffixInput.properties.text = batesModel.suffixString
  225. digitsInputNumber.properties.text = String(format: "%d", batesModel.digits)
  226. if true {
  227. var sizeItemArr: [ComponentMenuitemProperty] = []
  228. var indexArr: [String] = []
  229. for index in 0...totalPDFCount {
  230. indexArr.append(String(format: "%ld", index))
  231. }
  232. for string in indexArr {
  233. let item = ComponentMenuitemProperty(type: .normal, text: string, identifier: string)
  234. sizeItemArr.append(item)
  235. }
  236. startPageSelect.updateMenuItemsArr(sizeItemArr)
  237. }
  238. if let index = KMHeaderFooterManager.getPageFormats().firstIndex(of: batesModel.startString) {
  239. startPageSelect.selectItemAtIndex(index)
  240. }
  241. startPageSelect.properties.text = batesModel.startString
  242. startPageSelect.reloadData()
  243. //Layout
  244. layoutPosition.properties.selRow = positionSelRow
  245. layoutPosition.properties.selColumn = positionSelColumn
  246. layoutPosition.reloadData()
  247. layoutTextarea.properties.text = ""
  248. layoutTextarea.reloadData()
  249. updateTextAreaText()
  250. //Save
  251. if batesModel.topLeftString.count == 0 && batesModel.topCenterString.count == 0 && batesModel.topRightString.count == 0
  252. && batesModel.bottomLeftString.count == 0 && batesModel.bottomCenterString.count == 0 && batesModel.bottomRightString.count == 0 {
  253. saveButton.properties.isDisabled = true
  254. } else {
  255. saveButton.properties.isDisabled = false
  256. }
  257. saveButton.reloadData()
  258. }
  259. func updateTextAreaText() {
  260. if positionSelRow == 0 && positionSelColumn == 0 {
  261. //左下角
  262. layoutTextarea.properties.text = batesModel.bottomLeftString
  263. } else if positionSelRow == 0 && positionSelColumn == 1 {
  264. layoutTextarea.properties.text = batesModel.bottomCenterString
  265. } else if positionSelRow == 0 && positionSelColumn == 2 {
  266. layoutTextarea.properties.text = batesModel.bottomRightString
  267. } else if positionSelRow == 1 && positionSelColumn == 0 {
  268. layoutTextarea.properties.text = batesModel.topLeftString
  269. } else if positionSelRow == 1 && positionSelColumn == 1 {
  270. layoutTextarea.properties.text = batesModel.topCenterString
  271. } else if positionSelRow == 1 && positionSelColumn == 2 {
  272. layoutTextarea.properties.text = batesModel.topRightString
  273. }
  274. layoutTextarea.reloadData()
  275. layoutPosition.setString(batesModel.bottomLeftString, to: 0, 0)
  276. layoutPosition.setString(batesModel.bottomCenterString, to: 0, 1)
  277. layoutPosition.setString(batesModel.bottomRightString, to: 0, 2)
  278. layoutPosition.setString(batesModel.topLeftString, to: 1, 0)
  279. layoutPosition.setString(batesModel.topCenterString, to: 1, 1)
  280. layoutPosition.setString(batesModel.topRightString, to: 1, 2)
  281. }
  282. //MARK: - Action
  283. @objc func leftTopButtonClicked(_ sender: ComponentButton) {
  284. if sender == leftTopButton {
  285. var didChanged = false
  286. if let dict = self.originalDataDict {
  287. didChanged = KMBatesManager.compareIsChangedModel(batesModel, withDict: dict as NSDictionary)
  288. }
  289. if didChanged {
  290. let alert = NSAlert()
  291. alert.alertStyle = .critical
  292. alert.messageText = KMLocalizedString("Save template changes?")
  293. alert.informativeText = KMLocalizedString("Cancel and they will not be saved.")
  294. alert.addButton(withTitle: KMLocalizedString("Save"))
  295. alert.addButton(withTitle: KMLocalizedString("Cancel"))
  296. alert.beginSheetModal(for: NSApp.mainWindow!) { (response) in
  297. if response == NSApplication.ModalResponse.alertFirstButtonReturn {
  298. let _ = KMBatesManager.defaultManager.updateTemplate(self.batesModel)
  299. self.delegate?.batesPropertyControllerFinishTemplateEdit?(self)
  300. } else {
  301. if let dict = self.originalDataDict {
  302. KMBatesManager.defaultManager.updateModel(self.batesModel, with: dict as NSDictionary)
  303. let _ = KMBatesManager.defaultManager.updateTemplate(self.batesModel)
  304. }
  305. self.delegate?.batesPropertyControllerCancelTemplateEdit?(self)
  306. }
  307. }
  308. } else {
  309. delegate?.batesPropertyControllerCancelTemplateEdit?(self)
  310. }
  311. }
  312. }
  313. @objc func componentButtonClicked(_ sender: ComponentButton) {
  314. if sender == templateButton {
  315. delegate?.batesPropertyControllerDidChangetoTemplate?(self)
  316. } else if sender == layoutInsertButton {
  317. var menuItemArr: [ComponentMenuitemProperty] = []
  318. let items: [(String, String)] = [("Insert Bates", "InsertBatesKey")]
  319. for (i, value) in items {
  320. let properties_Menuitem: ComponentMenuitemProperty = ComponentMenuitemProperty(multipleSelect: false,
  321. itemSelected: false,
  322. isDisabled: false,
  323. keyEquivalent: nil,
  324. text: KMLocalizedString(i),
  325. identifier: value)
  326. menuItemArr.append(properties_Menuitem)
  327. }
  328. if groupView == nil {
  329. groupView = ComponentGroup.createFromNib(in: ComponentLibrary.shared.componentBundle())
  330. }
  331. groupView.groupDelegate = self
  332. groupView?.frame = CGRectMake(0, 0, 160, 44)
  333. groupView.updateGroupInfo(menuItemArr)
  334. if let point: CGPoint = sender.superview?.convert(sender.frame.origin, to: self.view.window?.contentView) {
  335. groupView.showWithPoint(CGPoint(x: point.x, y: point.y - CGRectGetHeight(groupView.frame)-4), relativeTo: self.view)
  336. }
  337. } else if sender == saveButton {
  338. batesModel.prefixString = prefixInput.properties.text
  339. batesModel.suffixString = suffixInput.properties.text
  340. let saveWindow: KMWatermarkSaveWindow = KMWatermarkSaveWindow(windowNibName: "KMWatermarkSaveWindow")
  341. saveWindow.nameValue = KMBatesManager.defaultManager.fetchBatesAvailableName()
  342. saveWindow.saveHandler = {[weak self] string in
  343. guard let weakSelf = self else { return }
  344. DispatchQueue.main.async {
  345. weakSelf.batesModel.name = string ?? ""
  346. if KMBatesManager.defaultManager.addTemplate(weakSelf.batesModel){
  347. weakSelf.delegate?.batesPropertyControllerSaveTemplateSuccess?(weakSelf, weakSelf.batesModel)
  348. }
  349. }
  350. }
  351. saveWindow.own_beginSheetModal(for: view.window) { string in
  352. }
  353. }
  354. }
  355. //MARK: - Mouse
  356. override func mouseDown(with event: NSEvent) {
  357. super.mouseDown(with: event)
  358. view.window?.makeFirstResponder(nil)
  359. }
  360. }
  361. //MARK: - ComponentInputNumberDelegate
  362. extension KMBatesPropertyController: ComponentInputNumberDelegate {
  363. func componentInputNumberDidValueChanged(inputNumber: ComponentInputNumber?) {
  364. if inputNumber == marginLeftInput {
  365. if let text = inputNumber?.properties.text {
  366. batesModel.leftMargin = Int(text) ?? 30
  367. }
  368. } else if inputNumber == marginTopInput {
  369. if let text = inputNumber?.properties.text {
  370. batesModel.topMargin = Int(text) ?? 30
  371. }
  372. } else if inputNumber == marginRightInput {
  373. if let text = inputNumber?.properties.text {
  374. batesModel.rightMargin = Int(text) ?? 30
  375. }
  376. } else if inputNumber == marginBottomInput {
  377. if let text = inputNumber?.properties.text {
  378. batesModel.bottomMargin = Int(text) ?? 30
  379. }
  380. } else if inputNumber == digitsInputNumber {
  381. if let text = inputNumber?.properties.text {
  382. batesModel.digits = Int(text) ?? 1
  383. }
  384. }
  385. reloadData()
  386. delegate?.batesPropertyControllerDidUpdate?(self)
  387. }
  388. }
  389. //MARK: - ComponentInputDelegate
  390. extension KMBatesPropertyController: ComponentInputDelegate {
  391. }
  392. //MARK: - ComponentSelectDelegate
  393. extension KMBatesPropertyController: ComponentSelectDelegate {
  394. func componentSelectDidSelect(view: ComponentSelect?, menuItemProperty: ComponentMenuitemProperty?) {
  395. if view == fontNameSelect {
  396. batesModel.fontName = menuItemProperty?.text ?? ""
  397. } else if view == fontSizeSelect {
  398. if let text = menuItemProperty?.text {
  399. let result = text.stringByDeleteCharString(" pt")
  400. batesModel.fontsize = result.stringToCGFloat()
  401. }
  402. } else if view == startPageSelect {
  403. if let text = menuItemProperty?.text {
  404. batesModel.startString = text
  405. }
  406. }
  407. reloadData()
  408. delegate?.batesPropertyControllerDidUpdate?(self)
  409. }
  410. }
  411. //MARK: - ComponentGroupDelegate
  412. extension KMBatesPropertyController: ComponentGroupDelegate {
  413. func componentGroupDidSelect(group: ComponentGroup?, menuItemProperty: ComponentMenuitemProperty?) {
  414. if menuItemProperty?.identifier == "InsertBatesKey" {
  415. guard let digitsText = digitsInputNumber.properties.text else {
  416. return
  417. }
  418. guard let startPageText = startPageSelect.properties.text else {
  419. return
  420. }
  421. batesModel.digits = Int(digitsText) ?? 1
  422. var tString = "<<#\((digitsText))#\(startPageText)"
  423. if !self.prefixInput.properties.text.isEmpty {
  424. tString += "#\(self.prefixInput.properties.text)"
  425. } else if self.prefixInput.properties.text.isEmpty && !self.suffixInput.properties.text.isEmpty {
  426. tString += "#"
  427. }
  428. if !self.suffixInput.properties.text.isEmpty {
  429. tString += "#\(self.suffixInput.properties.text)"
  430. }
  431. tString += ">>"
  432. if positionSelRow == 0 && positionSelColumn == 0 {
  433. //左下角
  434. batesModel.bottomLeftString = batesModel.bottomLeftString + tString
  435. } else if positionSelRow == 0 && positionSelColumn == 1 {
  436. batesModel.bottomCenterString = batesModel.bottomCenterString + tString
  437. } else if positionSelRow == 0 && positionSelColumn == 2 {
  438. batesModel.bottomRightString = batesModel.bottomRightString + tString
  439. } else if positionSelRow == 1 && positionSelColumn == 0 {
  440. batesModel.topLeftString = batesModel.topLeftString + tString
  441. } else if positionSelRow == 1 && positionSelColumn == 1 {
  442. batesModel.topCenterString = batesModel.topCenterString + tString
  443. } else if positionSelRow == 1 && positionSelColumn == 2 {
  444. batesModel.topRightString = batesModel.topRightString + tString
  445. }
  446. }
  447. reloadData()
  448. delegate?.batesPropertyControllerDidUpdate?(self)
  449. }
  450. }
  451. //MARK: - ComponentCPositionDelegate
  452. extension KMBatesPropertyController: ComponentCPositionDelegate {
  453. func componentCPositionDidChoose(_ view: NSView, _ row: Int, _ column: Int) {
  454. if view == layoutPosition {
  455. view.window?.makeFirstResponder(nil)
  456. positionSelRow = row
  457. positionSelColumn = column
  458. reloadData()
  459. delegate?.batesPropertyControllerDidUpdate?(self)
  460. }
  461. }
  462. }
  463. //MARK: - ComponentTextareaDelegate
  464. extension KMBatesPropertyController: ComponentTextareaDelegate {
  465. func componentTextareaTextDidChange(_ view: ComponentTextarea) {
  466. if positionSelRow == 0 && positionSelColumn == 0 {
  467. //左下角
  468. batesModel.bottomLeftString = layoutTextarea.properties.text
  469. } else if positionSelRow == 0 && positionSelColumn == 1 {
  470. batesModel.bottomCenterString = layoutTextarea.properties.text
  471. } else if positionSelRow == 0 && positionSelColumn == 2 {
  472. batesModel.bottomRightString = layoutTextarea.properties.text
  473. } else if positionSelRow == 1 && positionSelColumn == 0 {
  474. batesModel.topLeftString = layoutTextarea.properties.text
  475. } else if positionSelRow == 1 && positionSelColumn == 1 {
  476. batesModel.topCenterString = layoutTextarea.properties.text
  477. } else if positionSelRow == 1 && positionSelColumn == 2 {
  478. batesModel.topRightString = layoutTextarea.properties.text
  479. }
  480. reloadData()
  481. delegate?.batesPropertyControllerDidUpdate?(self)
  482. }
  483. func componentTextareaTextDidEndEditing(_ view: ComponentTextarea) {
  484. }
  485. }