Browse Source

【BOTA】注释 筛选逻辑调整(需要保留筛选数据,关闭文档后清除筛选数据)

lizhe 1 year ago
parent
commit
d8229ecb09

+ 1 - 0
PDF Office/PDF Master/Class/ChromiumTabs/src/Tab/CTTabController.m

@@ -228,6 +228,7 @@ static NSString* const kBrowserThemeDidChangeNotification =
 		[[self target] performSelector:@selector(closeTab:)
 							withObject:[self view]];
 	}
+    [[NSNotificationCenter defaultCenter] postNotificationName:@"KMTabControllerCloseTabs" object:self];
 }
 
 - (void)setTitle:(NSString*)title {

+ 8 - 3
PDF Office/PDF Master/Class/PDFWindowController/Side/LeftSide/Annotation/KMAnnotationViewController.swift

@@ -47,6 +47,10 @@ class KMAnnotationViewController: KMSideViewController {
     //localEvent
     var localEvent: Bool = false
     
+    
+    deinit {
+        print("KMAnnotationViewController")
+    }
     //MARK: View
         
     override func viewDidLoad() {
@@ -182,17 +186,17 @@ extension KMAnnotationViewController {
         var authorArr: [Any] = []
         
         let sud = UserDefaults.standard
-        let typeData = sud.object(forKey: "KMNoteOutlineFilterSelectArray_Type") as? Data
+        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") as? Data
+        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") as? Data
+        let authorData = sud.object(forKey: "KMNoteOutlineFilterSelectArray_Author" + self.listView.document.documentURL.path) as? Data
         if authorData != nil {
             authorArr = NSKeyedUnarchiver.unarchiveObject(with: authorData!) as! [Any]
         }
@@ -354,6 +358,7 @@ extension KMAnnotationViewController {
     @IBAction func filtrateButtonAction(_ sender: NSButton) {
         let menu = NSMenu()
         let filterVC = KMNoteOutlineFilterViewController()
+        filterVC.path = self.listView.document.documentURL.path
         filterVC.notesArray = self.allAnnotations
         filterVC.applyFilterCallback = { typeArr, colorArr,authArr,isEmpty in
             menu.cancelTracking()

+ 2 - 2
PDF Office/PDF Master/Class/PDFWindowController/Side/LeftSide/Annotation/KMAnnotationViewController.xib

@@ -5,7 +5,7 @@
         <capability name="documents saved in the Xcode 8 format" minToolsVersion="8.0"/>
     </dependencies>
     <objects>
-        <customObject id="-2" userLabel="File's Owner" customClass="KMAnnotationViewController" customModule="PDF_Office" customModuleProvider="target">
+        <customObject id="-2" userLabel="File's Owner" customClass="KMAnnotationViewController" customModule="PDF_Master" customModuleProvider="target">
             <connections>
                 <outlet property="annotationOutlineView" destination="xR1-8d-nCT" id="0AI-9O-2Va"/>
                 <outlet property="bigTipLabel" destination="Hgo-wn-Zbx" id="4WH-gT-Ehl"/>
@@ -24,7 +24,7 @@
             <rect key="frame" x="0.0" y="0.0" width="300" height="499"/>
             <autoresizingMask key="autoresizingMask" flexibleMaxX="YES" flexibleMinY="YES"/>
             <subviews>
-                <customView translatesAutoresizingMaskIntoConstraints="NO" id="xR1-8d-nCT" customClass="KMAnnotationOutlineView" customModule="PDF_Office" customModuleProvider="target">
+                <customView translatesAutoresizingMaskIntoConstraints="NO" id="xR1-8d-nCT" customClass="KMAnnotationOutlineView" customModule="PDF_Master" customModuleProvider="target">
                     <rect key="frame" x="0.0" y="0.0" width="300" height="451"/>
                 </customView>
                 <customView translatesAutoresizingMaskIntoConstraints="NO" id="nAQ-GY-tve">

+ 1 - 0
PDF Office/PDF Master/Class/PDFWindowController/Side/LeftSide/Annotation/KMNoteOutlineFilterViewController.h

@@ -14,6 +14,7 @@
 @property (nonatomic, retain) NSMutableArray *selectTypeArray;
 @property (nonatomic, retain) NSMutableArray *selectColorArray;
 @property (nonatomic, retain) NSMutableArray *selectAuthorArray;
+@property (nonatomic, retain) NSString *path;
 
 @property (nonatomic,copy) void (^applyFilterCallback) (NSArray *authorArr, NSArray *colorArr, NSArray *typeArr, BOOL isEmpty);
 

+ 6 - 6
PDF Office/PDF Master/Class/PDFWindowController/Side/LeftSide/Annotation/KMNoteOutlineFilterViewController.m

@@ -103,21 +103,21 @@ NSString *KMNoteOutlineFilterSelectArray_Color = @"KMNoteOutlineFilterSelectArra
 
     
     NSUserDefaults *sud = [NSUserDefaults standardUserDefaults];
-    NSData *typeData = [sud objectForKey:@"KMNoteOutlineFilterSelectArray_Type"];
+    NSData *typeData = [sud objectForKey: [NSString stringWithFormat:@"%@%@",KMNoteOutlineFilterSelectArray_Type, self.path]];
     NSArray *typeArr = (NSArray *)[NSKeyedUnarchiver unarchiveObjectWithData:typeData];
     if (typeArr) {
         self.selectTypeArray = [[NSMutableArray alloc] initWithArray:typeArr];
     } else {
         self.selectTypeArray = [[NSMutableArray alloc] init];
     }
-    NSData *colorData = [sud objectForKey:@"KMNoteOutlineFilterSelectArray_Color"];
+    NSData *colorData = [sud objectForKey: [NSString stringWithFormat:@"%@%@",KMNoteOutlineFilterSelectArray_Color, self.path]];
     NSArray *colorArr = (NSArray *)[NSKeyedUnarchiver unarchiveObjectWithData:colorData];
     if (colorArr) {
         self.selectColorArray = [[NSMutableArray alloc] initWithArray:colorArr];
     } else {
         self.selectColorArray = [[NSMutableArray alloc] init];
     }
-    NSData *authorData = [sud objectForKey:@"KMNoteOutlineFilterSelectArray_Author"];
+    NSData *authorData = [sud objectForKey: [NSString stringWithFormat:@"%@%@",KMNoteOutlineFilterSelectArray_Author, self.path]];
     NSArray *authorArr = (NSArray *)[NSKeyedUnarchiver unarchiveObjectWithData:authorData];
     if (authorArr) {
         self.selectAuthorArray = [[NSMutableArray alloc] initWithArray:authorArr];
@@ -312,9 +312,9 @@ NSString *KMNoteOutlineFilterSelectArray_Color = @"KMNoteOutlineFilterSelectArra
     NSData *data3 = [NSKeyedArchiver archivedDataWithRootObject:[NSArray arrayWithArray:_selectAuthorArray]];
     
     NSUserDefaults *sud = [NSUserDefaults standardUserDefaults];
-    [sud setObject:data1 forKey:KMNoteOutlineFilterSelectArray_Type];
-    [sud setObject:data2 forKey:KMNoteOutlineFilterSelectArray_Color];
-    [sud setObject:data3 forKey:KMNoteOutlineFilterSelectArray_Author];
+    [sud setObject:data1 forKey:[NSString stringWithFormat:@"%@%@",KMNoteOutlineFilterSelectArray_Type, self.path]];
+    [sud setObject:data2 forKey:[NSString stringWithFormat:@"%@%@",KMNoteOutlineFilterSelectArray_Color, self.path]];
+    [sud setObject:data3 forKey:[NSString stringWithFormat:@"%@%@",KMNoteOutlineFilterSelectArray_Author, self.path]];
     [sud synchronize];
     
     BOOL isEmpty = NO;

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

@@ -569,4 +569,18 @@ extension KMLeftSideViewController {
     }
 }
 
+//MARK: Cache
+extension KMLeftSideViewController {
+    func clearAnnotationFilterData() {
+        let userDefaults = UserDefaults.standard
+
+        let typeData = try?NSKeyedArchiver.archivedData(withRootObject: [Any](), requiringSecureCoding: false)
+        userDefaults.set(typeData, forKey: "KMNoteOutlineFilterSelectArray_Type" + self.listView.document.documentURL.path)
+        let colorData = try?NSKeyedArchiver.archivedData(withRootObject: [Any](), requiringSecureCoding: false)
+        userDefaults.set(colorData, forKey: "KMNoteOutlineFilterSelectArray_Color" + self.listView.document.documentURL.path)
+        let authorData = try?NSKeyedArchiver.archivedData(withRootObject: [Any](), requiringSecureCoding: false)
+        userDefaults.set(authorData, forKey: "KMNoteOutlineFilterSelectArray_Author" + self.listView.document.documentURL.path)
+        userDefaults.synchronize()
+    }
+}
 

+ 8 - 0
PDF Office/PDF Master/Class/PDFWindowController/ViewController/KMMainViewController+Action.swift

@@ -1537,6 +1537,14 @@ extension KMMainViewController {
         self.leftSideViewController.annotationViewController.annotationShowState = self.listView.hideNotes ? .hidden : .none
     }
     
+    func closeTab(_ sender: NSNotification) -> Void {
+        let tabController = sender.object as? CTTabController
+        if tabController?.title == self.document?.documentURL.lastPathComponent {
+            print("closeTab")
+            self.leftSideViewController.clearAnnotationFilterData()
+        }
+    }
+    
     // MARK: -
     // MARK: 显示窗口
     

+ 1 - 0
PDF Office/PDF Master/Class/PDFWindowController/ViewController/KMMainViewController.swift

@@ -272,6 +272,7 @@ import Cocoa
         readModelView.delegate = self
 
         NotificationCenter.default.addObserver(self, selector: #selector(rename(_:)), name: NSNotification.Name.init(rawValue: "KMTabControllerRename"), object: nil)
+        NotificationCenter.default.addObserver(self, selector: #selector(closeTab(_:)), name: NSNotification.Name.init(rawValue: "KMTabControllerCloseTabs"), object: nil)
         NotificationCenter.default.addObserver(self, selector: #selector(showInFinder(_:)), name: NSNotification.Name.init(rawValue: "KMTabControllerShowInFinder"), object: nil)
         NotificationCenter.default.addObserver(self, selector: #selector(preferenceDidChangeNotification), name: KMPreferenceManager.didChangeNotification, object: nil)
         NotificationCenter.default.addObserver(self, selector: #selector(documentDidUnlockNotification), name: Notification.Name("CPDFDocumentDidUnlockNotification"), object: nil)

+ 6 - 7
PDF Office/PDF Master/Class/PDFWindowController/ViewController/KMMainViewController.xib

@@ -1,12 +1,11 @@
 <?xml version="1.0" encoding="UTF-8"?>
 <document type="com.apple.InterfaceBuilder3.Cocoa.XIB" version="3.0" toolsVersion="21701" targetRuntime="MacOSX.Cocoa" propertyAccessControl="none" useAutolayout="YES" customObjectInstantitationMethod="direct">
     <dependencies>
-        <deployment identifier="macosx"/>
         <plugIn identifier="com.apple.InterfaceBuilder.CocoaPlugin" version="21701"/>
         <capability name="documents saved in the Xcode 8 format" minToolsVersion="8.0"/>
     </dependencies>
     <objects>
-        <customObject id="-2" userLabel="File's Owner" customClass="KMMainViewController" customModule="PDF_Office" customModuleProvider="target">
+        <customObject id="-2" userLabel="File's Owner" customClass="KMMainViewController" customModule="PDF_Master" customModuleProvider="target">
             <connections>
                 <outlet property="PDFContendView" destination="yMu-ou-GV9" id="diy-Q0-PHp"/>
                 <outlet property="bottomAreaView" destination="z7q-Gv-vF1" id="7WI-Yd-Ayi"/>
@@ -74,14 +73,14 @@ Gw
                                         <customView translatesAutoresizingMaskIntoConstraints="NO" id="Cdz-fv-u4h" customClass="CPDFListView">
                                             <rect key="frame" x="0.0" y="0.0" width="1000" height="578"/>
                                         </customView>
-                                        <customView hidden="YES" translatesAutoresizingMaskIntoConstraints="NO" id="3E1-9V-2lu" customClass="KMReadModelView" customModule="PDF_Office" customModuleProvider="target">
+                                        <customView hidden="YES" translatesAutoresizingMaskIntoConstraints="NO" id="3E1-9V-2lu" customClass="KMReadModelView" customModule="PDF_Master" customModuleProvider="target">
                                             <rect key="frame" x="325" y="16" width="350" height="32"/>
                                             <constraints>
                                                 <constraint firstAttribute="width" constant="350" id="8go-j7-y2w"/>
                                                 <constraint firstAttribute="height" constant="32" id="Opl-4j-wTU"/>
                                             </constraints>
                                         </customView>
-                                        <box boxType="custom" borderWidth="0.0" cornerRadius="4" title="Box" translatesAutoresizingMaskIntoConstraints="NO" id="zKE-Pq-I7d" customClass="KMBox" customModule="PDF_Office" customModuleProvider="target">
+                                        <box boxType="custom" borderWidth="0.0" cornerRadius="4" title="Box" translatesAutoresizingMaskIntoConstraints="NO" id="zKE-Pq-I7d" customClass="KMBox" customModule="PDF_Master" customModuleProvider="target">
                                             <rect key="frame" x="4" y="14" width="60" height="24"/>
                                             <view key="contentView" id="cbK-wK-42I">
                                                 <rect key="frame" x="0.0" y="0.0" width="60" height="24"/>
@@ -155,7 +154,7 @@ Gw
                                 <constraint firstAttribute="height" constant="32" id="Yz2-02-Ux4"/>
                             </constraints>
                         </box>
-                        <box boxType="custom" borderWidth="0.0" cornerRadius="4" translatesAutoresizingMaskIntoConstraints="NO" id="z7q-Gv-vF1" customClass="KMBox" customModule="PDF_Office" customModuleProvider="target">
+                        <box boxType="custom" borderWidth="0.0" cornerRadius="4" translatesAutoresizingMaskIntoConstraints="NO" id="z7q-Gv-vF1" customClass="KMBox" customModule="PDF_Master" customModuleProvider="target">
                             <rect key="frame" x="0.0" y="0.0" width="1335" height="48"/>
                             <view key="contentView" id="y3C-Id-Gzh">
                                 <rect key="frame" x="0.0" y="0.0" width="1335" height="48"/>
@@ -203,8 +202,8 @@ Gw
             </constraints>
             <point key="canvasLocation" x="457.5" y="352.5"/>
         </customView>
-        <viewController id="2rl-M4-8Gt" customClass="KMToolbarViewController" customModule="PDF_Office" customModuleProvider="target"/>
-        <viewController id="IRu-me-bV3" customClass="KMToolbarController" customModule="PDF_Office" customModuleProvider="target"/>
+        <viewController id="2rl-M4-8Gt" customClass="KMToolbarViewController" customModule="PDF_Master" customModuleProvider="target"/>
+        <viewController id="IRu-me-bV3" customClass="KMToolbarController" customModule="PDF_Master" customModuleProvider="target"/>
         <splitView dividerStyle="thin" vertical="YES" id="r2n-G7-pBF" customClass="KMSplitView">
             <rect key="frame" x="0.0" y="0.0" width="265" height="250"/>
             <autoresizingMask key="autoresizingMask" widthSizable="YES" heightSizable="YES"/>