Revision: 13301
http://sourceforge.net/p/skim-app/code/13301
Author: hofman
Date: 2023-02-25 10:42:28 +0000 (Sat, 25 Feb 2023)
Log Message:
-----------
Create textStorage for note skim note lazily in a private getter method.
Modified Paths:
--------------
trunk/SKNPDFAnnotationNote_SKExtensions.m
trunk/SkimNotes/SKNPDFAnnotationNote.m
Modified: trunk/SKNPDFAnnotationNote_SKExtensions.m
===================================================================
--- trunk/SKNPDFAnnotationNote_SKExtensions.m 2023-02-24 22:39:08 UTC (rev
13300)
+++ trunk/SKNPDFAnnotationNote_SKExtensions.m 2023-02-25 10:42:28 UTC (rev
13301)
@@ -49,6 +49,10 @@
NSString *SKPDFAnnotationRichTextKey = @"richText";
+@interface SKNPDFAnnotationNote (SKPrivateDeclarations)
+- (NSTextStorage *)mutableText;
+@end
+
@implementation SKNPDFAnnotationNote (SKExtensions)
+ (NSDictionary *)textToNoteSkimNoteProperties:(NSDictionary *)properties {
@@ -138,16 +142,16 @@
}
- (id)richText {
- return textStorage;
+ return [self mutableText];
}
- (void)setRichText:(id)newText {
- if ([self isEditable] && newText != textStorage) {
+ if ([self isEditable] && newText != [self mutableText]) {
// We are willing to accept either a string or an attributed string.
if ([newText isKindOfClass:[NSAttributedString class]])
- [textStorage replaceCharactersInRange:NSMakeRange(0, [textStorage
length]) withAttributedString:newText];
+ [[self mutableText] replaceCharactersInRange:NSMakeRange(0, [[self
mutableText] length]) withAttributedString:newText];
else
- [textStorage replaceCharactersInRange:NSMakeRange(0, [textStorage
length]) withString:newText];
+ [[self mutableText] replaceCharactersInRange:NSMakeRange(0, [[self
mutableText] length]) withString:newText];
}
}
Modified: trunk/SkimNotes/SKNPDFAnnotationNote.m
===================================================================
--- trunk/SkimNotes/SKNPDFAnnotationNote.m 2023-02-24 22:39:08 UTC (rev
13300)
+++ trunk/SkimNotes/SKNPDFAnnotationNote.m 2023-02-25 10:42:28 UTC (rev
13301)
@@ -67,7 +67,7 @@
#endif
@interface SKNPDFAnnotationNote (SKNPrivate)
-- (void)textDidChange:(NSNotification *)notification;
+- (NSTextStorage *)mutableText;
@end
#endif
@@ -89,23 +89,6 @@
[super setContents:contents];
}
-#if !defined(PDFKIT_PLATFORM_IOS)
-
-#pragma clang diagnostic push
-#pragma clang diagnostic ignored "-Wdeprecated-implementations"
-- (id)initWithBounds:(NSRect)bounds {
-#pragma clang diagnostic pop
- self = [super initWithBounds:bounds];
- if (self) {
- textStorage = [[NSTextStorage allocWithZone:[self zone]] init];
- [[NSNotificationCenter defaultCenter] addObserver:self
selector:@selector(textDidChange:)
name:NSTextStorageDidProcessEditingNotification object:textStorage];
- text = [[NSAttributedString alloc] init];
- }
- return self;
-}
-
-#endif
-
- (id)initSkimNoteWithProperties:(NSDictionary *)dict{
self = [super initSkimNoteWithProperties:dict];
if (self) {
@@ -196,7 +179,7 @@
#else
- (void)setText:(NSAttributedString *)newText {
- if (textStorage != newText) {
+ if ([self mutableText] != newText) {
// edit the textStorage, this will trigger KVO and update the text
automatically
if (newText)
[textStorage replaceCharactersInRange:NSMakeRange(0, [textStorage
length]) withAttributedString:newText];
@@ -224,7 +207,7 @@
[self willChangeValueForKey:SKNPDFAnnotationTextKey];
// update the text
[text release];
- text = [[NSAttributedString allocWithZone:[self zone]]
initWithAttributedString:textStorage];
+ text = [[NSAttributedString alloc] initWithAttributedString:textStorage];
[self didChangeValueForKey:SKNPDFAnnotationTextKey];
[texts makeObjectsPerformSelector:@selector(didChangeValueForKey:)
withObject:SKNPDFAnnotationTextKey];
// update the contents to string + text
@@ -231,6 +214,14 @@
[self updateContents];
}
+- (NSTextStorage *)mutableText {
+ if (textStorage == nil) {
+ textStorage = [[NSTextStorage alloc] init];
+ [[NSNotificationCenter defaultCenter] addObserver:self
selector:@selector(textDidChange:)
name:NSTextStorageDidProcessEditingNotification object:textStorage];
+ }
+ return textStorage;
+}
+
// private method called by -drawWithBox: before to 10.12, made public on
10.12, now calling -drawWithBox:
- (void)drawWithBox:(PDFDisplayBox)box inContext:(CGContextRef)context {
if (floor(NSAppKitVersionNumber) < SKNAppKitVersionNumber10_12 ||
floor(NSAppKitVersionNumber) > SKNAppKitVersionNumber10_14 || [self
hasAppearanceStream]) {
This was sent by the SourceForge.net collaborative development platform, the
world's largest Open Source development site.
_______________________________________________
Skim-app-commit mailing list
[email protected]
https://lists.sourceforge.net/lists/listinfo/skim-app-commit