2003-04-03 15:38:42 +00:00
|
|
|
#import "PasteboardDocument.h"
|
|
|
|
#import "Resource.h"
|
|
|
|
|
2008-07-31 20:27:55 +00:00
|
|
|
extern NSString *RKResourcePboardType;
|
|
|
|
|
2003-04-03 15:38:42 +00:00
|
|
|
@implementation PasteboardDocument
|
|
|
|
|
|
|
|
- (id)init
|
|
|
|
{
|
|
|
|
self = [super init];
|
|
|
|
if( self )
|
|
|
|
{
|
|
|
|
[self readPasteboard:NSGeneralPboard];
|
|
|
|
}
|
|
|
|
return self;
|
|
|
|
}
|
|
|
|
|
2008-07-31 20:27:55 +00:00
|
|
|
-(void)readPasteboard:(NSString *)pbName
|
2003-04-03 15:38:42 +00:00
|
|
|
{
|
2008-07-31 20:27:55 +00:00
|
|
|
// this method is mostly a duplicate of -[ResourceDocument paste:] but takes a pasteboard name for an argument
|
|
|
|
NSPasteboard *pb = [NSPasteboard pasteboardWithName:pbName];
|
|
|
|
NSEnumerator *enumerator = [[pb types] objectEnumerator];
|
|
|
|
NSString *pbType;
|
|
|
|
|
|
|
|
// clear current pasteboard representation
|
|
|
|
[self selectAll:nil];
|
|
|
|
[self clear:nil];
|
|
|
|
|
|
|
|
// set the window's title to represent the pasteboard being shown (at some point I anticipate having several of these)
|
|
|
|
[[self window] setTitle:pbName];
|
2003-04-03 15:38:42 +00:00
|
|
|
|
2008-07-31 20:27:55 +00:00
|
|
|
// disable undos during loading
|
2003-04-03 15:38:42 +00:00
|
|
|
[[self undoManager] disableUndoRegistration];
|
2008-07-31 20:27:55 +00:00
|
|
|
|
|
|
|
// get all types off the pasteboard
|
|
|
|
while( pbType = [enumerator nextObject] )
|
2003-04-03 15:38:42 +00:00
|
|
|
{
|
2008-07-31 20:27:55 +00:00
|
|
|
// 'paste' any resources into pbdoc's data source
|
|
|
|
if( [pbType isEqualToString:RKResourcePboardType] )
|
|
|
|
[self pasteResources:[NSUnarchiver unarchiveObjectWithData:[pb dataForType:RKResourcePboardType]]];
|
|
|
|
else
|
|
|
|
{
|
|
|
|
// create the faux resource & add it to the array
|
|
|
|
Resource *resource = [Resource resourceOfType:nil andID:nil withName:pbType andAttributes:nil data:[pb dataForType:pbType]];
|
|
|
|
[resources addObject:resource]; // array retains resource
|
|
|
|
}
|
2003-04-03 15:38:42 +00:00
|
|
|
}
|
2008-07-31 20:27:55 +00:00
|
|
|
|
|
|
|
// re-enable undos
|
2003-04-03 15:38:42 +00:00
|
|
|
[[self undoManager] enableUndoRegistration];
|
2003-08-10 13:59:58 +00:00
|
|
|
|
|
|
|
[outlineView reloadData];
|
|
|
|
}
|
|
|
|
|
2008-07-31 20:27:55 +00:00
|
|
|
-(void)windowDidBecomeKey:(NSNotification *)notification
|
2003-08-10 13:59:58 +00:00
|
|
|
{
|
|
|
|
// This mess sponsored by Uli Kusterer ;-)
|
|
|
|
generalChangeCount = [[NSPasteboard generalPasteboard] changeCount];
|
|
|
|
[resources removeAllObjects];
|
|
|
|
|
|
|
|
[self readPasteboard:NSGeneralPboard]; // Update window contents.
|
2003-04-03 15:38:42 +00:00
|
|
|
}
|
|
|
|
|
2003-08-10 13:59:58 +00:00
|
|
|
|
2003-04-03 15:38:42 +00:00
|
|
|
@end
|