// // SavedPasteboard.m // PastePacker // // Created by Daniel Grover on 10/10/07. // Copyright Wonder Warp Software 2007 . All rights reserved. // #import "SavedPasteboard.h" @implementation SavedPasteboard - (id)init { self = [super init]; if (self) { pasteboardData = [[NSMutableDictionary alloc] init]; } return self; } - (void) dealloc { [pasteboardData release]; [super dealloc]; } - (NSString *)windowNibName { return @"SavedPasteboard"; } - (void)windowControllerDidLoadNib:(NSWindowController *) aController { [super windowControllerDidLoadNib:aController]; [typeView setFont:[NSFont fontWithName:@"Monaco" size:10]]; [typeView setTextContainerInset:NSMakeSize(15,15)]; } - (NSData *)dataRepresentationOfType:(NSString *)aType { NSDictionary *d = [[[NSMutableDictionary alloc] init] autorelease]; [d setValue:pasteboardData forKey:@"pasteboardContents"]; [d setValue:[self comments] forKey:@"comments"]; return [NSPropertyListSerialization dataFromPropertyList:d format:NSPropertyListXMLFormat_v1_0 errorDescription:nil]; } - (BOOL)loadDataRepresentation:(NSData *)data ofType:(NSString *)aType { NSString *error; NSPropertyListFormat f = NSPropertyListXMLFormat_v1_0; NSMutableDictionary *d = [NSPropertyListSerialization propertyListFromData:data mutabilityOption:NSPropertyListMutableContainersAndLeaves format:&f errorDescription:&error]; if (error){ NSLog(error); return NO; } [self setComments:[d valueForKey:@"comments"]]; [pasteboardData release]; pasteboardData = [d valueForKey:@"pasteboardContents"]; [pasteboardData retain]; return YES; } - (void) addContentsOfPasteboard:(NSPasteboard *)p{ NSArray *pTypes = [p types]; int i; for (i = 0; i < [pTypes count]; i++){ NSString *type = [pTypes objectAtIndex:i]; [pasteboardData setValue:[p dataForType:type] forKey:type]; } [typesTable reloadData]; } - (NSArray *)types{ return [[pasteboardData allKeys] sortedArrayUsingSelector:@selector(compare:)]; } - (id)tableView:(NSTableView *)aTableView objectValueForTableColumn:(NSTableColumn *)aTableColumn row:(int)rowIndex { return [[self types] objectAtIndex:rowIndex]; } - (int)numberOfRowsInTableView:(NSTableView *)aTableView { return [[self types] count]; } - (BOOL)tableView:(NSTableView *)aTableView shouldSelectRow:(int)rowIndex{ NSString *s = [[pasteboardData objectForKey:[[self types] objectAtIndex:rowIndex]] description]; [typeView setString:[s substringWithRange:NSMakeRange(1, [s length] - 2)]]; // remove the <> on the outside. return YES; } - (NSString *)comments{ return comments; } - (void)setComments:(NSString *)newComments{ [comments release]; comments = newComments; [comments retain]; } @end