Implemented new methods and renamed some old which are now public.

git-svn-id: svn+ssh://svn.gna.org/svn/gnustep/libs/gui/trunk@11542 72102866-910b-0410-8b05-ffd578937521
This commit is contained in:
FredKiefer 2001-11-26 20:27:21 +00:00
parent c018f02e93
commit 9d857045a2

View file

@ -52,6 +52,27 @@
return self; return self;
} }
- (id) initWithWindowNibPath: (NSString *)windowNibPath
owner: (id)owner
{
if (windowNibPath == nil)
{
[NSException raise: NSInvalidArgumentException
format: @"attempt to init NSWindowController with nil windowNibPath"];
}
if (owner == nil)
{
[NSException raise: NSInvalidArgumentException
format: @"attempt to init NSWindowController with nil owner"];
}
self = [self initWithWindow: nil];
ASSIGN(_windowNibPath, windowNibPath);
_owner = owner;
return self;
}
- (id) initWithWindow: (NSWindow *)window - (id) initWithWindow: (NSWindow *)window
{ {
self = [super init]; self = [super init];
@ -79,6 +100,7 @@
{ {
[[NSNotificationCenter defaultCenter] removeObserver: self]; [[NSNotificationCenter defaultCenter] removeObserver: self];
RELEASE(_windowNibName); RELEASE(_windowNibName);
RELEASE(_windowNibPath);
RELEASE(_windowFrameAutosaveName); RELEASE(_windowFrameAutosaveName);
RELEASE(_topLevelObjects); RELEASE(_topLevelObjects);
AUTORELEASE (_window); /* FIXME - should be RELEASE I think */ AUTORELEASE (_window); /* FIXME - should be RELEASE I think */
@ -87,9 +109,34 @@
- (NSString *) windowNibName - (NSString *) windowNibName
{ {
if ((_windowNibName == nil) && (_windowNibPath != nil))
{
return [[_windowNibPath lastPathComponent]
stringByDeletingPathExtension];
}
return _windowNibName; return _windowNibName;
} }
- (NSString *)windowNibPath
{
if ((_windowNibName != nil) && (_windowNibPath == nil))
{
NSString *path;
// This is not fully correct as nib resources are searched different.
path = [[NSBundle bundleForClass: [_owner class]]
pathForNibResource: _windowNibName];
if (path == nil)
path = [[NSBundle mainBundle]
pathForNibResource: _windowNibName];
return path;
}
return _windowNibPath;
}
- (id) owner - (id) owner
{ {
return _owner; return _owner;
@ -99,7 +146,7 @@
{ {
// FIXME - this is RETAINed and never RELEASEd ... // FIXME - this is RETAINed and never RELEASEd ...
ASSIGN (_document, document); ASSIGN (_document, document);
[self _synchronizeWindowTitleWithDocumentName]; [self synchronizeWindowTitleWithDocumentName];
if (_document != nil) if (_document != nil)
{ {
@ -122,6 +169,11 @@
return _document; return _document;
} }
- (void) setDocumentEdited: (BOOL)flag
{
[_window setDocumentEdited: flag];
}
- (void) setWindowFrameAutosaveName:(NSString *)name - (void) setWindowFrameAutosaveName:(NSString *)name
{ {
ASSIGN(_windowFrameAutosaveName, name); ASSIGN(_windowFrameAutosaveName, name);
@ -162,7 +214,6 @@
[_window close]; [_window close];
} }
- (void) _windowWillClose: (NSNotification *)notification - (void) _windowWillClose: (NSNotification *)notification
{ {
if ([notification object] == _window) if ([notification object] == _window)
@ -223,10 +274,17 @@
return _window; return _window;
} }
// Private method; the nib loading will call this.
- (void) setWindow: (NSWindow *)aWindow - (void) setWindow: (NSWindow *)aWindow
{ {
ASSIGN (_window, aWindow); ASSIGN (_window, aWindow);
if (_document != nil)
{
[_window setReleasedWhenClosed: YES];
}
else
{
[_window setReleasedWhenClosed: NO];
}
} }
- (IBAction) showWindow: (id)sender - (IBAction) showWindow: (id)sender
@ -249,7 +307,7 @@
return displayName; return displayName;
} }
- (void) _synchronizeWindowTitleWithDocumentName - (void) synchronizeWindowTitleWithDocumentName
{ {
if (_document != nil) if (_document != nil)
{ {
@ -264,13 +322,12 @@
} }
else else
{ {
if (filename) [_window setRepresentedFilename:filename]; if (filename)
{ [_window setRepresentedFilename: filename];
[_window setTitle: title]; [_window setTitle: title];
} }
} }
} }
}
- (BOOL) isWindowLoaded - (BOOL) isWindowLoaded
{ {
@ -291,7 +348,7 @@
[_window setWindowController: self]; [_window setWindowController: self];
[self _synchronizeWindowTitleWithDocumentName]; [self synchronizeWindowTitleWithDocumentName];
[[NSNotificationCenter defaultCenter] [[NSNotificationCenter defaultCenter]
addObserver: self addObserver: self
@ -344,6 +401,26 @@
return; return;
} }
if ((_windowNibName == nil) && (_windowNibPath != nil))
{
NSDictionary *table;
table = [NSDictionary dictionaryWithObject: _owner forKey: @"NSOwner"];
if ([NSBundle loadNibFile: _windowNibPath
externalNameTable: table
withZone: [_owner zone]])
{
_wcFlags.nibIsLoaded = YES;
if (_window == nil && _document != nil && _owner == _document)
{
[self setWindow: [_document _transferWindowOwnership]];
}
return;
}
}
if ([NSBundle loadNibNamed: _windowNibName owner: _owner]) if ([NSBundle loadNibNamed: _windowNibName owner: _owner])
{ {
_wcFlags.nibIsLoaded = YES; _wcFlags.nibIsLoaded = YES;
@ -352,18 +429,10 @@
{ {
[self setWindow: [_document _transferWindowOwnership]]; [self setWindow: [_document _transferWindowOwnership]];
} }
if (_document != nil)
{
[_window setReleasedWhenClosed: YES];
}
else
{
[_window setReleasedWhenClosed: NO];
}
} }
else else
{ {
// FIXME: We should still try the main bundle
NSLog (@"%@: could not load nib named %@.nib", NSLog (@"%@: could not load nib named %@.nib",
[self class], _windowNibName); [self class], _windowNibName);
} }