Browse Source

【综合】页面编辑补充密码弹窗

tangchao 1 year ago
parent
commit
26486bde93

+ 23 - 27
PDF Office/PDF Master/Class/PDFTools/PageEdit/Window/KMPDFEditInsertPageWindow.swift

@@ -137,23 +137,23 @@ class KMPDFEditInsertPageWindow: NSWindowController {
         self.locationRangePopUpButton.isEnabled = false
         
         if let data = self.pdfDocument?.isLocked, data {
-//            dispatch_after(dispatch_time(DISPATCH_TIME_NOW, (int64_t)(0.5 * NSEC_PER_SEC)), dispatch_get_main_queue(), ^{
-//                PasswordWindowController *passwordVC = [[PasswordWindowController alloc] initWithWindowNibName:@"PasswordWindowController"];
-//                passwordVC.fileURL = [self.pdfDocument documentURL];
-//
+            DispatchQueue.main.asyncAfter(deadline: .now() + 0.5) {
+                let passwordVC = PasswordWindowController(windowNibName: "PasswordWindowController")
+                passwordVC.fileURL = self.pdfDocument?.documentURL
+                self.km_beginSheet(windowC: passwordVC)
+                
 //                [passwordVC beginSheetModalForWindow:self.window completionHandler:^(NSString *password) {
 //                    if (password) {
 //                        [_pdfDocument unlockWithPassword:password];
 //                        self.password = password;
-//
+
 //                        _pageCountLabel.stringValue = [NSString stringWithFormat:@"/%ld",_pdfDocument.pageCount];
 //                        _byPageStepper.minValue = 1.0;
 //                        _byPageStepper.maxValue = _pdfDocument.pageCount;
 //
 //                    }
 //                }];
-//                [passwordVC release];
-//            });
+            }
         } else {
             self.byPageStepper.minValue = 1.0
             self.byPageStepper.maxValue = Double(self.pdfDocument?.pageCount ?? 0)
@@ -316,18 +316,15 @@ class KMPDFEditInsertPageWindow: NSWindowController {
         let openPanel = NSOpenPanel()
         openPanel.allowedFileTypes = ["pdf"]
         openPanel.beginSheetModal(for: self.window!) { result in
-            
-//        }
-//        [openPanel beginSheetModalForWindow:self.window completionHandler:^(NSInteger result){
             if (result == .OK) {
                 for fileURL in openPanel.urls {
-//                for (NSURL * in [openPanel URLs]) {
-//                    PDFDocument *pdfDoc = [[PDFDocument alloc] initWithURL:fileURL];
-//                    if ([pdfDoc isLocked]) {
-//                        dispatch_after(dispatch_time(DISPATCH_TIME_NOW, (int64_t)(0.5 * NSEC_PER_SEC)), dispatch_get_main_queue(), ^{
-//                            PasswordWindowController *com = [[PasswordWindowController alloc] initWithWindowNibName:@"PasswordWindowController"];
-//                            com.fileURL = fileURL;
-//
+                    let pdfDoc = CPDFDocument(url: fileURL)
+                    if (pdfDoc!.isLocked) {
+                        DispatchQueue.main.asyncAfter(deadline: .now()+0.5) {
+                            let com = PasswordWindowController(windowNibName: "PasswordWindowController")
+                            com.fileURL = fileURL
+                            self.km_beginSheet(windowC: com)
+
 //                            [com beginSheetModalForWindow:self.window completionHandler:^(NSString *password) {
 //                                if (password) {
 //                                    self.password = password;
@@ -346,18 +343,17 @@ class KMPDFEditInsertPageWindow: NSWindowController {
 //                                }
 //                            }];
 //                            [com release];
-//                        });
-//                    } else {
+                        }
+                    } else {
                         self.fromFilePath = fileURL
-                    self.outputFolderText.stringValue = self.fromFilePath!.path
-                    self.insertDocument = CPDFDocument(url: fileURL)
-                    self.customTextField.stringValue = String(format: "/ %ld", self.insertDocument?.pageCount ?? 0)
-                    self.window?.makeFirstResponder(self)
+                        self.outputFolderText.stringValue = self.fromFilePath!.path
+                        self.insertDocument = CPDFDocument(url: fileURL)
+                        self.customTextField.stringValue = String(format: "/ %ld", self.insertDocument?.pageCount ?? 0)
+                        self.window?.makeFirstResponder(self)
                     
-                    self.pagesText.stringValue = "1"
-                    self.insertButton.isEnabled = true
-//                    }
-//                    [pdfDoc release];
+                        self.pagesText.stringValue = "1"
+                        self.insertButton.isEnabled = true
+                    }
                 }
             }
         }