Revision: 7399
          http://skim-app.svn.sourceforge.net/skim-app/?rev=7399&view=rev
Author:   hofman
Date:     2011-07-27 10:06:28 +0000 (Wed, 27 Jul 2011)

Log Message:
-----------
coerce and set all properties at once in duplicate command for notes, let the 
frameworks handle unsettable keys

Modified Paths:
--------------
    trunk/PDFPage_SKExtensions.m
    trunk/SKMainDocument.m

Modified: trunk/PDFPage_SKExtensions.m
===================================================================
--- trunk/PDFPage_SKExtensions.m        2011-07-27 00:08:05 UTC (rev 7398)
+++ trunk/PDFPage_SKExtensions.m        2011-07-27 10:06:28 UTC (rev 7399)
@@ -571,20 +571,18 @@
     if ([key isEqualToString:@"notes"]) {
         NSMutableArray *copiedValue = [[NSMutableArray alloc] init];
         for (PDFAnnotation *annotation in value) {
-            if ([annotation isMovable]) { // we don't want to duplicate markup
+            if ([annotation isMovable]) {
                 PDFAnnotation *copiedAnnotation = [[PDFAnnotation alloc] 
initSkimNoteWithProperties:[annotation SkimNoteProperties]];
                 [copiedAnnotation registerUserName];
-                if ([properties count]) {
-                    NSMutableDictionary *validProps = [NSMutableDictionary 
dictionary];
-                    NSScriptClassDescription *classDesc = 
[NSScriptClassDescription classDescriptionForClass:[copiedAnnotation class]];
-                    for (NSString *aKey in properties) {
-                        if ([classDesc hasWritablePropertyForKey:aKey])
-                            [validProps setValue:[copiedAnnotation 
coerceValue:[properties objectForKey:aKey] forKey:aKey] forKey:aKey];
-                    }
-                    if ([validProps count])
-                        [copiedAnnotation setScriptingProperties:validProps];
-                }
+                if ([properties count])
+                    [copiedAnnotation setScriptingProperties:[copiedAnnotation 
coerceValue:properties forKey:@"scriptingProperties"]];
                 [copiedValue addObject:copiedAnnotation];
+            } else {
+                // we don't want to duplicate markup
+                NSScriptCommand *cmd = [NSScriptCommand currentCommand];
+                [cmd 
setScriptErrorNumber:NSReceiversCantHandleCommandScriptError];
+                [cmd setScriptErrorString:NSLocalizedString(@"Cannot duplicate 
markup note.",@"Error description")];
+                SKDESTROY(copiedValue);
             }
         }
         return copiedValue;

Modified: trunk/SKMainDocument.m
===================================================================
--- trunk/SKMainDocument.m      2011-07-27 00:08:05 UTC (rev 7398)
+++ trunk/SKMainDocument.m      2011-07-27 10:06:28 UTC (rev 7399)
@@ -1825,22 +1825,20 @@
     if ([key isEqualToString:@"notes"]) {
         NSMutableArray *copiedValue = [[NSMutableArray alloc] init];
         for (PDFAnnotation *annotation in value) {
-            if ([annotation isMovable]) { // we don't want to duplicate markup
+            if ([annotation isMovable]) {
                 PDFAnnotation *copiedAnnotation = [[PDFAnnotation alloc] 
initSkimNoteWithProperties:[annotation SkimNoteProperties]];
                 [copiedAnnotation registerUserName];
                 if ([copiedAnnotation respondsToSelector:@selector(setPage:)])
                     [copiedAnnotation performSelector:@selector(setPage:) 
withObject:[annotation page]];
-                if ([properties count]) {
-                    NSMutableDictionary *validProps = [NSMutableDictionary 
dictionary];
-                    NSScriptClassDescription *classDesc = 
[NSScriptClassDescription classDescriptionForClass:[copiedAnnotation class]];
-                    for (NSString *aKey in properties) {
-                        if ([classDesc hasWritablePropertyForKey:aKey])
-                            [validProps setValue:[copiedAnnotation 
coerceValue:[properties objectForKey:aKey] forKey:aKey] forKey:aKey];
-                    }
-                    if ([validProps count])
-                        [copiedAnnotation setScriptingProperties:validProps];
-                }
+                if ([properties count])
+                    [copiedAnnotation setScriptingProperties:[copiedAnnotation 
coerceValue:properties forKey:@"scriptingProperties"]];
                 [copiedValue addObject:copiedAnnotation];
+            } else {
+                // we don't want to duplicate markup
+                NSScriptCommand *cmd = [NSScriptCommand currentCommand];
+                [cmd 
setScriptErrorNumber:NSReceiversCantHandleCommandScriptError];
+                [cmd setScriptErrorString:NSLocalizedString(@"Cannot duplicate 
markup note.",@"Error description")];
+                SKDESTROY(copiedValue);
             }
         }
         return copiedValue;


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

------------------------------------------------------------------------------
Got Input?   Slashdot Needs You.
Take our quick survey online.  Come on, we don't ask for help often.
Plus, you'll get a chance to win $100 to spend on ThinkGeek.
http://p.sf.net/sfu/slashdot-survey
_______________________________________________
Skim-app-commit mailing list
[email protected]
https://lists.sourceforge.net/lists/listinfo/skim-app-commit

Reply via email to