Browse Source

【综合】整理代码

tangchao 11 months ago
parent
commit
a4365cacf5

+ 1 - 18
PDF Office/PDF Master/Class/Common/Category/NSDocumentController+KMExtension.swift

@@ -31,27 +31,10 @@ extension NSDocumentController {
     }
     
     public func km_safe_limit_openDocument(withContentsOf url: URL, display displayDocument: Bool, needAlert: Bool = true, completionHandler: @escaping (NSDocument?, Bool, Error?) -> Void) {
-        if (!url.path.isPDFValid()) {
-            if (needAlert) {
-                let alert = NSAlert()
-                alert.alertStyle = .critical
-                alert.messageText = NSLocalizedString("An error occurred while opening this document. The file is damaged and could not be repaired.", comment: "")
-                alert.runModal()
-            }
-            completionHandler(nil, false, nil)
-            return
-        }
         if KMDataManager.default.isTabbingWin{
             completionHandler(nil, false, nil)
             return
         }
-        self.openDocument(withContentsOf: url, display: displayDocument) { document, isOpened, error in
-            if let _error = error {
-                if (needAlert) {
-                    NSApp.presentError(_error)
-                }
-            }
-            completionHandler(document, isOpened, error)
-        }
+        self.km_safe_openDocument(withContentsOf: url, display: displayDocument, needAlert: needAlert, completionHandler: completionHandler)
     }
 }

+ 2 - 101
PDF Office/PDF Master/Class/PDFWindowController/ViewController/KMMainViewController.swift

@@ -1074,12 +1074,6 @@ let LOCKED_KEY  = "locked"
         }
         controller.documentEditedCallback = { [weak self] params in
             self?.recordIsPDFDocumentEdited()
-//            self?.needSave = true
-            if let data = params.first as? KMPageEditType {
-                self?.recordSaveWatermarkFlag(type: data.toSubscribeWaterMarkType())
-            } else {
-                self?.recordSaveWatermarkFlag()
-            }
         }
         
         controller.selectionDidChange = { [weak self] selectedIndexs in
@@ -1431,37 +1425,6 @@ let LOCKED_KEY  = "locked"
     // MARR: 显示加密弹窗
     
     public func showSecureWindow(_ url: URL) {
-//        let windowController = KMSecureEncryptWindowController(windowNibName: "KMSecureEncryptWindowController")
-//        windowController.documentURL = url
-//        windowController.myDocument = self.listView.document
-//        self.currentWindowController = windowController
-//
-//        windowController.itemClick = { [weak self] index in
-//            self?.view.window?.endSheet((self?.currentWindowController.window)!)
-//            self?.currentWindowController = nil
-//        }
-//
-//        windowController.resultCallback = { [weak self] result in
-//            let windowController_secure = self?.currentWindowController as! KMSecureEncryptWindowController
-//            self?.view.window?.endSheet((self?.currentWindowController.window)!)
-//            self?.currentWindowController = nil
-//
-//            self?._secureOptions = windowController_secure.options
-//            self?.needSave = true
-//            self?.recordIsPDFDocumentEdited(type: .setPassword)
-//
-//            if (result) {
-//                self?.showSecureSuccessTip()
-//                self?.recordSaveWatermarkFlag(type: .setPassword)
-//            } else {
-//                let alert = NSAlert()
-//                alert.messageText = NSLocalizedString("Failure", comment: "")
-//                alert.runModal()
-//            }
-//        }
-//
-//        self.view.window?.beginSheet(windowController.window!)
-        
         let controller = KMSecurityWindowController(windowNibName: "KMSecurityWindowController")
         controller.pdfDocument = self.document
         self.currentWindowController = controller
@@ -1505,20 +1468,6 @@ let LOCKED_KEY  = "locked"
                     }
                 }
             }
-
-//            self._secureOptions = options
-//            self.documentAttribute = attribute
-//            self.needSave = true
-//            self.recordIsPDFDocumentEdited(type: .setPassword)
-//
-//            if (options.count != 0) {
-//                self.showSecureSuccessTip()
-//                self.recordSaveWatermarkFlag(type: .setPassword)
-//            } else {
-//                let alert = NSAlert()
-//                alert.messageText = NSLocalizedString("Failure", comment: "")
-//                alert.runModal()
-//            }
         }
 
         controller.cancelAction = { [unowned self] controller in
@@ -2076,7 +2025,7 @@ let LOCKED_KEY  = "locked"
     
     public func clearSecureOptions() {
         self._secureOptions = nil
-        self.documentAttribute
+        self.documentAttribute = nil
     }
     
     public func recordRemoveSecureFlag() {
@@ -2090,16 +2039,6 @@ let LOCKED_KEY  = "locked"
         self._removeSecureFlag = false
     }
     
-    public func recordSaveWatermarkFlag(type: KMSubscribeWaterMarkType = .none) {
-//        km_synchronized(self) {
-//            self._saveWatermarkFlag = true
-//        }
-//
-//        if let _document = self.myDocument as? KMMainDocument {
-//            _document.recordTrackEvent(type: type)
-//        }
-    }
-    
     public func clearSaveWatermarkFlag() {
         km_synchronized(self) {
             self._saveWatermarkFlag = false
@@ -2439,8 +2378,6 @@ let LOCKED_KEY  = "locked"
     }
     
     func pdfViewEditingSelectionDidChanged(_ pdfView: CPDFView!) {
-        self.recordSaveWatermarkFlag()
-        
         if self.rightSideViewController != nil && self.rightSideViewController.subViewType == .EditPDFAddText {
             self.rightSideViewController.eidtPDFTextProperty.reloadData()
             self.rightSideViewController.eidtPDFTextProperty.updateTextTextPresuppositionState()
@@ -2553,8 +2490,6 @@ let LOCKED_KEY  = "locked"
     }
     
     func pdfViewEditingCropBoundsDidChanged(_ pdfView: CPDFView!, editing editArea: CPDFEditArea!) {
-        self.recordSaveWatermarkFlag()
-        
         if  editArea != nil && (editArea is CPDFEditImageArea){
             self.listView.cropAreas = editArea as? CPDFEditImageArea
         }
@@ -2562,8 +2497,6 @@ let LOCKED_KEY  = "locked"
     
     //编辑PDF 创建图片区域回调
     func pdfViewEditingAddImageArea(_ pdfView: CPDFView!, add page: CPDFPage!, add rect: CGRect) {
-        self.recordSaveWatermarkFlag(type: .editImage)
-        
         if self.listView.isEditImage {
             self.menuItemEditingClick_CropImage(sender: NSMenuItem())
         } else {
@@ -2679,25 +2612,8 @@ let LOCKED_KEY  = "locked"
 //        self.asyncSaveDocument { params in
 //
 //        }
-        self.recordSaveWatermarkFlag(type: .editText)
     }
     
-//    func pdfViewEditingDoubleClick(_ pdfView: CPDFView!, imageArea editArea: CPDFEditArea!) {
-//        debugPrint("pdfViewEditingDoubleClick")
-//    }
-    
-    func pdfViewEditingOperationDidChanged(_ pdfView: CPDFView!) {
-        debugPrint("pdfViewEditingOperationDidChanged")
-        if self.listView.isEdited() {
-            self.recordSaveWatermarkFlag()
-        }
-    }
-    
-//    func pdfListViewEditAnnotation(_ pdfListView: CPDFListView!, for anotation: CPDFAnnotation!) {
-//        debugPrint("pdfListViewEditAnnotation")
-//    }
-    
-    
     func pdfListViewKeyDownIsContinue(_ pdfListView: CPDFListView!, theEvent: NSEvent!) -> Bool {
         let command = theEvent.modifierFlags.contains(.command)
         let control = theEvent.modifierFlags.contains(.control)
@@ -3148,25 +3064,10 @@ let LOCKED_KEY  = "locked"
     
     func pdfListViewAddAnnotations(_ pdfListView: CPDFListView!, forAdd annotations: [CPDFAnnotation]!, in pdfPage: CPDFPage!) {
         var addRedact = false
-        var saveWatermark = false
-        var saveWatermarkType: KMSubscribeWaterMarkType = .none
         for anno in annotations {
             if (anno.isKind(of: CPDFRedactAnnotation.self)) {
                 addRedact = true
-//                break
-            } else if (anno.isKind(of: CPDFLinkAnnotation.self)) { // link 注释
-                saveWatermark = true
-                saveWatermarkType = .link
-            } else if (anno.isKind(of: CPDFListStampAnnotation.self)) { // 图章注释
-                saveWatermark = true
-                saveWatermarkType = .stamp
-            } else if (anno.isKind(of: CPDFListSignatureAnnotation.self)) { // 签名注释
-                saveWatermark = true
-                saveWatermarkType = .sign
-            }
-        }
-        if (saveWatermark) {
-            self.recordSaveWatermarkFlag(type: saveWatermarkType)
+            }
         }
         self.hasAddRedact = addRedact
         if self.isReadMode || self.listView.toolMode == .moveToolMode {

+ 16 - 0
PDF Office/PDF Reader Pro.xcodeproj/xcuserdata/kdanmobile.xcuserdatad/xcdebugger/Breakpoints_v2.xcbkptlist

@@ -228,5 +228,21 @@
             landmarkType = "7">
          </BreakpointContent>
       </BreakpointProxy>
+      <BreakpointProxy
+         BreakpointExtensionID = "Xcode.Breakpoint.FileBreakpoint">
+         <BreakpointContent
+            uuid = "8B48DE07-E799-49FB-84C2-545601724021"
+            shouldBeEnabled = "Yes"
+            ignoreCount = "0"
+            continueAfterRunningActions = "No"
+            filePath = "PDF Master/Class/PDFWindowController/ViewController/KMMainViewController+Action.swift"
+            startingColumnNumber = "9223372036854775807"
+            endingColumnNumber = "9223372036854775807"
+            startingLineNumber = "976"
+            endingLineNumber = "976"
+            landmarkName = "cropAllPageItem(sender:)"
+            landmarkType = "7">
+         </BreakpointContent>
+      </BreakpointProxy>
    </Breakpoints>
 </Bucket>