12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031 |
- //
- // 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{
- var dataSourcesArray: [KMConvertWithPDFType]?
- @IBOutlet var bottomView: NSView!
-
- @IBOutlet var convertButton: NSButton!
-
- @IBOutlet var buttonBottemOffset: NSLayoutConstraint!
- @IBOutlet var detailInfoLabel: NSTextField!
- @IBOutlet var detailInfoBox: NSBox!
-
- @IBOutlet var separateStypeTopOffset: NSLayoutConstraint!
-
- @IBOutlet var separateStypeBox: NSBox!
- @IBOutlet var wordButtonOne: NSButton!
- @IBOutlet var wordButtonTwo: NSButton!
-
- @IBOutlet var excelStyleBox: NSBox!
- @IBOutlet var allContentMenu: NSPopUpButton!
- @IBOutlet var allContentMenu2: NSMenuItem!
- @IBOutlet var allContentMenu3: NSMenuItem!
- @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 tableMenu: NSPopUpButton!
-
- @IBOutlet var csvExtractButton: NSButton!
-
- @IBOutlet var ocrBox: NSBox!
- @IBOutlet var ocrLabel: NSTextField!
- @IBOutlet var ocrButton: NSButton!
- @IBOutlet var ocrLanguageBox: NSPopUpButton!
- @IBOutlet var ocrTopOffset: NSLayoutConstraint!
- @IBOutlet var headerView: KMConvertCollectionViewHeader!
- @IBOutlet var headerTopOffset: NSLayoutConstraint!
- @IBOutlet var formatLabel: NSTextField!
- @IBOutlet var formatSelectButton: 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 {
- formatSelectButton.isEnabled = 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)
- }
- }
- formatSelectButton.isEnabled = 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) {
- var index = -1
- updateFormatView()
- for i in 0..<self.dataSourcesArray!.count {
- let number = self.dataSourcesArray![i]
- if number.rawValue == convertType.rawValue {
- index = i
- break
- }
- }
- if index != -1 {
- self.formatSelectButton.selectItem(at: index)
- }
- }
-
- func updateBottomView() {
- var isShowUpgrade = false
-
- #if VERSION_FREE
- #if VERSION_DMG
- // 桌机版
- if IAPProductsManager.default().isAvailableAllFunction() {
- if IAPProductsManager.default().isAvailableAdvancedPDFToOffice() {
- } else {
- isShowUpgrade = true
- }
- } else {
- isShowUpgrade = true
- }
- #else
- // 免费版
- if IAPProductsManager.default().isAvailableAllFunction() {
- if IAPProductsManager.default().isAvailableAdvancedPDFToOffice() {
- } else {
- isShowUpgrade = true
- }
- } else {
- isShowUpgrade = true
- }
-
- #endif
- #else
- if IAPProductsManager.default().isAvailableAdvancedPDFToOffice() {
- } else {
- isShowUpgrade = true
- }
- #endif
- if !isShowUpgrade {
- headerView.isHidden = true
- headerTopOffset.constant = 0
- } else {
- headerView.isHidden = false
- headerTopOffset.constant = self.headerView.frame.height
- }
- var moreLabelString = ""
- #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 ||
- .Json == 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 ||
- .Json == self.convertType {
- moreLabelString = String(format: "%@ %@", KMLocalizedString("The first 10 pages for free"), KMLocalizedString("Unlimited Convert"))
- }
- }
- #endif
-
- 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 {
- detailInfoBox.isHidden = false
- buttonBottemOffset.constant = 45
- } else {
- detailInfoBox.isHidden = true
- buttonBottemOffset.constant = 10
- }
-
- if self.convertType == .WordAdvance {
- separateStypeBox.isHidden = false
- excelStyleBox.isHidden = true
- csvExtractButton.isHidden = true
- ocrBox.isHidden = false
- wordButtonOne.title = NSLocalizedString("Retain Flowing Text", comment: "")
- wordButtonTwo.title = NSLocalizedString("Retain Page Layout", comment: "")
-
- ocrTopOffset.constant = 15 + separateStypeBox.frame.height
- } else if self.convertType == .Excel {
- separateStypeBox.isHidden = true
- excelStyleBox.isHidden = false
- csvExtractButton.isHidden = true
- ocrBox.isHidden = false
-
- ocrTopOffset.constant = 15 + excelStyleBox.frame.height
- } else if .Json == convertType {
- wordButtonOne.title = NSLocalizedString("Extract text content", comment: "")
- wordButtonTwo.title = NSLocalizedString("Extract Table", comment: "")
-
- separateStypeBox.isHidden = false
- excelStyleBox.isHidden = true
- csvExtractButton.isHidden = true
- ocrBox.isHidden = false
-
- ocrTopOffset.constant = 15 + separateStypeBox.frame.height
- } else if (.PowerPoint == convertType ||
- .RTF == convertType ||
- .HTML == convertType ||
- .Text == convertType) {
-
- separateStypeBox.isHidden = true
- excelStyleBox.isHidden = true
- csvExtractButton.isHidden = true
- ocrBox.isHidden = false
- ocrTopOffset.constant = 15
- } else if self.convertType == .CSV {
- separateStypeBox.isHidden = true
- excelStyleBox.isHidden = true
- csvExtractButton.isHidden = false
- ocrBox.isHidden = true
-
- self.csvExtractButton.title = NSLocalizedString("Extract Tables Only", comment: "")
- } else {
- separateStypeBox.isHidden = true
- excelStyleBox.isHidden = true
- csvExtractButton.isHidden = true
- ocrBox.isHidden = true
- }
-
- }
- override func viewDidLoad() {
- super.viewDidLoad()
- self.prepareData()
- updateFormatView()
- self.view.wantsLayer = true
- convertButton.wantsLayer = true
- convertButton.font = NSFont.systemFont(ofSize: 13)
- convertButton.layer?.cornerRadius = 1.0
- interfaceStatus = .PrepareProcess
-
- 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: "")
- formatLabel.stringValue = KMLocalizedString("Format:", nil)
- ocrBox.title = KMLocalizedString("Text Recognition Settings", nil)
- ocrBox.titleFont = .SFProTextBoldFont(14.0)
- formatLabel.font = .SFProTextBoldFont(14.0)
-
- headerView.convertHeaderClickedCallBack = { [weak self] in
- self?.moreConvertInfoAction()
- }
-
- ocrLanguageBox.selectItem(at: 0)
- ocrLabel.textColor = KMAppearance.Layout.h2Color()
- ocrLanguageBox.isEnabled = false
- ocrButton.state = .off
-
- 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.updateFormatView()
- }
- }
-
- @objc func IAPProductPurchasedNotification(notification: NSNotification) {
- DispatchQueue.main.asyncAfter(deadline: .now() + 0.3) {
- self.updateBottomView()
- self.prepareData()
- self.updateFormatView()
- }
- }
-
- @objc func deviceActivateStatusChanged(notification: NSNotification) {
- DispatchQueue.main.asyncAfter(deadline: .now() + 0.3) {
- self.updateBottomView()
- self.prepareData()
- self.updateFormatView()
- }
- }
-
- 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
- } else {
- self.view.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, .Json]
- 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)
- }
- }
-
- func updateFormatView() {
- var isShowAdvanced = false
-
- #if VERSION_FREE
- #if VERSION_DMG
- // 桌机版
- isShowAdvanced = true
- if IAPProductsManager.default().isAvailableAllFunction() {
- if IAPProductsManager.default().isAvailableAdvancedPDFToOffice() {
- isShowAdvanced = false
- }
- }
- #else
- // 免费版
- isShowAdvanced = true
- if IAPProductsManager.default().isAvailableAllFunction() {
- if IAPProductsManager.default().isAvailableAdvancedPDFToOffice() {
- isShowAdvanced = false
- }
- }
-
- #endif
- #else
- isShowAdvanced = true
- if IAPProductsManager.default().isAvailableAdvancedPDFToOffice() {
- isShowAdvanced = false
- }
- #endif
- self.formatSelectButton.removeAllItems()
- for i in 0..<self.dataSourcesArray!.count {
- let number = self.dataSourcesArray![i]
- let item = NSMenuItem()
- item.target = self
-
- if(number == .WordAdvance) {
- if isShowAdvanced {
- let originStr = " \(NSLocalizedString("Advanced", comment: "")) "
- let str = NSLocalizedString("Word (.docx)", comment: "")
-
- let attributedStr = NSMutableAttributedString(string: "\(str) \(originStr)")
-
- attributedStr.addAttribute(NSAttributedString.Key.backgroundColor, value: NSColor(red: 245.0/255.0, green: 142.0/255.0, blue: 38.0/255.0, alpha: 1.0), range: NSMakeRange(str.count + 2, originStr.count))
-
- attributedStr.addAttribute(NSAttributedString.Key.foregroundColor, value: NSColor.white, range: NSMakeRange(str.count + 2, originStr.count))
-
- item.attributedTitle = attributedStr
- } else {
- item.title = "Word (.docx)"
- }
- item.tag = KMConvertWithPDFType.WordAdvance.rawValue
- } else if(number == .WordStandard) {
- if isShowAdvanced {
- let originStr = " \(KMLocalizedString("Standard", nil)) "
- let str = KMLocalizedString("Word (.docx)", nil)
-
- let attributedStr = NSMutableAttributedString(string: "\(str) \(originStr)")
-
- attributedStr.addAttribute(NSAttributedString.Key.backgroundColor, value: NSColor(red: 40/255.0, green: 193.0/255.0, blue: 107.0/255.0, alpha: 1.0), range: NSMakeRange(str.count + 2, originStr.count))
-
- attributedStr.addAttribute(NSAttributedString.Key.foregroundColor, value: NSColor.white, range: NSMakeRange(str.count + 2, originStr.count))
-
- item.attributedTitle = attributedStr
- } else {
- item.title = "Word (.docx)"
- }
- item.tag = KMConvertWithPDFType.WordStandard.rawValue
- } else if(number == .Excel) {
- item.title = "Excel (.xlsx)"
- item.tag = KMConvertWithPDFType.Excel.rawValue
- } else if(number == .PowerPoint) {
- item.title = "PowerPoint (.pptx)"
- item.tag = KMConvertWithPDFType.PowerPoint.rawValue
- } else if(number == .RTF) {
- item.title = "RTF (.rtf)"
- item.tag = KMConvertWithPDFType.RTF.rawValue
- } else if(number == .CSV) {
- item.title = "CSV (.csv)"
- item.tag = KMConvertWithPDFType.CSV.rawValue
- } else if(number == .HTML) {
- item.title = "Html (.html)"
- item.tag = KMConvertWithPDFType.HTML.rawValue
- } else if(number == .Text) {
- item.title = "Text (.txt)"
- item.tag = KMConvertWithPDFType.Text.rawValue
- } else if(number == .JPEG) {
- item.title = "JPEG (.jpeg)"
- item.tag = KMConvertWithPDFType.JPEG.rawValue
- } else if(number == .JPG) {
- item.title = "JPG (.jpg)"
- item.tag = KMConvertWithPDFType.JPG.rawValue
- } else if(number == .PNG) {
- item.title = "PNG (.png)"
- item.tag = KMConvertWithPDFType.PNG.rawValue
- } else if(number == .GIF) {
- item.title = "GIF (.gif)"
- item.tag = KMConvertWithPDFType.GIF.rawValue
- } else if(number == .TIFF) {
- item.title = "TIFF (.tiff)"
- item.tag = KMConvertWithPDFType.TIFF.rawValue
- } else if(number == .TGA) {
- item.title = "TGA (.tga)"
- item.tag = KMConvertWithPDFType.TGA.rawValue
- } else if(number == .BMP) {
- item.title = "BMP (.bmp)"
- item.tag = KMConvertWithPDFType.BMP.rawValue
- } else if(number == .JPEG2000) {
- item.title = "JPEG-2000 (.jp2)"
- item.tag = KMConvertWithPDFType.JPEG2000.rawValue
- } else if(number == .Json) {
- item.title = "Json(.json)"
- item.tag = KMConvertWithPDFType.Json.rawValue
- }
-
- self.formatSelectButton.menu?.addItem(item)
- }
-
- }
-
- @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 = 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.moreConvertInfoAction()
- }
-
- @IBAction func layoutButtonAction(_ sender: Any) {
- }
-
- @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 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
- case 16:
- type = .Json
- 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{
- let winC = KMPurchaseCompareWindowController.sharedInstance()
- if let viewC = self.view.window?.contentViewController, viewC.kEventTag == 1 {
- winC?.kEventName = "Onbrd_ConvertPDF_BuyNow"
- } else {
- if convertType == .WordStandard || convertType == .WordAdvance {
- winC?.kEventName = "Onbrd_PDFtoWord_BuyNow"
- } else if convertType == .Excel {
- winC?.kEventName = "Onbrd_PDFtoExcel_BuyNow"
- } else if convertType == .PowerPoint {
- winC?.kEventName = "Onbrd_PDFtoPPT_BuyNow"
- }
- }
-
- winC?.showWindow(nil)
- }
- #else
- if IAPProductsManager.default().isAvailableAllFunction() {
- self.convertActionVC()
- } else {
- KMPurchaseCompareWindowController.sharedInstance().showWindow(nil)
- }
- #endif
- }
- }
-
- @IBAction func buttonClicked_FormatSelect(_ sender: NSButton) {
- guard let item = self.formatSelectButton.selectedItem else { return }
- convertType = KMConvertWithPDFType(rawValue: item.tag) ?? .WordAdvance
-
- updateBottomView()
- }
-
- @IBAction func comboxClicked_OcrLanguage(_ sender: AnyObject?) {
- KMPrint("语言 ...")
-
- switch (ocrLanguageBox.indexOfSelectedItem) {
- case 0:
- //chinese
- // COCRLanguageChinese;
- break;
- case 1:
- //chinese zht
- // COCRLanguageChineseTraditional;
-
- break;
-
- case 2:
- //English
- // COCRLanguageEnglish;
- break;
-
- case 3:
- //Japanese
- // COCRLanguageJapanese;
-
- break;
-
- case 4:
- //Kroean
- // COCRLanguageKorean;
- break;
-
- case 5:
- //Serbian
-
- // COCRLanguageSerbian;
- break;
-
- case 6:
- //Occitan
- // COCRLanguageOccitan;
- break;
-
- case 7:
- //Danish
- // COCRLanguageDanish;
- break;
-
- case 8:
- //German
- // COCRLanguageGerman;
- break;
-
- case 9:
- //French
- // COCRLanguageFrench;
- break;
-
- case 10:
- //Italian
- // COCRLanguageItalian;
- break;
-
- case 11:
- //Spanish
- // COCRLanguageSpanish;
- break;
-
- case 12:
- //Portuguese
- // COCRLanguagePortuguese;
- break;
-
- case 13:
- //Maori
-
- // COCRLanguageMaori;
- break;
-
- case 14:
- //Malay
- // COCRLanguageMalay;
- break;
-
- case 15:
- //Malay
- // COCRLanguageMaltese;
- break;
-
- case 16:
- //Dutch
- // COCRLanguageDutch;
- break;
-
- case 17:
- //Norwegian
- // COCRLanguageNorwegian;
- break;
-
- case 18:
- //Polish
- // COCRLanguagePolish;
- break;
-
- case 19:
- //Romanian
- // COCRLanguageRomanian;
- break;
-
- case 20:
- //Slovak
- // COCRLanguageSlovak;
- break;
-
- case 21:
- //Slovenian
- // COCRLanguageSlovenian;
- break;
-
- case 22:
- //Albanian
-
- // COCRLanguageAlbanian;
- break;
-
- case 23:
- //Swedish
- // COCRLanguageSwedish;
- break;
-
- case 24:
- //Swahili
- // COCRLanguageSwahili;
- break;
-
- case 25:
- //Tagalog
- // COCRLanguageTagalog;
- break;
-
- case 26:
- //Turish
- // COCRLanguageTurish;
- break;
- case 27:
- //Uzbek
- // COCRLanguageUzbek;
- break;
- case 28:
- //Vietnamese
- // COCRLanguageVietnamese;
- break;
- case 29:
- //Afrikaans
- // COCRLanguageAfrikaans;
- break;
- case 30:
- //Azerbaijani
- // COCRLanguageAzerbaijani;
- break;
- case 31:
- //Bosnian
- // COCRLanguageBosnian;
- break;
- case 32:
- //Czech
- // COCRLanguageCzech;
- break;
- case 33:
- //Welsh
- // COCRLanguageWelsh;
- break;
- case 34:
- //Estonian
- // COCRLanguageEstonian;
- break;
-
- case 35:
- //Irish
- // COCRLanguageIrish;
- break;
- case 36:
- //Croatian
- // COCRLanguageCroatian;
- break;
- case 37:
- //Hungarian
- // COCRLanguageHungarian;
- break;
- case 38:
- //Indonesian
- // COCRLanguageIndonesian;
- break;
- case 39:
- //Icelandic
- // COCRLanguageIcelandic;
- break;
- case 40:
- //Kurdish
- // COCRLanguageKurdish;
- break;
- case 41:
- //Lithuanian
- // COCRLanguageLithuanian;
- break;
- case 42:
- //Latvian
- // COCRLanguageLatvian;
- break;
-
- case 43:
- //Marathi
- // COCRLanguageMarathi;
- break;
-
- case 44:
- //Nepali
- // COCRLanguageNepali;
- break;
-
- case 45:
- //Latvia
- // COCRLanguageHindi;
- break;
-
- case 46:
- //Bihari
- // COCRLanguageBihari;
- break;
-
- case 47:
- //Maithili
- // COCRLanguageMaithili;
- break;
-
- case 48:
- //Angika
- // COCRLanguageAngika;
- break;
-
- case 49:
- //Bhojpuri
- // COCRLanguageBhojpuri;
- break;
-
- case 50:
- //Magahi
- // COCRLanguageMagahi;
- break;
-
- case 51:
- //Nagpur
- // COCRLanguageNagpur;
- break;
-
- case 52:
- //Newari
- // COCRLanguageNewari;
- break;
-
- case 53:
- //GoanKonkani
- // COCRLanguageGoanKonkani;
- break;
-
- case 54:
- //SaudiArabia
- // COCRLanguageSaudiArabia;
- break;
-
-
- default:
- //Other Language such as Lagtin or Hindu
- break;
- }
- }
-
- @IBAction func comboxClicked_SupoortOCR(_ sender: AnyObject?) {
- KMPrint("是否支持OCR ...")
- if(ocrButton.state == .on) {
- ocrLabel.textColor = KMAppearance.titleColor()
- ocrLanguageBox.isEnabled = true
- } else {
- ocrLabel.textColor = KMAppearance.Layout.h2Color()
- ocrLanguageBox.isEnabled = false
- }
- }
- }
|