123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649 |
- //
- // KMBatchOperateConvertViewController.swift
- // PDF Reader Pro
- //
- // 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,NSCollectionViewDelegate,NSCollectionViewDataSource{
- var dataSourcesArray: [KMConvertWithPDFType]?
- @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.rawValue == 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 !IAPProductsManager.default().isAvailableAllFunction() {
- moreLabelString = String(format: "%@ %@", KMLocalizedString("The first 10 pages for free"), KMLocalizedString("Unlimited Convert"))
- }else {
- if !IAPProductsManager.default().isAvailableAdvancedPDFToOffice() {
- if .WordAdvance == self.convertType ||
- .WordStandard == 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 = String(format: "%@ %@", KMLocalizedString("The first 10 pages for free"), KMLocalizedString("Unlimited Convert"))
- }
- }
- }
- #else
- // 付费版
- if !IAPProductsManager.default().isAvailableAdvancedPDFToOffice() {
- if .WordAdvance == self.convertType ||
- .WordStandard == 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 = String(format: "%@ %@", KMLocalizedString("The first 10 pages for free"), KMLocalizedString("Unlimited Convert"))
- }
- }
- #endif
-
- var hasInfo = false
- var isExcel = false
- self.detailInfoLabel.stringValue = moreLabelString
- if let range = moreLabelString.range(of: NSLocalizedString("Unlimited Convert", comment: "")) {
- let newR: NSRange = moreLabelString.nsRange(from: range)!
- let attributedStr = NSMutableAttributedString(string: moreLabelString)
- attributedStr.addAttribute(.foregroundColor, value: NSColor.labelColor, range: NSRange(location: 0, length: newR.location - 1))
- attributedStr.addAttribute(.foregroundColor, value: NSColor(red: 8/255, green: 124/255, blue: 1, alpha: 1), range: newR)
- attributedStr.addAttribute(.underlineStyle, value: NSUnderlineStyle.single.rawValue, range: newR)
- detailInfoLabel.attributedStringValue = attributedStr
- }
-
- 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"))
- self.collectionView.register(KMBatchoperateConvertCollectionViewItem.self, forItemWithIdentifier: NSUserInterfaceItemIdentifier(rawValue: "KMBatchoperateConvertCollectionViewItem"))
- self.collectionView.register(KMConvertCollectionViewHeader.self, forSupplementaryViewOfKind: NSCollectionView.elementKindSectionHeader, withIdentifier: NSUserInterfaceItemIdentifier(rawValue: "convertHeader"))
-
- 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 {
- self?.moreConvertInfoAction()
- }
- }
- self.updateViewColor()
-
- NotificationCenter.default.addObserver(self, selector: #selector(batchFilesCountNotification(notification:)), name: Notification.Name(rawValue: "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)
- DistributedNotificationCenter.default().addObserver(self, selector: #selector(themeChanged(notification:)), name: NSNotification.Name("AppleInterfaceThemeChangedNotification"), object: nil)
- NotificationCenter.default.addObserver(self, selector: #selector(deviceActivateStatusChanged(notification:)), name: NSNotification.Name("kDeviceActivateNotification"), object: nil)
- }
-
-
- @objc func batchFilesCountNotification(notification: NSNotification) {
- let arr: Array? = notification.object as? [KMBatchOperateFile]
- self.files? = arr ?? []
- 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()
- }
- }
- @objc func deviceActivateStatusChanged(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() {
- var vc: KMToolCompareWindowController? = nil
- if(.WordStandard == self.convertType ||
- .WordAdvance == self.convertType) {
- vc = KMToolCompareWindowController(toolType: .Convert, selectNum: 1)
- } else if (.Excel == self.convertType) {
- vc = KMToolCompareWindowController(toolType: .Convert, selectNum: 2)
- } else if (.PowerPoint == self.convertType) {
- vc = KMToolCompareWindowController(toolType: .Convert, selectNum: 3)
- } else if (self.convertType == .JPG || self.convertType == .PNG || self.convertType == .GIF || self.convertType == .TIFF || self.convertType == .TGA || self.convertType == .BMP){
- vc = KMToolCompareWindowController(toolType: .Convert, selectNum: 4)
- } else {
- vc = KMToolCompareWindowController(toolType: .Convert, selectNum: 0)
- }
- vc?.showWindow(nil)
- }
- func prepareData() {
- let arr: [KMConvertWithPDFType] = [.Excel, .PowerPoint, .RTF, .CSV, .HTML, .Text, .JPEG, .JPG, .PNG, .GIF, .TIFF, .TGA, .BMP, .JPEG2000]
- self.dataSourcesArray = arr
-
- var needShowAdvance = true
- var needShowDefault = true
-
- #if VERSION_FREE
- // 桌机版
- if IAPProductsManager.default().isAvailableAllFunction() {
- if IAPProductsManager.default().isAvailableAdvancedPDFToOffice() {
- needShowAdvance = true
- needShowDefault = false
- }
- }
- #else
- if IAPProductsManager.default().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) {
- #if VERSION_DMG
- KMPurchaseCompareWindowController.sharedInstance().showWindow(nil)
- #else
- if IAPProductsManager.default().isAvailableAllFunction() {
- self.convertActionVC()
- } else {
- KMPurchaseCompareWindowController.sharedInstance().showWindow(nil)
- }
- #endif
- 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, didSelectItemsAt indexPaths: Set<IndexPath>) {
- if let indexPath = indexPaths.first {
- convertType = dataSourcesArray![indexPath.item]
- 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?.refreshData()
-
- view?.convertHeaderClickedCallBack = { [weak self] in
- self?.moreConvertInfoAction()
- }
- return view ?? NSView()
- }
-
- 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!
- }
-
- func moreConvertInfoAction() {
- if IAPProductsManager.default().isAvailableAdvancedPDFToOffice() == false {
- #if VERSION_DMG
- if IAPProductsManager.default().isAvailableAllFunction() && IAPProductsManager.default().isAvailableAdvancedPDFToOffice() == false {
- let limitWC = KMPurchaseLimitWindowController.currentLimitWC()
- limitWC.continueBlock = { windowController in
-
- }
- limitWC.window?.center()
- limitWC.showWindow(nil)
- }else{
- KMPurchaseCompareWindowController.sharedInstance().showWindow(nil)
- }
- #else
- if IAPProductsManager.default().isAvailableAllFunction() {
- self.convertActionVC()
- } else {
- KMPurchaseCompareWindowController.sharedInstance().showWindow(nil)
- }
- #endif
- }
- }
- }
- extension KMBatchOperateConvertViewController: NSCollectionViewDelegateFlowLayout {
- func collectionView(_ collectionView: NSCollectionView, itemForRepresentedObjectAt indexPath: IndexPath) -> NSCollectionViewItem {
- let item = collectionView.makeItem(withIdentifier: NSUserInterfaceItemIdentifier(rawValue: "KMBatchoperateConvertCollectionViewItem"), for: indexPath) as! KMBatchoperateConvertCollectionViewItem
- item.updateInterface(dataSourcesArray![indexPath.item])
- 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)
- }
- }
|