|
@@ -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
|