KMBatchOperateConvertViewController.swift 26 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591
  1. //
  2. // KMBatchOperateConvertViewController.swift
  3. // PDF Master
  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{
  18. var dataSourcesArray: NSMutableArray?
  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 as AnyObject).intValue == 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. collectionView.enclosingScrollView?.drawsBackground = false
  256. let v = NSView(frame: NSRect(x: 0, y: 0, width: 100, height: 100))
  257. v.wantsLayer = true
  258. v.layer?.backgroundColor = KMAppearance.Layout.l0Color().cgColor
  259. collectionView.backgroundView = v
  260. collectionView.enclosingScrollView?.horizontalScrollElasticity = .none
  261. collectionView.enclosingScrollView?.verticalScrollElasticity = .none
  262. allContentBtn.state = .on
  263. allContentMenu.isEnabled = true
  264. tableMenu.isEnabled = false
  265. excelContentOption = .allContent
  266. excelWorksheetOption = .forEachPage
  267. onlyTextBtn.title = NSLocalizedString("Only Text", comment: "")
  268. onlyTableBtn.title = NSLocalizedString("Only Table", comment: "")
  269. allContentBtn.title = NSLocalizedString("All Content", comment: "")
  270. onlyTextBtn.toolTip = NSLocalizedString("Only Text", comment: "")
  271. onlyTableBtn.toolTip = NSLocalizedString("Only Table", comment: "")
  272. allContentBtn.toolTip = NSLocalizedString("All Content", comment: "")
  273. tableMenu1.title = NSLocalizedString("Create Sheet for each Table", comment: "")
  274. tableMenu2.title = NSLocalizedString("Create Sheet for each Page", comment: "")
  275. allContentMenu2.title = NSLocalizedString("Create Sheet for each Page", comment: "")
  276. tableMenu3.title = NSLocalizedString("Create single Sheet for File", comment: "")
  277. allContentMenu3.title = NSLocalizedString("Create single Sheet for File", comment: "")
  278. self.detailInfoView.mouseDownCallback = { [weak self] (downEntered: Bool) in
  279. if downEntered {
  280. // if (![IAPProductsManager defaultManager].isAvailableAdvancedPDFToOffice) {
  281. self?.convertActionVC()
  282. // }
  283. }
  284. }
  285. self.updateViewColor()
  286. NotificationCenter.default.addObserver(self, selector: #selector(batchFilesCountNotification(notification:)), name: NSNotification.Name("KMBatchFilesCountNotification"), object: nil)
  287. NotificationCenter.default.addObserver(self, selector: #selector(IAPProductPurchasedNotification(notification:)), name: NSNotification.Name("KMIAPProductPurchasedNotification"), object: nil)
  288. NotificationCenter.default.addObserver(self, selector: #selector(IAPProductRestoreFinishedNotification(notification:)), name: NSNotification.Name("KMIAPProductRestoreFinishedNotification"), object: nil)
  289. NotificationCenter.default.addObserver(self, selector: #selector(themeChanged(notification:)), name: NSNotification.Name("AppleInterfaceThemeChangedNotification"), object: nil)
  290. }
  291. @objc func batchFilesCountNotification(notification: NSNotification) {
  292. let files = notification.object as? [Any]
  293. if files!.count > 0 {
  294. self.convertButton.setTitleColor(NSColor.white)
  295. self.convertButton.layer?.backgroundColor = KMAppearance.Interactive.m0Color().cgColor
  296. self.haveFiles = true
  297. } else {
  298. self.convertButton.setTitleColor(KMAppearance.Layout.w0Color().withAlphaComponent(0.6))
  299. self.convertButton.layer?.backgroundColor = KMAppearance.Interactive.m0Color().withAlphaComponent(0.4).cgColor
  300. self.haveFiles = false
  301. }
  302. }
  303. @objc func themeChanged(notification: NSNotification) {
  304. DispatchQueue.main.asyncAfter(deadline: .now() + 0.3) {
  305. self.updateViewColor()
  306. }
  307. }
  308. @objc func IAPProductRestoreFinishedNotification(notification: NSNotification) {
  309. DispatchQueue.main.asyncAfter(deadline: .now() + 0.3) {
  310. self.updateBottomView()
  311. self.prepareData()
  312. self.collectionView.reloadData()
  313. }
  314. }
  315. @objc func IAPProductPurchasedNotification(notification: NSNotification) {
  316. DispatchQueue.main.asyncAfter(deadline: .now() + 0.3) {
  317. self.updateBottomView()
  318. self.prepareData()
  319. self.collectionView.reloadData()
  320. }
  321. }
  322. func updateViewColor() {
  323. self.view.wantsLayer = true
  324. if KMAppearance.isDarkMode() {
  325. self.view.layer?.backgroundColor = NSColor(red: 0.055, green: 0.067, blue: 0.078, alpha: 1).cgColor
  326. self.collectionView.backgroundView?.layer?.backgroundColor = NSColor(red: 0.055, green: 0.067, blue: 0.078, alpha: 1).cgColor
  327. } else {
  328. self.view.layer?.backgroundColor = NSColor(red: 0.922, green: 0.925, blue: 0.941, alpha: 1).cgColor
  329. self.collectionView.backgroundView?.layer?.backgroundColor = NSColor(red: 0.922, green: 0.925, blue: 0.941, alpha: 1).cgColor
  330. }
  331. }
  332. func convertActionVC() {
  333. // KMToolCompareWindowController *vc = nil;
  334. if(.WordStandard == self.convertType ||
  335. .WordAdvance == self.convertType) {
  336. // vc = [KMToolCompareWindowController toolCompareWithType:KMCompareWithToolType_Convert setSelectIndex:1];
  337. } else if (.Excel == self.convertType) {
  338. // vc = [KMToolCompareWindowController toolCompareWithType:KMCompareWithToolType_Convert setSelectIndex:2];
  339. } else if (.PowerPoint == self.convertType) {
  340. // vc = [KMToolCompareWindowController toolCompareWithType:KMCompareWithToolType_Convert setSelectIndex:3];
  341. } else if (self.convertType == .JPG || self.convertType == .PNG || self.convertType == .GIF || self.convertType == .TIFF || self.convertType == .TGA || self.convertType == .BMP){
  342. // vc = [KMToolCompareWindowController toolCompareWithType:KMCompareWithToolType_Convert setSelectIndex:4];
  343. } else {
  344. // vc = [KMToolCompareWindowController toolCompareWithType:KMCompareWithToolType_Convert setSelectIndex:0];
  345. }
  346. // [vc showWindow:nil];
  347. }
  348. func prepareData() {
  349. let arr: [KMConvertWithPDFType] = [.Excel, .PowerPoint, .RTF, .CSV, .CSV, .HTML, .Text, .JPEG, .JPG, .PNG, .GIF, .TIFF, .TGA, .BMP, .JPEG2000]
  350. self.dataSourcesArray = NSMutableArray(array: arr)
  351. var needShowAdvance = true
  352. var needShowDefault = true
  353. #if VERSION_FREE
  354. // 桌机版
  355. // if IAPProductsManager.defaultManager().isAvailableAllFunction {
  356. // if IAPProductsManager.defaultManager().isAvailableAdvancedPDFToOffice {
  357. // needShowAdvance = true
  358. // needShowDefault = false
  359. // }
  360. // }
  361. #else
  362. // if IAPProductsManager.defaultManager().isAvailableAdvancedPDFToOffice {
  363. // needShowAdvance = true
  364. // needShowDefault = false
  365. // }
  366. #endif
  367. if needShowDefault {
  368. var wordType: KMConvertWithPDFType = .WordStandard
  369. self.dataSourcesArray?.insert(wordType, at: 0)
  370. }
  371. if needShowAdvance {
  372. var wordType: KMConvertWithPDFType = .WordAdvance
  373. self.dataSourcesArray?.insert(wordType, at: 0)
  374. }
  375. }
  376. @IBAction func buttonClicked_Convert(_ sender: NSButton) {
  377. if !self.haveFiles { return }
  378. self.view.window?.makeFirstResponder(nil)
  379. for i in 0..<self.files!.count {
  380. let file = self.files?[i]
  381. file?.excelParameter.allInOneSheet = (self.convertEveryPageButton.state == .on) ? false : true
  382. file?.advanceWordParameter.isRetainLayout = (self.wordButtonTwo.state == .on) ? true : false
  383. file?.excelParameter.isExtreactTabel = (self.extractButton.state == .on) ? true : false
  384. file?.CSVParameter.isExtreactTabel = (self.csvExtractButton.state == .on) ? true : false
  385. file?.excelParameter.excelContentOption = self.excelContentOption
  386. file?.excelParameter.excelWorksheetOption = self.excelWorksheetOption
  387. }
  388. if sender.tag == 1 {
  389. self.beginBatchOperation()
  390. } else {
  391. self.cancelBatchOperation()
  392. }
  393. }
  394. @IBAction func moreButtonAction(_ sender: NSButton) {
  395. self.convertActionVC()
  396. self.buttonClicked_Cancel("")
  397. }
  398. @IBAction func layoutButtonAction(_ sender: Any) {
  399. }
  400. @IBAction func exctractTableButtonAction(_ sender: Any) {
  401. if extractButton.state == .on {
  402. convertEveryPageButton.state = .off
  403. convertEveryPageButtonLabel.isEnabled = false
  404. convertEveryPageButton.isEnabled = false
  405. convertEveryPageButtonLabel.textColor = KMAppearance.Layout.b15_1Color()
  406. } else {
  407. convertEveryPageButton.state = .on
  408. convertEveryPageButtonLabel.isEnabled = true
  409. convertEveryPageButton.isEnabled = true
  410. convertEveryPageButtonLabel.textColor = NSColor.labelColor
  411. }
  412. }
  413. @IBAction func buttonClicked_Cancel(_ sender: Any) {
  414. let basePath = NSSearchPathForDirectoriesInDomains(.applicationSupportDirectory, .userDomainMask, true).last ?? ""
  415. let newPath = (basePath as NSString).appendingPathComponent(Bundle.main.bundleIdentifier ?? "")
  416. let filePath = newPath.stringByAppendingPathComponent("convert.pdf")
  417. if FileManager.default.fileExists(atPath: filePath) {
  418. try? FileManager.default.removeItem(atPath: filePath)
  419. }
  420. }
  421. func transform(withString string: String) {
  422. if string == NSLocalizedString("Create Sheet for each Table", comment: "") {
  423. self.excelWorksheetOption = .forEachTable
  424. } else if string == NSLocalizedString("Create Sheet for each Page", comment: "") {
  425. self.excelWorksheetOption = .forEachPage
  426. } else if string == NSLocalizedString("Create single Sheet for File", comment: "") {
  427. self.excelWorksheetOption = .forTheDocument
  428. }
  429. }
  430. @IBAction func buttonClicked_excelStyle(_ sender: NSButton) {
  431. if sender == onlyTextBtn {
  432. onlyTextBtn.state = NSControl.StateValue.on
  433. onlyTableBtn.state = NSControl.StateValue.off
  434. allContentBtn.state = NSControl.StateValue.off
  435. tableMenu.isEnabled = false
  436. allContentMenu.isEnabled = false
  437. excelContentOption = .onlyText
  438. excelWorksheetOption = .forEachTable
  439. } else if sender == onlyTableBtn {
  440. onlyTableBtn.state = NSControl.StateValue.on
  441. onlyTextBtn.state = NSControl.StateValue.off
  442. allContentBtn.state = NSControl.StateValue.off
  443. tableMenu.isEnabled = true
  444. allContentMenu.isEnabled = false
  445. excelContentOption = .onlyTable
  446. transform(withString: tableMenu.selectedItem?.title ?? "")
  447. } else if sender == allContentBtn {
  448. allContentBtn.state = NSControl.StateValue.on
  449. onlyTextBtn.state = NSControl.StateValue.off
  450. onlyTableBtn.state = NSControl.StateValue.off
  451. tableMenu.isEnabled = false
  452. allContentMenu.isEnabled = true
  453. excelContentOption = .allContent
  454. transform(withString: allContentMenu.selectedItem?.title ?? "")
  455. }
  456. }
  457. @IBAction func buttonClicked_tableMenu(_ sender: NSPopUpButton) {
  458. transform(withString: self.tableMenu.selectedItem!.title)
  459. }
  460. @IBAction func buttonClickec_allContentMenu(_ sender: NSButton) {
  461. transform(withString: self.allContentMenu.selectedItem!.title)
  462. }
  463. func collectionView(_ collectionView: NSCollectionView, numberOfItemsInSection section: Int) -> Int {
  464. return dataSourcesArray!.count
  465. }
  466. func collectionView(_ collectionView: NSCollectionView, itemForRepresentedObjectAt indexPath: IndexPath) -> NSCollectionViewItem {
  467. let item = collectionView.makeItem(withIdentifier: NSUserInterfaceItemIdentifier(rawValue: "KMBatchoperateConvertCollectionViewItem"), for: indexPath) as! KMBatchoperateConvertCollectionViewItem
  468. let number = dataSourcesArray![indexPath.item]
  469. item.updateInterface(KMConvertWithPDFType(rawValue: (number as AnyObject).intValue!) ?? .WordAdvance)
  470. return item
  471. }
  472. func collectionView(_ collectionView: NSCollectionView, layout collectionViewLayout: NSCollectionViewLayout, sizeForItemAt indexPath: IndexPath) -> NSSize {
  473. return NSSize(width: 74, height: 80)
  474. }
  475. func collectionView(_ collectionView: NSCollectionView, layout collectionViewLayout: NSCollectionViewLayout, insetForSectionAt section: Int) -> NSEdgeInsets {
  476. return NSEdgeInsets(top: 0, left: 10, bottom: 0, right: 0)
  477. }
  478. func collectionView(_ collectionView: NSCollectionView, didSelectItemsAt indexPaths: Set<IndexPath>) {
  479. if let indexPath = indexPaths.first {
  480. let number = dataSourcesArray![indexPath.item]
  481. convertType = intConvertType(num: number as! Int)
  482. updateBottomView()
  483. }
  484. }
  485. func collectionView(_ collectionView: NSCollectionView, layout collectionViewLayout: NSCollectionViewLayout, referenceSizeForHeaderInSection section: Int) -> NSSize {
  486. return NSSize(width: 10000, height: 50)
  487. }
  488. func collectionView(_ collectionView: NSCollectionView, viewForSupplementaryElementOfKind kind: NSCollectionView.SupplementaryElementKind, at indexPath: IndexPath) -> NSView {
  489. let view = collectionView.makeSupplementaryView(ofKind: kind, withIdentifier:NSUserInterfaceItemIdentifier(rawValue: "convertHeader") , for: indexPath) as! KMConvertCollectionViewHeader
  490. view.convertHeaderClickedCallBack = {
  491. self.convertActionVC()
  492. }
  493. return view
  494. }
  495. func intConvertType(num: Int) -> KMConvertWithPDFType {
  496. var type: KMConvertWithPDFType?
  497. switch num {
  498. case 0:
  499. type = .WordAdvance
  500. case 1:
  501. type = .WordStandard
  502. case 2:
  503. type = .Excel
  504. case 3:
  505. type = .PowerPoint
  506. case 4:
  507. type = .RTF
  508. case 5:
  509. type = .CSV
  510. case 6:
  511. type = .HTML
  512. case 7:
  513. type = .Text
  514. case 8:
  515. type = .JPEG
  516. case 9:
  517. type = .JPG
  518. case 10:
  519. type = .PNG
  520. case 11:
  521. type = .GIF
  522. case 12:
  523. type = .TIFF
  524. case 13:
  525. type = .TGA
  526. case 14:
  527. type = .BMP
  528. case 15:
  529. type = .JPEG2000
  530. default:
  531. type = .WordAdvance
  532. }
  533. return type!
  534. }
  535. }