Browse Source

【OCToSwift】CPDFListAnnotationNoteWindowController替换为Swift

wanjun 1 year ago
parent
commit
5dd7c1cc16

+ 8 - 10
PDF Office/PDF Master.xcodeproj/project.pbxproj

@@ -1000,6 +1000,9 @@
 		9FD0D2AF2AD51BCC00DA3FF8 /* CPDFListEditAnnotationViewController.swift in Sources */ = {isa = PBXBuildFile; fileRef = 9FD0D2AE2AD51BCC00DA3FF8 /* CPDFListEditAnnotationViewController.swift */; };
 		9FD0D2B02AD51BCC00DA3FF8 /* CPDFListEditAnnotationViewController.swift in Sources */ = {isa = PBXBuildFile; fileRef = 9FD0D2AE2AD51BCC00DA3FF8 /* CPDFListEditAnnotationViewController.swift */; };
 		9FD0D2B12AD51BCC00DA3FF8 /* CPDFListEditAnnotationViewController.swift in Sources */ = {isa = PBXBuildFile; fileRef = 9FD0D2AE2AD51BCC00DA3FF8 /* CPDFListEditAnnotationViewController.swift */; };
+		9FD0D2B32AD5265A00DA3FF8 /* CPDFListAnnotationNoteWindowController.swift in Sources */ = {isa = PBXBuildFile; fileRef = 9FD0D2B22AD5265A00DA3FF8 /* CPDFListAnnotationNoteWindowController.swift */; };
+		9FD0D2B42AD5265A00DA3FF8 /* CPDFListAnnotationNoteWindowController.swift in Sources */ = {isa = PBXBuildFile; fileRef = 9FD0D2B22AD5265A00DA3FF8 /* CPDFListAnnotationNoteWindowController.swift */; };
+		9FD0D2B52AD5265A00DA3FF8 /* CPDFListAnnotationNoteWindowController.swift in Sources */ = {isa = PBXBuildFile; fileRef = 9FD0D2B22AD5265A00DA3FF8 /* CPDFListAnnotationNoteWindowController.swift */; };
 		9FD0FA2929CD3ED400F2AB0D /* KMRightSideEmptyVC.swift in Sources */ = {isa = PBXBuildFile; fileRef = 9FD0FA2729CD3ED400F2AB0D /* KMRightSideEmptyVC.swift */; };
 		9FD0FA2A29CD3ED400F2AB0D /* KMRightSideEmptyVC.swift in Sources */ = {isa = PBXBuildFile; fileRef = 9FD0FA2729CD3ED400F2AB0D /* KMRightSideEmptyVC.swift */; };
 		9FD0FA2B29CD3ED400F2AB0D /* KMRightSideEmptyVC.swift in Sources */ = {isa = PBXBuildFile; fileRef = 9FD0FA2729CD3ED400F2AB0D /* KMRightSideEmptyVC.swift */; };
@@ -3264,9 +3267,6 @@
 		F34BF9532953DA91002C25A2 /* NSGeometry+PDFListView.m in Sources */ = {isa = PBXBuildFile; fileRef = F34BF9522953DA91002C25A2 /* NSGeometry+PDFListView.m */; };
 		F34BF9542953DA91002C25A2 /* NSGeometry+PDFListView.m in Sources */ = {isa = PBXBuildFile; fileRef = F34BF9522953DA91002C25A2 /* NSGeometry+PDFListView.m */; };
 		F34BF9552953DA91002C25A2 /* NSGeometry+PDFListView.m in Sources */ = {isa = PBXBuildFile; fileRef = F34BF9522953DA91002C25A2 /* NSGeometry+PDFListView.m */; };
-		F356720529AF184A00740FF3 /* CPDFListAnnotationNoteWindowController.m in Sources */ = {isa = PBXBuildFile; fileRef = F356720329AF184A00740FF3 /* CPDFListAnnotationNoteWindowController.m */; };
-		F356720629AF184A00740FF3 /* CPDFListAnnotationNoteWindowController.m in Sources */ = {isa = PBXBuildFile; fileRef = F356720329AF184A00740FF3 /* CPDFListAnnotationNoteWindowController.m */; };
-		F356720729AF184A00740FF3 /* CPDFListAnnotationNoteWindowController.m in Sources */ = {isa = PBXBuildFile; fileRef = F356720329AF184A00740FF3 /* CPDFListAnnotationNoteWindowController.m */; };
 		F356720829AF184A00740FF3 /* CPDFListAnnotationNoteWindowController.xib in Resources */ = {isa = PBXBuildFile; fileRef = F356720429AF184A00740FF3 /* CPDFListAnnotationNoteWindowController.xib */; };
 		F356720929AF184A00740FF3 /* CPDFListAnnotationNoteWindowController.xib in Resources */ = {isa = PBXBuildFile; fileRef = F356720429AF184A00740FF3 /* CPDFListAnnotationNoteWindowController.xib */; };
 		F356720A29AF184A00740FF3 /* CPDFListAnnotationNoteWindowController.xib in Resources */ = {isa = PBXBuildFile; fileRef = F356720429AF184A00740FF3 /* CPDFListAnnotationNoteWindowController.xib */; };
@@ -3893,6 +3893,7 @@
 		9FD0D2A62AD4EFB000DA3FF8 /* KMSavePanelAccessoryController.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = KMSavePanelAccessoryController.swift; sourceTree = "<group>"; };
 		9FD0D2AA2AD5143D00DA3FF8 /* KMTableRowView.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = KMTableRowView.swift; sourceTree = "<group>"; };
 		9FD0D2AE2AD51BCC00DA3FF8 /* CPDFListEditAnnotationViewController.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = CPDFListEditAnnotationViewController.swift; sourceTree = "<group>"; };
+		9FD0D2B22AD5265A00DA3FF8 /* CPDFListAnnotationNoteWindowController.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = CPDFListAnnotationNoteWindowController.swift; sourceTree = "<group>"; };
 		9FD0FA2729CD3ED400F2AB0D /* KMRightSideEmptyVC.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = KMRightSideEmptyVC.swift; sourceTree = "<group>"; };
 		9FD0FA2829CD3ED400F2AB0D /* KMRightSideEmptyVC.xib */ = {isa = PBXFileReference; lastKnownFileType = file.xib; path = KMRightSideEmptyVC.xib; sourceTree = "<group>"; };
 		9FD0FA2F29CD947000F2AB0D /* KMOpacityPanel.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = KMOpacityPanel.swift; sourceTree = "<group>"; };
@@ -4777,8 +4778,6 @@
 		F34BF93429530708002C25A2 /* NSImage+PDFListView.m */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.objc; path = "NSImage+PDFListView.m"; sourceTree = "<group>"; };
 		F34BF9512953DA91002C25A2 /* NSGeometry+PDFListView.h */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.h; path = "NSGeometry+PDFListView.h"; sourceTree = "<group>"; };
 		F34BF9522953DA91002C25A2 /* NSGeometry+PDFListView.m */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.objc; path = "NSGeometry+PDFListView.m"; sourceTree = "<group>"; };
-		F356720229AF184A00740FF3 /* CPDFListAnnotationNoteWindowController.h */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.h; path = CPDFListAnnotationNoteWindowController.h; sourceTree = "<group>"; };
-		F356720329AF184A00740FF3 /* CPDFListAnnotationNoteWindowController.m */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.objc; path = CPDFListAnnotationNoteWindowController.m; sourceTree = "<group>"; };
 		F356720429AF184A00740FF3 /* CPDFListAnnotationNoteWindowController.xib */ = {isa = PBXFileReference; lastKnownFileType = file.xib; path = CPDFListAnnotationNoteWindowController.xib; sourceTree = "<group>"; };
 		F359916729261F0D000D25DE /* CPDFListView+Tool.h */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.h; path = "CPDFListView+Tool.h"; sourceTree = "<group>"; };
 		F359916829261F0D000D25DE /* CPDFListView+Tool.m */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.objc; path = "CPDFListView+Tool.m"; sourceTree = "<group>"; wrapsLines = 0; };
@@ -8990,8 +8989,7 @@
 				F34BF9522953DA91002C25A2 /* NSGeometry+PDFListView.m */,
 				9FD0D2AE2AD51BCC00DA3FF8 /* CPDFListEditAnnotationViewController.swift */,
 				F3A9DC7D294309D80074E5D2 /* CPDFListEditAnnotationViewController.xib */,
-				F356720229AF184A00740FF3 /* CPDFListAnnotationNoteWindowController.h */,
-				F356720329AF184A00740FF3 /* CPDFListAnnotationNoteWindowController.m */,
+				9FD0D2B22AD5265A00DA3FF8 /* CPDFListAnnotationNoteWindowController.swift */,
 				F356720429AF184A00740FF3 /* CPDFListAnnotationNoteWindowController.xib */,
 				F3B7DF972948565000333201 /* CPDFListHoverAnnotationViewController.h */,
 				F3B7DF982948565000333201 /* CPDFListHoverAnnotationViewController.m */,
@@ -10534,7 +10532,6 @@
 				9F0CB4C92986533F00007028 /* KMDesignToken+Sizing.swift in Sources */,
 				9F8539DE29470A0700DF644E /* KMTabStripView.swift in Sources */,
 				AD9527EE295578BD0039D2BC /* KMBaseTextFieldPresenter.swift in Sources */,
-				F356720529AF184A00740FF3 /* CPDFListAnnotationNoteWindowController.m in Sources */,
 				F37322F6292DF9410013862C /* CSelfSignAnnotation.m in Sources */,
 				BB49ED1D293F4FB200C82CA2 /* KMConvertPPTsSettingView.swift in Sources */,
 				F37322ED292DF9410013862C /* CPDFMarkupAnnotation+PDFListView.m in Sources */,
@@ -10838,6 +10835,7 @@
 				9F1FE4CC29406E4700E952CA /* CTTabContentsController.m in Sources */,
 				BB146FF0299DC0D100784A6A /* GTLRUploadParameters.m in Sources */,
 				AD88108329A719D400178CA1 /* KMRegisterView.swift in Sources */,
+				9FD0D2B32AD5265A00DA3FF8 /* CPDFListAnnotationNoteWindowController.swift in Sources */,
 				BB74DA7F2AC42959006EDFE7 /* NSButton+KMExtension.swift in Sources */,
 				BBF38A62294F53FD0086D025 /* KMWatermarkFileView.swift in Sources */,
 				BBC3482E29559E12008D2CD1 /* KMBackgroundModel.swift in Sources */,
@@ -11225,6 +11223,7 @@
 				BB89722F294B08DE0045787C /* KMWatermarkViewController.swift in Sources */,
 				BB99ACD0292E2AEF0048AFD9 /* KMMergeCollectionViewItem.swift in Sources */,
 				BB89DD7F2953F863007C3FFA /* KMWatermarkFileOutsideView.swift in Sources */,
+				9FD0D2B42AD5265A00DA3FF8 /* CPDFListAnnotationNoteWindowController.swift in Sources */,
 				9F3D819429A33A290087B5AD /* KMDesignDropdown.swift in Sources */,
 				9F0CB4802967F64D00007028 /* KMPropertiesPanelReadOnlySubVC.swift in Sources */,
 				BB9695A929BDA3A800FD68D3 /* SKInfoWindowController.m in Sources */,
@@ -11331,7 +11330,6 @@
 				9F0CB4CA2986533F00007028 /* KMDesignToken+Sizing.swift in Sources */,
 				9F8539DF29470A0700DF644E /* KMTabStripView.swift in Sources */,
 				AD9527EF295578BD0039D2BC /* KMBaseTextFieldPresenter.swift in Sources */,
-				F356720629AF184A00740FF3 /* CPDFListAnnotationNoteWindowController.m in Sources */,
 				8942F80029260EC700389627 /* KMLeftMethodMode.swift in Sources */,
 				BB49ED1E293F4FB200C82CA2 /* KMConvertPPTsSettingView.swift in Sources */,
 				9FA607DA28F8227500B46586 /* KMBox.swift in Sources */,
@@ -12063,7 +12061,6 @@
 				F36EB6CB2987C9FE004C25FB /* KMDocumentAIViewController.m in Sources */,
 				9FDD0F71294AD13C000C4DAD /* KMMainViewController+Action.swift in Sources */,
 				ADF1569529A62D1D001D1018 /* KMLoginLeftImageView.swift in Sources */,
-				F356720729AF184A00740FF3 /* CPDFListAnnotationNoteWindowController.m in Sources */,
 				9F1F82E52934D5240092C4B4 /* KMHomeExtractActionViewController.swift in Sources */,
 				ADCB98C72924730000B51A03 /* KMBatchProcessingTableViewModel.swift in Sources */,
 				ADBC375F29CC61E100D93208 /* KMReadModelView.swift in Sources */,
@@ -12606,6 +12603,7 @@
 				9FF94F1B29A770B500B1EF69 /* KMFillSignShapePanel.swift in Sources */,
 				BBA5429E29F13A140041BAD0 /* KMMemorandumPattern.swift in Sources */,
 				896DD4572985FB3200ADE514 /* KMPageDisplayThemeCollectionViewItem.swift in Sources */,
+				9FD0D2B52AD5265A00DA3FF8 /* CPDFListAnnotationNoteWindowController.swift in Sources */,
 				F359916B29261F0E000D25DE /* CPDFListView+Tool.m in Sources */,
 				89752DEC293875FC003FF08E /* KMMainToolbarController.swift in Sources */,
 				AD0E8ABB2A31BDDD00DBFD3C /* KMProduct.swift in Sources */,

+ 0 - 25
PDF Office/PDF Master/Class/PDFWindowController/PDFListView/AppKitCategories/CPDFListAnnotationNoteWindowController.h

@@ -1,25 +0,0 @@
-//
-//  CPDFListAnnotationNoteWindowController.h
-//  ComPDFKit
-//
-//  Copyright © 2014-2022 PDF Technologies, Inc. All Rights Reserved.
-//
-//  THIS SOURCE CODE AND ANY ACCOMPANYING DOCUMENTATION ARE PROTECTED BY INTERNATIONAL COPYRIGHT LAW
-//  AND MAY NOT BE RESOLD OR REDISTRIBUTED. USAGE IS BOUND TO THE ComPDFKit LICENSE AGREEMENT.
-//  UNAUTHORIZED REPRODUCTION OR DISTRIBUTION IS SUBJECT TO CIVIL AND CRIMINAL PENALTIES.
-//  This notice may not be removed from this file.
-//
-
-#import <Cocoa/Cocoa.h>
-#import <ComPDFKit/ComPDFKit.h>
-
-@interface CPDFListAnnotationNoteWindowController : NSWindowController
-
-@property (nonatomic,readonly) CPDFAnnotation *note;
-
-+ (CPDFListAnnotationNoteWindowController *)sharedInstance;
-
--(void)updateAnnotation:(CPDFAnnotation *)note;
-
-
-@end

+ 0 - 201
PDF Office/PDF Master/Class/PDFWindowController/PDFListView/AppKitCategories/CPDFListAnnotationNoteWindowController.m

@@ -1,201 +0,0 @@
-//
-//  CPDFListAnnotationNoteWindowController.m
-//  ComPDFKit
-//
-//  Copyright © 2014-2022 PDF Technologies, Inc. All Rights Reserved.
-//
-//  THIS SOURCE CODE AND ANY ACCOMPANYING DOCUMENTATION ARE PROTECTED BY INTERNATIONAL COPYRIGHT LAW
-//  AND MAY NOT BE RESOLD OR REDISTRIBUTED. USAGE IS BOUND TO THE ComPDFKit LICENSE AGREEMENT.
-//  UNAUTHORIZED REPRODUCTION OR DISTRIBUTION IS SUBJECT TO CIVIL AND CRIMINAL PENALTIES.
-//  This notice may not be removed from this file.
-//
-
-#import "CPDFListAnnotationNoteWindowController.h"
-#import "CPDFListView.h"
-#import <PDF_Master-Swift.h>
-
-static char CNoteWindowNoteObservationContext;
-
-@interface CPDFListAnnotationNoteWindowController ()<NSTextViewDelegate>
-
-@property (weak) IBOutlet NSBox *contentBox;
-@property (nonatomic,assign)IBOutlet NSTextView *contentTextView;
-
-@property (nonatomic,assign)IBOutlet NSTextField *titleLabel;
-
-@property (nonatomic,assign)IBOutlet NSButton *sureButton;
-
-@property (nonatomic,assign)IBOutlet NSButton *cancelButton;
-
-@property (nonatomic,retain) CPDFAnnotation *note;
-
-@property (nonatomic, strong) KMDesignButton *cancelButtonVC;
-@property (nonatomic, strong) KMDesignButton *sureButtonVC;
-
-@end
-
-@implementation CPDFListAnnotationNoteWindowController
-- (id)init {
-    if (self = [super initWithWindowNibName:@"CPDFListAnnotationNoteWindowController"]) {
-    }
-    return self;
-}
-
-+ (NSWindowController *)sharedInstance {
-    static CPDFListAnnotationNoteWindowController *singleton = nil;
-    static dispatch_once_t pred;
-    dispatch_once(&pred, ^{
-        singleton = [[CPDFListAnnotationNoteWindowController alloc] init];
-    });
-    return singleton;
-}
-
--(void)updateAnnotation:(CPDFAnnotation *)note {
-    self.contentTextView.delegate = self;
-    
-    self.note = note;
-    
-    if ([self.note isKindOfClass:[CPDFMarkupAnnotation class]]) {
-        NSString *markupString = [(CPDFMarkupAnnotation *)self.note markupText];
-        NSString *contentString = self.note.contents;
-        
-        markupString = [markupString stringByReplacingOccurrencesOfString:@" " withString:@""];
-        contentString = [contentString stringByReplacingOccurrencesOfString:@" " withString:@""];
-        if ([markupString isEqualToString:contentString]) {
-            self.contentTextView.string = @"";
-        } else {
-            self.contentTextView.string = markupString;
-        }
-    } else  {
-        self.contentTextView.string = self.note.contents?:@"";
-    }
-    
-    if (self.contentTextView.string.length > 0) {
-        self.contentTextView.placeholderLabel.hidden = YES;
-    } else {
-        self.contentTextView.placeholderLabel.hidden = NO;
-    }
-    
-    [self.note addObserver:self forKeyPath:@"page" options:0 context:&CNoteWindowNoteObservationContext];
-    [self.note addObserver:self forKeyPath:@"bounds" options:0 context:&CNoteWindowNoteObservationContext];
-    if ([self.note isKindOfClass:[CPDFMarkupAnnotation class]]) {
-        [self.note addObserver:self forKeyPath:@"markupText" options:0 context:&CNoteWindowNoteObservationContext];
-    } else {
-        [self.note addObserver:self forKeyPath:@"contents" options:0 context:&CNoteWindowNoteObservationContext];
-    }
-}
-
-- (void)windowDidLoad {
-    [super windowDidLoad];
-    
-    self.window.movableByWindowBackground = YES;
-    self.window.backgroundColor = [NSColor clearColor];
-    self.window.contentView.wantsLayer = YES;
-    self.window.contentView.layer.backgroundColor = [NSColor whiteColor].CGColor;
-    self.window.contentView.layer.borderWidth = 1.f;
-    self.window.contentView.layer.borderColor = [NSColor colorWithWhite:0 alpha:0.1].CGColor;
-    self.window.contentView.layer.cornerRadius = 8.f;
-    self.window.contentView.layer.masksToBounds = YES;
-    
-//    self.window.contentView.shadow = [[NSShadow alloc] init];
-//    self.window.contentView.layer.shadowColor = [NSColor redColor].CGColor;
-//    self.window.contentView.layer.shadowOpacity = 1;
-//    self.window.contentView.layer.shadowRadius = 8;
-    
-    self.cancelButtonVC = [[KMDesignButton alloc] initWithType:DesignButtonTypeText];
-    [self.cancelButton addSubview:self.cancelButtonVC.view];
-    self.cancelButtonVC.view.frame = self.cancelButton.bounds;
-    self.cancelButtonVC.view.autoresizingMask = NSViewWidthSizable | NSViewHeightSizable;
-    self.cancelButtonVC.stringValue = NSLocalizedString(@"Cancel", nil);
-    [self.cancelButtonVC buttonWithType:TokenButtonTypeSec size:TokenButtonSizeM height:[NSLayoutConstraint new]];
-    self.cancelButtonVC.target = self;
-    self.cancelButtonVC.action = @selector(buttonItemClick_Cancel:);
-    
-    self.sureButtonVC = [[KMDesignButton alloc] initWithType:DesignButtonTypeText];
-    [self.sureButton addSubview:self.sureButtonVC.view];
-    self.sureButtonVC.view.frame = self.sureButton.bounds;
-    self.sureButtonVC.view.autoresizingMask = NSViewWidthSizable | NSViewHeightSizable;
-    self.sureButtonVC.stringValue = NSLocalizedString(@"OK", nil);
-    [self.sureButtonVC buttonWithType:TokenButtonTypeCta size:TokenButtonSizeM height:[NSLayoutConstraint new]];
-    self.sureButtonVC.target = self;
-    self.sureButtonVC.action = @selector(buttonItemClick_Sure:);
-    
-    self.titleLabel.stringValue = NSLocalizedString(@"Add Note", nil);
-    self.sureButton.title = NSLocalizedString(@"", nil);
-    self.cancelButton.title = NSLocalizedString(@"", nil);
-//    [self.contentTextView becomeFirstResponder];
-    self.titleLabel.textColor = [NSColor colorWithRed:37/255.f green:38/255.f blue:41/255.f alpha:1.f];
-    self.titleLabel.font = [NSFont fontWithName:@"SFProText-Semibold" size:16];
-    
-    self.contentBox.cornerRadius = 4;
-    self.contentBox.borderWidth = 1;
-    self.contentBox.borderColor = [NSColor colorWithRed:223/255.f green:225/255.f blue:229/255.f alpha:1.f];
-    self.contentBox.fillColor = [NSColor whiteColor];
-    
-    self.contentTextView.textContainerInset = NSMakeSize(2, 5);
-    self.contentTextView.textContainer.lineBreakMode = NSLineBreakByWordWrapping;
-    self.contentTextView.km_placeholderString = NSLocalizedString(@"Please add notes", nil);
-}
-
-- (void)windowWillClose:(NSNotification *)aNotification {
-    [self.note removeObserver:self forKeyPath:@"bounds"];
-    if ([self.note isKindOfClass:[CPDFMarkupAnnotation class]]) {
-        [self.note removeObserver:self forKeyPath:@"markupText"];
-    } else {
-        [self.note removeObserver:self forKeyPath:@"contents"];
-    }
-}
-
-//- (BOOL)canBecomeKeyWindow {
-//    return YES;
-//}
-
-- (IBAction)buttonItemClick_Cancel:(id)sender {
-    [self close];
-}
-
-- (IBAction)buttonItemClick_Sure:(id)sender {
-    if (self.note != nil) {
-        if ([self.note isKindOfClass:[CPDFMarkupAnnotation class]]) {
-            [(CPDFMarkupAnnotation *)self.note setMarkupText:self.contentTextView.string?:@""];
-        } else {
-            [self.note setContents:self.contentTextView.string?:@""];
-        }
-        [[NSNotificationCenter defaultCenter] postNotificationName:CPDFListViewAnnotationsAttributeHasChangeNotification object:@{@"keyPath": @"text", @"object": self.note}];
-    }
-    [self close];
-}
-
-- (void)observeValueForKeyPath:(NSString *)keyPath ofObject:(id)object change:(NSDictionary *)change context:(void *)context {
-   if (context == &CNoteWindowNoteObservationContext) {
-         if ([keyPath isEqualToString:@"contents"]) {
-            [self synchronizeWindowTitleWithDocumentName];
-         } else if ([keyPath isEqualToString:@"markupText"]) {
-             [self synchronizeWindowTitleWithDocumentName];
-             if ([self.note isKindOfClass:[CPDFMarkupAnnotation class]]) {
-                 self.contentTextView.string = [(CPDFMarkupAnnotation *)self.note markupText] ?:@"";
-             }
-         }
-    } else {
-        [super observeValueForKeyPath:keyPath ofObject:object change:change context:context];
-    }
-}
-
-#pragma -
-#pragma mark - NSTextViewDelegate
-
-- (void)textDidChange:(NSNotification *)notification {
-    if ([notification.object isEqual:self.contentTextView]) {
-        if (self.contentTextView.string.length > 0) {
-            self.contentTextView.placeholderLabel.hidden = YES;
-        } else {
-            self.contentTextView.placeholderLabel.hidden = NO;
-        }
-    }
-}
-
-- (void)controlTextDidChange:(NSNotification *)obj {
-    
-}
-
-@end

+ 188 - 0
PDF Office/PDF Master/Class/PDFWindowController/PDFListView/AppKitCategories/CPDFListAnnotationNoteWindowController.swift

@@ -0,0 +1,188 @@
+//
+//  CPDFListAnnotationNoteWindowController.swift
+//  PDF Master
+//
+//  Created by wanjun on 2023/10/10.
+//
+
+import Cocoa
+
+private var CNoteWindowNoteObservationContext = 0
+
+@objcMembers
+class CPDFListAnnotationNoteWindowController: NSWindowController {
+    
+    private(set) var note: CPDFAnnotation?
+    
+    @IBOutlet weak var contentBox: NSBox!
+    @IBOutlet var contentTextView: NSTextView!
+    
+    @IBOutlet var titleLabel: NSTextField!
+    
+    @IBOutlet var sureButton: NSButton!
+    
+    @IBOutlet var cancelButton: NSButton!
+    
+//    var note: CPDFAnnotation?
+    
+    var cancelButtonVC: KMDesignButton?
+    var sureButtonVC: KMDesignButton?
+    
+    static let sharedInstance: CPDFListAnnotationNoteWindowController = {
+        let controller = CPDFListAnnotationNoteWindowController(windowNibName: NSNib.Name("CPDFListAnnotationNoteWindowController"))
+        return controller
+    }()
+    
+    override init(window: NSWindow?) {
+        super.init(window: window)
+    }
+    
+    required init?(coder: NSCoder) {
+        super.init(coder: coder)
+    }
+    
+    func updateAnnotation(_ note: CPDFAnnotation) {
+        self.contentTextView.delegate = self
+        self.note = note
+        
+        if let markupNote = self.note as? CPDFMarkupAnnotation {
+            var markupString = markupNote.markupText().replacingOccurrences(of: " ", with: "")
+            let contentString = self.note!.contents.replacingOccurrences(of: " ", with: "")
+            
+            if markupString == contentString {
+                markupString = ""
+            }
+            self.contentTextView.string = markupString
+        } else {
+            self.contentTextView.string = self.note!.contents ?? ""
+        }
+        
+        if self.contentTextView.string.count > 0 {
+            self.contentTextView.placeholderLabel.isHidden = true
+        } else {
+            self.contentTextView.placeholderLabel.isHidden = false
+        }
+        
+        self.note!.addObserver(self, forKeyPath: "page", options: [], context: &CNoteWindowNoteObservationContext)
+        self.note!.addObserver(self, forKeyPath: "bounds", options: [], context: &CNoteWindowNoteObservationContext)
+        
+        if self.note is CPDFMarkupAnnotation {
+            self.note!.addObserver(self, forKeyPath: "markupText", options: [], context: &CNoteWindowNoteObservationContext)
+        } else {
+            self.note!.addObserver(self, forKeyPath: "contents", options: [], context: &CNoteWindowNoteObservationContext)
+        }
+    }
+    
+    override func windowDidLoad() {
+        super.windowDidLoad()
+    
+        // Implement this method to handle any initialization after your window controller's window has been loaded from its nib file.
+        
+        self.window?.isMovableByWindowBackground = true
+        self.window?.backgroundColor = NSColor.clear
+        self.window?.contentView?.wantsLayer = true
+        self.window?.contentView?.layer?.backgroundColor = NSColor.white.cgColor
+        self.window?.contentView?.layer?.borderWidth = 1.0
+        self.window?.contentView?.layer?.borderColor = NSColor(white: 0, alpha: 0.1).cgColor
+        window?.contentView?.layer?.cornerRadius = 8.0
+        window?.contentView?.layer?.masksToBounds = true
+        
+        self.cancelButtonVC = KMDesignButton.init(withType: .Text)
+        self.cancelButton.addSubview(self.cancelButtonVC!.view)
+        self.cancelButtonVC?.view.frame = self.cancelButton.bounds
+        self.cancelButtonVC?.view.autoresizingMask = [.width, .height]
+        self.cancelButtonVC?.stringValue = NSLocalizedString("Cancel", comment: "")
+        self.cancelButtonVC?.button(type: .Sec, size: .m, height: NSLayoutConstraint())
+        self.cancelButtonVC?.target = self
+        self.cancelButtonVC?.action = #selector(buttonItemClick_Cancel(_:))
+        
+        self.sureButtonVC = KMDesignButton.init(withType: .Text)
+        self.sureButton.addSubview(self.sureButtonVC!.view)
+        self.sureButtonVC?.view.frame = sureButton.bounds
+        self.sureButtonVC?.view.autoresizingMask = [.width, .height]
+        self.sureButtonVC?.stringValue = NSLocalizedString("OK", comment: "")
+        self.sureButtonVC?.button(type: .Cta, size: .m, height: NSLayoutConstraint())
+        self.sureButtonVC?.target = self
+        self.sureButtonVC?.action = #selector(buttonItemClick_Sure(_:))
+        
+        self.titleLabel.stringValue = NSLocalizedString("Add Note", comment: "")
+        self.sureButton.title = NSLocalizedString("", comment: "")
+        self.cancelButton.title = NSLocalizedString("", comment: "")
+        self.titleLabel.textColor = NSColor(red: 37/255.0, green: 38/255.0, blue: 41/255.0, alpha: 1.0)
+        self.titleLabel.font = NSFont(name: "SFProText-Semibold", size: 16)
+        
+        self.contentBox.cornerRadius = 4
+        self.contentBox.borderWidth = 1
+        self.contentBox.borderColor = NSColor(red: 223/255.0, green: 225/255.0, blue: 229/255.0, alpha: 1.0)
+        self.contentBox.fillColor = NSColor.white
+        
+        self.contentTextView.textContainerInset = NSSize(width: 2, height: 5)
+        self.contentTextView.textContainer?.lineBreakMode = .byWordWrapping
+        self.contentTextView.km_placeholderString = NSLocalizedString("Please add notes", comment: "")
+    }
+    
+    override func windowWillLoad() {
+        if let note = self.note {
+            note.removeObserver(self, forKeyPath: "bounds")
+            if let note = self.note as? CPDFMarkupAnnotation {
+                note.removeObserver(self, forKeyPath: "markupText")
+            } else {
+                note.removeObserver(self, forKeyPath: "contents")
+            }
+        }
+    }
+    
+    //MARK: Action
+    
+    @IBAction func buttonItemClick_Cancel(_ sender: Any) {
+        self.close()
+    }
+
+    @IBAction func buttonItemClick_Sure(_ sender: Any) {
+        if let note = self.note {
+            if let markupNote = note as? CPDFMarkupAnnotation {
+                markupNote.setMarkupText(self.contentTextView.string)
+            } else {
+                note.contents = self.contentTextView.string 
+            }
+            
+            NotificationCenter.default.post(
+                name: Notification.Name("CPDFListViewAnnotationsAttributeHasChangeNotification"),
+                object: ["keyPath": "text", "object": note]
+            )
+        }
+        
+        self.close()
+    }
+    
+    override func observeValue(forKeyPath keyPath: String?, of object: Any?, change: [NSKeyValueChangeKey : Any]?, context: UnsafeMutableRawPointer?) {
+        if context == &CNoteWindowNoteObservationContext {
+            if keyPath == "contents" {
+                synchronizeWindowTitleWithDocumentName()
+            } else if keyPath == "markupText" {
+                synchronizeWindowTitleWithDocumentName()
+                if let note = self.note as? CPDFMarkupAnnotation {
+                    contentTextView.string = note.markupText()
+                }
+            }
+        } else {
+            super.observeValue(forKeyPath: keyPath, of: object, change: change, context: context)
+        }
+    }
+}
+
+extension CPDFListAnnotationNoteWindowController: NSTextViewDelegate {
+    func textDidChange(_ notification: Notification) {
+        if notification.object as AnyObject === contentTextView {
+            if contentTextView.string.count > 0 {
+                contentTextView.placeholderLabel.isHidden = true
+            } else {
+                contentTextView.placeholderLabel.isHidden = false
+            }
+        }
+    }
+    
+    @objc func controlTextDidChange(_ obj: Notification) {
+        // 在这里添加 controlTextDidChange 方法的实现
+    }
+}

+ 17 - 17
PDF Office/PDF Master/Class/PDFWindowController/PDFListView/AppKitCategories/CPDFListAnnotationNoteWindowController.xib

@@ -1,12 +1,12 @@
 <?xml version="1.0" encoding="UTF-8"?>
-<document type="com.apple.InterfaceBuilder3.Cocoa.XIB" version="3.0" toolsVersion="21507" targetRuntime="MacOSX.Cocoa" propertyAccessControl="none" useAutolayout="YES" customObjectInstantitationMethod="direct">
+<document type="com.apple.InterfaceBuilder3.Cocoa.XIB" version="3.0" toolsVersion="22154" targetRuntime="MacOSX.Cocoa" propertyAccessControl="none" useAutolayout="YES" customObjectInstantitationMethod="direct">
     <dependencies>
         <deployment identifier="macosx"/>
-        <plugIn identifier="com.apple.InterfaceBuilder.CocoaPlugin" version="21507"/>
+        <plugIn identifier="com.apple.InterfaceBuilder.CocoaPlugin" version="22154"/>
         <capability name="documents saved in the Xcode 8 format" minToolsVersion="8.0"/>
     </dependencies>
     <objects>
-        <customObject id="-2" userLabel="File's Owner" customClass="CPDFListAnnotationNoteWindowController">
+        <customObject id="-2" userLabel="File's Owner" customClass="CPDFListAnnotationNoteWindowController" customModule="PDF_Master" customModuleProvider="target">
             <connections>
                 <outlet property="cancelButton" destination="oTs-Lx-i2P" id="ud5-Wn-eEf"/>
                 <outlet property="contentBox" destination="M3J-EC-MnB" id="z4S-lR-uP8"/>
@@ -22,7 +22,7 @@
             <windowStyleMask key="styleMask" titled="YES" fullSizeContentView="YES"/>
             <windowPositionMask key="initialPositionMask" leftStrut="YES" rightStrut="YES" topStrut="YES" bottomStrut="YES"/>
             <rect key="contentRect" x="1019" y="610" width="432" height="222"/>
-            <rect key="screenRect" x="0.0" y="0.0" width="1440" height="875"/>
+            <rect key="screenRect" x="0.0" y="0.0" width="2560" height="1415"/>
             <value key="minSize" type="size" width="432" height="222"/>
             <value key="maxSize" type="size" width="432" height="222"/>
             <value key="minFullScreenContentSize" type="size" width="432" height="222"/>
@@ -33,10 +33,6 @@
                 <subviews>
                     <button verticalHuggingPriority="750" translatesAutoresizingMaskIntoConstraints="NO" id="oTs-Lx-i2P">
                         <rect key="frame" x="240" y="16" width="80" height="32"/>
-                        <constraints>
-                            <constraint firstAttribute="width" constant="80" id="GJJ-WK-ESM"/>
-                            <constraint firstAttribute="height" constant="32" id="fAB-6b-WIL"/>
-                        </constraints>
                         <buttonCell key="cell" type="bevel" title="Cancel" bezelStyle="rounded" alignment="center" imageScaling="proportionallyDown" inset="2" id="nTr-Lz-ngY">
                             <behavior key="behavior" pushIn="YES" lightByBackground="YES" lightByGray="YES"/>
                             <font key="font" metaFont="system"/>
@@ -44,6 +40,10 @@
 Gw
 </string>
                         </buttonCell>
+                        <constraints>
+                            <constraint firstAttribute="width" constant="80" id="GJJ-WK-ESM"/>
+                            <constraint firstAttribute="height" constant="32" id="fAB-6b-WIL"/>
+                        </constraints>
                         <connections>
                             <action selector="buttonItemClick_Cancel:" target="-2" id="NKY-2l-jfb"/>
                         </connections>
@@ -57,15 +57,15 @@ Gw
                                 <scrollView borderType="none" horizontalLineScroll="10" horizontalPageScroll="10" verticalLineScroll="10" verticalPageScroll="10" hasHorizontalScroller="NO" translatesAutoresizingMaskIntoConstraints="NO" id="DMr-kv-h9X">
                                     <rect key="frame" x="0.0" y="0.0" width="398" height="106"/>
                                     <clipView key="contentView" drawsBackground="NO" id="i1t-gU-3aH">
-                                        <rect key="frame" x="0.0" y="0.0" width="398" height="106"/>
+                                        <rect key="frame" x="0.0" y="0.0" width="383" height="106"/>
                                         <autoresizingMask key="autoresizingMask" widthSizable="YES" heightSizable="YES"/>
                                         <subviews>
                                             <textView drawsBackground="NO" importsGraphics="NO" richText="NO" verticallyResizable="YES" spellingCorrection="YES" smartInsertDelete="YES" id="Uh9-lF-veX">
-                                                <rect key="frame" x="0.0" y="0.0" width="398" height="106"/>
+                                                <rect key="frame" x="0.0" y="0.0" width="383" height="106"/>
                                                 <autoresizingMask key="autoresizingMask" widthSizable="YES" heightSizable="YES"/>
                                                 <color key="textColor" name="textColor" catalog="System" colorSpace="catalog"/>
                                                 <color key="backgroundColor" name="textBackgroundColor" catalog="System" colorSpace="catalog"/>
-                                                <size key="minSize" width="398" height="106"/>
+                                                <size key="minSize" width="383" height="106"/>
                                                 <size key="maxSize" width="398" height="10000000"/>
                                                 <color key="insertionPointColor" name="textColor" catalog="System" colorSpace="catalog"/>
                                             </textView>
@@ -76,7 +76,7 @@ Gw
                                         <autoresizingMask key="autoresizingMask"/>
                                     </scroller>
                                     <scroller key="verticalScroller" wantsLayer="YES" verticalHuggingPriority="750" horizontal="NO" id="e6O-T1-Mzb">
-                                        <rect key="frame" x="382" y="0.0" width="16" height="106"/>
+                                        <rect key="frame" x="383" y="0.0" width="15" height="106"/>
                                         <autoresizingMask key="autoresizingMask"/>
                                     </scroller>
                                 </scrollView>
@@ -96,10 +96,6 @@ Gw
                     </box>
                     <button verticalHuggingPriority="750" translatesAutoresizingMaskIntoConstraints="NO" id="5YO-PQ-Jry">
                         <rect key="frame" x="336" y="16" width="80" height="32"/>
-                        <constraints>
-                            <constraint firstAttribute="height" constant="32" id="7L0-nN-vjJ"/>
-                            <constraint firstAttribute="width" constant="80" id="DDp-cb-6ct"/>
-                        </constraints>
                         <buttonCell key="cell" type="bevel" title="OK" bezelStyle="rounded" alignment="center" imageScaling="proportionallyDown" inset="2" id="PGR-iC-CVd">
                             <behavior key="behavior" pushIn="YES" lightByBackground="YES" lightByGray="YES"/>
                             <font key="font" metaFont="system"/>
@@ -107,11 +103,15 @@ Gw
 DQ
 </string>
                         </buttonCell>
+                        <constraints>
+                            <constraint firstAttribute="height" constant="32" id="7L0-nN-vjJ"/>
+                            <constraint firstAttribute="width" constant="80" id="DDp-cb-6ct"/>
+                        </constraints>
                         <connections>
                             <action selector="buttonItemClick_Sure:" target="-2" id="wk4-Fn-MYM"/>
                         </connections>
                     </button>
-                    <textField horizontalHuggingPriority="251" verticalHuggingPriority="750" translatesAutoresizingMaskIntoConstraints="NO" id="lFm-XQ-Nwc">
+                    <textField focusRingType="none" horizontalHuggingPriority="251" verticalHuggingPriority="750" translatesAutoresizingMaskIntoConstraints="NO" id="lFm-XQ-Nwc">
                         <rect key="frame" x="14" y="187" width="73" height="19"/>
                         <textFieldCell key="cell" lineBreakMode="clipping" title="Add Note" id="jgq-BQ-kjA">
                             <font key="font" metaFont="system" size="16"/>

+ 0 - 1
PDF Office/PDF Master/Class/PDFWindowController/PDFListView/CPDFListView.m

@@ -16,7 +16,6 @@
 #import "CSelfSignAnnotation.h"
 #import "CSelfSignAnnotationFreeText.h"
 #import "CPDFListViewConfig.h"
-#import "CPDFListAnnotationNoteWindowController.h"
 
 #import "CPDFListView+Private.h"
 #import "CPDFListView+Event.h"