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:
jagapen 2000-04-07 23:49:10 +00:00
parent 5e57d2f303
commit 8344d89c2a
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> 2000-04-06 Adam Fedor <fedor@gnu.org>
* Source/GSFontInfo.m: allFonts returns GSFontInfo objects. * Source/GSFontInfo.m: allFonts returns GSFontInfo objects.

View file

@ -1780,6 +1780,18 @@ resetCursorRectsForView(NSView *theView)
return; 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:)]) 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/NSWindowController.h>
#import <AppKit/NSPanel.h> #import <AppKit/NSPanel.h>
#import <AppKit/NSNibLoading.h> #import <AppKit/NSNibLoading.h>
@ -7,204 +29,201 @@
- (id)initWithWindowNibName:(NSString *)windowNibName - (id)initWithWindowNibName:(NSString *)windowNibName
{ {
return [self initWithWindowNibName:windowNibName owner:self]; return [self initWithWindowNibName:windowNibName owner:self];
} }
- (id)initWithWindowNibName:(NSString *)windowNibName owner:(id)owner - (id)initWithWindowNibName:(NSString *)windowNibName owner:(id)owner
{ {
[self initWithWindow:nil]; [self initWithWindow:nil];
_windowNibName = [windowNibName retain]; _windowNibName = RETAIN(windowNibName);
_owner = owner; _owner = owner;
return self; return self;
} }
- (id)initWithWindow:(NSWindow *)window - (id)initWithWindow:(NSWindow *)window
{ {
[super init]; [super init];
_window = [window retain]; _window = RETAIN(window);
_windowFrameAutosaveName = @""; _windowFrameAutosaveName = @"";
_wcFlags.shouldCascade = YES; _wcFlags.shouldCascade = YES;
_wcFlags.shouldCloseDocument = NO; _wcFlags.shouldCloseDocument = NO;
if (_window) if (_window)
{ {
[self _windowDidLoad]; [self _windowDidLoad];
} }
return self; return self;
} }
- (id)init - (id)init
{ {
return [self initWithWindowNibName:nil]; return [self initWithWindowNibName:nil];
} }
- (void)dealloc - (void)dealloc
{ {
[[NSNotificationCenter defaultCenter] removeObserver:self]; [[NSNotificationCenter defaultCenter] removeObserver:self];
[_windowNibName release]; RELEASE(_windowNibName);
[_windowFrameAutosaveName release]; RELEASE(_windowFrameAutosaveName);
[_topLevelObjects release]; RELEASE(_topLevelObjects);
[_window autorelease]; AUTORELEASE(_window);
[super dealloc]; [super dealloc];
} }
- (NSString *)windowNibName - (NSString *)windowNibName
{ {
return _windowNibName; return _windowNibName;
} }
- (id)owner - (id)owner
{ {
return _owner; return _owner;
} }
- (void)setDocument:(NSDocument *)document - (void)setDocument:(NSDocument *)document
{ {
_document = document; ASSIGN(_document, document);
[self _synchronizeWindowTitleWithDocumentName]; [self _synchronizeWindowTitleWithDocumentName];
} }
- (id)document - (id)document
{ {
return _document; return _document;
} }
- (void)setWindowFrameAutosaveName:(NSString *)name - (void)setWindowFrameAutosaveName:(NSString *)name
{ {
[name retain]; ASSIGN(_windowFrameAutosaveName, name);
[_windowFrameAutosaveName release];
_windowFrameAutosaveName = name;
if ([self isWindowLoaded]) if ([self isWindowLoaded])
{ {
[[self window] setFrameAutosaveName:name? name : @""]; [[self window] setFrameAutosaveName:name? name : @""];
} }
} }
- (NSString *)windowFrameAutosaveName; - (NSString *)windowFrameAutosaveName;
{ {
return _windowFrameAutosaveName; return _windowFrameAutosaveName;
} }
- (void)setShouldCloseDocument:(BOOL)flag - (void)setShouldCloseDocument:(BOOL)flag
{ {
_wcFlags.shouldCloseDocument = flag; _wcFlags.shouldCloseDocument = flag;
} }
- (BOOL)shouldCloseDocument - (BOOL)shouldCloseDocument
{ {
return _wcFlags.shouldCloseDocument; return _wcFlags.shouldCloseDocument;
} }
- (void)setShouldCascadeWindows:(BOOL)flag - (void)setShouldCascadeWindows:(BOOL)flag
{ {
_wcFlags.shouldCascade = flag; _wcFlags.shouldCascade = flag;
} }
- (BOOL)shouldCascadeWindows - (BOOL)shouldCascadeWindows
{ {
return _wcFlags.shouldCascade; return _wcFlags.shouldCascade;
} }
- (void)close - (void)close
{ {
[_window close]; [_window close];
} }
- (void)_windowWillClose:(NSNotification *)notification - (void)_windowWillClose:(NSNotification *)notification
{ {
if ([notification object] == _window) if ([notification object] == _window)
{ {
if ([_window delegate] == self) [_window setDelegate:nil]; if ([_window delegate] == self) [_window setDelegate:nil];
if ([_window windowController] == self) [_window setWindowController:nil]; if ([_window windowController] == self) [_window setWindowController:nil];
/* /*
* If the window is set to isReleasedWhenClosed, it will release * If the window is set to isReleasedWhenClosed, it will release
* itself, so nil out our reference so we don't release it again. * 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 * We may want to unilaterally turn off the setting in the NSWindow
* instance so it doesn't cause problems. * instance so it doesn't cause problems.
* *
* Apple's implementation doesn't seem to deal with this case, and * Apple's implementation doesn't seem to deal with this case, and
* crashes if isReleaseWhenClosed is set. * crashes if isReleaseWhenClosed is set.
*/ */
if ([_window isReleasedWhenClosed]) if ([_window isReleasedWhenClosed])
{ {
_window = nil; _window = nil;
} }
[_document _removeWindowController:self]; [_document _removeWindowController:self];
} }
} }
- (NSWindow *)window - (NSWindow *)window
{ {
if (_window == nil && ![self isWindowLoaded]) if (_window == nil && ![self isWindowLoaded])
{ {
// Do all the notifications. Yes, the docs say this should // Do all the notifications. Yes, the docs say this should
// be implemented here instead of in -loadWindow itself. // be implemented here instead of in -loadWindow itself.
[self windowWillLoad]; [self windowWillLoad];
if ([_document respondsToSelector:@selector(windowControllerWillLoadNib:)]) if ([_document respondsToSelector:@selector(windowControllerWillLoadNib:)])
[_document windowControllerWillLoadNib:self]; [_document windowControllerWillLoadNib:self];
[self loadWindow]; [self loadWindow];
[self _windowDidLoad];
if ([_document respondsToSelector:@selector(windowControllerDidLoadNib:)])
[_document windowControllerDidLoadNib:self];
}
return _window; [self _windowDidLoad];
if ([_document respondsToSelector:@selector(windowControllerDidLoadNib:)])
[_document windowControllerDidLoadNib:self];
}
return _window;
} }
// Private method; the nib loading will call this. // Private method; the nib loading will call this.
- (void)setWindow:(NSWindow *)aWindow - (void)setWindow:(NSWindow *)aWindow
{ {
[_window autorelease]; ASSIGN(_window, aWindow);
_window = [aWindow retain];
} }
- (IBAction)showWindow:(id)sender - (IBAction)showWindow:(id)sender
{ {
NSWindow *window = [self window]; NSWindow *window = [self window];
if ([window isKindOfClass:[NSPanel class]] && [(NSPanel*)window becomesKeyOnlyIfNeeded]) if ([window isKindOfClass:[NSPanel class]] && [(NSPanel*)window becomesKeyOnlyIfNeeded])
[window orderFront:sender]; [window orderFront:sender];
else else
[window makeKeyAndOrderFront:sender]; [window makeKeyAndOrderFront:sender];
} }
- (NSString *)windowTitleForDocumentDisplayName:(NSString *)displayName - (NSString *)windowTitleForDocumentDisplayName:(NSString *)displayName
{ {
return displayName; return displayName;
} }
- (void)_synchronizeWindowTitleWithDocumentName - (void)_synchronizeWindowTitleWithDocumentName
{ {
if (_document) if (_document)
{ {
NSString *filename = [_document fileName]; NSString *filename = [_document fileName];
NSString *displayName = [_document displayName]; NSString *displayName = [_document displayName];
NSString *title = [self windowTitleForDocumentDisplayName:displayName]; NSString *title = [self windowTitleForDocumentDisplayName:displayName];
/* If they just want to display the filename, use the fancy method */ /* If they just want to display the filename, use the fancy method */
if (filename != nil && [title isEqualToString:filename]) if (filename != nil && [title isEqualToString:filename])
{ {
[_window setTitleWithRepresentedFilename:filename]; [_window setTitleWithRepresentedFilename:filename];
} }
else else
{ {
if (filename) [_window setRepresentedFilename:filename]; if (filename) [_window setRepresentedFilename:filename];
[_window setTitle:title]; [_window setTitle:title];
} }
} }
} }
- (BOOL)isWindowLoaded - (BOOL)isWindowLoaded
{ {
return _wcFlags.nibIsLoaded; return _wcFlags.nibIsLoaded;
} }
- (void)windowDidLoad - (void)windowDidLoad
@ -217,68 +236,68 @@
- (void)_windowDidLoad - (void)_windowDidLoad
{ {
_wcFlags.nibIsLoaded = YES; _wcFlags.nibIsLoaded = YES;
[_window setWindowController:self]; [_window setWindowController:self];
[self _synchronizeWindowTitleWithDocumentName]; [self _synchronizeWindowTitleWithDocumentName];
[[NSNotificationCenter defaultCenter] [[NSNotificationCenter defaultCenter]
addObserver:self addObserver:self
selector:@selector(_windowWillClose:) selector:@selector(_windowWillClose:)
name:NSWindowWillCloseNotification name:NSWindowWillCloseNotification
object:_window]; object:_window];
/* Make sure window sizes itself right */ /* Make sure window sizes itself right */
if ([_windowFrameAutosaveName length] > 0) if ([_windowFrameAutosaveName length] > 0)
{ {
[_window setFrameUsingName:_windowFrameAutosaveName]; [_window setFrameUsingName:_windowFrameAutosaveName];
[_window setFrameAutosaveName:_windowFrameAutosaveName]; [_window setFrameAutosaveName:_windowFrameAutosaveName];
} }
if ([self shouldCascadeWindows]) if ([self shouldCascadeWindows])
{ {
static NSPoint nextWindowLocation = { 0.0, 0.0 }; static NSPoint nextWindowLocation = { 0.0, 0.0 };
static BOOL firstWindow = YES; static BOOL firstWindow = YES;
if (firstWindow) if (firstWindow)
{ {
NSRect windowFrame = [_window frame]; NSRect windowFrame = [_window frame];
/* Start with the frame as set */ /* Start with the frame as set */
nextWindowLocation = NSMakePoint(NSMinX(windowFrame), NSMaxY(windowFrame)); nextWindowLocation = NSMakePoint(NSMinX(windowFrame), NSMaxY(windowFrame));
firstWindow = NO; firstWindow = NO;
} }
else else
{ {
/* /*
* cascadeTopLeftFromPoint will "wrap" the point back to the * cascadeTopLeftFromPoint will "wrap" the point back to the
* top left if the normal cascading will cause the window to go * top left if the normal cascading will cause the window to go
* off the screen. In Apple's implementation, this wraps to the * off the screen. In Apple's implementation, this wraps to the
* extreme top of the screen, and offset only a small amount * extreme top of the screen, and offset only a small amount
* from the left. * from the left.
*/ */
nextWindowLocation = [_window cascadeTopLeftFromPoint:nextWindowLocation]; nextWindowLocation = [_window cascadeTopLeftFromPoint:nextWindowLocation];
} }
} }
[self windowDidLoad]; [self windowDidLoad];
} }
- (void)loadWindow - (void)loadWindow
{ {
if ([self isWindowLoaded]) return; if ([self isWindowLoaded]) return;
if ([NSBundle loadNibNamed:_windowNibName owner:_owner]) if ([NSBundle loadNibNamed:_windowNibName owner:_owner])
{
_wcFlags.nibIsLoaded = YES;
if (_window == nil && _document && _owner == _document)
[self setWindow:[_document _transferWindowOwnership]];
}
else
{ {
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 - initWithCoder:(NSCoder *)coder
{ {
return [self init]; return [self init];
} }
- (void)encodeWithCoder:(NSCoder *)coder - (void)encodeWithCoder:(NSCoder *)coder
{ {
// What are we supposed to encode? Window nib name? Or should these // 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 // be empty, just to conform to NSCoding, so we do an -init on
// unarchival. ? // unarchival. ?
} }
@end @end

View file

@ -50,6 +50,8 @@
#define stringify_it(X) #X #define stringify_it(X) #X
#define mkpath(X) stringify_it(X) "/Tools" #define mkpath(X) stringify_it(X) "/Tools"
#define PosixExecutePermission (0111)
static NSString *GSWorkspaceNotification = @"GSWorkspaceNotification"; static NSString *GSWorkspaceNotification = @"GSWorkspaceNotification";
@interface _GSWorkspaceCenter: NSNotificationCenter @interface _GSWorkspaceCenter: NSNotificationCenter
@ -736,7 +738,69 @@ inFileViewerRootedAtPath: (NSString *)rootFullpath
application: (NSString **)appName application: (NSString **)appName
type: (NSString **)type 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 - (NSImage *) iconForFile: (NSString *)aPath