Просмотр исходного кода

合并-补充新增已开启的文件置灰状态

tangchao 2 лет назад
Родитель
Сommit
5e180b5356

BIN
PDF Office/PDF Office.xcodeproj/project.xcworkspace/xcuserdata/kdanmobile.xcuserdatad/UserInterfaceState.xcuserstate


+ 36 - 2
PDF Office/PDF Office/Class/Common/Tools/KMTools.swift

@@ -7,6 +7,40 @@
 
 import Cocoa
 
-class KMTools: NSObject {
-
+@objc class KMTools: NSObject {
+    
+    // MARK: -
+    // 获取已打开的文件
+    @objc class func getOpenDocumentURLs() -> [URL] {
+        var files:[URL] = []
+        for window in NSApp.windows {
+            if ((window.windowController is KMBrowserWindowController) == false) {
+                continue
+            }
+            
+            let controller: KMBrowserWindowController = window.windowController as! KMBrowserWindowController
+            let model = controller.browser?.tabStripModel
+            guard let count = model?.count() else {
+                continue
+            }
+            
+            if (count <= 0) {
+                continue
+            }
+            
+            for i in 0 ..< count {
+                let document = model?.tabContents(at: Int32(i))
+                if (document?.fileURL == nil) {
+                    continue
+                }
+                
+                if (document?.isHome == nil || document!.isHome) {
+                    continue
+                }
+                
+                files.append((document?.fileURL)!)
+            }
+        }
+        return files
+    }
 }

+ 14 - 0
PDF Office/PDF Office/Class/Merge/OCPart/KMPDFEditAppendWindow.m

@@ -663,6 +663,20 @@ static NSString * const KMTableColumnSizeID = @"size";
     }
 }
 
+- (BOOL)hasOpenFiles {
+    NSArray *array = [KMTools getOpenDocumentURLs];
+    if (array.count == 0) {
+        return NO;
+    }
+    
+    for (NSURL *fileURL in array) {
+        if ([self isExistAtFilepath:fileURL.path]) {
+            return YES;
+        }
+    }
+    return NO;
+}
+
 #pragma mark - KMSelectPopButtonDelegate
 
 - (void)km_comboBoxSelectionDidChange:(KMDesignSelect *)obj {

+ 4 - 0
PDF Office/PDF Office/Class/PDFWindowController/ViewController/KMMainViewController+Action.swift

@@ -1444,6 +1444,8 @@ extension KMMainViewController : KMMainToolbarControllerDelegate {
     
     func clickChildTool(type: KMToolbarType, index: Int) {
         if (type == .compress) { /// 压缩
+            self.saveDocument()
+            
             let windowController = KMCompressWindowController(windowNibName: "KMCompressWindowController")
             self.view.window?.beginSheet(windowController.window!)
             self.currentWindowController = windowController
@@ -1501,6 +1503,8 @@ extension KMMainViewController : KMMainToolbarControllerDelegate {
                 windowController = KMConvertImageWindowController(windowNibName: "KMConvertBaseWindowController")
             }
             
+            self.saveDocument()
+            
             let model = KMDocumentModel()
             model.documentURL = self.listView.document.documentURL
             if (self.listView.document.password != nil) {