浏览代码

【存储文件】拖拽图片到首页打开,文档不应该自动存在Application Support路径下

liujiajie 6 月之前
父节点
当前提交
45d30a7e5d
共有 1 个文件被更改,包括 12 次插入2 次删除
  1. 12 2
      PDF Office/PDF Master/Class/Home/ViewController/KMHomeViewController+Action.swift

+ 12 - 2
PDF Office/PDF Master/Class/Home/ViewController/KMHomeViewController+Action.swift

@@ -600,8 +600,18 @@ extension KMHomeViewController {
         } else {
         }
         if success {
-            NSDocumentController.shared.km_safe_openDocument(withContentsOf: URL(fileURLWithPath: path), display: true) { _, _, _ in
-                
+            NSDocumentController.shared.km_safe_openDocument(withContentsOf: URL(fileURLWithPath: path), display: true) { document, isOpened, error in
+                if error != nil {
+                    NSApp.presentError(error!)
+                } else {
+                    if FileManager.default.fileExists(atPath: filePath) {
+                        try? FileManager.default.removeItem(atPath: filePath)
+                    }
+                    if document is KMMainDocument {
+                        let newDocument = document
+                        (newDocument as! KMMainDocument).isNewCreated = true
+                    }
+                }
             }
         }
     }