|
@@ -0,0 +1,591 @@
|
|
|
|
+//
|
|
|
|
+// KMBatchOperateConvertViewController.swift
|
|
|
|
+// PDF Master
|
|
|
|
+//
|
|
|
|
+// Created by kdanmobile on 2023/11/1.
|
|
|
|
+//
|
|
|
|
+
|
|
|
|
+import Cocoa
|
|
|
|
+
|
|
|
|
+typealias detailInfoViewMouseDownCallback = (_ mouseDown: Bool) -> ()
|
|
|
|
+
|
|
|
|
+class KMDetailInfoView: NSView{
|
|
|
|
+ var mouseDownCallback: detailInfoViewMouseDownCallback?
|
|
|
|
+ override func mouseDown(with event: NSEvent) {
|
|
|
|
+ super.mouseDown(with: event)
|
|
|
|
+ guard let callBack = mouseDownCallback else { return }
|
|
|
|
+ callBack(true)
|
|
|
|
+ }
|
|
|
|
+}
|
|
|
|
+
|
|
|
|
+class KMBatchOperateConvertViewController: KMBatchOperateBaseViewController{
|
|
|
|
+ var dataSourcesArray: NSMutableArray?
|
|
|
|
+ @IBOutlet var collectionView: NSCollectionView!
|
|
|
|
+ @IBOutlet var bottomView: NSView!
|
|
|
|
+ @IBOutlet var convertEveryPageButton: NSButton!
|
|
|
|
+
|
|
|
|
+ @IBOutlet var convertButton: NSButton!
|
|
|
|
+
|
|
|
|
+ @IBOutlet var detailInfoView: KMDetailInfoView!
|
|
|
|
+ @IBOutlet var detailInfoLabel: NSTextField!
|
|
|
|
+
|
|
|
|
+ @IBOutlet var checkBoxTopConstraint: NSLayoutConstraint!
|
|
|
|
+ @IBOutlet var containerViewTopConstraint: NSLayoutConstraint!
|
|
|
|
+ @IBOutlet var checkBoxBottomConstaint: NSLayoutConstraint!
|
|
|
|
+
|
|
|
|
+ @IBOutlet var convertEveryPageButtonLabel: NSTextField!
|
|
|
|
+
|
|
|
|
+ @IBOutlet var extractButton: NSButton!
|
|
|
|
+
|
|
|
|
+ @IBOutlet var wordButtonOne: NSButton!
|
|
|
|
+
|
|
|
|
+ @IBOutlet var wordButtonTwo: NSButton!
|
|
|
|
+
|
|
|
|
+ @IBOutlet var csvExtractButton: NSButton!
|
|
|
|
+
|
|
|
|
+ @IBOutlet var onlyTextBtn: NSButton!
|
|
|
|
+
|
|
|
|
+ @IBOutlet var onlyTableBtn: NSButton!
|
|
|
|
+
|
|
|
|
+ @IBOutlet var allContentBtn: NSButton!
|
|
|
|
+
|
|
|
|
+ @IBOutlet var tableMenu1: NSMenuItem!
|
|
|
|
+
|
|
|
|
+ @IBOutlet var tableMenu2: NSMenuItem!
|
|
|
|
+
|
|
|
|
+ @IBOutlet var tableMenu3: NSMenuItem!
|
|
|
|
+
|
|
|
|
+ @IBOutlet var allContentMenu2: NSMenuItem!
|
|
|
|
+
|
|
|
|
+ @IBOutlet var allContentMenu3: NSMenuItem!
|
|
|
|
+
|
|
|
|
+ @IBOutlet var tableMenu: NSPopUpButton!
|
|
|
|
+
|
|
|
|
+ @IBOutlet var allContentMenu: NSPopUpButton!
|
|
|
|
+
|
|
|
|
+ var excelContentOption: CPDFConvertExcelContentOptions?
|
|
|
|
+ var excelWorksheetOption: CPDFConvertExcelWorksheetOptions?
|
|
|
|
+ var haveFiles: Bool = false
|
|
|
|
+
|
|
|
|
+ deinit {
|
|
|
|
+ NotificationCenter.default.removeObserver(self)
|
|
|
|
+ }
|
|
|
|
+ override var interfaceStatus: KMBatchOperateInterfaceStatus?{
|
|
|
|
+ set{
|
|
|
|
+ super.interfaceStatus = newValue
|
|
|
|
+ self.convertButton.isEnabled = true
|
|
|
|
+ if newValue == .Processing {
|
|
|
|
+ self.collectionView.isSelectable = false
|
|
|
|
+ self.convertButton.title = NSLocalizedString("Cancel", comment: "")
|
|
|
|
+ self.convertButton.tag = 2
|
|
|
|
+ self.convertButton.setTitleColor(KMAppearance.Layout.w0Color())
|
|
|
|
+ self.convertButton.layer?.backgroundColor = KMAppearance.Interactive.m0Color().cgColor
|
|
|
|
+ if self.convertType == .WordStandard {
|
|
|
|
+ self.convertButton.title = NSLocalizedString("Convert", comment: "")
|
|
|
|
+ self.convertButton.layer?.backgroundColor = KMAppearance.Interactive.m0Color().withAlphaComponent(0.4).cgColor
|
|
|
|
+ self.convertButton.isEnabled = false
|
|
|
|
+ }
|
|
|
|
+ } else {
|
|
|
|
+ DispatchQueue.main.asyncAfter(deadline: .now() + 0.4) {
|
|
|
|
+ var files: [URL] = []
|
|
|
|
+ for url in self.successFilePathURLArray! {
|
|
|
|
+ if FileManager.default.fileExists(atPath: url.path) {
|
|
|
|
+ files.append(url)
|
|
|
|
+ }
|
|
|
|
+ }
|
|
|
|
+ if files.count > 0 {
|
|
|
|
+ let workspace = NSWorkspace.shared
|
|
|
|
+ workspace.activateFileViewerSelecting(files)
|
|
|
|
+ }
|
|
|
|
+ }
|
|
|
|
+ self.collectionView.isSelectable = true
|
|
|
|
+ self.convertButton.title = NSLocalizedString("Convert", comment: "")
|
|
|
|
+ self.convertButton.tag = 1
|
|
|
|
+ self.convertButton.setTitleColor(KMAppearance.Layout.w0Color())
|
|
|
|
+ self.convertButton.layer?.backgroundColor = KMAppearance.Interactive.m0Color().cgColor
|
|
|
|
+ }
|
|
|
|
+ }
|
|
|
|
+ get{
|
|
|
|
+ return super.interfaceStatus
|
|
|
|
+ }
|
|
|
|
+ }
|
|
|
|
+ override var convertType: KMConvertWithPDFType?{
|
|
|
|
+ set{
|
|
|
|
+ super.convertType = newValue
|
|
|
|
+ changeAllFilesToConvertType(convertType!)
|
|
|
|
+ fetchFileListViewController()?.reloadConvertInterface(withType: convertType!)
|
|
|
|
+ }
|
|
|
|
+ get{
|
|
|
|
+ return super.convertType
|
|
|
|
+ }
|
|
|
|
+ }
|
|
|
|
+ func changeAllFilesToConvertType(_ type: KMConvertWithPDFType) {
|
|
|
|
+ for i in 0..<self.files!.count {
|
|
|
|
+ let file = self.files![i]
|
|
|
|
+ file.convertType = type
|
|
|
|
+ }
|
|
|
|
+ }
|
|
|
|
+ func switchToConvertType(_ convertType: KMConvertWithPDFType) {
|
|
|
|
+ self.convertType = convertType
|
|
|
|
+ self.manualSelectRow(convertType)
|
|
|
|
+ self.updateBottomView()
|
|
|
|
+ }
|
|
|
|
+ func manualSelectRow(_ convertType: KMConvertWithPDFType) {
|
|
|
|
+ self.collectionView.deselectAll(nil)
|
|
|
|
+ self.collectionView.reloadData()
|
|
|
|
+ var set = Set<IndexPath>()
|
|
|
|
+ var index = -1
|
|
|
|
+ for i in 0..<self.dataSourcesArray!.count {
|
|
|
|
+ let number = self.dataSourcesArray![i]
|
|
|
|
+ if (number as AnyObject).intValue == convertType.rawValue {
|
|
|
|
+ index = i
|
|
|
|
+ break
|
|
|
|
+ }
|
|
|
|
+ }
|
|
|
|
+ if index != -1 {
|
|
|
|
+ let indexPath = IndexPath(item: index, section: 0)
|
|
|
|
+ set.insert(indexPath)
|
|
|
|
+ self.collectionView.selectItems(at: set, scrollPosition: [])
|
|
|
|
+ let selectionRect = self.collectionView.frameForItem(at: self.collectionView.selectionIndexes.first ?? 0)
|
|
|
|
+ self.collectionView.scrollToVisible(selectionRect)
|
|
|
|
+
|
|
|
|
+ }
|
|
|
|
+ }
|
|
|
|
+ func updateBottomView() {
|
|
|
|
+ var moreLabelString = ""
|
|
|
|
+ self.onlyTextBtn.isHidden = true
|
|
|
|
+ self.onlyTableBtn.isHidden = true
|
|
|
|
+ self.allContentBtn.isHidden = true
|
|
|
|
+ self.tableMenu.isHidden = true
|
|
|
|
+ self.allContentMenu.isHidden = true
|
|
|
|
+#if VERSION_FREE
|
|
|
|
+ if .WordStandard == self.convertType {
|
|
|
|
+ moreLabelString = NSLocalizedString("Export PDF to Word and other Microsoft Office formats", comment: "")
|
|
|
|
+ } else if .WordAdvance == self.convertType ||
|
|
|
|
+ .Excel == self.convertType ||
|
|
|
|
+ .PowerPoint == self.convertType ||
|
|
|
|
+ .CSV == self.convertType ||
|
|
|
|
+ .RTF == self.convertType ||
|
|
|
|
+ .GIF == self.convertType ||
|
|
|
|
+ .TIFF == self.convertType ||
|
|
|
|
+ .JPEG2000 == self.convertType ||
|
|
|
|
+ .BMP == self.convertType ||
|
|
|
|
+ .TGA == self.convertType {
|
|
|
|
+ moreLabelString = NSLocalizedString("The first 10 pages for free. More precise one.", comment: "")
|
|
|
|
+ }
|
|
|
|
+#else
|
|
|
|
+ // 付费版
|
|
|
|
+ if .WordStandard == self.convertType {
|
|
|
|
+ moreLabelString = NSLocalizedString("Export PDF to Word and other Microsoft Office formats", comment: "")
|
|
|
|
+ } else if .WordAdvance == self.convertType ||
|
|
|
|
+ .Excel == self.convertType ||
|
|
|
|
+ .PowerPoint == self.convertType ||
|
|
|
|
+ .CSV == self.convertType ||
|
|
|
|
+ .RTF == self.convertType ||
|
|
|
|
+ .GIF == self.convertType ||
|
|
|
|
+ .TIFF == self.convertType ||
|
|
|
|
+ .JPEG2000 == self.convertType ||
|
|
|
|
+ .BMP == self.convertType ||
|
|
|
|
+ .TGA == self.convertType {
|
|
|
|
+ moreLabelString = NSLocalizedString("The first 10 pages for free. More precise one.", comment: "")
|
|
|
|
+ }
|
|
|
|
+#endif
|
|
|
|
+
|
|
|
|
+ var hasInfo = false
|
|
|
|
+ var isExcel = false
|
|
|
|
+ self.detailInfoLabel.stringValue = moreLabelString
|
|
|
|
+ if moreLabelString.count > 0 {
|
|
|
|
+ self.detailInfoView.isHidden = false
|
|
|
|
+ self.containerViewTopConstraint.constant = 16
|
|
|
|
+ hasInfo = true
|
|
|
|
+ } else {
|
|
|
|
+ self.detailInfoView.isHidden = true
|
|
|
|
+ self.containerViewTopConstraint.constant = 11
|
|
|
|
+ }
|
|
|
|
+
|
|
|
|
+ if self.convertType == .WordAdvance {
|
|
|
|
+ isExcel = true
|
|
|
|
+ self.convertEveryPageButton.isHidden = true
|
|
|
|
+ self.wordButtonOne.isHidden = false
|
|
|
|
+ self.wordButtonOne.title = NSLocalizedString("Retain Flowing Text", comment: "")
|
|
|
|
+ self.convertEveryPageButtonLabel.isHidden = true
|
|
|
|
+ self.extractButton.isHidden = true
|
|
|
|
+ self.csvExtractButton.isHidden = true
|
|
|
|
+ self.wordButtonTwo.isHidden = false
|
|
|
|
+ self.wordButtonTwo.title = NSLocalizedString("Retain Page Layout", comment: "")
|
|
|
|
+ self.checkBoxBottomConstaint.constant = 15 + self.wordButtonTwo.frame.size.height + self.wordButtonOne.frame.size.height
|
|
|
|
+ self.checkBoxTopConstraint.constant = 5
|
|
|
|
+ } else if self.convertType == .Excel {
|
|
|
|
+ isExcel = true
|
|
|
|
+
|
|
|
|
+ self.convertEveryPageButtonLabel.stringValue = NSLocalizedString("Convert each page to a separate worksheet", comment: "")
|
|
|
|
+ self.onlyTextBtn.isHidden = false
|
|
|
|
+ self.onlyTableBtn.isHidden = false
|
|
|
|
+ self.allContentBtn.isHidden = false
|
|
|
|
+ self.tableMenu.isHidden = false
|
|
|
|
+ self.allContentMenu.isHidden = false
|
|
|
|
+ self.convertEveryPageButtonLabel.isHidden = true
|
|
|
|
+ self.convertEveryPageButton.isHidden = true
|
|
|
|
+ self.wordButtonOne.isHidden = true
|
|
|
|
+ self.extractButton.isHidden = true
|
|
|
|
+ self.wordButtonTwo.isHidden = true
|
|
|
|
+ self.csvExtractButton.isHidden = true
|
|
|
|
+
|
|
|
|
+ self.extractButton.title = NSLocalizedString("Extract Tables Only", comment: "")
|
|
|
|
+ var oneHeight = self.convertEveryPageButtonLabel.frame.size.height
|
|
|
|
+ let language = Bundle.main.preferredLocalizations[0]
|
|
|
|
+ if language != "zh_CN" && language != "zh_TW" {
|
|
|
|
+ oneHeight = 34.0
|
|
|
|
+ }
|
|
|
|
+ self.checkBoxBottomConstaint.constant = 83
|
|
|
|
+ self.checkBoxTopConstraint.constant = 5
|
|
|
|
+ } else if self.convertType == .CSV {
|
|
|
|
+ isExcel = true
|
|
|
|
+ self.convertEveryPageButtonLabel.isHidden = true
|
|
|
|
+ self.convertEveryPageButton.isHidden = true
|
|
|
|
+ self.extractButton.isHidden = true
|
|
|
|
+ self.wordButtonTwo.isHidden = true
|
|
|
|
+ self.wordButtonOne.isHidden = true
|
|
|
|
+ self.csvExtractButton.isHidden = false
|
|
|
|
+
|
|
|
|
+ self.csvExtractButton.title = NSLocalizedString("Extract Tables Only", comment: "")
|
|
|
|
+ self.checkBoxBottomConstaint.constant = 15 + self.csvExtractButton.frame.size.height
|
|
|
|
+ self.checkBoxTopConstraint.constant = 5
|
|
|
|
+ } else {
|
|
|
|
+ self.convertEveryPageButton.isHidden = true
|
|
|
|
+ self.extractButton.isHidden = true
|
|
|
|
+ self.wordButtonTwo.isHidden = true
|
|
|
|
+ self.wordButtonOne.isHidden = true
|
|
|
|
+ self.csvExtractButton.isHidden = true
|
|
|
|
+ self.convertEveryPageButtonLabel.stringValue = NSLocalizedString("", comment: "")
|
|
|
|
+ self.checkBoxTopConstraint.constant = -10
|
|
|
|
+ self.checkBoxBottomConstaint.constant = 5
|
|
|
|
+ }
|
|
|
|
+
|
|
|
|
+ if !hasInfo && !isExcel {
|
|
|
|
+ self.containerViewTopConstraint.constant = 0
|
|
|
|
+ self.checkBoxTopConstraint.constant = 0
|
|
|
|
+ self.checkBoxBottomConstaint.constant = 1
|
|
|
|
+ }
|
|
|
|
+ }
|
|
|
|
+ override func viewDidLoad() {
|
|
|
|
+ super.viewDidLoad()
|
|
|
|
+ self.prepareData()
|
|
|
|
+ self.view.wantsLayer = true
|
|
|
|
+ collectionView.allowsMultipleSelection = false
|
|
|
|
+ collectionView.enclosingScrollView?.borderType = .noBorder
|
|
|
|
+ collectionView.allowsEmptySelection = false
|
|
|
|
+ convertButton.wantsLayer = true
|
|
|
|
+ convertButton.font = NSFont.systemFont(ofSize: 13)
|
|
|
|
+ convertButton.layer?.cornerRadius = 1.0
|
|
|
|
+ interfaceStatus = .PrepareProcess
|
|
|
|
+ convertEveryPageButton.title = NSLocalizedString("", comment: "")
|
|
|
|
+ // Convert each page to a separate worksheet
|
|
|
|
+ convertEveryPageButtonLabel.stringValue = NSLocalizedString("Convert each page to a separate worksheet", comment: "")
|
|
|
|
+
|
|
|
|
+ self.collectionView.register(KMConvertCollectionViewHeader.self, forItemWithIdentifier: NSUserInterfaceItemIdentifier(rawValue: "KMAdvertisementCollectionViewItem"))
|
|
|
|
+
|
|
|
|
+ collectionView.enclosingScrollView?.drawsBackground = false
|
|
|
|
+ let v = NSView(frame: NSRect(x: 0, y: 0, width: 100, height: 100))
|
|
|
|
+ v.wantsLayer = true
|
|
|
|
+ v.layer?.backgroundColor = KMAppearance.Layout.l0Color().cgColor
|
|
|
|
+ collectionView.backgroundView = v
|
|
|
|
+ collectionView.enclosingScrollView?.horizontalScrollElasticity = .none
|
|
|
|
+ collectionView.enclosingScrollView?.verticalScrollElasticity = .none
|
|
|
|
+ allContentBtn.state = .on
|
|
|
|
+ allContentMenu.isEnabled = true
|
|
|
|
+ tableMenu.isEnabled = false
|
|
|
|
+ excelContentOption = .allContent
|
|
|
|
+ excelWorksheetOption = .forEachPage
|
|
|
|
+
|
|
|
|
+ onlyTextBtn.title = NSLocalizedString("Only Text", comment: "")
|
|
|
|
+ onlyTableBtn.title = NSLocalizedString("Only Table", comment: "")
|
|
|
|
+ allContentBtn.title = NSLocalizedString("All Content", comment: "")
|
|
|
|
+ onlyTextBtn.toolTip = NSLocalizedString("Only Text", comment: "")
|
|
|
|
+ onlyTableBtn.toolTip = NSLocalizedString("Only Table", comment: "")
|
|
|
|
+ allContentBtn.toolTip = NSLocalizedString("All Content", comment: "")
|
|
|
|
+ tableMenu1.title = NSLocalizedString("Create Sheet for each Table", comment: "")
|
|
|
|
+ tableMenu2.title = NSLocalizedString("Create Sheet for each Page", comment: "")
|
|
|
|
+ allContentMenu2.title = NSLocalizedString("Create Sheet for each Page", comment: "")
|
|
|
|
+ tableMenu3.title = NSLocalizedString("Create single Sheet for File", comment: "")
|
|
|
|
+ allContentMenu3.title = NSLocalizedString("Create single Sheet for File", comment: "")
|
|
|
|
+
|
|
|
|
+ self.detailInfoView.mouseDownCallback = { [weak self] (downEntered: Bool) in
|
|
|
|
+ if downEntered {
|
|
|
|
+// if (![IAPProductsManager defaultManager].isAvailableAdvancedPDFToOffice) {
|
|
|
|
+ self?.convertActionVC()
|
|
|
|
+// }
|
|
|
|
+ }
|
|
|
|
+ }
|
|
|
|
+ self.updateViewColor()
|
|
|
|
+
|
|
|
|
+
|
|
|
|
+ NotificationCenter.default.addObserver(self, selector: #selector(batchFilesCountNotification(notification:)), name: NSNotification.Name("KMBatchFilesCountNotification"), object: nil)
|
|
|
|
+ NotificationCenter.default.addObserver(self, selector: #selector(IAPProductPurchasedNotification(notification:)), name: NSNotification.Name("KMIAPProductPurchasedNotification"), object: nil)
|
|
|
|
+ NotificationCenter.default.addObserver(self, selector: #selector(IAPProductRestoreFinishedNotification(notification:)), name: NSNotification.Name("KMIAPProductRestoreFinishedNotification"), object: nil)
|
|
|
|
+ NotificationCenter.default.addObserver(self, selector: #selector(themeChanged(notification:)), name: NSNotification.Name("AppleInterfaceThemeChangedNotification"), object: nil)
|
|
|
|
+ }
|
|
|
|
+ @objc func batchFilesCountNotification(notification: NSNotification) {
|
|
|
|
+ let files = notification.object as? [Any]
|
|
|
|
+ if files!.count > 0 {
|
|
|
|
+ self.convertButton.setTitleColor(NSColor.white)
|
|
|
|
+ self.convertButton.layer?.backgroundColor = KMAppearance.Interactive.m0Color().cgColor
|
|
|
|
+ self.haveFiles = true
|
|
|
|
+ } else {
|
|
|
|
+ self.convertButton.setTitleColor(KMAppearance.Layout.w0Color().withAlphaComponent(0.6))
|
|
|
|
+ self.convertButton.layer?.backgroundColor = KMAppearance.Interactive.m0Color().withAlphaComponent(0.4).cgColor
|
|
|
|
+ self.haveFiles = false
|
|
|
|
+ }
|
|
|
|
+ }
|
|
|
|
+ @objc func themeChanged(notification: NSNotification) {
|
|
|
|
+ DispatchQueue.main.asyncAfter(deadline: .now() + 0.3) {
|
|
|
|
+ self.updateViewColor()
|
|
|
|
+ }
|
|
|
|
+ }
|
|
|
|
+ @objc func IAPProductRestoreFinishedNotification(notification: NSNotification) {
|
|
|
|
+ DispatchQueue.main.asyncAfter(deadline: .now() + 0.3) {
|
|
|
|
+ self.updateBottomView()
|
|
|
|
+ self.prepareData()
|
|
|
|
+ self.collectionView.reloadData()
|
|
|
|
+ }
|
|
|
|
+ }
|
|
|
|
+ @objc func IAPProductPurchasedNotification(notification: NSNotification) {
|
|
|
|
+ DispatchQueue.main.asyncAfter(deadline: .now() + 0.3) {
|
|
|
|
+ self.updateBottomView()
|
|
|
|
+ self.prepareData()
|
|
|
|
+ self.collectionView.reloadData()
|
|
|
|
+ }
|
|
|
|
+ }
|
|
|
|
+ func updateViewColor() {
|
|
|
|
+ self.view.wantsLayer = true
|
|
|
|
+ if KMAppearance.isDarkMode() {
|
|
|
|
+ self.view.layer?.backgroundColor = NSColor(red: 0.055, green: 0.067, blue: 0.078, alpha: 1).cgColor
|
|
|
|
+ self.collectionView.backgroundView?.layer?.backgroundColor = NSColor(red: 0.055, green: 0.067, blue: 0.078, alpha: 1).cgColor
|
|
|
|
+ } else {
|
|
|
|
+ self.view.layer?.backgroundColor = NSColor(red: 0.922, green: 0.925, blue: 0.941, alpha: 1).cgColor
|
|
|
|
+ self.collectionView.backgroundView?.layer?.backgroundColor = NSColor(red: 0.922, green: 0.925, blue: 0.941, alpha: 1).cgColor
|
|
|
|
+ }
|
|
|
|
+ }
|
|
|
|
+
|
|
|
|
+ func convertActionVC() {
|
|
|
|
+// KMToolCompareWindowController *vc = nil;
|
|
|
|
+ if(.WordStandard == self.convertType ||
|
|
|
|
+ .WordAdvance == self.convertType) {
|
|
|
|
+// vc = [KMToolCompareWindowController toolCompareWithType:KMCompareWithToolType_Convert setSelectIndex:1];
|
|
|
|
+ } else if (.Excel == self.convertType) {
|
|
|
|
+// vc = [KMToolCompareWindowController toolCompareWithType:KMCompareWithToolType_Convert setSelectIndex:2];
|
|
|
|
+ } else if (.PowerPoint == self.convertType) {
|
|
|
|
+// vc = [KMToolCompareWindowController toolCompareWithType:KMCompareWithToolType_Convert setSelectIndex:3];
|
|
|
|
+ } else if (self.convertType == .JPG || self.convertType == .PNG || self.convertType == .GIF || self.convertType == .TIFF || self.convertType == .TGA || self.convertType == .BMP){
|
|
|
|
+// vc = [KMToolCompareWindowController toolCompareWithType:KMCompareWithToolType_Convert setSelectIndex:4];
|
|
|
|
+ } else {
|
|
|
|
+// vc = [KMToolCompareWindowController toolCompareWithType:KMCompareWithToolType_Convert setSelectIndex:0];
|
|
|
|
+ }
|
|
|
|
+// [vc showWindow:nil];
|
|
|
|
+ }
|
|
|
|
+ func prepareData() {
|
|
|
|
+ let arr: [KMConvertWithPDFType] = [.Excel, .PowerPoint, .RTF, .CSV, .CSV, .HTML, .Text, .JPEG, .JPG, .PNG, .GIF, .TIFF, .TGA, .BMP, .JPEG2000]
|
|
|
|
+ self.dataSourcesArray = NSMutableArray(array: arr)
|
|
|
|
+
|
|
|
|
+ var needShowAdvance = true
|
|
|
|
+ var needShowDefault = true
|
|
|
|
+
|
|
|
|
+#if VERSION_FREE
|
|
|
|
+ // 桌机版
|
|
|
|
+ // if IAPProductsManager.defaultManager().isAvailableAllFunction {
|
|
|
|
+ // if IAPProductsManager.defaultManager().isAvailableAdvancedPDFToOffice {
|
|
|
|
+ // needShowAdvance = true
|
|
|
|
+ // needShowDefault = false
|
|
|
|
+ // }
|
|
|
|
+ // }
|
|
|
|
+#else
|
|
|
|
+
|
|
|
|
+ // if IAPProductsManager.defaultManager().isAvailableAdvancedPDFToOffice {
|
|
|
|
+ // needShowAdvance = true
|
|
|
|
+ // needShowDefault = false
|
|
|
|
+ // }
|
|
|
|
+
|
|
|
|
+#endif
|
|
|
|
+
|
|
|
|
+ if needShowDefault {
|
|
|
|
+ var wordType: KMConvertWithPDFType = .WordStandard
|
|
|
|
+ self.dataSourcesArray?.insert(wordType, at: 0)
|
|
|
|
+ }
|
|
|
|
+
|
|
|
|
+ if needShowAdvance {
|
|
|
|
+ var wordType: KMConvertWithPDFType = .WordAdvance
|
|
|
|
+ self.dataSourcesArray?.insert(wordType, at: 0)
|
|
|
|
+ }
|
|
|
|
+ }
|
|
|
|
+
|
|
|
|
+ @IBAction func buttonClicked_Convert(_ sender: NSButton) {
|
|
|
|
+ if !self.haveFiles { return }
|
|
|
|
+ self.view.window?.makeFirstResponder(nil)
|
|
|
|
+ for i in 0..<self.files!.count {
|
|
|
|
+ let file = self.files?[i]
|
|
|
|
+ file?.excelParameter.allInOneSheet = (self.convertEveryPageButton.state == .on) ? false : true
|
|
|
|
+ file?.advanceWordParameter.isRetainLayout = (self.wordButtonTwo.state == .on) ? true : false
|
|
|
|
+ file?.excelParameter.isExtreactTabel = (self.extractButton.state == .on) ? true : false
|
|
|
|
+ file?.CSVParameter.isExtreactTabel = (self.csvExtractButton.state == .on) ? true : false
|
|
|
|
+ file?.excelParameter.excelContentOption = self.excelContentOption
|
|
|
|
+ file?.excelParameter.excelWorksheetOption = self.excelWorksheetOption
|
|
|
|
+ }
|
|
|
|
+ if sender.tag == 1 {
|
|
|
|
+ self.beginBatchOperation()
|
|
|
|
+ } else {
|
|
|
|
+ self.cancelBatchOperation()
|
|
|
|
+ }
|
|
|
|
+
|
|
|
|
+ }
|
|
|
|
+
|
|
|
|
+ @IBAction func moreButtonAction(_ sender: NSButton) {
|
|
|
|
+ self.convertActionVC()
|
|
|
|
+ self.buttonClicked_Cancel("")
|
|
|
|
+ }
|
|
|
|
+
|
|
|
|
+ @IBAction func layoutButtonAction(_ sender: Any) {
|
|
|
|
+ }
|
|
|
|
+
|
|
|
|
+ @IBAction func exctractTableButtonAction(_ sender: Any) {
|
|
|
|
+ if extractButton.state == .on {
|
|
|
|
+ convertEveryPageButton.state = .off
|
|
|
|
+ convertEveryPageButtonLabel.isEnabled = false
|
|
|
|
+ convertEveryPageButton.isEnabled = false
|
|
|
|
+ convertEveryPageButtonLabel.textColor = KMAppearance.Layout.b15_1Color()
|
|
|
|
+ } else {
|
|
|
|
+ convertEveryPageButton.state = .on
|
|
|
|
+ convertEveryPageButtonLabel.isEnabled = true
|
|
|
|
+ convertEveryPageButton.isEnabled = true
|
|
|
|
+ convertEveryPageButtonLabel.textColor = NSColor.labelColor
|
|
|
|
+ }
|
|
|
|
+ }
|
|
|
|
+
|
|
|
|
+ @IBAction func buttonClicked_Cancel(_ sender: Any) {
|
|
|
|
+ let basePath = NSSearchPathForDirectoriesInDomains(.applicationSupportDirectory, .userDomainMask, true).last ?? ""
|
|
|
|
+ let newPath = (basePath as NSString).appendingPathComponent(Bundle.main.bundleIdentifier ?? "")
|
|
|
|
+ let filePath = newPath.stringByAppendingPathComponent("convert.pdf")
|
|
|
|
+ if FileManager.default.fileExists(atPath: filePath) {
|
|
|
|
+ try? FileManager.default.removeItem(atPath: filePath)
|
|
|
|
+ }
|
|
|
|
+ }
|
|
|
|
+
|
|
|
|
+ func transform(withString string: String) {
|
|
|
|
+ if string == NSLocalizedString("Create Sheet for each Table", comment: "") {
|
|
|
|
+ self.excelWorksheetOption = .forEachTable
|
|
|
|
+ } else if string == NSLocalizedString("Create Sheet for each Page", comment: "") {
|
|
|
|
+ self.excelWorksheetOption = .forEachPage
|
|
|
|
+ } else if string == NSLocalizedString("Create single Sheet for File", comment: "") {
|
|
|
|
+ self.excelWorksheetOption = .forTheDocument
|
|
|
|
+ }
|
|
|
|
+ }
|
|
|
|
+
|
|
|
|
+ @IBAction func buttonClicked_excelStyle(_ sender: NSButton) {
|
|
|
|
+ if sender == onlyTextBtn {
|
|
|
|
+ onlyTextBtn.state = NSControl.StateValue.on
|
|
|
|
+ onlyTableBtn.state = NSControl.StateValue.off
|
|
|
|
+ allContentBtn.state = NSControl.StateValue.off
|
|
|
|
+ tableMenu.isEnabled = false
|
|
|
|
+ allContentMenu.isEnabled = false
|
|
|
|
+ excelContentOption = .onlyText
|
|
|
|
+ excelWorksheetOption = .forEachTable
|
|
|
|
+ } else if sender == onlyTableBtn {
|
|
|
|
+ onlyTableBtn.state = NSControl.StateValue.on
|
|
|
|
+ onlyTextBtn.state = NSControl.StateValue.off
|
|
|
|
+ allContentBtn.state = NSControl.StateValue.off
|
|
|
|
+ tableMenu.isEnabled = true
|
|
|
|
+ allContentMenu.isEnabled = false
|
|
|
|
+ excelContentOption = .onlyTable
|
|
|
|
+ transform(withString: tableMenu.selectedItem?.title ?? "")
|
|
|
|
+ } else if sender == allContentBtn {
|
|
|
|
+ allContentBtn.state = NSControl.StateValue.on
|
|
|
|
+ onlyTextBtn.state = NSControl.StateValue.off
|
|
|
|
+ onlyTableBtn.state = NSControl.StateValue.off
|
|
|
|
+ tableMenu.isEnabled = false
|
|
|
|
+ allContentMenu.isEnabled = true
|
|
|
|
+ excelContentOption = .allContent
|
|
|
|
+ transform(withString: allContentMenu.selectedItem?.title ?? "")
|
|
|
|
+ }
|
|
|
|
+ }
|
|
|
|
+
|
|
|
|
+ @IBAction func buttonClicked_tableMenu(_ sender: NSPopUpButton) {
|
|
|
|
+ transform(withString: self.tableMenu.selectedItem!.title)
|
|
|
|
+ }
|
|
|
|
+
|
|
|
|
+ @IBAction func buttonClickec_allContentMenu(_ sender: NSButton) {
|
|
|
|
+ transform(withString: self.allContentMenu.selectedItem!.title)
|
|
|
|
+ }
|
|
|
|
+ func collectionView(_ collectionView: NSCollectionView, numberOfItemsInSection section: Int) -> Int {
|
|
|
|
+ return dataSourcesArray!.count
|
|
|
|
+ }
|
|
|
|
+ func collectionView(_ collectionView: NSCollectionView, itemForRepresentedObjectAt indexPath: IndexPath) -> NSCollectionViewItem {
|
|
|
|
+ let item = collectionView.makeItem(withIdentifier: NSUserInterfaceItemIdentifier(rawValue: "KMBatchoperateConvertCollectionViewItem"), for: indexPath) as! KMBatchoperateConvertCollectionViewItem
|
|
|
|
+ let number = dataSourcesArray![indexPath.item]
|
|
|
|
+ item.updateInterface(KMConvertWithPDFType(rawValue: (number as AnyObject).intValue!) ?? .WordAdvance)
|
|
|
|
+ return item
|
|
|
|
+ }
|
|
|
|
+ func collectionView(_ collectionView: NSCollectionView, layout collectionViewLayout: NSCollectionViewLayout, sizeForItemAt indexPath: IndexPath) -> NSSize {
|
|
|
|
+ return NSSize(width: 74, height: 80)
|
|
|
|
+ }
|
|
|
|
+ func collectionView(_ collectionView: NSCollectionView, layout collectionViewLayout: NSCollectionViewLayout, insetForSectionAt section: Int) -> NSEdgeInsets {
|
|
|
|
+ return NSEdgeInsets(top: 0, left: 10, bottom: 0, right: 0)
|
|
|
|
+ }
|
|
|
|
+ func collectionView(_ collectionView: NSCollectionView, didSelectItemsAt indexPaths: Set<IndexPath>) {
|
|
|
|
+ if let indexPath = indexPaths.first {
|
|
|
|
+ let number = dataSourcesArray![indexPath.item]
|
|
|
|
+ convertType = intConvertType(num: number as! Int)
|
|
|
|
+ updateBottomView()
|
|
|
|
+ }
|
|
|
|
+ }
|
|
|
|
+ func collectionView(_ collectionView: NSCollectionView, layout collectionViewLayout: NSCollectionViewLayout, referenceSizeForHeaderInSection section: Int) -> NSSize {
|
|
|
|
+ return NSSize(width: 10000, height: 50)
|
|
|
|
+ }
|
|
|
|
+ func collectionView(_ collectionView: NSCollectionView, viewForSupplementaryElementOfKind kind: NSCollectionView.SupplementaryElementKind, at indexPath: IndexPath) -> NSView {
|
|
|
|
+ let view = collectionView.makeSupplementaryView(ofKind: kind, withIdentifier:NSUserInterfaceItemIdentifier(rawValue: "convertHeader") , for: indexPath) as! KMConvertCollectionViewHeader
|
|
|
|
+
|
|
|
|
+ view.convertHeaderClickedCallBack = {
|
|
|
|
+ self.convertActionVC()
|
|
|
|
+ }
|
|
|
|
+ return view
|
|
|
|
+ }
|
|
|
|
+
|
|
|
|
+ func intConvertType(num: Int) -> KMConvertWithPDFType {
|
|
|
|
+ var type: KMConvertWithPDFType?
|
|
|
|
+ switch num {
|
|
|
|
+ case 0:
|
|
|
|
+ type = .WordAdvance
|
|
|
|
+ case 1:
|
|
|
|
+ type = .WordStandard
|
|
|
|
+ case 2:
|
|
|
|
+ type = .Excel
|
|
|
|
+ case 3:
|
|
|
|
+ type = .PowerPoint
|
|
|
|
+ case 4:
|
|
|
|
+ type = .RTF
|
|
|
|
+ case 5:
|
|
|
|
+ type = .CSV
|
|
|
|
+ case 6:
|
|
|
|
+ type = .HTML
|
|
|
|
+ case 7:
|
|
|
|
+ type = .Text
|
|
|
|
+ case 8:
|
|
|
|
+ type = .JPEG
|
|
|
|
+ case 9:
|
|
|
|
+ type = .JPG
|
|
|
|
+ case 10:
|
|
|
|
+ type = .PNG
|
|
|
|
+ case 11:
|
|
|
|
+ type = .GIF
|
|
|
|
+ case 12:
|
|
|
|
+ type = .TIFF
|
|
|
|
+ case 13:
|
|
|
|
+ type = .TGA
|
|
|
|
+ case 14:
|
|
|
|
+ type = .BMP
|
|
|
|
+ case 15:
|
|
|
|
+ type = .JPEG2000
|
|
|
|
+ default:
|
|
|
|
+ type = .WordAdvance
|
|
|
|
+ }
|
|
|
|
+ return type!
|
|
|
|
+ }
|
|
|
|
+}
|