Revision: 5569
http://skim-app.svn.sourceforge.net/skim-app/?rev=5569&view=rev
Author: hofman
Date: 2009-08-19 20:55:58 +0000 (Wed, 19 Aug 2009)
Log Message:
-----------
add script command to parse a template for an object
Modified Paths:
--------------
trunk/Skim.sdef
trunk/Skim.xcodeproj/project.pbxproj
Added Paths:
-----------
trunk/SKFormatCommand.h
trunk/SKFormatCommand.m
Added: trunk/SKFormatCommand.h
===================================================================
--- trunk/SKFormatCommand.h (rev 0)
+++ trunk/SKFormatCommand.h 2009-08-19 20:55:58 UTC (rev 5569)
@@ -0,0 +1,43 @@
+//
+// SKFormatCommand.h
+// Skim
+//
+// Created by Christiaan on 8/19/09.
+/*
+ This software is Copyright (c) 2009
+ Christiaan Hofman. All rights reserved.
+
+ Redistribution and use in source and binary forms, with or without
+ modification, are permitted provided that the following conditions
+ are met:
+
+ - Redistributions of source code must retain the above copyright
+ notice, this list of conditions and the following disclaimer.
+
+ - Redistributions in binary form must reproduce the above copyright
+ notice, this list of conditions and the following disclaimer in
+ the documentation and/or other materials provided with the
+ distribution.
+
+ - Neither the name of Christiaan Hofman nor the names of any
+ contributors may be used to endorse or promote products derived
+ from this software without specific prior written permission.
+
+ THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
+ "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
+ LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
+ A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
+ OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
+ SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
+ LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
+ DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
+ THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
+ (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
+ OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
+ */
+
+#import <Cocoa/Cocoa.h>
+
+
+...@interface SKFormatCommand : NSScriptCommand
+...@end
Added: trunk/SKFormatCommand.m
===================================================================
--- trunk/SKFormatCommand.m (rev 0)
+++ trunk/SKFormatCommand.m 2009-08-19 20:55:58 UTC (rev 5569)
@@ -0,0 +1,108 @@
+//
+// SKFormatCommand.m
+// Skim
+//
+// Created by Christiaan on 8/19/09.
+/*
+ This software is Copyright (c) 2009
+ Christiaan Hofman. All rights reserved.
+
+ Redistribution and use in source and binary forms, with or without
+ modification, are permitted provided that the following conditions
+ are met:
+
+ - Redistributions of source code must retain the above copyright
+ notice, this list of conditions and the following disclaimer.
+
+ - Redistributions in binary form must reproduce the above copyright
+ notice, this list of conditions and the following disclaimer in
+ the documentation and/or other materials provided with the
+ distribution.
+
+ - Neither the name of Christiaan Hofman nor the names of any
+ contributors may be used to endorse or promote products derived
+ from this software without specific prior written permission.
+
+ THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
+ "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
+ LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
+ A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
+ OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
+ SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
+ LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
+ DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
+ THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
+ (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
+ OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
+ */
+
+#import "SKFormatCommand.h"
+#import "SKTemplateParser.h"
+#import "SKRichTextFormat.h"
+
+
+...@implementation SKFormatCommand
+
+- (id)performDefaultImplementation {
+ id receiver = [self evaluatedReceivers];
+ NSDictionary *args = [self evaluatedArguments];
+ id template = [args objectForKey:@"template"];
+ id file = [args objectForKey:@"to"];
+ NSAttributedString *attrString = nil;
+ NSString *string = nil;
+ NSDictionary *docAttrs = nil;
+ id text = nil;
+
+ if (template == nil)
+ [self
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];
+ else if ([[NSSet setWithObjects:@"rtf", @"doc", @"docx", @"odt", @"rtfd",
nil] containsObject:[[[template path] pathExtension] lowercaseString]])
+ attrString = [[[NSAttributedString alloc] initWithURL:template
documentAttributes:&docAttrs] autorelease];
+ else
+ string = [NSString stringWithContentsOfURL:template
encoding:NSUTF8StringEncoding error:NULL];
+
+ if (string) {
+ text = [SKTemplateParser stringByParsingTemplateString:string
usingObject:receiver];
+ if (file)
+ [text writeToURL:file atomically:YES encoding:NSUTF8StringEncoding
error:NULL];
+ } else if (attrString) {
+ NSAttributedString *attrText = [SKTemplateParser
attributedStringByParsingTemplateAttributedString:attrString
usingObject:receiver];
+ if (attrText) {
+ NSMutableDictionary *mutableDocAttrs = [NSMutableDictionary
dictionaryWithDictionary:docAttrs];
+ [mutableDocAttrs setObject:NSRTFTextDocumentType
forKey:NSDocumentTypeDocumentAttribute];
+ NSData *data = [attrText RTFFromRange:NSMakeRange(0, [attrText
length]) documentAttributes:mutableDocAttrs];
+ text = [SKRichTextFormat richTextSpecifierWithData:data];
+ if (file) {
+ NSString *ext = [[[file path] pathExtension] lowercaseString];
+ if ([ext isEqualToString:@"rtfd"]) {
+ [mutableDocAttrs setObject:NSRTFDTextDocumentType
forKey:NSDocumentTypeDocumentAttribute];
+ [[text RTFDFileWrapperFromRange:NSMakeRange(0, [attrText
length]) documentAttributes:mutableDocAttrs] writeToFile:[file path]
atomically:YES updateFilenames:NO];
+ } else {
+ NSString *docType = nil;
+ if ([ext isEqualToString:@"rtf"])
+ docType = NSRTFTextDocumentType;
+ else if ([ext isEqualToString:@"doc"])
+ docType = NSDocFormatTextDocumentType;
+ else if ([ext isEqualToString:@"docx"])
+ docType = NSWordMLTextDocumentType;
+ else if (floor(NSAppKitVersionNumber) >
NSAppKitVersionNumber10_4 && [ext isEqualToString:@"odt"])
+ docType = NSOfficeOpenXMLTextDocumentType;
+ if (docType && [docType
isEqualToString:NSRTFTextDocumentType] == NO) {
+ [mutableDocAttrs setObject:docType
forKey:NSDocumentTypeDocumentAttribute];
+ data = [attrText dataFromRange:NSMakeRange(0,
[attrText length]) documentAttributes:mutableDocAttrs error:NULL];
+ }
+ [data writeToURL:file atomically:YES];
+ }
+ }
+ }
+ }
+
+ return text;
+}
+
+...@end
Modified: trunk/Skim.sdef
===================================================================
--- trunk/Skim.sdef 2009-08-19 20:50:59 UTC (rev 5568)
+++ trunk/Skim.sdef 2009-08-19 20:55:58 UTC (rev 5569)
@@ -189,6 +189,9 @@
<responds-to name="get pages for">
<cocoa method=""/>
</responds-to>
+ <responds-to name="format">
+ <cocoa method=""/>
+ </responds-to>
</class>
<class name="window" code="cwin"
@@ -704,6 +707,9 @@
<responds-to name="grab">
<cocoa method="handleGrabScriptCommand:"/>
</responds-to>
+ <responds-to name="format">
+ <cocoa method=""/>
+ </responds-to>
</class>
<class name="note" plural="notes" code="Note"
@@ -808,6 +814,9 @@
<responds-to name="get pages for">
<cocoa method=""/>
</responds-to>
+ <responds-to name="format">
+ <cocoa method=""/>
+ </responds-to>
</class>
<class name="point list" plural="point lists" code="PtLi"
@@ -1416,6 +1425,33 @@
description="The PDF or TIFF data of the picture."/>
</command>
+ <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="document"/>
+ <type type="page"/>
+ <type type="note"/>
+ </direct-parameter>
+ <parameter name="using template" code="Tmpl"
+ description="The template to use as a file, text, or rich
text.">
+ <type type="file"/>
+ <type type="text"/>
+ <type type="rich text"/>
+ <cocoa key="template"/>
+ </parameter>
+ <parameter name="to" type="file" code="to " optional="yes"
+ description="The file to write the resulting text to.">
+ <cocoa key="to"/>
+ </parameter>
+ <result
+ description="The text or rich text generated using the
template.">
+ <type type="text"/>
+ <type type="specifier"/>
+ </result>
+ </command>
+
</suite>
</dictionary>
Modified: trunk/Skim.xcodeproj/project.pbxproj
===================================================================
--- trunk/Skim.xcodeproj/project.pbxproj 2009-08-19 20:50:59 UTC (rev
5568)
+++ trunk/Skim.xcodeproj/project.pbxproj 2009-08-19 20:55:58 UTC (rev
5569)
@@ -252,6 +252,7 @@
CEF82CE60EC4B2FE009652CF /* libcrypto.dylib in Frameworks */ =
{isa = PBXBuildFile; fileRef = CEF82CE50EC4B2FE009652CF /* libcrypto.dylib */;
};
CEF839B30C77742A00A3AD51 /* Files_SKExtensions.m in Sources */
= {isa = PBXBuildFile; fileRef = CEF839B10C77742A00A3AD51 /*
Files_SKExtensions.m */; };
CEF84C630C78A89A00A3AD51 /* SmallPreferences.tiff in Resources
*/ = {isa = PBXBuildFile; fileRef = CEF84C620C78A89900A3AD51 /*
SmallPreferences.tiff */; };
+ CEFBC96A103C5CBF00535C74 /* SKFormatCommand.m in Sources */ =
{isa = PBXBuildFile; fileRef = CEFBC969103C5CBF00535C74 /* SKFormatCommand.m
*/; };
CEFD68740C01D4080027B933 /* SkimImporter.mdimporter in Copy
Files: Spotlight */ = {isa = PBXBuildFile; fileRef = CEFD68690C01D3BB0027B933
/* SkimImporter.mdimporter */; };
CEFDF8BE0B3848C40091C61A /* SKNavigationWindow.m in Sources */
= {isa = PBXBuildFile; fileRef = CEFDF8BD0B3848C40091C61A /*
SKNavigationWindow.m */; };
F92DB5AD0B36FE1F002A26E9 /* SKSnapshotPDFView.m in Sources */ =
{isa = PBXBuildFile; fileRef = F92DB5AB0B36FE1F002A26E9 /* SKSnapshotPDFView.m
*/; };
@@ -972,6 +973,8 @@
CEF839B00C77742A00A3AD51 /* Files_SKExtensions.h */ = {isa =
PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path =
Files_SKExtensions.h; sourceTree = "<group>"; };
CEF839B10C77742A00A3AD51 /* Files_SKExtensions.m */ = {isa =
PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path
= Files_SKExtensions.m; sourceTree = "<group>"; };
CEF84C620C78A89900A3AD51 /* SmallPreferences.tiff */ = {isa =
PBXFileReference; lastKnownFileType = image.tiff; path = SmallPreferences.tiff;
sourceTree = "<group>"; };
+ CEFBC968103C5CBF00535C74 /* SKFormatCommand.h */ = {isa =
PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path =
SKFormatCommand.h; sourceTree = "<group>"; };
+ CEFBC969103C5CBF00535C74 /* SKFormatCommand.m */ = {isa =
PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path
= SKFormatCommand.m; sourceTree = "<group>"; };
CEFD68610C01D3BB0027B933 /* SkimImporter.xcodeproj */ = {isa =
PBXFileReference; lastKnownFileType = "wrapper.pb-project"; name =
SkimImporter.xcodeproj; path = SkimImporter/SkimImporter.xcodeproj; sourceTree
= "<group>"; };
CEFDF8BC0B3848C40091C61A /* SKNavigationWindow.h */ = {isa =
PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path =
SKNavigationWindow.h; sourceTree = "<group>"; };
CEFDF8BD0B3848C40091C61A /* SKNavigationWindow.m */ = {isa =
PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path
= SKNavigationWindow.m; sourceTree = "<group>"; };
@@ -1476,6 +1479,8 @@
children = (
CE4643DC0DF6B77800CFD8D2 /* SKBoundsCommand.h
*/,
CE4643DD0DF6B77800CFD8D2 /* SKBoundsCommand.m
*/,
+ CEFBC968103C5CBF00535C74 /* SKFormatCommand.h
*/,
+ CEFBC969103C5CBF00535C74 /* SKFormatCommand.m
*/,
CE4643D90DF6B66000CFD8D2 /* SKIndexCommand.h */,
CE4643DA0DF6B66000CFD8D2 /* SKIndexCommand.m */,
CE4643CD0DF6B5A400CFD8D2 /* SKJoinCommand.h */,
@@ -2222,6 +2227,7 @@
CE32531F0F4723EA0021BADD /*
SKMainWindowController_Actions.m in Sources */,
CE80A81E0FDAB1690086A46C /*
SKHighlightingPopUpButton.m in Sources */,
CE9B804A1030642400EA8774 /* SKTransitionInfo.m
in Sources */,
+ CEFBC96A103C5CBF00535C74 /* SKFormatCommand.m
in Sources */,
);
runOnlyForDeploymentPostprocessing = 0;
};
This was sent by the SourceForge.net collaborative development platform, the
world's largest Open Source development site.
------------------------------------------------------------------------------
Let Crystal Reports handle the reporting - Free Crystal Reports 2008 30-Day
trial. Simplify your report design, integration and deployment - and focus on
what you do best, core application coding. Discover what's new with
Crystal Reports now. http://p.sf.net/sfu/bobj-july
_______________________________________________
Skim-app-commit mailing list
[email protected]
https://lists.sourceforge.net/lists/listinfo/skim-app-commit