Revision: 4100
          http://skim-app.svn.sourceforge.net/skim-app/?rev=4100&view=rev
Author:   hofman
Date:     2008-06-29 05:42:30 -0700 (Sun, 29 Jun 2008)

Log Message:
-----------
Set text of anchored note using accessor in initializer, so both the 
textStorage as the text ivars are updated properly.

Modified Paths:
--------------
    trunk/SkimNotes/SKNPDFAnnotationNote.m

Modified: trunk/SkimNotes/SKNPDFAnnotationNote.m
===================================================================
--- trunk/SkimNotes/SKNPDFAnnotationNote.m      2008-06-29 10:04:10 UTC (rev 
4099)
+++ trunk/SkimNotes/SKNPDFAnnotationNote.m      2008-06-29 12:42:30 UTC (rev 
4100)
@@ -78,9 +78,9 @@
         if ([anImage isKindOfClass:imageClass])
             image = [anImage retain];
         if ([aText isKindOfClass:attrStringClass])
-            text = [aText copy];
+            [self setText:aText];
         else if ([aText isKindOfClass:stringClass])
-            text = [[NSAttributedString alloc] initWithString:(NSString 
*)aText];
+            [self setText:[[[NSAttributedString alloc] 
initWithString:(NSString *)aText] autorelease]];
         [self updateContents];
     }
     return self;
@@ -113,6 +113,7 @@
     if (string != newString) {
         [string release];
         string = [newString retain];
+        // update the contents to string + text
         [self updateContents];
     }
 }
@@ -128,6 +129,8 @@
     }
 }
 
+// changes to text are made through textStorage, this allows Skim to provide 
edits through AppleScript, which works directly on the textStorage
+// KVO is triggered manually when the textStorage is edited, either through 
setText: or through some other means, e.g. through AppleScript
 + (BOOL)automaticallyNotifiesObserversForKey:(NSString *)key {
     if ([key isEqualToString:SKNPDFAnnotationTextKey])
         return NO;
@@ -141,6 +144,7 @@
 
 - (void)setText:(NSAttributedString *)newText {
     if (textStorage != newText) {
+        // edit the textStorage, this will trigger KVO and update the text 
automatically
         if (newText)
             [textStorage replaceCharactersInRange:NSMakeRange(0, [textStorage 
length]) withAttributedString:newText];
         else
@@ -148,14 +152,17 @@
     }
 }
 
-- (void)textStorageDidProcessEditing:(NSNotification *)notification;
-{
+- (void)textStorageDidProcessEditing:(NSNotification *)notification {
+    // texts should be an array of objects wrapping the text of the note, used 
by Skim to provide a data source for the children in the outlineView
     [texts makeObjectsPerformSelector:@selector(willChangeValueForKey:) 
withObject:SKNPDFAnnotationTextKey];
+    // trigger KVO manually
     [self willChangeValueForKey:SKNPDFAnnotationTextKey];
+    // update the text
     [text release];
     text = [[NSAttributedString allocWithZone:[self zone]] 
initWithAttributedString:textStorage];
     [self didChangeValueForKey:SKNPDFAnnotationTextKey];
     [texts makeObjectsPerformSelector:@selector(didChangeValueForKey:) 
withObject:SKNPDFAnnotationTextKey];
+    // update the contents to string + text
     [self updateContents];
 }
 


This was sent by the SourceForge.net collaborative development platform, the 
world's largest Open Source development site.

-------------------------------------------------------------------------
Check out the new SourceForge.net Marketplace.
It's the best place to buy or sell services for
just about anything Open Source.
http://sourceforge.net/services/buy/index.php
_______________________________________________
Skim-app-commit mailing list
[email protected]
https://lists.sourceforge.net/lists/listinfo/skim-app-commit

Reply via email to