Переглянути джерело

【BOTA】大纲添加功能补充

tangchao 1 рік тому
батько
коміт
0325536e75

+ 16 - 0
PDF Office/PDF Master.xcodeproj/project.pbxproj

@@ -3260,6 +3260,12 @@
 		BB8B173C2907CDD9001C5EA5 /* NibLoadable.swift in Sources */ = {isa = PBXBuildFile; fileRef = BB8B173B2907CDD8001C5EA5 /* NibLoadable.swift */; };
 		BB8B173D2907CDD9001C5EA5 /* NibLoadable.swift in Sources */ = {isa = PBXBuildFile; fileRef = BB8B173B2907CDD8001C5EA5 /* NibLoadable.swift */; };
 		BB8B173E2907CDD9001C5EA5 /* NibLoadable.swift in Sources */ = {isa = PBXBuildFile; fileRef = BB8B173B2907CDD8001C5EA5 /* NibLoadable.swift */; };
+		BB8B99FD2B355E7600A066EC /* KMLeftSideViewController+Action.swift in Sources */ = {isa = PBXBuildFile; fileRef = BB8B99FC2B355E7600A066EC /* KMLeftSideViewController+Action.swift */; };
+		BB8B99FE2B355E7600A066EC /* KMLeftSideViewController+Action.swift in Sources */ = {isa = PBXBuildFile; fileRef = BB8B99FC2B355E7600A066EC /* KMLeftSideViewController+Action.swift */; };
+		BB8B99FF2B355E7600A066EC /* KMLeftSideViewController+Action.swift in Sources */ = {isa = PBXBuildFile; fileRef = BB8B99FC2B355E7600A066EC /* KMLeftSideViewController+Action.swift */; };
+		BB8B9A012B355EFB00A066EC /* KMLeftSideViewController+Outline.swift in Sources */ = {isa = PBXBuildFile; fileRef = BB8B9A002B355EFB00A066EC /* KMLeftSideViewController+Outline.swift */; };
+		BB8B9A022B355EFB00A066EC /* KMLeftSideViewController+Outline.swift in Sources */ = {isa = PBXBuildFile; fileRef = BB8B9A002B355EFB00A066EC /* KMLeftSideViewController+Outline.swift */; };
+		BB8B9A032B355EFB00A066EC /* KMLeftSideViewController+Outline.swift in Sources */ = {isa = PBXBuildFile; fileRef = BB8B9A002B355EFB00A066EC /* KMLeftSideViewController+Outline.swift */; };
 		BB8F453F295A98960037EA22 /* KMHeaderFooterPropertyController.swift in Sources */ = {isa = PBXBuildFile; fileRef = BB8F453D295A98960037EA22 /* KMHeaderFooterPropertyController.swift */; };
 		BB8F4540295A98960037EA22 /* KMHeaderFooterPropertyController.swift in Sources */ = {isa = PBXBuildFile; fileRef = BB8F453D295A98960037EA22 /* KMHeaderFooterPropertyController.swift */; };
 		BB8F4541295A98960037EA22 /* KMHeaderFooterPropertyController.swift in Sources */ = {isa = PBXBuildFile; fileRef = BB8F453D295A98960037EA22 /* KMHeaderFooterPropertyController.swift */; };
@@ -5522,6 +5528,8 @@
 		BB8B17312907B63D001C5EA5 /* CipherTextView.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = CipherTextView.swift; sourceTree = "<group>"; };
 		BB8B17352907B64D001C5EA5 /* CipherTextView.xib */ = {isa = PBXFileReference; lastKnownFileType = file.xib; path = CipherTextView.xib; sourceTree = "<group>"; };
 		BB8B173B2907CDD8001C5EA5 /* NibLoadable.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = NibLoadable.swift; sourceTree = "<group>"; };
+		BB8B99FC2B355E7600A066EC /* KMLeftSideViewController+Action.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = "KMLeftSideViewController+Action.swift"; sourceTree = "<group>"; };
+		BB8B9A002B355EFB00A066EC /* KMLeftSideViewController+Outline.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = "KMLeftSideViewController+Outline.swift"; sourceTree = "<group>"; };
 		BB8F453D295A98960037EA22 /* KMHeaderFooterPropertyController.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = KMHeaderFooterPropertyController.swift; sourceTree = "<group>"; };
 		BB8F453E295A98960037EA22 /* KMHeaderFooterPropertyController.xib */ = {isa = PBXFileReference; lastKnownFileType = file.xib; path = KMHeaderFooterPropertyController.xib; sourceTree = "<group>"; };
 		BB8F4545295A9CDC0037EA22 /* KMHeaderFooterListController.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = KMHeaderFooterListController.swift; sourceTree = "<group>"; };
@@ -6189,6 +6197,8 @@
 				ADCFFC0529C04617007D3657 /* BOTA.xcassets */,
 				8942F7BE2923670F00389627 /* KMBOTAManagerClass.swift */,
 				8997011D28F41AB8009AF911 /* KMLeftSideViewController.swift */,
+				BB8B99FC2B355E7600A066EC /* KMLeftSideViewController+Action.swift */,
+				BB8B9A002B355EFB00A066EC /* KMLeftSideViewController+Outline.swift */,
 				BB0B2CD72B04AE560088FFD8 /* LeftSideView.xib */,
 				8997011E28F41AB8009AF911 /* KMLeftSideViewController.xib */,
 				8942F7E82925E1C400389627 /* KMLiftSideCellView.swift */,
@@ -12623,6 +12633,7 @@
 				BBD25BF12B18768600EB85D4 /* KMCompressOperation.swift in Sources */,
 				BB3A81B52AC2C0F4006FC66C /* NSObject+KMExtension.swift in Sources */,
 				BB99ACCF292E2AEF0048AFD9 /* KMMergeCollectionViewItem.swift in Sources */,
+				BB8B99FD2B355E7600A066EC /* KMLeftSideViewController+Action.swift in Sources */,
 				BBF729AF2B1962C900576AC5 /* KMRemoveHeaderFooterQueue.swift in Sources */,
 				BB7648EC29ECEEF400931039 /* KMAppearance.swift in Sources */,
 				BB8B17322907B63D001C5EA5 /* CipherTextView.swift in Sources */,
@@ -13036,6 +13047,7 @@
 				894A00F22976314C0070ED83 /* KMPDFViewPanelSetViewController.swift in Sources */,
 				BB135C2A29B6CD9A00FD5965 /* KMTools.swift in Sources */,
 				89D2D2BD29486D2400BFF5FE /* KMSignatureCellView.swift in Sources */,
+				BB8B9A012B355EFB00A066EC /* KMLeftSideViewController+Outline.swift in Sources */,
 				9F1FE49629406E4700E952CA /* common.c in Sources */,
 				BBD1F79C296FF7A600343885 /* KMPageEditSplitSettingModel.swift in Sources */,
 				BB3198122AC5142900107371 /* NSMenu+KMExtension.swift in Sources */,
@@ -13481,6 +13493,7 @@
 				BB6719FE2AD2CE1B003D44D5 /* CPDFSquareAnnotation+PDFListView.swift in Sources */,
 				BB147018299DC0D100784A6A /* OIDGrantTypes.m in Sources */,
 				BB3D971B2B3060B5007094C8 /* KMPDFAnnotationRedactConfig.swift in Sources */,
+				BB8B9A022B355EFB00A066EC /* KMLeftSideViewController+Outline.swift in Sources */,
 				BB8F4540295A98960037EA22 /* KMHeaderFooterPropertyController.swift in Sources */,
 				ADBC373D29CA9AE100D93208 /* KMComparativeManager.swift in Sources */,
 				BB147009299DC0D100784A6A /* OIDRegistrationRequest.m in Sources */,
@@ -13904,6 +13917,7 @@
 				BB8F4561295AA39F0037EA22 /* KMHeaderFooterModel.swift in Sources */,
 				BBB9B326299A5D6D004F3235 /* GTMKeychain_macOS.m in Sources */,
 				BB146FAF299DC0D100784A6A /* GTLRService.m in Sources */,
+				BB8B99FE2B355E7600A066EC /* KMLeftSideViewController+Action.swift in Sources */,
 				9F1FE4C729406E4700E952CA /* CTUtil.m in Sources */,
 				BBD1F799296FF78C00343885 /* KMPageEditSettingBaseModel.swift in Sources */,
 				9FAAA33F290FECA70046FFCE /* NSImage+QuickLook.swift in Sources */,
@@ -14717,6 +14731,7 @@
 				AD3AAD3A2B0B7B1900DE5FE7 /* KMCompareToolbar.swift in Sources */,
 				AD8DD2A52A9C35B2007CC9D0 /* KMThumbnailManager.swift in Sources */,
 				BB6719FF2AD2CE1B003D44D5 /* CPDFSquareAnnotation+PDFListView.swift in Sources */,
+				BB8B99FF2B355E7600A066EC /* KMLeftSideViewController+Action.swift in Sources */,
 				BB146FBF299DC0D100784A6A /* GTMGatherInputStream.m in Sources */,
 				BB8116012992682F0008F536 /* KMSecureLimitAlertView.swift in Sources */,
 				AD3A3589294C11ED00D72802 /* KMPrintPreviewPresenter.swift in Sources */,
@@ -14917,6 +14932,7 @@
 				BB4F7E8F2B0C7FE70077EC8C /* KMNoteColorCollectionViewItem.swift in Sources */,
 				BB7648EE29ECEEF400931039 /* KMAppearance.swift in Sources */,
 				BB4A94932B04926700940F8B /* KMGOCROperation.swift in Sources */,
+				BB8B9A032B355EFB00A066EC /* KMLeftSideViewController+Outline.swift in Sources */,
 				9FDD0F8E2952FCE0000C4DAD /* KMGlobalParser.swift in Sources */,
 				BBC348352955A118008D2CD1 /* KMCreateBackgroundController.swift in Sources */,
 				89E4E757296427E5002DBA6F /* NSImage_SKExtensions.m in Sources */,

+ 12 - 0
PDF Office/PDF Master/Class/PDFWindowController/Side/LeftSide/KMLeftSideViewController+Action.swift

@@ -0,0 +1,12 @@
+//
+//  KMLeftSideViewController+Action.swift
+//  PDF Master
+//
+//  Created by tangchao on 2023/12/22.
+//
+
+import Foundation
+
+extension KMLeftSideViewController {
+    
+}

+ 64 - 0
PDF Office/PDF Master/Class/PDFWindowController/Side/LeftSide/KMLeftSideViewController+Outline.swift

@@ -0,0 +1,64 @@
+//
+//  KMLeftSideViewController+Outline.swift
+//  PDF Master
+//
+//  Created by tangchao on 2023/12/22.
+//
+
+import Foundation
+
+extension KMLeftSideViewController {
+    func updateOutlineSelection() {
+//        if ([[pdfView document] outlineRoot] == nil || mwcFlags.updatingOutlineSelection)
+        if self.listView.document.outlineRoot() == nil {
+            return
+        }
+//        mwcFlags.updatingOutlineSelection = YES;
+        let numRows = self.tocOutlineView.numberOfRows
+        
+        var arr = NSMutableArray()
+        for i in 0 ..< numRows {
+            guard let tPDFOutline = self.tocOutlineView.item(atRow: i) as? CPDFOutline else {
+                continue
+            }
+            let tPage = tPDFOutline.destination.page()
+            if (tPage == nil) {
+                continue
+            }
+
+            let tDict = NSDictionary(object: tPage as Any, forKey: "\(i)" as NSCopying)
+            arr.add(tDict)
+        }
+        let currentPage = self.listView.currentPage()
+        var hasExistInOutlineView = false
+        for dict in arr {
+            guard let _dict = dict as? NSDictionary else {
+                continue
+            }
+            let page = _dict.allValues.last as? CPDFPage
+//            NSInteger index = [dict.allKeys.lastObject integerValue];
+            let index = Int(_dict.allKeys.last as? String ?? "0") ?? 0
+            if let data = page?.isEqual(to: currentPage), data {
+                self.tocOutlineView.selectRowIndexes(IndexSet(integer: index), byExtendingSelection: false)
+                self.tocOutlineView.scrollRowToVisible(index)
+                hasExistInOutlineView = true
+                break
+            }
+        }
+        if (!hasExistInOutlineView) {
+            self.tocOutlineView.deselectRow(self.tocOutlineView.selectedRow)
+        }
+//        mwcFlags.updatingOutlineSelection = NO;
+    }
+     
+    func newAddOutlineEntryEditingMode(_ index: Int) {
+        self.renamePDFOutline = self.tocOutlineView.item(atRow: self.tocOutlineView.selectedRow) as? CPDFOutline
+        let row = self.tocOutlineView.selectedRow
+        let viewS = self.tocOutlineView.view(atColumn: 0, row: row, makeIfNecessary: true)
+        let targrtTextField = viewS?.subviews.first as? NSTextField
+        self.renamePDFOutlineTextField = targrtTextField
+        targrtTextField?.delegate = self
+        targrtTextField?.isEditable = true
+        targrtTextField?.becomeFirstResponder()
+    }
+}

+ 94 - 49
PDF Office/PDF Master/Class/PDFWindowController/Side/LeftSide/KMLeftSideViewController.swift

@@ -230,6 +230,9 @@ class KMLeftSideViewController: KMSideViewController {
     
     private var allFoldNotes: [CPDFAnnotation] = []
     
+    var renamePDFOutline: CPDFOutline?
+    var renamePDFOutlineTextField: NSTextField?
+    
     override func loadView() {
         super.loadView()
         
@@ -901,8 +904,6 @@ class KMLeftSideViewController: KMSideViewController {
         frame.size.height = self.snapshotTableView.enclosingScrollView?.superview?.frame.size.height ?? 0
         self.snapshotTableView.enclosingScrollView?.frame = frame
         
-//        [self updateOutlineSelection];
-        
         let view = self.tocOutlineView.enclosingScrollView!
         let emptyVcSize =  self.leftSideEmptyVC.emptyOutlineView.frame.size
         
@@ -910,6 +911,7 @@ class KMLeftSideViewController: KMSideViewController {
         
         DispatchQueue.main.async {
             self.tocOutlineView.reloadData()
+            self.updateOutlineSelection()
         }
     }
     
@@ -1407,52 +1409,6 @@ class KMLeftSideViewController: KMSideViewController {
         self.outlineSearchField.becomeFirstResponder()
     }
     
-//    @objc func outlineContextMenuItemClicked_AddEntry(_ sender: NSMenuItem) {
-//        NSMutableArray *PDFOutlineArray = [[NSMutableArray new] autorelease];
-//        NSIndexSet *rowSet = [self selectedRowIndexes] ;
-//
-//        [rowSet enumerateIndexesUsingBlock:^(NSUInteger idx, BOOL * _Nonnull stop) {
-//            [PDFOutlineArray addObject:[leftSideController.tocOutlineView itemAtRow:idx]];
-//        }];
-//
-//        if (PDFOutlineArray.count == 0) {
-//            PDFOutline *lastPDFLine = [leftSideController.tocOutlineView itemAtRow:leftSideController.tocOutlineView.numberOfRows - 1];
-//
-//            PDFOutline *rootPDFOutline;
-//            if (lastPDFLine) {
-//                while (lastPDFLine.parent) {
-//                    lastPDFLine = lastPDFLine.parent;
-//                }
-//                rootPDFOutline = lastPDFLine;
-//            } else {
-//                rootPDFOutline = self.pdfView.document.outlineRoot;
-//                if (!rootPDFOutline) {
-//                    rootPDFOutline = [[[PDFOutline alloc] init] autorelease];
-//                    [self.pdfView.document setOutlineRoot:rootPDFOutline];
-//                }
-//            }
-//
-//            PDFOutline *addOutLine = [[[PDFOutline alloc] init] autorelease];
-//            addOutLine.label = [NSString stringWithFormat:@"%@ %ld",NSLocalizedString(@"Page", nil) ,[self.pdfView.document indexForPage:self.pdfView.currentDestination.page] + 1];
-//            addOutLine.destination = self.pdfView.currentDestination;
-//            [self addoutlineWithParent:rootPDFOutline addOutline:addOutLine index:rootPDFOutline.numberOfChildren needExpand:NO];
-//
-//        } else {
-//            PDFOutline *currentPDFline = PDFOutlineArray.lastObject;
-//            NSInteger currentIndex = currentPDFline.index;
-//            PDFOutline *parent;
-//            parent  = currentPDFline.parent;
-//
-//            PDFOutline *addOutLine = [[[PDFOutline alloc] init] autorelease];
-//            addOutLine.label = [NSString stringWithFormat:@"%@ %ld",NSLocalizedString(@"Page", nil) ,[self.pdfView.document indexForPage:self.pdfView.currentDestination.page] + 1];
-//            addOutLine.destination = self.pdfView.currentDestination;
-//            [self addoutlineWithParent:parent addOutline:addOutLine index:currentIndex + 1 needExpand:NO];
-//            [self.leftSideController.tocOutlineView scrollRowToVisible:currentIndex + 1];
-//            [self.leftSideController.tocOutlineView deselectRow:currentIndex+1];
-//
-//        }
-//    }
-    
     @IBAction func toc_expandAllComments(_ sender: AnyObject?) {
         if (self.tocType == .unfold) {
             return
@@ -5539,7 +5495,49 @@ extension KMLeftSideViewController {
     }
     
     @objc func outlineContextMenuItemClicked_AddEntry(_ sender: AnyObject?) {
-        KMPrint("KMLeftSideViewController-outlineContextMenuItemClicked_AddEntry...")
+        var PDFOutlineArray = NSMutableArray()
+        let rowSet = self.selectedRowIndexes()
+
+        for idx in rowSet {
+            PDFOutlineArray.add(self.tocOutlineView.item(atRow: idx))
+        }
+
+        if (PDFOutlineArray.count == 0) {
+            var lastPDFLine = self.tocOutlineView.item(atRow: self.tocOutlineView.numberOfRows-1) as? CPDFOutline
+
+            var rootPDFOutline: CPDFOutline?
+            if (lastPDFLine != nil) {
+                while (lastPDFLine!.parent != nil) {
+                    lastPDFLine = lastPDFLine?.parent
+                }
+                rootPDFOutline = lastPDFLine
+            } else {
+                rootPDFOutline = self.listView.document.outlineRoot()
+                if ((rootPDFOutline == nil)) {
+                    rootPDFOutline = CPDFOutline()
+                    
+                    self.listView.document.setOutlineRoot(rootPDFOutline)
+                }
+            }
+
+            let addOutLine = CPDFOutline()
+            addOutLine.label = String(format: "%@ %ld", KMLocalizedString("Page", nil), self.listView.currentPageIndex+1)
+            addOutLine.destination = self.listView.currentDestination
+            self.addoutline(parent: rootPDFOutline, addOutline: addOutLine, index: Int(rootPDFOutline?.numberOfChildren ?? 0), needExpand: false)
+        } else {
+            let currentPDFline = PDFOutlineArray.lastObject as? CPDFOutline
+            let currentIndex = currentPDFline?.index ?? 0
+            var parent: CPDFOutline?
+            parent  = currentPDFline?.parent
+
+            let addOutLine = CPDFOutline()
+            
+            addOutLine.label = String(format: "%@ %ld", KMLocalizedString("Page", nil), self.listView.currentPageIndex+1)
+            addOutLine.destination = self.listView.currentDestination
+            self.addoutline(parent: parent, addOutline: addOutLine, index: Int(currentIndex) + 1, needExpand: false)
+            self.tocOutlineView.scrollRowToVisible(Int(currentIndex) + 1)
+            self.tocOutlineView.deselectRow(Int(currentIndex)+1)
+        }
     }
     
     @objc func outlineContextMenuItemClicked_AddChildEntry(_ sender: AnyObject?) {
@@ -5924,6 +5922,53 @@ extension KMLeftSideViewController {
         }
         return ""
     }
+    
+    // MARK: - Outline
+    
+    func selectedRowIndexes() -> IndexSet {
+        var selectedIndexes = self.tocOutlineView.selectedRowIndexes
+        let clickedRow = self.tocOutlineView.clickedRow
+        if clickedRow != -1 && selectedIndexes.contains(clickedRow) == false {
+            var indexes = IndexSet(integer: clickedRow)
+            selectedIndexes = indexes
+        }
+        return selectedIndexes
+    }
+     
+    func addoutline(parent parentOutline: CPDFOutline?, addOutline: CPDFOutline, index: Int, needExpand: Bool) {
+        var tempO = addOutline
+        if addOutline.label != nil {
+            parentOutline?.insertChild(addOutline, at: UInt(index))
+        } else {
+            let outline = parentOutline?.insertChild(at: UInt(index))
+            outline?.label = String(format: "%@ %ld", KMLocalizedString("Page", nil), self.listView.currentPageIndex+1)
+            outline?.destination = self.listView.currentDestination
+            tempO = outline!
+        }
+        
+//        [[[self.document undoManager] prepareWithInvocationTarget:self] removeOutlineWithParent:parentOutline removeOutline:addOutline index:index needExpand:needExpand];
+
+        self.view.window?.makeFirstResponder(nil)
+
+        Task { @MainActor in
+            self.tocOutlineView.reloadData()
+            
+            if (needExpand) {
+                self.tocOutlineView.expandItem(parentOutline)
+            }
+            let idx = self.tocOutlineView.row(forItem: tempO)
+            self.tocOutlineView.selectRowIndexes(IndexSet(integer: idx), byExtendingSelection: false)
+            
+            self.newAddOutlineEntryEditingMode(index)
+        }
+
+//        __block PDFOutline *taddOutline = [addOutline retain];
+//        dispatch_after(dispatch_time(DISPATCH_TIME_NOW, (int64_t)(0.1 * NSEC_PER_SEC)), dispatch_get_main_queue(), ^{
+//            [self.leftSideController.tocOutlineView scrollRowToVisible:[leftSideController.tocOutlineView rowForItem:taddOutline]];
+//            [taddOutline release];
+//        });
+
+    }
 
 }