Document system change to NSWindow, GC update for NSWindowController

New method implemented in NSWorkspace


git-svn-id: svn+ssh://svn.gna.org/svn/gnustep/libs/gui/trunk@6434 72102866-910b-0410-8b05-ffd578937521
This commit is contained in:
Jonathan Gapen 2000-04-07 23:49:10 +00:00
parent 25dde4dec4
commit ed92f00777
4 changed files with 241 additions and 139 deletions

View file

@ -1,3 +1,11 @@
2000-04-07 Jonathan Gapen <jagapen@whitewater.chem.wisc.edu>
* Source/NSWindow.m: Update [-performClose:] to check send
[-windowWillClose:] message to window controller's document.
* Source/NSWindowController.m: Add copyright notice, update
to GC-compatible RETAIN/ASSIGN macros, re-format.
* Source/NSWorkspace.m: [-getInfoForFile:application:type:] Implement.
2000-04-06 Adam Fedor <fedor@gnu.org>
* Source/GSFontInfo.m: allFonts returns GSFontInfo objects.

View file

@ -1780,6 +1780,18 @@ resetCursorRectsForView(NSView *theView)
return;
}
if (_windowController)
{
NSDocument *document = [_windowController document];
if (document && (document != _delegate)
&& [document respondsToSelector: @selector(windowShouldClose:)]
&& ![document windowShouldClose: self])
{
NSBeep();
return;
}
}
if ([_delegate respondsToSelector: @selector(windowShouldClose:)])
{
/*

View file

@ -1,3 +1,25 @@
/*
NSWindowController.m
Copyright (C) 2000 Free Software Foundation, Inc.
This file is part of the GNUstep GUI Library.
This library is free software; you can redistribute it and/or
modify it under the terms of the GNU Library General Public
License as published by the Free Software Foundation; either
version 2 of the License, or (at your option) any later version.
This library is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
Library General Public License for more details.
You should have received a copy of the GNU Library General Public
License along with this library; if not, write to the Free
Software Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111 USA.
*/
#import <AppKit/NSWindowController.h>
#import <AppKit/NSPanel.h>
#import <AppKit/NSNibLoading.h>
@ -7,204 +29,201 @@
- (id)initWithWindowNibName:(NSString *)windowNibName
{
return [self initWithWindowNibName:windowNibName owner:self];
return [self initWithWindowNibName:windowNibName owner:self];
}
- (id)initWithWindowNibName:(NSString *)windowNibName owner:(id)owner
{
[self initWithWindow:nil];
_windowNibName = [windowNibName retain];
_owner = owner;
return self;
[self initWithWindow:nil];
_windowNibName = RETAIN(windowNibName);
_owner = owner;
return self;
}
- (id)initWithWindow:(NSWindow *)window
{
[super init];
[super init];
_window = [window retain];
_windowFrameAutosaveName = @"";
_wcFlags.shouldCascade = YES;
_wcFlags.shouldCloseDocument = NO;
_window = RETAIN(window);
_windowFrameAutosaveName = @"";
_wcFlags.shouldCascade = YES;
_wcFlags.shouldCloseDocument = NO;
if (_window)
{
[self _windowDidLoad];
}
if (_window)
{
[self _windowDidLoad];
}
return self;
return self;
}
- (id)init
{
return [self initWithWindowNibName:nil];
return [self initWithWindowNibName:nil];
}
- (void)dealloc
{
[[NSNotificationCenter defaultCenter] removeObserver:self];
[_windowNibName release];
[_windowFrameAutosaveName release];
[_topLevelObjects release];
[_window autorelease];
[super dealloc];
[[NSNotificationCenter defaultCenter] removeObserver:self];
RELEASE(_windowNibName);
RELEASE(_windowFrameAutosaveName);
RELEASE(_topLevelObjects);
AUTORELEASE(_window);
[super dealloc];
}
- (NSString *)windowNibName
{
return _windowNibName;
return _windowNibName;
}
- (id)owner
{
return _owner;
return _owner;
}
- (void)setDocument:(NSDocument *)document
{
_document = document;
[self _synchronizeWindowTitleWithDocumentName];
ASSIGN(_document, document);
[self _synchronizeWindowTitleWithDocumentName];
}
- (id)document
{
return _document;
return _document;
}
- (void)setWindowFrameAutosaveName:(NSString *)name
{
[name retain];
[_windowFrameAutosaveName release];
_windowFrameAutosaveName = name;
ASSIGN(_windowFrameAutosaveName, name);
if ([self isWindowLoaded])
{
[[self window] setFrameAutosaveName:name? name : @""];
}
if ([self isWindowLoaded])
{
[[self window] setFrameAutosaveName:name? name : @""];
}
}
- (NSString *)windowFrameAutosaveName;
{
return _windowFrameAutosaveName;
return _windowFrameAutosaveName;
}
- (void)setShouldCloseDocument:(BOOL)flag
{
_wcFlags.shouldCloseDocument = flag;
_wcFlags.shouldCloseDocument = flag;
}
- (BOOL)shouldCloseDocument
{
return _wcFlags.shouldCloseDocument;
return _wcFlags.shouldCloseDocument;
}
- (void)setShouldCascadeWindows:(BOOL)flag
{
_wcFlags.shouldCascade = flag;
_wcFlags.shouldCascade = flag;
}
- (BOOL)shouldCascadeWindows
{
return _wcFlags.shouldCascade;
return _wcFlags.shouldCascade;
}
- (void)close
{
[_window close];
[_window close];
}
- (void)_windowWillClose:(NSNotification *)notification
{
if ([notification object] == _window)
if ([notification object] == _window)
{
if ([_window delegate] == self) [_window setDelegate:nil];
if ([_window windowController] == self) [_window setWindowController:nil];
if ([_window delegate] == self) [_window setDelegate:nil];
if ([_window windowController] == self) [_window setWindowController:nil];
/*
* If the window is set to isReleasedWhenClosed, it will release
* itself, so nil out our reference so we don't release it again.
* We may want to unilaterally turn off the setting in the NSWindow
* instance so it doesn't cause problems.
*
* Apple's implementation doesn't seem to deal with this case, and
* crashes if isReleaseWhenClosed is set.
*/
if ([_window isReleasedWhenClosed])
/*
* If the window is set to isReleasedWhenClosed, it will release
* itself, so nil out our reference so we don't release it again
* We may want to unilaterally turn off the setting in the NSWindow
* instance so it doesn't cause problems.
*
* Apple's implementation doesn't seem to deal with this case, and
* crashes if isReleaseWhenClosed is set.
*/
if ([_window isReleasedWhenClosed])
{
_window = nil;
_window = nil;
}
[_document _removeWindowController:self];
[_document _removeWindowController:self];
}
}
- (NSWindow *)window
{
if (_window == nil && ![self isWindowLoaded])
{
// Do all the notifications. Yes, the docs say this should
// be implemented here instead of in -loadWindow itself.
[self windowWillLoad];
if ([_document respondsToSelector:@selector(windowControllerWillLoadNib:)])
[_document windowControllerWillLoadNib:self];
if (_window == nil && ![self isWindowLoaded])
{
// Do all the notifications. Yes, the docs say this should
// be implemented here instead of in -loadWindow itself.
[self windowWillLoad];
if ([_document respondsToSelector:@selector(windowControllerWillLoadNib:)])
[_document windowControllerWillLoadNib:self];
[self loadWindow];
[self _windowDidLoad];
if ([_document respondsToSelector:@selector(windowControllerDidLoadNib:)])
[_document windowControllerDidLoadNib:self];
}
[self loadWindow];
return _window;
[self _windowDidLoad];
if ([_document respondsToSelector:@selector(windowControllerDidLoadNib:)])
[_document windowControllerDidLoadNib:self];
}
return _window;
}
// Private method; the nib loading will call this.
- (void)setWindow:(NSWindow *)aWindow
{
[_window autorelease];
_window = [aWindow retain];
ASSIGN(_window, aWindow);
}
- (IBAction)showWindow:(id)sender
{
NSWindow *window = [self window];
NSWindow *window = [self window];
if ([window isKindOfClass:[NSPanel class]] && [(NSPanel*)window becomesKeyOnlyIfNeeded])
[window orderFront:sender];
else
[window makeKeyAndOrderFront:sender];
if ([window isKindOfClass:[NSPanel class]] && [(NSPanel*)window becomesKeyOnlyIfNeeded])
[window orderFront:sender];
else
[window makeKeyAndOrderFront:sender];
}
- (NSString *)windowTitleForDocumentDisplayName:(NSString *)displayName
{
return displayName;
return displayName;
}
- (void)_synchronizeWindowTitleWithDocumentName
{
if (_document)
if (_document)
{
NSString *filename = [_document fileName];
NSString *displayName = [_document displayName];
NSString *title = [self windowTitleForDocumentDisplayName:displayName];
NSString *filename = [_document fileName];
NSString *displayName = [_document displayName];
NSString *title = [self windowTitleForDocumentDisplayName:displayName];
/* If they just want to display the filename, use the fancy method */
if (filename != nil && [title isEqualToString:filename])
/* If they just want to display the filename, use the fancy method */
if (filename != nil && [title isEqualToString:filename])
{
[_window setTitleWithRepresentedFilename:filename];
}
else
{
if (filename) [_window setRepresentedFilename:filename];
[_window setTitle:title];
}
}
[_window setTitleWithRepresentedFilename:filename];
}
else
{
if (filename) [_window setRepresentedFilename:filename];
[_window setTitle:title];
}
}
}
- (BOOL)isWindowLoaded
{
return _wcFlags.nibIsLoaded;
return _wcFlags.nibIsLoaded;
}
- (void)windowDidLoad
@ -217,68 +236,68 @@
- (void)_windowDidLoad
{
_wcFlags.nibIsLoaded = YES;
_wcFlags.nibIsLoaded = YES;
[_window setWindowController:self];
[_window setWindowController:self];
[self _synchronizeWindowTitleWithDocumentName];
[self _synchronizeWindowTitleWithDocumentName];
[[NSNotificationCenter defaultCenter]
addObserver:self
selector:@selector(_windowWillClose:)
name:NSWindowWillCloseNotification
object:_window];
[[NSNotificationCenter defaultCenter]
addObserver:self
selector:@selector(_windowWillClose:)
name:NSWindowWillCloseNotification
object:_window];
/* Make sure window sizes itself right */
if ([_windowFrameAutosaveName length] > 0)
/* Make sure window sizes itself right */
if ([_windowFrameAutosaveName length] > 0)
{
[_window setFrameUsingName:_windowFrameAutosaveName];
[_window setFrameAutosaveName:_windowFrameAutosaveName];
[_window setFrameUsingName:_windowFrameAutosaveName];
[_window setFrameAutosaveName:_windowFrameAutosaveName];
}
if ([self shouldCascadeWindows])
if ([self shouldCascadeWindows])
{
static NSPoint nextWindowLocation = { 0.0, 0.0 };
static BOOL firstWindow = YES;
static NSPoint nextWindowLocation = { 0.0, 0.0 };
static BOOL firstWindow = YES;
if (firstWindow)
if (firstWindow)
{
NSRect windowFrame = [_window frame];
NSRect windowFrame = [_window frame];
/* Start with the frame as set */
nextWindowLocation = NSMakePoint(NSMinX(windowFrame), NSMaxY(windowFrame));
firstWindow = NO;
/* Start with the frame as set */
nextWindowLocation = NSMakePoint(NSMinX(windowFrame), NSMaxY(windowFrame));
firstWindow = NO;
}
else
else
{
/*
* cascadeTopLeftFromPoint will "wrap" the point back to the
* top left if the normal cascading will cause the window to go
* off the screen. In Apple's implementation, this wraps to the
* extreme top of the screen, and offset only a small amount
* from the left.
*/
nextWindowLocation = [_window cascadeTopLeftFromPoint:nextWindowLocation];
/*
* cascadeTopLeftFromPoint will "wrap" the point back to the
* top left if the normal cascading will cause the window to go
* off the screen. In Apple's implementation, this wraps to the
* extreme top of the screen, and offset only a small amount
* from the left.
*/
nextWindowLocation = [_window cascadeTopLeftFromPoint:nextWindowLocation];
}
}
[self windowDidLoad];
[self windowDidLoad];
}
- (void)loadWindow
{
if ([self isWindowLoaded]) return;
if ([self isWindowLoaded]) return;
if ([NSBundle loadNibNamed:_windowNibName owner:_owner])
{
_wcFlags.nibIsLoaded = YES;
if (_window == nil && _document && _owner == _document)
[self setWindow:[_document _transferWindowOwnership]];
}
else
if ([NSBundle loadNibNamed:_windowNibName owner:_owner])
{
NSLog(@"%@: could not load nib named %@.nib", [self class], _windowNibName);
_wcFlags.nibIsLoaded = YES;
if (_window == nil && _document && _owner == _document)
[self setWindow:[_document _transferWindowOwnership]];
}
else
{
NSLog(@"%@: could not load nib named %@.nib", [self class], _windowNibName);
}
}
@ -288,15 +307,14 @@
*/
- initWithCoder:(NSCoder *)coder
{
return [self init];
return [self init];
}
- (void)encodeWithCoder:(NSCoder *)coder
{
// What are we supposed to encode? Window nib name? Or should these
// be empty, just to conform to NSCoding, so we do an -init on
// unarchival. ?
// What are we supposed to encode? Window nib name? Or should these
// be empty, just to conform to NSCoding, so we do an -init on
// unarchival. ?
}
@end
@end

View file

@ -50,6 +50,8 @@
#define stringify_it(X) #X
#define mkpath(X) stringify_it(X) "/Tools"
#define PosixExecutePermission (0111)
static NSString *GSWorkspaceNotification = @"GSWorkspaceNotification";
@interface _GSWorkspaceCenter: NSNotificationCenter
@ -736,7 +738,69 @@ inFileViewerRootedAtPath: (NSString *)rootFullpath
application: (NSString **)appName
type: (NSString **)type
{
return NO;
NSFileManager *fm = [NSFileManager defaultManager];
NSDictionary *attributes;
NSString *fileType;
NSString *extension = [fullPath pathExtension];
attributes = [fm fileAttributesAtPath:fullPath traverseLink:YES];
if (attributes)
{
fileType = [attributes fileType];
if ([fileType isEqualToString: NSFileTypeRegular])
{
if ([attributes filePosixPermissions] & PosixExecutePermission)
{
*type = NSShellCommandFileType;
*appName = nil;
}
else
{
*type = NSPlainFileType;
*appName = [self getBestAppInRole:nil forExtension:extension];
}
}
else if([fileType isEqualToString: NSFileTypeDirectory])
{
if ([extension isEqualToString: @"app"]
|| [extension isEqualToString: @"debug"]
|| [extension isEqualToString: @"profile"])
{
*type = NSApplicationFileType;
*appName = nil;
}
else if ([extension isEqualToString: @"bundle"])
{
*type = NSPlainFileType;
*appName = nil;
}
// the idea here is that if the parent directory's fileSystemNumber
// differs, this must be a filesystem mount point
else if ([[fm fileAttributesAtPath:
[fullPath stringByDeletingLastPathComponent]
traverseLink:YES] fileSystemNumber]
!= [attributes fileSystemNumber])
{
*type = NSFilesystemFileType;
*appName = nil;
}
else
{
*type = NSDirectoryFileType;
*appName = nil;
}
}
else
{
// this catches sockets, character special, block special, and
// unknown file types
*type = NSPlainFileType;
*appName = nil;
}
return YES;
}
else
return NO;
}
- (NSImage *) iconForFile: (NSString *)aPath