Pārlūkot izejas kodu

【快速教学】打开快速教学文档,切换到另一个文档,再点击帮助-快速教学文档,未跳转到快速教学文档

liujiajie 11 mēneši atpakaļ
vecāks
revīzija
1a322b8f8e

+ 2 - 2
PDF Office/PDF Master/Base.lproj/Main.storyboard

@@ -1,8 +1,8 @@
 <?xml version="1.0" encoding="UTF-8"?>
-<document type="com.apple.InterfaceBuilder3.Cocoa.Storyboard.XIB" version="3.0" toolsVersion="22505" targetRuntime="MacOSX.Cocoa" propertyAccessControl="none" useAutolayout="YES">
+<document type="com.apple.InterfaceBuilder3.Cocoa.Storyboard.XIB" version="3.0" toolsVersion="22155" targetRuntime="MacOSX.Cocoa" propertyAccessControl="none" useAutolayout="YES">
     <dependencies>
         <deployment identifier="macosx"/>
-        <plugIn identifier="com.apple.InterfaceBuilder.CocoaPlugin" version="22505"/>
+        <plugIn identifier="com.apple.InterfaceBuilder.CocoaPlugin" version="22155"/>
         <capability name="documents saved in the Xcode 8 format" minToolsVersion="8.0"/>
     </dependencies>
     <scenes>

+ 41 - 0
PDF Office/PDF Master/Class/Common/Category/NSDocumentController+KMExtension.swift

@@ -20,6 +20,9 @@ extension NSDocumentController {
             return
         }
         
+        if alreadyOpenDocument(url: url) {
+            return
+        }
         self.openDocument(withContentsOf: url, display: displayDocument) { document, isOpened, error in
             if let _error = error {
                 if (needAlert) {
@@ -30,6 +33,44 @@ extension NSDocumentController {
         }
     }
     
+    func alreadyOpenDocument(url: URL) -> Bool{
+        let pdfDoc = CPDFDocument.init(url: url)
+        if pdfDoc != nil{
+            let document = NSDocumentController.shared.document(for: url)
+            var alreadyOpen = false
+            for openDocument in NSDocumentController.shared.documents {
+                if document == openDocument {
+                    alreadyOpen = true
+                }
+            }
+            if !alreadyOpen {
+              return false
+            } else {
+                var selectDocument: KMMainDocument? = nil
+                if ((document?.isKind(of: KMMainDocument.self)) != nil) {
+                    selectDocument = (document as! KMMainDocument)
+                }
+                if selectDocument != nil {
+                    if selectDocument?.browser != nil {
+                        let currentIndex = selectDocument?.browser.tabStripModel.index(of: selectDocument)
+                        selectDocument?.browser.tabStripModel.selectTabContents(at: Int32(currentIndex!), userGesture: true)
+                        if (selectDocument?.browser.window.isVisible)! as Bool {
+                            selectDocument?.browser.window.orderFront(nil)
+                        } else if (selectDocument?.browser.window.isMiniaturized)! as Bool {
+                            selectDocument?.browser.window.orderFront(nil)
+                        }
+                    }
+                } else {
+                    NSDocumentController.shared.km_safe_openDocument(withContentsOf: url, display: true) { _, _, _ in
+                        
+                    }
+                }
+                return true
+            }
+        }
+        return false
+    }
+    
     public func km_safe_limit_openDocument(withContentsOf url: URL, display displayDocument: Bool, needAlert: Bool = true, completionHandler: @escaping (NSDocument?, Bool, Error?) -> Void) {
         if KMDataManager.default.isTabbingWin{
             completionHandler(nil, false, nil)