Browse Source

Merge branch 'develop' of git.kdan.cc:Mac_PDF/PDF_Office into develop

tangchao 1 year ago
parent
commit
b1ed96e72c

+ 3 - 3
PDF Office/PDF Master/Class/KMLightMember/Controller/AccountInfo/KMAccountInfoWindowController.swift

@@ -112,12 +112,12 @@ class KMAccountInfoWindowController: NSWindowController {
             let alert = NSAlert()
             alert.messageText = NSLocalizedString("Are you sure you want to cancel?", comment: "")
             alert.informativeText = NSLocalizedString("Cancellation cannot be withdrawn, it will be completed within 3 working days, until then your account will be frozen and cannot be logged in, are you sure you want to delete your account?", comment: "")
-            alert.addButton(withTitle: NSLocalizedString("Yes", comment: ""))
             alert.addButton(withTitle: NSLocalizedString("No", comment: ""))
+            alert.addButton(withTitle: NSLocalizedString("Yes", comment: ""))
             alert.beginSheetModal(for: view.window!) { [unowned self] result in
-                if (result == .alertSecondButtonReturn) { /// 取消
+                if (result == .alertFirstButtonReturn) { /// 取消
                     return
-                } else if result == .alertFirstButtonReturn {
+                } else if result == .alertSecondButtonReturn {
                     guard let callBack = cancellAtionAction else { return }
 //                    accountInfoMainWindow?.endSheet(view.window!)
 //                    view.window?.close()

+ 1 - 1
PDF Office/PDF Master/Class/Merge/Tools/KMMergeTools.swift

@@ -30,7 +30,7 @@ class KMMergeTools: NSObject {
             var isDirectory: ObjCBool = ObjCBool(false)
             fileManager.fileExists(atPath: documentURL.path, isDirectory: &isDirectory)
             if (isDirectory.boolValue) {
-                findAllFiles(folder: documentURL, result: &result)
+                findAllFiles(folder: documentURL, result: &result, types: types)
             } else {
                 if !array.contains(documentURL.pathExtension.lowercased()) {
                     continue

+ 1 - 0
PDF Office/PDF Master/Class/PDFTools/ImageToPDF/KMImageToPDFWindowController.swift

@@ -100,6 +100,7 @@ class KMImageToPDFWindowController: NSWindowController {
                     let point = CGPoint(x: window.frame.origin.x + window.frame.width / 2 - (imageToPDFWindow.window?.frame.size.width)! / 2,
                                         y: window.frame.origin.y + window.frame.height / 2 - (imageToPDFWindow.window?.frame.size.height)! / 2)
                     window.addChildWindow(imageToPDFWindow.window!, ordered: NSWindow.OrderingMode.above)
+                    imageToPDFWindow.window?.center()
 //                    DispatchQueue.main.asyncAfter(deadline: .now() + 0.5) {
 //                        imageToPDFWindow.window?.setFrameOrigin(point)
 //                        imageToPDFWindow.window?.makeKeyAndOrderFront(nil)

+ 13 - 1
PDF Office/PDF Master/Class/PDFTools/ImageToPDF/View/KMBatchProcessingView/KMBatchProcessingView.swift

@@ -156,7 +156,19 @@ extension KMBatchProcessingView: KMBatchProcessingViewAction {
             }
         } completion: { [unowned self] (panel ,data) in
             if data.count != 0 {
-                self.tableView.presenter.addData(data: data)
+                var filePaths: [URL] = []
+                
+                var types: [String] = []
+                if self.inputType == .OCR {
+                    types = KMOCRModel.supportedTypes()
+                } else if self.inputType == .ImageToPDF {
+                    types = KMBatchProcessingTableViewModel.supportedImageTypes()
+                } else {
+                    types = KMOCRModel.supportedTypes()
+                }
+                
+                KMMergeTools.findAllFiles(folder: data.first!, result: &filePaths, types: types)
+                self.tableView.presenter.addData(data: filePaths)
                 self.reloadData()
             }
         }

+ 1 - 1
PDF Office/PDF Master/Class/PDFTools/ImageToPDF/View/KMBatchProcessingView/Tableview/Views/Tableview/Views/KMBatchProcessingNameTableCell.swift

@@ -69,7 +69,7 @@ class KMBatchProcessingNameTableCell: KMBatchProcessingTableCell {
             self.iconImageView.image = NSImage(named: "icon_popups_file_png")
         }
         
-        if self.model.name.contains("jpg") || self.model.name.contains("JPG") {
+        if self.model.name.contains("jpg") || self.model.name.contains("JPG") || self.model.name.contains("jpeg") || self.model.name.contains("JPEG") {
             self.iconImageView.image = NSImage(named: "icon_popups_file_jpg")
         }
     }

+ 3 - 0
PDF Office/PDF Master/Class/PDFTools/PageEdit/Controller/KMPDFEditViewController.swift

@@ -424,6 +424,8 @@ class KMPDFEditViewController: NSViewController {
             self.undoRedoManager.registerUndo(withTarget: self, selector: #selector(rightRotate), object: indexs)
             
             self.refreshUIForKeepSelecteds(indexs: indexs)
+            
+            NotificationCenter.default.post(name: NSNotification.Name(rawValue: "KMPDFViewRotatePage"), object: self.listView?.document)
         }
     }
     
@@ -456,6 +458,7 @@ class KMPDFEditViewController: NSViewController {
             self.undoRedoManager.registerUndo(withTarget: self, selector: #selector(leftRotate), object: indexs)
             
             self.refreshUIForKeepSelecteds(indexs: indexs)
+            NotificationCenter.default.post(name: NSNotification.Name(rawValue: "KMPDFViewRotatePage"), object: self.listView?.document)
         }
     }
     

+ 5 - 4
PDF Office/PDF Master/Class/PDFWindowController/PDFListView/CPDFListViewExtension/CPDFListView+Event.m

@@ -196,7 +196,7 @@ static inline CPDFAreaOfInterest CAreaOfInterestForResizeHandle(CRectEdges mask,
     
     CPDFAnnotation *newActiveAnnotation = nil;
     for (CPDFAnnotation *annotation in annotations) {
-        if ([annotation hitTest:point]) {
+        if ([annotation hitTest:point] && [annotation annotationShouldDisplay]) {
             newActiveAnnotation = annotation;
             break;
         }
@@ -2587,7 +2587,7 @@ static inline CPDFAreaOfInterest CAreaOfInterestForResizeHandle(CRectEdges mask,
     id annotations = [page annotations];
     
     for (CPDFAnnotation *annotation in annotations) {
-        if ([annotation hitTest:point]) {
+        if ([annotation hitTest:point] && [annotation annotationShouldDisplay] ) {
             newActiveAnnotation = annotation;
             break;
         }
@@ -2633,7 +2633,8 @@ static inline CPDFAreaOfInterest CAreaOfInterestForResizeHandle(CRectEdges mask,
     CPDFPage *page = [self pageAndPoint:&point forEvent:theEvent nearest:YES];
     if ([self.activeAnnotation page] == page &&
         [self.activeAnnotation isResizable] &&
-        [self.activeAnnotation resizeHandleForPoint:point scaleFactor:[self scaleFactor]] != 0) {
+        [self.activeAnnotation resizeHandleForPoint:point scaleFactor:[self scaleFactor]] != 0 &&
+        [self.activeAnnotation annotationShouldDisplay]) {
         *annotation = self.activeAnnotation;
         return YES;
     }
@@ -3045,7 +3046,7 @@ static inline CPDFAreaOfInterest CAreaOfInterestForResizeHandle(CRectEdges mask,
         theEvent = [[self window] nextEventMatchingMask:eventMask];
         if ([theEvent type] == NSEventTypeLeftMouseUp) {
             for(CPDFAnnotation *annotation in [activePage annotations]){
-                if (!annotation.isHidden && NSIntersectsRect(annotation.bounds, selectBounds) &&
+                if ([annotation annotationShouldDisplay] && NSIntersectsRect(annotation.bounds, selectBounds) &&
                     ![annotation isKindOfClass:[CPDFLinkAnnotation class]] &&
                     ![annotation isKindOfClass:[CPDFButtonWidgetAnnotation class]] &&
                     ![annotation isKindOfClass:[CPDFTextWidgetAnnotation class]] &&

+ 110 - 106
PDF Office/PDF Master/Class/PDFWindowController/Side/LeftSide/Annotation/KMAnnotationViewController.swift

@@ -25,8 +25,8 @@ class KMAnnotationViewController: KMSideViewController {
     
     var annotations: [KMBOTAAnnotationSection] = [] {
         didSet {
-            self.updateExtempViewState()
             self.annotationOutlineView.inputData = annotations
+            self.updateExtempViewState()
         }
     }
     var screenAnnotations: [KMBOTAAnnotationSection] = [] {
@@ -38,7 +38,7 @@ class KMAnnotationViewController: KMSideViewController {
     //注释状态
     var annotationShowState: KMAnnotationViewShowType = .none {
         didSet {
-            self.updateExtempViewState()
+            self.reloadData()
         }
     }
     
@@ -139,113 +139,123 @@ extension KMAnnotationViewController {
     }
     
     func reloadAnnotation() {
-        var dataArray: [KMBOTAAnnotationSection] = []
-        var annotationArray: [CPDFAnnotation] = []
-        for i in 0 ..< self.listView.document.pageCount {
-            var annotationItemArray: [KMBOTAAnnotationItem] = []
-            let page = self.listView.document.page(at: i)
-            let types = ["Highlight","Underline","Strikeout","Freehand","FreeText","Note","Square","Circle","Line","Stamp","Arrow","Image","Redact","Sign"]
-            var pageAnnotations: [CPDFAnnotation] = KMOCToolClass.filterAnnotation(page!.annotations,types: types) as! [CPDFAnnotation]
-            //添加签名注释
-            for annotation in page!.annotations {
-               if annotation.isKind(of: CPDFSignatureAnnotation.self) {
-                   pageAnnotations.append(annotation)
-               }
-            }
+        if self.listView != nil {
+            var dataArray: [KMBOTAAnnotationSection] = []
+            var annotationArray: [CPDFAnnotation] = []
+            for i in 0 ..< self.listView.document.pageCount {
+                var annotationItemArray: [KMBOTAAnnotationItem] = []
+                let page = self.listView.document.page(at: i)
+                let types = ["Highlight","Underline","Strikeout","Freehand","FreeText","Note","Square","Circle","Line","Stamp","Arrow","Image","Redact","Sign"]
+                var pageAnnotations: [CPDFAnnotation] = KMOCToolClass.filterAnnotation(page!.annotations,types: types) as! [CPDFAnnotation]
+                //添加签名注释
+                for annotation in page!.annotations {
+                   if annotation.isKind(of: CPDFSignatureAnnotation.self) {
+                       pageAnnotations.append(annotation)
+                   }
+                }
+                
+                for annotation in pageAnnotations {
+                    if annotation.annotationShouldDisplay() == false {
+                        pageAnnotations.removeObject(annotation)
+                    }
+                }
 
-            //转换所有annotation类型
-            let section = KMBOTAAnnotationSection()
-            for annotation in pageAnnotations {
-                let item = KMBOTAAnnotationItem()
-                item.section = section
-                item.annotation = annotation
-                item.index = Int(annotation.page.pageIndex())
-                annotationItemArray.append(item)
+                //转换所有annotation类型
+                let section = KMBOTAAnnotationSection()
+                for annotation in pageAnnotations {
+                    let item = KMBOTAAnnotationItem()
+                    item.section = section
+                    item.annotation = annotation
+                    item.index = Int(annotation.page.pageIndex())
+                    annotationItemArray.append(item)
+                }
+                
+                if annotationItemArray.count != 0 {
+                    section.annotations = annotationItemArray
+                    section.page = page
+                    section.isItemExpanded = true
+                    dataArray.append(section)
+                }
+                
+                //添加所有annotation 用于筛选
+                annotationArray += pageAnnotations
             }
             
-            if annotationItemArray.count != 0 {
-                section.annotations = annotationItemArray
-                section.page = page
-                section.isItemExpanded = true
-                dataArray.append(section)
-            }
+            //转换对象,用于数据显示
+            self.annotations = dataArray
+            self.allAnnotations = annotationArray
             
-            //添加所有annotation 用于筛选
-            annotationArray += pageAnnotations
-        }
-        
-        //转换对象,用于数据显示
-        self.annotations = dataArray
-        self.allAnnotations = annotationArray
-        
-        if self.annotations.count < 1 {
-           self.filtrateButton.isEnabled = false
-        } else {
-           self.filtrateButton.isEnabled = true
+            if self.annotations.count < 1 {
+               self.filtrateButton.isEnabled = false
+            } else {
+               self.filtrateButton.isEnabled = true
+            }
         }
     }
     
     func annotationSort(sortArray:[[Any]]) {
-        var typeArr: [Any] = []
-        var colorArr: [Any] = []
-        var authorArr: [Any] = []
-        
-        let sud = UserDefaults.standard
-        let typeData = sud.object(forKey: "KMNoteOutlineFilterSelectArray_Type" + self.listView.document.documentURL.path) as? Data
-        if typeData != nil {
-            typeArr = NSKeyedUnarchiver.unarchiveObject(with: typeData!) as! [Any]
-        }
-        
-        let colorData = sud.object(forKey: "KMNoteOutlineFilterSelectArray_Color" + self.listView.document.documentURL.path) as? Data
-        if colorData != nil {
-            colorArr = NSKeyedUnarchiver.unarchiveObject(with: colorData!) as! [Any]
-        }
-        
-        let authorData = sud.object(forKey: "KMNoteOutlineFilterSelectArray_Author" + self.listView.document.documentURL.path) as? Data
-        if authorData != nil {
-            authorArr = NSKeyedUnarchiver.unarchiveObject(with: authorData!) as! [Any]
-        }
-        
-        if typeArr.count == 0 && colorArr.count == 0 && authorArr.count == 0 {
-            self.filtrateButton.image = NSImage(named: "KMImageNameAnnotationsFiltrate")
-            self.reloadAnnotation()
-        } else {
-            self.filtrateButton.image = NSImage(named: "icon_annotation_screening_select")
-            var dataArray: [KMBOTAAnnotationSection] = []
-            for i in 0 ..< self.listView.document.pageCount {
-                var annotationItemArray: [KMBOTAAnnotationItem] = []
-                let page = self.listView.document.page(at: i)
-                if page!.annotations.count > 0 {
-                    var filterAnnotations: [CPDFAnnotation] = page!.annotations
-                    if typeArr.count > 0 {
-                        filterAnnotations = (KMOCToolClass.filterAnnotation(filterAnnotations, types: typeArr) as! [CPDFAnnotation])
-                    }
-                    if (colorArr.count > 0) {
-                        filterAnnotations = (KMOCToolClass.filterAnnotation(filterAnnotations,colors: colorArr) as! [CPDFAnnotation])
-                    }
-                    if (authorArr.count > 0) {
-                        filterAnnotations = (KMOCToolClass.filterAnnotation(filterAnnotations,authors: authorArr) as! [CPDFAnnotation])
-                    }
-                    
-                    let section = KMBOTAAnnotationSection()
-                    for annotation in filterAnnotations {
-                        let item = KMBOTAAnnotationItem()
-                        item.section = section
-                        item.annotation = annotation
-                        item.index = Int(page!.pageIndex())
-                        annotationItemArray.append(item)
-                    }
-                    
-                    if annotationItemArray.count != 0 {
-                        section.annotations = annotationItemArray
-                        section.page = page
-                        section.isItemExpanded = true
-                        dataArray.append(section)
+        if self.listView != nil {
+            var typeArr: [Any] = []
+            var colorArr: [Any] = []
+            var authorArr: [Any] = []
+            
+            let sud = UserDefaults.standard
+            let typeData = sud.object(forKey: "KMNoteOutlineFilterSelectArray_Type" + self.listView.document.documentURL.path) as? Data
+            if typeData != nil {
+                typeArr = NSKeyedUnarchiver.unarchiveObject(with: typeData!) as! [Any]
+            }
+            
+            let colorData = sud.object(forKey: "KMNoteOutlineFilterSelectArray_Color" + self.listView.document.documentURL.path) as? Data
+            if colorData != nil {
+                colorArr = NSKeyedUnarchiver.unarchiveObject(with: colorData!) as! [Any]
+            }
+            
+            let authorData = sud.object(forKey: "KMNoteOutlineFilterSelectArray_Author" + self.listView.document.documentURL.path) as? Data
+            if authorData != nil {
+                authorArr = NSKeyedUnarchiver.unarchiveObject(with: authorData!) as! [Any]
+            }
+            
+            if typeArr.count == 0 && colorArr.count == 0 && authorArr.count == 0 {
+                self.filtrateButton.image = NSImage(named: "KMImageNameAnnotationsFiltrate")
+                self.reloadAnnotation()
+            } else {
+                self.filtrateButton.image = NSImage(named: "icon_annotation_screening_select")
+                var dataArray: [KMBOTAAnnotationSection] = []
+                for i in 0 ..< self.listView.document.pageCount {
+                    var annotationItemArray: [KMBOTAAnnotationItem] = []
+                    let page = self.listView.document.page(at: i)
+                    if page!.annotations.count > 0 {
+                        var filterAnnotations: [CPDFAnnotation] = page!.annotations
+                        if typeArr.count > 0 {
+                            filterAnnotations = (KMOCToolClass.filterAnnotation(filterAnnotations, types: typeArr) as! [CPDFAnnotation])
+                        }
+                        if (colorArr.count > 0) {
+                            filterAnnotations = (KMOCToolClass.filterAnnotation(filterAnnotations,colors: colorArr) as! [CPDFAnnotation])
+                        }
+                        if (authorArr.count > 0) {
+                            filterAnnotations = (KMOCToolClass.filterAnnotation(filterAnnotations,authors: authorArr) as! [CPDFAnnotation])
+                        }
+                        
+                        let section = KMBOTAAnnotationSection()
+                        for annotation in filterAnnotations {
+                            let item = KMBOTAAnnotationItem()
+                            item.section = section
+                            item.annotation = annotation
+                            item.index = Int(page!.pageIndex())
+                            annotationItemArray.append(item)
+                        }
+                        
+                        if annotationItemArray.count != 0 {
+                            section.annotations = annotationItemArray
+                            section.page = page
+                            section.isItemExpanded = true
+                            dataArray.append(section)
+                        }
                     }
                 }
+                
+                self.annotations = dataArray
             }
-            
-            self.annotations = dataArray
         }
     }
 }
@@ -255,14 +265,8 @@ extension KMAnnotationViewController {
     func updateExtempViewState() {
         if self.emptyView != nil {
             var hidden = false
-            if self.annotationShowState == .none {
-                for section in annotations {
-                    if section.annotations?.count != 0 {
-                        hidden = true
-                    }
-                }
-            } else {
-                hidden = false
+            if self.annotationOutlineView.outlineView.numberOfRows != 0 {
+                hidden = true
             }
             self.emptyView.isHidden = hidden
             self.annotationOutlineView.isHidden = !hidden

+ 3 - 1
PDF Office/PDF Master/Class/PDFWindowController/Side/LeftSide/Thumbnail/KMPDFThumbnailItem.swift

@@ -76,7 +76,9 @@ class KMPDFThumbnailItem: NSCollectionViewItem {
         didSet {
             if self.annotationShowState == .hidden {
                 for annotation in self.page.annotations {
-                    annotation.setHidden(true)
+                    if annotation.annotationShouldDisplay() == false {
+                        annotation.setHidden(true)
+                    }
                 }
             } else {
                 for annotation in self.page.annotations {

+ 37 - 22
PDF Office/PDF Master/Class/PDFWindowController/Side/LeftSide/Thumbnail/KMThumbnailViewController.swift

@@ -47,6 +47,16 @@ class KMThumbnailViewController: NSViewController {
         NotificationCenter.default.removeObserver(self)
         print("KMThumbnailViewController 释放")
     }
+    
+    override func viewWillAppear() {
+        super.viewWillAppear()
+        self.thumbnailView.reloadData()
+    }
+    
+    override func centerSelectionInVisibleArea(_ sender: Any?) {
+        super.centerSelectionInVisibleArea(sender)
+    }
+    
     override func viewDidLoad() {
         super.viewDidLoad()
         self.view.wantsLayer = true
@@ -88,7 +98,6 @@ class KMThumbnailViewController: NSViewController {
         
         NotificationCenter.default.addObserver(self, selector: #selector(AnnotationDidChangeNoti), name: NSNotification.Name.init(rawValue: "CPDFPageDidAddAnnotationNotification"), object: nil)
         NotificationCenter.default.addObserver(self, selector: #selector(AnnotationDidChangeNoti), name: NSNotification.Name.init(rawValue: "CPDFPageDidRemoveAnnotationNotification"), object: nil)
-        
     }
     
     func removeNotification() {
@@ -184,37 +193,43 @@ class KMThumbnailViewController: NSViewController {
     
     //MARK: Noti
     @objc func KMPDFViewCurrentPageDidChangedNotification(notification: NSNotification) {
-        let pdfdocument : CPDFDocument = notification.object as! CPDFDocument
-        if pdfdocument.isEqual(self.listView.document) {
-            if !isLocalEvent {
-//                DispatchQueue.main.asyncAfter(deadline: DispatchTime.now() + 0.3) { [unowned self] in
-                    self.pdfCurrentPageChange()
-                    self.delegate?.pageDidSelect?(controller: self, pages: [self.listView.currentPageIndex])
-//                }
+        if notification.object is CPDFDocument {
+            let pdfdocument : CPDFDocument = notification.object as! CPDFDocument
+            if pdfdocument.isEqual(self.listView.document) {
+                if !isLocalEvent {
+    //                DispatchQueue.main.asyncAfter(deadline: DispatchTime.now() + 0.3) { [unowned self] in
+                        self.pdfCurrentPageChange()
+                        self.delegate?.pageDidSelect?(controller: self, pages: [self.listView.currentPageIndex])
+    //                }
+                }
+                isLocalEvent = false
             }
-            isLocalEvent = false
         }
     }
     
     @objc func KMPDFViewPageCountChangedNotification(notification: NSNotification) {
-        let pdfdocument : CPDFDocument = notification.object as! CPDFDocument
-        if pdfdocument.isEqual(self.listView.document) {
-            if !isLocalEvent {
-//                DispatchQueue.main.asyncAfter(deadline: DispatchTime.now() + 0.3) { [unowned self] in
-                    self.reloadData()
-//                }
+        if notification.object is CPDFDocument {
+            let pdfdocument : CPDFDocument = notification.object as! CPDFDocument
+            if pdfdocument.isEqual(self.listView.document) {
+                if !isLocalEvent {
+    //                DispatchQueue.main.asyncAfter(deadline: DispatchTime.now() + 0.3) { [unowned self] in
+                        self.reloadData()
+    //                }
+                }
+                isLocalEvent = false
             }
-            isLocalEvent = false
         }
     }
     
     @objc func AnnotationDidChangeNoti(notification: NSNotification) {
-        let pdfAnnotation : CPDFAnnotation = notification.object as! CPDFAnnotation
-        
-        if (pdfAnnotation.page != nil) {
-            var indexs: IndexSet = IndexSet()
-            indexs.insert(IndexSet.Element(pdfAnnotation.page.pageIndex()))
-            self.reloadDataAtIndexs(indexs: indexs)
+        if notification.object is CPDFAnnotation {
+            let pdfAnnotation : CPDFAnnotation = notification.object as! CPDFAnnotation
+            
+            if (pdfAnnotation.page != nil) {
+                var indexs: IndexSet = IndexSet()
+                indexs.insert(IndexSet.Element(pdfAnnotation.page.pageIndex()))
+                self.reloadDataAtIndexs(indexs: indexs)
+            }
         }
     }