2001-10-19 19:41:13 +00:00
|
|
|
#import "InfoWindowController.h"
|
|
|
|
#import <Carbon/Carbon.h> // Actually I only need CarbonCore.framework, but <Carbon/CarbonCore.h> and <CarbonCore/CarbonCore.h> don't work, so I don't know what else to do
|
|
|
|
#import "ResourceDocument.h"
|
|
|
|
#import "Resource.h"
|
2002-02-23 03:40:24 +00:00
|
|
|
#import "NSOutlineView-SelectedItems.h"
|
2001-10-19 19:41:13 +00:00
|
|
|
|
|
|
|
@implementation InfoWindowController
|
|
|
|
|
|
|
|
- (id)init
|
|
|
|
{
|
|
|
|
self = [self initWithWindowNibName:@"InfoWindow"];
|
2002-02-07 07:37:51 +00:00
|
|
|
if( self ) [self setWindowFrameAutosaveName:@"InfoWindow"];
|
2001-10-19 19:41:13 +00:00
|
|
|
return self;
|
|
|
|
}
|
|
|
|
|
2002-02-11 01:22:17 +00:00
|
|
|
- (void)dealloc
|
|
|
|
{
|
|
|
|
[[NSNotificationCenter defaultCenter] removeObserver:self];
|
|
|
|
[super dealloc];
|
|
|
|
}
|
|
|
|
|
2001-10-19 19:41:13 +00:00
|
|
|
- (void)windowDidLoad
|
|
|
|
{
|
|
|
|
[super windowDidLoad];
|
|
|
|
|
2002-02-15 01:52:23 +00:00
|
|
|
// set window to only accept key when editing text boxes
|
|
|
|
[(NSPanel *)[self window] setBecomesKeyOnlyIfNeeded:YES];
|
|
|
|
|
2002-02-07 07:37:51 +00:00
|
|
|
// retain views for swapping in and out
|
|
|
|
[documentView retain];
|
|
|
|
[documentView removeFromSuperview];
|
|
|
|
[resourceView retain];
|
|
|
|
[resourceView removeFromSuperview];
|
|
|
|
|
2001-10-19 19:41:13 +00:00
|
|
|
[self setMainWindow:[NSApp mainWindow]];
|
|
|
|
[self updateInfoWindow];
|
|
|
|
|
|
|
|
[[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(mainWindowChanged:) name:NSWindowDidBecomeMainNotification object:nil];
|
|
|
|
[[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(selectedResourceChanged:) name:NSOutlineViewSelectionDidChangeNotification object:nil];
|
2002-02-14 23:24:53 +00:00
|
|
|
[[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(resourceAttributesDidChange:) name:ResourceAttributesDidChangeNotification object:nil];
|
2001-10-19 19:41:13 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
- (void)updateInfoWindow
|
|
|
|
{
|
|
|
|
if( selectedResource )
|
|
|
|
{
|
2002-02-07 07:37:51 +00:00
|
|
|
[[self window] setTitle:@"Resource Info"];
|
|
|
|
[placeholderView setContentView:resourceView];
|
2001-10-19 19:41:13 +00:00
|
|
|
[nameView setStringValue:[selectedResource name]];
|
2002-02-12 04:01:47 +00:00
|
|
|
[iconView setImage:[[NSWorkspace sharedWorkspace] iconForFileType:[selectedResource type]]];
|
2001-10-19 19:41:13 +00:00
|
|
|
[[attributesMatrix cellAtRow:changedBox column:0] setState:[[selectedResource attributes] shortValue] & resChanged];
|
|
|
|
[[attributesMatrix cellAtRow:preloadBox column:0] setState:[[selectedResource attributes] shortValue] & resPreload];
|
|
|
|
[[attributesMatrix cellAtRow:protectedBox column:0] setState:[[selectedResource attributes] shortValue] & resProtected];
|
|
|
|
[[attributesMatrix cellAtRow:lockedBox column:0] setState:[[selectedResource attributes] shortValue] & resLocked];
|
|
|
|
[[attributesMatrix cellAtRow:purgableBox column:0] setState:[[selectedResource attributes] shortValue] & resPurgeable];
|
|
|
|
[[attributesMatrix cellAtRow:systemHeapBox column:0] setState:[[selectedResource attributes] shortValue] & resSysHeap];
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
2002-02-07 07:37:51 +00:00
|
|
|
[[self window] setTitle:@"Document Info"];
|
2002-02-23 03:40:24 +00:00
|
|
|
[iconView setImage:[NSImage imageNamed:@"Resource file"]];
|
2002-02-07 20:33:31 +00:00
|
|
|
[nameView setStringValue:[currentDocument fileName]? [[currentDocument fileName] lastPathComponent]:[currentDocument displayName]];
|
2002-02-23 03:40:24 +00:00
|
|
|
[placeholderView setContentView:documentView];
|
2001-10-19 19:41:13 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
- (void)setMainWindow:(NSWindow *)mainWindow
|
|
|
|
{
|
|
|
|
NSWindowController *controller = [mainWindow windowController];
|
|
|
|
|
|
|
|
if( [[controller document] isKindOfClass:[ResourceDocument class]] )
|
|
|
|
currentDocument = [controller document];
|
|
|
|
else currentDocument = nil;
|
|
|
|
|
2002-02-23 03:40:24 +00:00
|
|
|
selectedResource = [[currentDocument outlineView] selectedItem];
|
2001-10-19 19:41:13 +00:00
|
|
|
[self updateInfoWindow];
|
|
|
|
}
|
|
|
|
|
|
|
|
- (void)mainWindowChanged:(NSNotification *)notification
|
|
|
|
{
|
|
|
|
[self setMainWindow:[notification object]];
|
|
|
|
}
|
|
|
|
|
|
|
|
- (void)selectedResourceChanged:(NSNotification *)notification
|
|
|
|
{
|
2002-02-23 03:40:24 +00:00
|
|
|
selectedResource = [[notification object] selectedItem];
|
2001-10-19 19:41:13 +00:00
|
|
|
[self updateInfoWindow];
|
|
|
|
}
|
|
|
|
|
|
|
|
- (IBAction)attributesChanged:(id)sender
|
|
|
|
{
|
|
|
|
short attr = 0x0001 << [sender selectedRow]+1;
|
|
|
|
short number = ([[selectedResource attributes] shortValue] ^ attr);
|
|
|
|
[selectedResource setAttributes:[NSNumber numberWithShort:number]];
|
2002-02-14 23:24:53 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
- (void)resourceAttributesDidChange:(NSNotification *)notification;
|
|
|
|
{
|
2001-10-19 19:41:13 +00:00
|
|
|
[self updateInfoWindow];
|
|
|
|
}
|
|
|
|
|
|
|
|
+ (id)sharedInfoWindowController
|
|
|
|
{
|
|
|
|
static InfoWindowController *sharedInfoWindowController = nil;
|
|
|
|
|
|
|
|
if( !sharedInfoWindowController )
|
|
|
|
{
|
|
|
|
sharedInfoWindowController = [[InfoWindowController allocWithZone:[self zone]] init];
|
|
|
|
}
|
|
|
|
return sharedInfoWindowController;
|
|
|
|
}
|
|
|
|
|
|
|
|
@end
|