|
@@ -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)
|