KMBatchOperateConvertViewController.swift 26 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594
  1. //
  2. // KMBatchOperateConvertViewController.swift
  3. // PDF Reader Pro
  4. //
  5. // Created by kdanmobile on 2023/11/1.
  6. //
  7. import Cocoa
  8. typealias detailInfoViewMouseDownCallback = (_ mouseDown: Bool) -> ()
  9. class KMDetailInfoView: NSView{
  10. var mouseDownCallback: detailInfoViewMouseDownCallback?
  11. override func mouseDown(with event: NSEvent) {
  12. super.mouseDown(with: event)
  13. guard let callBack = mouseDownCallback else { return }
  14. callBack(true)
  15. }
  16. }
  17. class KMBatchOperateConvertViewController: KMBatchOperateBaseViewController,NSCollectionViewDelegate,NSCollectionViewDataSource{
  18. var dataSourcesArray: [KMConvertWithPDFType]?
  19. @IBOutlet var collectionView: NSCollectionView!
  20. @IBOutlet var bottomView: NSView!
  21. @IBOutlet var convertEveryPageButton: NSButton!
  22. @IBOutlet var convertButton: NSButton!
  23. @IBOutlet var detailInfoView: KMDetailInfoView!
  24. @IBOutlet var detailInfoLabel: NSTextField!
  25. @IBOutlet var checkBoxTopConstraint: NSLayoutConstraint!
  26. @IBOutlet var containerViewTopConstraint: NSLayoutConstraint!
  27. @IBOutlet var checkBoxBottomConstaint: NSLayoutConstraint!
  28. @IBOutlet var convertEveryPageButtonLabel: NSTextField!
  29. @IBOutlet var extractButton: NSButton!
  30. @IBOutlet var wordButtonOne: NSButton!
  31. @IBOutlet var wordButtonTwo: NSButton!
  32. @IBOutlet var csvExtractButton: NSButton!
  33. @IBOutlet var onlyTextBtn: NSButton!
  34. @IBOutlet var onlyTableBtn: NSButton!
  35. @IBOutlet var allContentBtn: NSButton!
  36. @IBOutlet var tableMenu1: NSMenuItem!
  37. @IBOutlet var tableMenu2: NSMenuItem!
  38. @IBOutlet var tableMenu3: NSMenuItem!
  39. @IBOutlet var allContentMenu2: NSMenuItem!
  40. @IBOutlet var allContentMenu3: NSMenuItem!
  41. @IBOutlet var tableMenu: NSPopUpButton!
  42. @IBOutlet var allContentMenu: NSPopUpButton!
  43. var excelContentOption: CPDFConvertExcelContentOptions?
  44. var excelWorksheetOption: CPDFConvertExcelWorksheetOptions?
  45. var haveFiles: Bool = false
  46. deinit {
  47. NotificationCenter.default.removeObserver(self)
  48. }
  49. override var interfaceStatus: KMBatchOperateInterfaceStatus?{
  50. set{
  51. super.interfaceStatus = newValue
  52. self.convertButton.isEnabled = true
  53. if newValue == .Processing {
  54. self.collectionView.isSelectable = false
  55. self.convertButton.title = NSLocalizedString("Cancel", comment: "")
  56. self.convertButton.tag = 2
  57. self.convertButton.setTitleColor(KMAppearance.Layout.w0Color())
  58. self.convertButton.layer?.backgroundColor = KMAppearance.Interactive.m0Color().cgColor
  59. if self.convertType == .WordStandard {
  60. self.convertButton.title = NSLocalizedString("Convert", comment: "")
  61. self.convertButton.layer?.backgroundColor = KMAppearance.Interactive.m0Color().withAlphaComponent(0.4).cgColor
  62. self.convertButton.isEnabled = false
  63. }
  64. } else {
  65. DispatchQueue.main.asyncAfter(deadline: .now() + 0.4) {
  66. var files: [URL] = []
  67. for url in self.successFilePathURLArray! {
  68. if FileManager.default.fileExists(atPath: url.path) {
  69. files.append(url)
  70. }
  71. }
  72. if files.count > 0 {
  73. let workspace = NSWorkspace.shared
  74. workspace.activateFileViewerSelecting(files)
  75. }
  76. }
  77. self.collectionView.isSelectable = true
  78. self.convertButton.title = NSLocalizedString("Convert", comment: "")
  79. self.convertButton.tag = 1
  80. self.convertButton.setTitleColor(KMAppearance.Layout.w0Color())
  81. self.convertButton.layer?.backgroundColor = KMAppearance.Interactive.m0Color().cgColor
  82. }
  83. }
  84. get{
  85. return super.interfaceStatus
  86. }
  87. }
  88. override var convertType: KMConvertWithPDFType?{
  89. set{
  90. super.convertType = newValue
  91. changeAllFilesToConvertType(convertType!)
  92. fetchFileListViewController()?.reloadConvertInterface(withType: convertType!)
  93. }
  94. get{
  95. return super.convertType
  96. }
  97. }
  98. func changeAllFilesToConvertType(_ type: KMConvertWithPDFType) {
  99. for i in 0..<self.files!.count {
  100. let file = self.files![i]
  101. file.convertType = type
  102. }
  103. }
  104. func switchToConvertType(_ convertType: KMConvertWithPDFType) {
  105. self.convertType = convertType
  106. self.manualSelectRow(convertType)
  107. self.updateBottomView()
  108. }
  109. func manualSelectRow(_ convertType: KMConvertWithPDFType) {
  110. self.collectionView.deselectAll(nil)
  111. self.collectionView.reloadData()
  112. var set = Set<IndexPath>()
  113. var index = -1
  114. for i in 0..<self.dataSourcesArray!.count {
  115. let number = self.dataSourcesArray![i]
  116. if number.rawValue == convertType.rawValue {
  117. index = i
  118. break
  119. }
  120. }
  121. if index != -1 {
  122. let indexPath = IndexPath(item: index, section: 0)
  123. set.insert(indexPath)
  124. self.collectionView.selectItems(at: set, scrollPosition: [])
  125. let selectionRect = self.collectionView.frameForItem(at: self.collectionView.selectionIndexes.first ?? 0)
  126. self.collectionView.scrollToVisible(selectionRect)
  127. }
  128. }
  129. func updateBottomView() {
  130. var moreLabelString = ""
  131. self.onlyTextBtn.isHidden = true
  132. self.onlyTableBtn.isHidden = true
  133. self.allContentBtn.isHidden = true
  134. self.tableMenu.isHidden = true
  135. self.allContentMenu.isHidden = true
  136. #if VERSION_FREE
  137. if .WordStandard == self.convertType {
  138. moreLabelString = NSLocalizedString("Export PDF to Word and other Microsoft Office formats", comment: "")
  139. } else if .WordAdvance == self.convertType ||
  140. .Excel == self.convertType ||
  141. .PowerPoint == self.convertType ||
  142. .CSV == self.convertType ||
  143. .RTF == self.convertType ||
  144. .GIF == self.convertType ||
  145. .TIFF == self.convertType ||
  146. .JPEG2000 == self.convertType ||
  147. .BMP == self.convertType ||
  148. .TGA == self.convertType {
  149. moreLabelString = NSLocalizedString("The first 10 pages for free. More precise one.", comment: "")
  150. }
  151. #else
  152. // 付费版
  153. if .WordStandard == self.convertType {
  154. moreLabelString = NSLocalizedString("Export PDF to Word and other Microsoft Office formats", comment: "")
  155. } else if .WordAdvance == self.convertType ||
  156. .Excel == self.convertType ||
  157. .PowerPoint == self.convertType ||
  158. .CSV == self.convertType ||
  159. .RTF == self.convertType ||
  160. .GIF == self.convertType ||
  161. .TIFF == self.convertType ||
  162. .JPEG2000 == self.convertType ||
  163. .BMP == self.convertType ||
  164. .TGA == self.convertType {
  165. moreLabelString = NSLocalizedString("The first 10 pages for free. More precise one.", comment: "")
  166. }
  167. #endif
  168. var hasInfo = false
  169. var isExcel = false
  170. self.detailInfoLabel.stringValue = moreLabelString
  171. if moreLabelString.count > 0 {
  172. self.detailInfoView.isHidden = false
  173. self.containerViewTopConstraint.constant = 16
  174. hasInfo = true
  175. } else {
  176. self.detailInfoView.isHidden = true
  177. self.containerViewTopConstraint.constant = 11
  178. }
  179. if self.convertType == .WordAdvance {
  180. isExcel = true
  181. self.convertEveryPageButton.isHidden = true
  182. self.wordButtonOne.isHidden = false
  183. self.wordButtonOne.title = NSLocalizedString("Retain Flowing Text", comment: "")
  184. self.convertEveryPageButtonLabel.isHidden = true
  185. self.extractButton.isHidden = true
  186. self.csvExtractButton.isHidden = true
  187. self.wordButtonTwo.isHidden = false
  188. self.wordButtonTwo.title = NSLocalizedString("Retain Page Layout", comment: "")
  189. self.checkBoxBottomConstaint.constant = 15 + self.wordButtonTwo.frame.size.height + self.wordButtonOne.frame.size.height
  190. self.checkBoxTopConstraint.constant = 5
  191. } else if self.convertType == .Excel {
  192. isExcel = true
  193. self.convertEveryPageButtonLabel.stringValue = NSLocalizedString("Convert each page to a separate worksheet", comment: "")
  194. self.onlyTextBtn.isHidden = false
  195. self.onlyTableBtn.isHidden = false
  196. self.allContentBtn.isHidden = false
  197. self.tableMenu.isHidden = false
  198. self.allContentMenu.isHidden = false
  199. self.convertEveryPageButtonLabel.isHidden = true
  200. self.convertEveryPageButton.isHidden = true
  201. self.wordButtonOne.isHidden = true
  202. self.extractButton.isHidden = true
  203. self.wordButtonTwo.isHidden = true
  204. self.csvExtractButton.isHidden = true
  205. self.extractButton.title = NSLocalizedString("Extract Tables Only", comment: "")
  206. var oneHeight = self.convertEveryPageButtonLabel.frame.size.height
  207. let language = Bundle.main.preferredLocalizations[0]
  208. if language != "zh_CN" && language != "zh_TW" {
  209. oneHeight = 34.0
  210. }
  211. self.checkBoxBottomConstaint.constant = 83
  212. self.checkBoxTopConstraint.constant = 5
  213. } else if self.convertType == .CSV {
  214. isExcel = true
  215. self.convertEveryPageButtonLabel.isHidden = true
  216. self.convertEveryPageButton.isHidden = true
  217. self.extractButton.isHidden = true
  218. self.wordButtonTwo.isHidden = true
  219. self.wordButtonOne.isHidden = true
  220. self.csvExtractButton.isHidden = false
  221. self.csvExtractButton.title = NSLocalizedString("Extract Tables Only", comment: "")
  222. self.checkBoxBottomConstaint.constant = 15 + self.csvExtractButton.frame.size.height
  223. self.checkBoxTopConstraint.constant = 5
  224. } else {
  225. self.convertEveryPageButton.isHidden = true
  226. self.extractButton.isHidden = true
  227. self.wordButtonTwo.isHidden = true
  228. self.wordButtonOne.isHidden = true
  229. self.csvExtractButton.isHidden = true
  230. self.convertEveryPageButtonLabel.stringValue = NSLocalizedString("", comment: "")
  231. self.checkBoxTopConstraint.constant = -10
  232. self.checkBoxBottomConstaint.constant = 5
  233. }
  234. if !hasInfo && !isExcel {
  235. self.containerViewTopConstraint.constant = 0
  236. self.checkBoxTopConstraint.constant = 0
  237. self.checkBoxBottomConstaint.constant = 1
  238. }
  239. }
  240. override func viewDidLoad() {
  241. super.viewDidLoad()
  242. self.prepareData()
  243. self.view.wantsLayer = true
  244. collectionView.allowsMultipleSelection = false
  245. collectionView.enclosingScrollView?.borderType = .noBorder
  246. collectionView.allowsEmptySelection = false
  247. convertButton.wantsLayer = true
  248. convertButton.font = NSFont.systemFont(ofSize: 13)
  249. convertButton.layer?.cornerRadius = 1.0
  250. interfaceStatus = .PrepareProcess
  251. convertEveryPageButton.title = NSLocalizedString("", comment: "")
  252. // Convert each page to a separate worksheet
  253. convertEveryPageButtonLabel.stringValue = NSLocalizedString("Convert each page to a separate worksheet", comment: "")
  254. self.collectionView.register(KMConvertCollectionViewHeader.self, forItemWithIdentifier: NSUserInterfaceItemIdentifier(rawValue: "KMAdvertisementCollectionViewItem"))
  255. self.collectionView.register(KMBatchoperateConvertCollectionViewItem.self, forItemWithIdentifier: NSUserInterfaceItemIdentifier(rawValue: "KMBatchoperateConvertCollectionViewItem"))
  256. self.collectionView.register(KMConvertCollectionViewHeader.self, forSupplementaryViewOfKind: NSCollectionView.elementKindSectionHeader, withIdentifier: NSUserInterfaceItemIdentifier(rawValue: "convertHeader"))
  257. collectionView.enclosingScrollView?.drawsBackground = false
  258. let v = NSView(frame: NSRect(x: 0, y: 0, width: 100, height: 100))
  259. v.wantsLayer = true
  260. v.layer?.backgroundColor = KMAppearance.Layout.l0Color().cgColor
  261. collectionView.backgroundView = v
  262. collectionView.enclosingScrollView?.horizontalScrollElasticity = .none
  263. collectionView.enclosingScrollView?.verticalScrollElasticity = .none
  264. allContentBtn.state = .on
  265. allContentMenu.isEnabled = true
  266. tableMenu.isEnabled = false
  267. excelContentOption = .allContent
  268. excelWorksheetOption = .forEachPage
  269. onlyTextBtn.title = NSLocalizedString("Only Text", comment: "")
  270. onlyTableBtn.title = NSLocalizedString("Only Table", comment: "")
  271. allContentBtn.title = NSLocalizedString("All Content", comment: "")
  272. onlyTextBtn.toolTip = NSLocalizedString("Only Text", comment: "")
  273. onlyTableBtn.toolTip = NSLocalizedString("Only Table", comment: "")
  274. allContentBtn.toolTip = NSLocalizedString("All Content", comment: "")
  275. tableMenu1.title = NSLocalizedString("Create Sheet for each Table", comment: "")
  276. tableMenu2.title = NSLocalizedString("Create Sheet for each Page", comment: "")
  277. allContentMenu2.title = NSLocalizedString("Create Sheet for each Page", comment: "")
  278. tableMenu3.title = NSLocalizedString("Create single Sheet for File", comment: "")
  279. allContentMenu3.title = NSLocalizedString("Create single Sheet for File", comment: "")
  280. self.detailInfoView.mouseDownCallback = { [weak self] (downEntered: Bool) in
  281. if downEntered {
  282. // if (![IAPProductsManager defaultManager].isAvailableAdvancedPDFToOffice) {
  283. self?.convertActionVC()
  284. // }
  285. }
  286. }
  287. self.updateViewColor()
  288. NotificationCenter.default.addObserver(self, selector: #selector(batchFilesCountNotification(notification:)), name: Notification.Name(rawValue: "KMBatchFilesCountNotification"), object: nil)
  289. NotificationCenter.default.addObserver(self, selector: #selector(IAPProductPurchasedNotification(notification:)), name: NSNotification.Name("KMIAPProductPurchasedNotification"), object: nil)
  290. NotificationCenter.default.addObserver(self, selector: #selector(IAPProductRestoreFinishedNotification(notification:)), name: NSNotification.Name("KMIAPProductRestoreFinishedNotification"), object: nil)
  291. NotificationCenter.default.addObserver(self, selector: #selector(themeChanged(notification:)), name: NSNotification.Name("AppleInterfaceThemeChangedNotification"), object: nil)
  292. }
  293. @objc func batchFilesCountNotification(notification: NSNotification) {
  294. let arr: Array? = notification.object as? [KMBatchOperateFile]
  295. self.files? = arr ?? []
  296. if files!.count > 0 {
  297. self.convertButton.setTitleColor(NSColor.white)
  298. self.convertButton.layer?.backgroundColor = KMAppearance.Interactive.m0Color().cgColor
  299. self.haveFiles = true
  300. } else {
  301. self.convertButton.setTitleColor(KMAppearance.Layout.w0Color().withAlphaComponent(0.6))
  302. self.convertButton.layer?.backgroundColor = KMAppearance.Interactive.m0Color().withAlphaComponent(0.4).cgColor
  303. self.haveFiles = false
  304. }
  305. }
  306. @objc func themeChanged(notification: NSNotification) {
  307. DispatchQueue.main.asyncAfter(deadline: .now() + 0.3) {
  308. self.updateViewColor()
  309. }
  310. }
  311. @objc func IAPProductRestoreFinishedNotification(notification: NSNotification) {
  312. DispatchQueue.main.asyncAfter(deadline: .now() + 0.3) {
  313. self.updateBottomView()
  314. self.prepareData()
  315. self.collectionView.reloadData()
  316. }
  317. }
  318. @objc func IAPProductPurchasedNotification(notification: NSNotification) {
  319. DispatchQueue.main.asyncAfter(deadline: .now() + 0.3) {
  320. self.updateBottomView()
  321. self.prepareData()
  322. self.collectionView.reloadData()
  323. }
  324. }
  325. func updateViewColor() {
  326. self.view.wantsLayer = true
  327. if KMAppearance.isDarkMode() {
  328. self.view.layer?.backgroundColor = NSColor(red: 0.055, green: 0.067, blue: 0.078, alpha: 1).cgColor
  329. self.collectionView.backgroundView?.layer?.backgroundColor = NSColor(red: 0.055, green: 0.067, blue: 0.078, alpha: 1).cgColor
  330. } else {
  331. self.view.layer?.backgroundColor = NSColor(red: 0.922, green: 0.925, blue: 0.941, alpha: 1).cgColor
  332. self.collectionView.backgroundView?.layer?.backgroundColor = NSColor(red: 0.922, green: 0.925, blue: 0.941, alpha: 1).cgColor
  333. }
  334. }
  335. func convertActionVC() {
  336. var vc: KMToolCompareWindowController? = nil
  337. if(.WordStandard == self.convertType ||
  338. .WordAdvance == self.convertType) {
  339. vc = KMToolCompareWindowController(toolType: .Convert, selectNum: 1)
  340. } else if (.Excel == self.convertType) {
  341. vc = KMToolCompareWindowController(toolType: .Convert, selectNum: 2)
  342. } else if (.PowerPoint == self.convertType) {
  343. vc = KMToolCompareWindowController(toolType: .Convert, selectNum: 3)
  344. } else if (self.convertType == .JPG || self.convertType == .PNG || self.convertType == .GIF || self.convertType == .TIFF || self.convertType == .TGA || self.convertType == .BMP){
  345. vc = KMToolCompareWindowController(toolType: .Convert, selectNum: 4)
  346. } else {
  347. vc = KMToolCompareWindowController(toolType: .Convert, selectNum: 0)
  348. }
  349. vc?.showWindow(nil)
  350. }
  351. func prepareData() {
  352. let arr: [KMConvertWithPDFType] = [.Excel, .PowerPoint, .RTF, .CSV, .HTML, .Text, .JPEG, .JPG, .PNG, .GIF, .TIFF, .TGA, .BMP, .JPEG2000]
  353. self.dataSourcesArray = arr
  354. var needShowAdvance = true
  355. var needShowDefault = true
  356. #if VERSION_FREE
  357. // 桌机版
  358. // if IAPProductsManager.defaultManager().isAvailableAllFunction {
  359. // if IAPProductsManager.defaultManager().isAvailableAdvancedPDFToOffice {
  360. // needShowAdvance = true
  361. // needShowDefault = false
  362. // }
  363. // }
  364. #else
  365. // if IAPProductsManager.defaultManager().isAvailableAdvancedPDFToOffice {
  366. // needShowAdvance = true
  367. // needShowDefault = false
  368. // }
  369. #endif
  370. if needShowDefault {
  371. var wordType: KMConvertWithPDFType = .WordStandard
  372. self.dataSourcesArray?.insert(wordType, at: 0)
  373. }
  374. if needShowAdvance {
  375. var wordType: KMConvertWithPDFType = .WordAdvance
  376. self.dataSourcesArray?.insert(wordType, at: 0)
  377. }
  378. }
  379. @IBAction func buttonClicked_Convert(_ sender: NSButton) {
  380. if !self.haveFiles { return }
  381. self.view.window?.makeFirstResponder(nil)
  382. for i in 0..<self.files!.count {
  383. let file = self.files?[i]
  384. file?.excelParameter.allInOneSheet = (self.convertEveryPageButton.state == .on) ? false : true
  385. file?.advanceWordParameter.isRetainLayout = (self.wordButtonTwo.state == .on) ? true : false
  386. file?.excelParameter.isExtreactTabel = (self.extractButton.state == .on) ? true : false
  387. file?.CSVParameter.isExtreactTabel = (self.csvExtractButton.state == .on) ? true : false
  388. file?.excelParameter.excelContentOption = self.excelContentOption
  389. file?.excelParameter.excelWorksheetOption = self.excelWorksheetOption
  390. }
  391. if sender.tag == 1 {
  392. self.beginBatchOperation()
  393. } else {
  394. self.cancelBatchOperation()
  395. }
  396. }
  397. @IBAction func moreButtonAction(_ sender: NSButton) {
  398. self.convertActionVC()
  399. self.buttonClicked_Cancel("")
  400. }
  401. @IBAction func layoutButtonAction(_ sender: Any) {
  402. }
  403. @IBAction func exctractTableButtonAction(_ sender: Any) {
  404. if extractButton.state == .on {
  405. convertEveryPageButton.state = .off
  406. convertEveryPageButtonLabel.isEnabled = false
  407. convertEveryPageButton.isEnabled = false
  408. convertEveryPageButtonLabel.textColor = KMAppearance.Layout.b15_1Color()
  409. } else {
  410. convertEveryPageButton.state = .on
  411. convertEveryPageButtonLabel.isEnabled = true
  412. convertEveryPageButton.isEnabled = true
  413. convertEveryPageButtonLabel.textColor = NSColor.labelColor
  414. }
  415. }
  416. @IBAction func buttonClicked_Cancel(_ sender: Any) {
  417. let basePath = NSSearchPathForDirectoriesInDomains(.applicationSupportDirectory, .userDomainMask, true).last ?? ""
  418. let newPath = (basePath as NSString).appendingPathComponent(Bundle.main.bundleIdentifier ?? "")
  419. let filePath = newPath.stringByAppendingPathComponent("convert.pdf")
  420. if FileManager.default.fileExists(atPath: filePath) {
  421. try? FileManager.default.removeItem(atPath: filePath)
  422. }
  423. }
  424. func transform(withString string: String) {
  425. if string == NSLocalizedString("Create Sheet for each Table", comment: "") {
  426. self.excelWorksheetOption = .forEachTable
  427. } else if string == NSLocalizedString("Create Sheet for each Page", comment: "") {
  428. self.excelWorksheetOption = .forEachPage
  429. } else if string == NSLocalizedString("Create single Sheet for File", comment: "") {
  430. self.excelWorksheetOption = .forTheDocument
  431. }
  432. }
  433. @IBAction func buttonClicked_excelStyle(_ sender: NSButton) {
  434. if sender == onlyTextBtn {
  435. onlyTextBtn.state = NSControl.StateValue.on
  436. onlyTableBtn.state = NSControl.StateValue.off
  437. allContentBtn.state = NSControl.StateValue.off
  438. tableMenu.isEnabled = false
  439. allContentMenu.isEnabled = false
  440. excelContentOption = .onlyText
  441. excelWorksheetOption = .forEachTable
  442. } else if sender == onlyTableBtn {
  443. onlyTableBtn.state = NSControl.StateValue.on
  444. onlyTextBtn.state = NSControl.StateValue.off
  445. allContentBtn.state = NSControl.StateValue.off
  446. tableMenu.isEnabled = true
  447. allContentMenu.isEnabled = false
  448. excelContentOption = .onlyTable
  449. transform(withString: tableMenu.selectedItem?.title ?? "")
  450. } else if sender == allContentBtn {
  451. allContentBtn.state = NSControl.StateValue.on
  452. onlyTextBtn.state = NSControl.StateValue.off
  453. onlyTableBtn.state = NSControl.StateValue.off
  454. tableMenu.isEnabled = false
  455. allContentMenu.isEnabled = true
  456. excelContentOption = .allContent
  457. transform(withString: allContentMenu.selectedItem?.title ?? "")
  458. }
  459. }
  460. @IBAction func buttonClicked_tableMenu(_ sender: NSPopUpButton) {
  461. transform(withString: self.tableMenu.selectedItem!.title)
  462. }
  463. @IBAction func buttonClickec_allContentMenu(_ sender: NSButton) {
  464. transform(withString: self.allContentMenu.selectedItem!.title)
  465. }
  466. func collectionView(_ collectionView: NSCollectionView, numberOfItemsInSection section: Int) -> Int {
  467. return dataSourcesArray!.count
  468. }
  469. func collectionView(_ collectionView: NSCollectionView, didSelectItemsAt indexPaths: Set<IndexPath>) {
  470. if let indexPath = indexPaths.first {
  471. convertType = dataSourcesArray![indexPath.item]
  472. updateBottomView()
  473. }
  474. }
  475. func collectionView(_ collectionView: NSCollectionView, layout collectionViewLayout: NSCollectionViewLayout, referenceSizeForHeaderInSection section: Int) -> NSSize {
  476. return NSSize(width: 10000, height: 50)
  477. }
  478. func collectionView(_ collectionView: NSCollectionView, viewForSupplementaryElementOfKind kind: NSCollectionView.SupplementaryElementKind, at indexPath: IndexPath) -> NSView {
  479. let view = collectionView.makeSupplementaryView(ofKind: kind, withIdentifier:NSUserInterfaceItemIdentifier(rawValue: "convertHeader") , for: indexPath) as? KMConvertCollectionViewHeader
  480. view?.convertHeaderClickedCallBack = {
  481. self.convertActionVC()
  482. }
  483. return view ?? NSView()
  484. }
  485. func intConvertType(num: Int) -> KMConvertWithPDFType {
  486. var type: KMConvertWithPDFType?
  487. switch num {
  488. case 0:
  489. type = .WordAdvance
  490. case 1:
  491. type = .WordStandard
  492. case 2:
  493. type = .Excel
  494. case 3:
  495. type = .PowerPoint
  496. case 4:
  497. type = .RTF
  498. case 5:
  499. type = .CSV
  500. case 6:
  501. type = .HTML
  502. case 7:
  503. type = .Text
  504. case 8:
  505. type = .JPEG
  506. case 9:
  507. type = .JPG
  508. case 10:
  509. type = .PNG
  510. case 11:
  511. type = .GIF
  512. case 12:
  513. type = .TIFF
  514. case 13:
  515. type = .TGA
  516. case 14:
  517. type = .BMP
  518. case 15:
  519. type = .JPEG2000
  520. default:
  521. type = .WordAdvance
  522. }
  523. return type!
  524. }
  525. }
  526. extension KMBatchOperateConvertViewController: NSCollectionViewDelegateFlowLayout {
  527. func collectionView(_ collectionView: NSCollectionView, itemForRepresentedObjectAt indexPath: IndexPath) -> NSCollectionViewItem {
  528. let item = collectionView.makeItem(withIdentifier: NSUserInterfaceItemIdentifier(rawValue: "KMBatchoperateConvertCollectionViewItem"), for: indexPath) as! KMBatchoperateConvertCollectionViewItem
  529. item.updateInterface(dataSourcesArray![indexPath.item])
  530. return item
  531. }
  532. func collectionView(_ collectionView: NSCollectionView, layout collectionViewLayout: NSCollectionViewLayout, sizeForItemAt indexPath: IndexPath) -> NSSize {
  533. return NSSize(width: 74, height: 80)
  534. }
  535. func collectionView(_ collectionView: NSCollectionView, layout collectionViewLayout: NSCollectionViewLayout, insetForSectionAt section: Int) -> NSEdgeInsets {
  536. return NSEdgeInsets(top: 0, left: 10, bottom: 0, right: 0)
  537. }
  538. }