Revision: 12715
          http://sourceforge.net/p/skim-app/code/12715
Author:   hofman
Date:     2022-01-14 14:52:56 +0000 (Fri, 14 Jan 2022)
Log Message:
-----------
Make format script command object-first, make file NSObject category

Modified Paths:
--------------
    trunk/NSNumber_SKExtensions.h
    trunk/NSNumber_SKExtensions.m
    trunk/SKFormatCommand.h
    trunk/SKFormatCommand.m
    trunk/Skim.sdef

Modified: trunk/NSNumber_SKExtensions.h
===================================================================
--- trunk/NSNumber_SKExtensions.h       2022-01-13 15:24:38 UTC (rev 12714)
+++ trunk/NSNumber_SKExtensions.h       2022-01-14 14:52:56 UTC (rev 12715)
@@ -49,10 +49,3 @@
 - (NSString *)greekCounterValue;
 
 @end
-
-@interface NSObject (SKExtensions)
-
-- (NSUInteger)countOfTexLines;
-- (id)objectInTexLinesAtIndex:(NSUInteger)idx;
-
-@end

Modified: trunk/NSNumber_SKExtensions.m
===================================================================
--- trunk/NSNumber_SKExtensions.m       2022-01-13 15:24:38 UTC (rev 12714)
+++ trunk/NSNumber_SKExtensions.m       2022-01-14 14:52:56 UTC (rev 12715)
@@ -125,15 +125,3 @@
 }
 
 @end
-
-@implementation NSObject (SKExtensions)
-
-- (NSUInteger)countOfTexLines {
-    return INT_MAX;
-}
-
-- (id)objectInTexLinesAtIndex:(NSUInteger)idx {
-    return [NSNumber numberWithUnsignedInteger:idx];
-}
-
-@end

Modified: trunk/SKFormatCommand.h
===================================================================
--- trunk/SKFormatCommand.h     2022-01-13 15:24:38 UTC (rev 12714)
+++ trunk/SKFormatCommand.h     2022-01-14 14:52:56 UTC (rev 12715)
@@ -1,5 +1,5 @@
 //
-//  SKFormatCommand.h
+//  NSObject_SKExtensions.h
 //  Skim
 //
 //  Created by Christiaan Hofman on 8/19/09.
@@ -39,5 +39,12 @@
 #import <Cocoa/Cocoa.h>
 
 
-@interface SKFormatCommand : NSScriptCommand
+
+@interface NSObject (SKExtensions)
+
+- (NSUInteger)countOfTexLines;
+- (id)objectInTexLinesAtIndex:(NSUInteger)idx;
+
+- (id)handleFormatScriptCommand:(NSScriptCommand *)command;
+
 @end

Modified: trunk/SKFormatCommand.m
===================================================================
--- trunk/SKFormatCommand.m     2022-01-13 15:24:38 UTC (rev 12714)
+++ trunk/SKFormatCommand.m     2022-01-14 14:52:56 UTC (rev 12715)
@@ -1,5 +1,5 @@
 //
-//  SKFormatCommand.m
+//  NSObject_SKExtensions.m
 //  Skim
 //
 //  Created by Christiaan Hofman on 8/19/09.
@@ -42,11 +42,18 @@
 #import "NSAttributedString_SKExtensions.h"
 
 
-@implementation SKFormatCommand
+@implementation NSObject (SKExtensions)
 
-- (id)performDefaultImplementation {
-    id receiver = [self evaluatedReceivers];
-    NSDictionary *args = [self evaluatedArguments];
+- (NSUInteger)countOfTexLines {
+    return INT_MAX;
+}
+
+- (id)objectInTexLinesAtIndex:(NSUInteger)idx {
+    return [NSNumber numberWithUnsignedInteger:idx];
+}
+
+- (id)handleFormatScriptCommand:(NSScriptCommand *)comand {
+    NSDictionary *args = [comand evaluatedArguments];
     id template = [args objectForKey:@"Template"];
     id file = [args objectForKey:@"File"];
     NSAttributedString *attrString = nil;
@@ -55,13 +62,13 @@
     id text = nil;
     
     if (template == nil)
-               [self 
setScriptErrorNumber:NSRequiredArgumentsMissingScriptError]; 
+               [comand 
setScriptErrorNumber:NSRequiredArgumentsMissingScriptError];
     else if ([template isKindOfClass:[NSString class]])
         string = template;
     else if ([template isKindOfClass:[NSAttributedString class]])
         attrString = template;
     else if ([template isKindOfClass:[NSURL class]] == NO)
-               [self setScriptErrorNumber:NSArgumentsWrongScriptError]; 
+               [comand setScriptErrorNumber:NSArgumentsWrongScriptError];
     else if ([[SKTemplateManager sharedManager] 
isRichTextTemplateType:[template path]])
         attrString = [[[NSAttributedString alloc] initWithURL:template 
options:[NSDictionary dictionary] documentAttributes:&docAttrs error:NULL] 
autorelease];
     else
@@ -68,11 +75,11 @@
         string = [NSString stringWithContentsOfURL:template 
encoding:NSUTF8StringEncoding error:NULL];
     
     if (string) {
-        text = [SKTemplateParser stringByParsingTemplateString:string 
usingObject:receiver];
+        text = [SKTemplateParser stringByParsingTemplateString:string 
usingObject:self];
         if (file)
             [text writeToURL:file atomically:YES encoding:NSUTF8StringEncoding 
error:NULL];
     } else if (attrString) {
-        NSAttributedString *attrText = [SKTemplateParser 
attributedStringByParsingTemplateAttributedString:attrString 
usingObject:receiver];
+        NSAttributedString *attrText = [SKTemplateParser 
attributedStringByParsingTemplateAttributedString:attrString usingObject:self];
         if (attrText) {
             text = [attrText richTextSpecifier];
             if (file) {

Modified: trunk/Skim.sdef
===================================================================
--- trunk/Skim.sdef     2022-01-13 15:24:38 UTC (rev 12714)
+++ trunk/Skim.sdef     2022-01-14 14:52:56 UTC (rev 12715)
@@ -554,7 +554,6 @@
 
         <command name="format" code="SKIMFrmt"
             description="Format an object using a template.">
-            <cocoa class="SKFormatCommand"/>
             <direct-parameter
                 description="The object to format using a template.">
                 <type type="specifier"/>
@@ -602,7 +601,7 @@
                 <cocoa key="texLines"/>
             </element>
             <responds-to name="format">
-                <cocoa method=""/>
+                <cocoa method="handleFormatScriptCommand:"/>
             </responds-to>
         </class-extension>
 

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



_______________________________________________
Skim-app-commit mailing list
Skim-app-commit@lists.sourceforge.net
https://lists.sourceforge.net/lists/listinfo/skim-app-commit

Reply via email to