ResKnife/Cocoa/Classes/PasteboardDocument.m

66 lines
1.8 KiB
Mathematica
Raw Normal View History

2003-04-03 15:38:42 +00:00
#import "PasteboardDocument.h"
#import "Resource.h"
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;
}
-(void)readPasteboard:(NSString *)pbName
2003-04-03 15:38:42 +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
// disable undos during loading
2003-04-03 15:38:42 +00:00
[[self undoManager] disableUndoRegistration];
// get all types off the pasteboard
while( pbType = [enumerator nextObject] )
2003-04-03 15:38:42 +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
}
// re-enable undos
2003-04-03 15:38:42 +00:00
[[self undoManager] enableUndoRegistration];
[outlineView reloadData];
}
-(void)windowDidBecomeKey:(NSNotification *)notification
{
// 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-04-03 15:38:42 +00:00
@end