// // RDocument.m // Script editor document // RemoteR // // Created by Simon Urbanek on 2/13/11. // Copyright 2011 Simon Urbanek. All rights reserved. // #import "RDocument.h" #import "MyDocument.h" @implementation RDocument - (NSString *)windowNibName { // Implement this to return a nib to load OR implement -makeWindowControllers to manually create your controllers. return @"RDocument"; } - (void)windowControllerDidLoadNib:(NSWindowController *)windowController { // FIXME: set the font manually for now [textView setFont:[NSFont fontWithName:@"Monaco" size:11.0]]; } - (NSAttributedString*) string { NSLog(@"%@> string", self); return string; } - (void) setString: (NSAttributedString*) newString { NSLog(@"%@> setString", self); if (string) [string release]; string = newString; if (string) [string retain]; } - (IBAction) execute: (id) sender { NSLog(@"%@> execute:%@", self, sender); NSRange sr = [textView selectedRange]; NSString *txt = nil; if (sr.length == 0) { } else txt = [[textView string] substringWithRange:sr]; if (txt) [[MyDocument currentConsole] executeInput:txt]; } - (NSData *)dataOfType:(NSString *)typeName error:(NSError **)outError { // You can also choose to override -fileWrapperOfType:error:, -writeToURL:ofType:error:, or -writeToURL:ofType:forSaveOperation:originalContentsURL:error: instead. // For applications targeted for Panther or earlier systems, you should use the deprecated API -dataRepresentationOfType:. In this case you can also choose to override -fileWrapperRepresentationOfType: or -writeToFile:ofType: instead. NSLog(@"%@> dataOfType:%@", self, typeName); return [[textView string] dataUsingEncoding:NSUTF8StringEncoding]; } - (BOOL)readFromData:(NSData *)data ofType:(NSString *)typeName error:(NSError **)outError { // You can also choose to override -readFromFileWrapper:ofType:error: or -readFromURL:ofType:error: instead. // For applications targeted for Panther or earlier systems, you should use the deprecated API -loadDataRepresentation:ofType. In this case you can also choose to override -readFromFile:ofType: or -loadFileWrapperRepresentation:ofType: instead. NSLog(@"%@> readFromData: ofType:%@", self, typeName); NSString *txt = [[NSString alloc] initWithData:data encoding:NSUTF8StringEncoding]; if (!txt) { if (outError) outError[0] = [NSError errorWithDomain:@"encoding" code:1 userInfo:nil]; return NO; } NSLog(@"textView: %@", textView); if (!textView) // this is normally the case - we just set the attributed string which is then used by the text view string = [[NSAttributedString alloc] initWithString:txt]; else [textView setString:txt]; [txt release]; return YES; } @end