Explorar el Código

菜单栏-主页,菜单栏 - File- 转档,有4个选项无法使用(已修复)

tangchao hace 1 año
padre
commit
5306c3a122

+ 74 - 8
PDF Office/PDF Master/Class/Home/ViewController/KMHomeViewController+Action.swift

@@ -616,6 +616,56 @@ extension KMHomeViewController {
         }
     }
     
+    internal func showConvertWindow(type: KMPDFConvertType) {
+        Task { @MainActor in
+            if await (KMLightMemberManager.manager.canUseAdvanced() == false) {
+                let _ =  KMComparativeTableViewController.show(window: self.view.window!)
+                return
+            }
+            
+            NSOpenPanel.km_secure_openPanel_success(window: self.view.window!) { url, password in
+                var windowController: KMConvertBaseWindowController?
+                if (type == .word) { /// Word
+                    windowController = KMConvertWordWindowController()
+                } else if (type == .excel) {
+                    windowController = KMConvertExcelWindowController()
+                } else if (type == .ppt || type == .rtf || type == .html || type == .text) {
+                    windowController = KMConvertPPTsWindowController()
+                    if (type == .ppt) {
+                        windowController?.subType = 1
+                    } else if (type == .rtf) {
+                        windowController?.subType = 2
+                    } else if (type == .html) {
+                        windowController?.subType = 3
+                    } else if (type == .text) {
+                        windowController?.subType = 4
+                    }
+                } else if (type == .csv) {
+                    windowController = KMConvertCSVWindowController()
+                } else if (type == .image) {
+                    windowController = KMConvertImageWindowController()
+                }
+                
+                let model = KMDocumentModel(url: url)
+                if (password != nil) {
+                    let _ = model.unlock(password!)
+                }
+                windowController?.documentModel = model
+
+                windowController?.itemClick = { [weak self] index in
+                    if (self?.currentWindowController == nil) {
+                        return
+                    }
+                    self?.view.window?.endSheet((self?.currentWindowController?.window)!)
+                    self?.currentWindowController = nil
+                }
+
+                self.view.window?.beginSheet((windowController?.window)!)
+                self.currentWindowController = windowController
+            }
+        }
+    }
+    
     // MARK: PDF Tools
     
     // 插入
@@ -914,10 +964,10 @@ extension KMHomeViewController {
                 windowController.documentModel = model
                 
                 windowController.itemClick = { [weak self] (index: Int) in
-                    if (self!.currentWindowController == nil) {
+                    if (self?.currentWindowController == nil) {
                         return
                     }
-                    self!.view.window?.endSheet(self!.currentWindowController!.window!)
+                    self?.view.window?.endSheet((self?.currentWindowController?.window)!)
                     self?.currentWindowController = nil
                 }
                 
@@ -943,10 +993,10 @@ extension KMHomeViewController {
                 windowController.documentModel = model
                 
                 windowController.itemClick = { [weak self] (index: Int) in
-                    if (self!.currentWindowController == nil) {
+                    if (self?.currentWindowController == nil) {
                         return
                     }
-                    self!.view.window?.endSheet(self!.currentWindowController!.window!)
+                    self?.view.window?.endSheet((self?.currentWindowController?.window)!)
                     self?.currentWindowController = nil
                 }
                 
@@ -972,10 +1022,10 @@ extension KMHomeViewController {
                 windowController.documentModel = model
                 
                 windowController.itemClick = { [weak self] (index: Int) in
-                    if (self!.currentWindowController == nil) {
+                    if (self?.currentWindowController == nil) {
                         return
                     }
-                    self!.view.window?.endSheet(self!.currentWindowController!.window!)
+                    self?.view.window?.endSheet((self?.currentWindowController?.window)!)
                     self?.currentWindowController = nil
                 }
                 
@@ -1001,10 +1051,10 @@ extension KMHomeViewController {
                 windowController.documentModel = model
                 
                 windowController.itemClick = { [weak self] (index: Int) in
-                    if (self!.currentWindowController == nil) {
+                    if (self?.currentWindowController == nil) {
                         return
                     }
-                    self!.view.window?.endSheet(self!.currentWindowController!.window!)
+                    self?.view.window?.endSheet((self?.currentWindowController?.window)!)
                     self?.currentWindowController = nil
                 }
                 
@@ -1386,6 +1436,22 @@ extension KMHomeViewController {
         self.fastTool_PDFToPPT()
     }
     
+    @IBAction func menuItemAction_ConvertToRTF(_ sender: Any) {
+        self.showConvertWindow(type: .rtf)
+    }
+    
+    @IBAction func menuItemAction_ConvertToHTML(_ sender: Any) {
+        self.showConvertWindow(type: .html)
+    }
+    
+    @IBAction func menuItemAction_ConvertToText(_ sender: Any) {
+        self.showConvertWindow(type: .text)
+    }
+    
+    @IBAction func menuItemAction_ConvertToCSV(_ sender: Any) {
+        self.showConvertWindow(type: .csv)
+    }
+    
     @IBAction func menuItemAction_ConvertToImage(_ sender: Any) {
         self.fastTool_PDFToImage()
     }

+ 2 - 0
PDF Office/PDF Master/Class/PDFTools/Convert/Common/KMPDFConvert.swift

@@ -28,6 +28,8 @@ enum KMPDFConvertType: Int {
     case tga = 12
     case bmp = 13
     case jp2 = 14
+    
+    static let image: KMPDFConvertType = .jpeg
 }
 
 typealias KMPDFConvertCallback = (_ finished: Bool, _ error: Error?) -> ()

+ 4 - 0
PDF Office/PDF Master/Class/PDFTools/Convert/Controller/KMConvertBaseWindowController.swift

@@ -185,6 +185,10 @@ class KMConvertBaseWindowController: NSWindowController {
     var progressController: SKProgressController?
     var convert: KMPDFConvert?
     
+    convenience init() {
+        self.init(windowNibName: "KMConvertBaseWindowController")
+    }
+    
     override func awakeFromNib() {
         super.awakeFromNib()
         DispatchQueue.main.async {