// // KMLeftSideViewController+Note.swift // PDF Reader Pro // // Created by tangchao on 2023/12/23. // import Foundation // Menu extension KMLeftSideViewController { @IBAction func note_expandAllComments(_ sender: AnyObject?) { if (self.foldType == .unfold) { return } self.foldType = .unfold self.loadUnfoldDate(.none) self.noteOutlineView.reloadData() } @IBAction func note_foldAllComments(_ sender: AnyObject?) { if (self.foldType == .fold) { return } self.foldType = .fold self.loadUnfoldDate(.none) self.noteOutlineView.reloadData() } @IBAction func noteShowNoteAction(_ sender: AnyObject?) { let item = sender as? NSMenuItem let tag = item?.tag ?? 0 if (tag == 100) { // BOOL isType = [[self.noteTypeDict objectForKey:@"kKMNoteFilterAnnotationTypeKey"] boolValue]; // [self.noteTypeDict setObject:[NSNumber numberWithBool:!isType] forKey:@"kKMNoteFilterAnnotationTypeKey"]; } else if (tag == 101) { let isPage = self.noteTypeDict["kKMNoteFilterAnnotationPageKey"] as? Bool ?? false self.noteTypeDict["kKMNoteFilterAnnotationPageKey"] = isPage } else if (tag == 102) { let isTime = self.noteTypeDict["kKMNoteFilterAnnotationTimeKey"] as? Bool ?? false self.noteTypeDict["kKMNoteFilterAnnotationTimeKey"] = isTime } else if (tag == 103) { let isAuther = self.noteTypeDict["kKMNoteFilterAnnotationAutherKey"] as? Bool ?? false self.noteTypeDict["kKMNoteFilterAnnotationAutherKey"] = isAuther } UserDefaults.standard.set(self.noteTypeDict, forKey: "KMNoteOutlineViewTableColumnKey") UserDefaults.standard.synchronize() let selectRow = self.noteOutlineView.selectedRow self.noteOutlineView.reloadData() self.noteOutlineView.selectRowIndexes(IndexSet(integer: selectRow), byExtendingSelection: false) } @objc func exportAnnotationNotes(_ sender: AnyObject?) { let doc = self.view.window?.windowController?.document as? NSDocument doc?.saveTo(sender) } @objc func leftSideEmptyAnnotationClick_DeleteAnnotation(_ sender: AnyObject?) { guard let doc = self.listView.document else { return } Task { let response = await KMAlertTool.runModel(message: KMLocalizedString("This will permanently remove all annotations. Are you sure to continue?", nil), buttons: [KMLocalizedString("Yes", nil), KMLocalizedString("No", nil)]) if response == .alertFirstButtonReturn { var annotations = NSMutableArray() for i in 0 ..< doc.pageCount { let page = self.listView.document.page(at: i) for anno in page?.annotations ?? [] { if anno is CPDFTextWidgetAnnotation || anno is CPDFButtonWidgetAnnotation || anno is CPDFChoiceWidgetAnnotation { continue } // if (@available(macOS 10.13, *)) { // if ([annotation.widgetFieldType isEqualToString:PDFAnnotationWidgetSubtypeSignature]) { // continue; // } // } // if anno is CPDFInkAnnotation { // continue // } annotations.add(anno) } } for anno in annotations { if let data = anno as? CPDFAnnotation { self.listView.remove(data) } } self.reloadAnnotation() self.noteOutlineView.reloadData() } } } @objc func unfoldNoteAction(_ sender: NSMenuItem) { if sender.state == .on { return } let row = self.noteOutlineView.clickedRow let foldNote = self.allAnnotations[row] if self.allFoldNotes.contains(foldNote) == false { self.allFoldNotes.append(foldNote) } if self.allFoldNotes.count == self.canFoldNotes.count { self.foldType = .unfold } else { self.foldType = .none } let viewS = self.noteOutlineView.view(atColumn: 0, row: row, makeIfNecessary: true) (viewS as? KMNoteTableViewCell)?.isFold = false } @objc func foldNoteAction(_ sender: NSMenuItem) { // if sender.state == .on { // return // } let row = self.noteOutlineView.clickedRow let foldNote = self.allAnnotations[row] if self.allFoldNotes.contains(foldNote) == false { self.allFoldNotes.append(foldNote) } if (self.allFoldNotes.count == 0) { self.foldType = .fold } else { self.foldType = .none } let viewS = self.noteOutlineView.view(atColumn: 0, row: row, makeIfNecessary: true) (viewS as? KMNoteTableViewCell)?.isFold = true } @objc func deleteNotes(_ sender: NSMenuItem) { self.outlineView(self.noteOutlineView, deleteItems: sender.representedObject as! [Any]) } @objc func removeAllAnnotations(_ sender: AnyObject?) { self.leftSideEmptyAnnotationClick_DeleteAnnotation(nil) } @objc func editNoteTextFromTable(_ sender: NSMenuItem) { // PDFAnnotation *annotation = [sender representedObject]; guard let annotation = sender.representedObject as? CPDFAnnotation else { return } self.listView.scrollAnnotationToVisible(annotation) // self.listView.activeAnnotation = annotation // [self showNote:annotation]; // SKNoteWindowController *noteController = (SKNoteWindowController *)[self windowControllerForNote:annotation]; // [[noteController window] makeFirstResponder:[noteController textView]]; // [[noteController textView] selectAll:nil]; } @objc func editThisAnnotation(_ sender: AnyObject?) { KMPrint("editThisAnnotation ...") } @objc func editNoteFromTable(_ sender: AnyObject?) { KMPrint("editNoteFromTable ...") } }