From 3beb184c77f31f96d43a7fade0e462f5f05bba70 Mon Sep 17 00:00:00 2001 From: Christiaan Hofman <1167268+hofman@users.noreply.github.com> Date: Fri, 14 Jan 2022 14:52:56 +0000 Subject: [PATCH] Make format script command object-first, make file NSObject category --- NSNumber_SKExtensions.h | 7 ------- NSNumber_SKExtensions.m | 12 ------------ SKFormatCommand.h | 11 +++++++++-- SKFormatCommand.m | 25 ++++++++++++++++--------- Skim.sdef | 3 +-- 5 files changed, 26 insertions(+), 32 deletions(-) diff --git a/NSNumber_SKExtensions.h b/NSNumber_SKExtensions.h index 93c1c7e34..16112e880 100644 --- a/NSNumber_SKExtensions.h +++ b/NSNumber_SKExtensions.h @@ -49,10 +49,3 @@ - (NSString *)greekCounterValue; @end - -@interface NSObject (SKExtensions) - -- (NSUInteger)countOfTexLines; -- (id)objectInTexLinesAtIndex:(NSUInteger)idx; - -@end diff --git a/NSNumber_SKExtensions.m b/NSNumber_SKExtensions.m index 486a59882..8b8678fb2 100644 --- a/NSNumber_SKExtensions.m +++ b/NSNumber_SKExtensions.m @@ -125,15 +125,3 @@ - (NSAppleEventDescriptor *)scriptingTexLineDescriptor { } @end - -@implementation NSObject (SKExtensions) - -- (NSUInteger)countOfTexLines { - return INT_MAX; -} - -- (id)objectInTexLinesAtIndex:(NSUInteger)idx { - return [NSNumber numberWithUnsignedInteger:idx]; -} - -@end diff --git a/SKFormatCommand.h b/SKFormatCommand.h index e4ac39e10..acfe72827 100644 --- a/SKFormatCommand.h +++ b/SKFormatCommand.h @@ -1,5 +1,5 @@ // -// SKFormatCommand.h +// NSObject_SKExtensions.h // Skim // // Created by Christiaan Hofman on 8/19/09. @@ -39,5 +39,12 @@ #import -@interface SKFormatCommand : NSScriptCommand + +@interface NSObject (SKExtensions) + +- (NSUInteger)countOfTexLines; +- (id)objectInTexLinesAtIndex:(NSUInteger)idx; + +- (id)handleFormatScriptCommand:(NSScriptCommand *)command; + @end diff --git a/SKFormatCommand.m b/SKFormatCommand.m index 565af041d..2e01fce2c 100644 --- a/SKFormatCommand.m +++ b/SKFormatCommand.m @@ -1,5 +1,5 @@ // -// SKFormatCommand.m +// NSObject_SKExtensions.m // Skim // // Created by Christiaan Hofman on 8/19/09. @@ -42,11 +42,18 @@ This software is Copyright (c) 2009-2022 #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,24 +62,24 @@ - (id)performDefaultImplementation { 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 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) { diff --git a/Skim.sdef b/Skim.sdef index e92680b99..3e95ac0e5 100644 --- a/Skim.sdef +++ b/Skim.sdef @@ -554,7 +554,6 @@ - @@ -602,7 +601,7 @@ - +