Custom Fields in Pages

Originator:charles.parnot
Number:rdar://8258643 Date Originated:07/31/2010
Status:Open Resolved:
Product:iWork Product Version:
Classification: Reproducible:
 
Charles Parnot31-Jul-2010 01:20 AM

Summary:

Pages offers a number of built-in "fields" for things like the current date, the current page number,... It also uses "fields" for Endnote citations. However, there is no option for other 3rd-part developers to insert custom fields that would provide alternative citation ability for other applications, or that could open up Pages to other types of "niche" needs. This could be solved by abstracting out the concept of a "field" having a visible user-facing content, and a custom invisible content where the 3rd-party developer could embed its own metadata. These fields would then only be editable via Applescript, so the user would typically not be exposed to the "magic" happening behind the scenes.



Notes:

I am working with Mekentosj (http://mekentosj.com) on version 2 of Papers, that is currently in developement and expected to be released at the end of 2010 (either beta or full release 2.0). Papers 2 includes a Citations component that provides the same functionality as EndNote (though we believe we provide a much nicer user experience). We have already built support for Pages, but we cannot provide the higher level of integration that exists for EndNote. Instead, we insert temporary plain-text "codes", like for instance '{Smith:2001a}' and when the user is ready to format the bibliography, we create a separate document to replace these codes with the final formatted citations (a destructive process, hence the need to create a separate document).

Here we propose what we think should be the simplest way to open up Pages for us, and for other 3rd-party developers as well:

1. add the concept of a custom field in Pages, which is made of 2 components:
	* visible user-facing styled content, same as the normal Pages content, but not editable (similar to what happens when the user chooses Insert...Page Number, or one of the other options in that menu)
	* invisible metadata, that can just be a string
	
2. provide Applescript hooks to those fields that allows to:
	* iterate over custom fields in a document
	* read/write the visible text (with same properties as what can be set for all the rest of the normal text)
	* read/write the metadata (unformatted text is enough to do it all)


The above would make it possible to provide first-class integration of Papers citation feature with Pages, similar to what we are able to do with MS Word (which has the concept of custom fields).

Then it would be great to also consider this approach in addition to the Applescript hooks:

3. provide a pasteboard hook, where a developer can load a custom field in the pasteboard so that it can then be pasted in Pages, and generate a custom field. This would be particularly useful for Pages on iPad. On the Mac (and similarly on iOS), for a Cocoa app like Papers, that would mean loading NSPasteboard with a specific type using a specific data structure, for instance (probably no need for an SDK, it's really just 3 strings that need to be documented):
 
 
	// load a Pages custom field in the pasteboard
	NSAttributedString *visibleString = [[NSAttributedString alloc] initWithString:@"Smith et al. 2001"];
	NSData *visibleStringRTFData = [visibleString RTFDFromRange:NSMakeRange(0, [visibleString length])];
	NSString *metadataString = @"PAPERS2 { first_citation }"
	NSDictionary *pagescustomField = [NSDictionary dictionaryWithObjectsAndKeys:
									  visibleStringRTFData, @"PGCustomFieldContentKey",
									  metadataString,       @"PGCustomFieldMetadataKey",
									  nil];
	NSData *customFieldData = [NSPropertyListSerialization dataFromPropertyList:pagescustomField format:NSPropertyListBinaryFormat_v1_0 errorDescription:nil];
	[[NSPasteboard generalPasteboard] declareTypes:[NSArray arrayWithObjects:@"PGCustomFieldPboardType", nil] owner:nil];
	[[NSPasteboard generalPasteboard] setData:customFieldData forType:@"PGCustomFieldPboardType"];


Of course, if there are other ways we can add EndNote-like functionality in Pages, but instead via Papers, we would definitely adopt it.


Steps to Reproduce:
N/A

Expected Results:
N/A

Actual Results:
N/A

Regression:
N/A

Comments


Please note: Reports posted here will not necessarily be seen by Apple. All problems should be submitted at bugreport.apple.com before they are posted here. Please only post information for Radars that you have filed yourself, and please do not include Apple confidential information in your posts. Thank you!