Implemented [URL]. New methods [_setupForDirectory:file:] and

[_shouldShowExtension:isDir:]. Removed check for extension filter
in [init]. Simplified [runModalForDirectory:file:]. Implemented
[runModalForDirectory:...relativeToWindow:] and
[beginSheetForDirectory:...]. In [browser:createRowsForColumn:inMatrix:]
allways call [_shouldShowExtension:isDir:].


git-svn-id: svn+ssh://svn.gna.org/svn/gnustep/libs/gui/trunk@10925 72102866-910b-0410-8b05-ffd578937521
This commit is contained in:
Fred Kiefer 2001-09-17 12:13:38 +00:00
parent 37ebea42c2
commit 9977f8f7cf

View file

@ -59,14 +59,6 @@ static NSFileManager *_fm = nil;
static BOOL _gs_display_reading_progress = NO;
// Pacify the compiler
// Subclasses (read NSOpenPanel) may implement this
// to filter some extensions out of displayed files.
@interface NSObject (_SavePanelPrivate)
-(BOOL) _shouldShowExtension: (NSString*)extension isDir: (BOOL *)isDir;
@end
//
//
// NSSavePanel private methods
//
@ -82,7 +74,8 @@ static BOOL _gs_display_reading_progress = NO;
- (void) _unmountMedia;
- (void) _selectTextInColumn: (int)column;
- (void) _selectCellName: (NSString *)title;
- (void) _setupForDirectory: (NSString *)path file: (NSString *)name;
- (BOOL) _shouldShowExtension: (NSString *)extension isDir: (BOOL *)isDir;
@end /* NSSavePanel (PrivateMethods) */
@implementation NSSavePanel (_PrivateMethods)
@ -398,6 +391,47 @@ static BOOL _gs_display_reading_progress = NO;
}
}
- (void) _setupForDirectory: (NSString *)path file: (NSString *)filename
{
if (path == nil || filename == nil)
[NSException raise: NSInvalidArgumentException
format: @"NSSavePanel runModalForDirectory:file: "
@"does not accept nil arguments."];
ASSIGN (_directory, path);
ASSIGN (_fullFileName, [path stringByAppendingPathComponent: filename]);
[_browser setPath: _fullFileName];
[self _selectCellName:filename];
[[_form cellAtIndex: 0] setStringValue: filename];
[_form selectTextAtIndex: 0];
[_form setNeedsDisplay: YES];
/*
* We need to take care of the possibility of
* the panel being aborted. We return NSCancelButton
* in that case.
*/
_OKButtonPressed = NO;
[self browser: _browser
selectCellWithString: [[_browser selectedCell] stringValue]
inColumn: [_browser selectedColumn]];
}
- (BOOL) _shouldShowExtension: (NSString *)extension
isDir: (BOOL *)isDir;
{
if (_treatsFilePackagesAsDirectories == NO && *isDir == YES &&
![extension isEqualToString: @""])
{
if ([extension isEqualToString: _requiredFileType] == YES)
*isDir = NO;
}
return YES;
}
@end /* NSSavePanel (PrivateMethods) */
//
@ -460,11 +494,6 @@ static BOOL _gs_display_reading_progress = NO;
_delegateHasShowFilenameFilter = NO;
_delegateHasValidNameFilter = NO;
if ([self respondsToSelector: @selector(_shouldShowExtension:isDir:)])
_selfHasShowExtensionFilter = YES;
else
_selfHasShowExtensionFilter = NO;
[self _getOriginalSize];
return self;
}
@ -670,37 +699,7 @@ static BOOL _gs_display_reading_progress = NO;
- (int) runModalForDirectory: (NSString*)path file: (NSString*)filename
{
if (path == nil || filename == nil)
[NSException raise: NSInvalidArgumentException
format: @"NSSavePanel runModalForDirectory:file: "
@"does not accept nil arguments."];
ASSIGN (_directory, path);
ASSIGN (_fullFileName, [path stringByAppendingPathComponent: filename]);
[_browser setPath: _fullFileName];
[self _selectCellName:filename];
[[_form cellAtIndex: 0] setStringValue: filename];
[_form selectTextAtIndex:0];
[_form setNeedsDisplay: YES];
if([self isKindOfClass:[NSOpenPanel class]] == NO)
{
if([filename isEqual:@""] == NO)
[_okButton setEnabled:YES];
}
/*
* We need to take care of the possibility of
* the panel being aborted. We return NSCancelButton
* in that case.
*/
_OKButtonPressed = NO;
[self browser: _browser
selectCellWithString: [[_browser selectedCell] stringValue]
inColumn: [_browser selectedColumn]];
[self _setupForDirectory: path file: filename];
[NSApp runModalForWindow: self];
if (_OKButtonPressed)
@ -709,6 +708,35 @@ static BOOL _gs_display_reading_progress = NO;
return NSCancelButton;
}
- (int) runModalForDirectory: (NSString *)path
file: (NSString *)filename
relativeToWindow: (NSWindow*)window
{
[self _setupForDirectory: path file: filename];
[NSApp runModalForWindow: self
relativeToWindow: window];
if (_OKButtonPressed)
return NSOKButton;
else
return NSCancelButton;
}
- (void) beginSheetForDirectory: (NSString *)path
file: (NSString *)filename
modalForWindow: (NSWindow *)docWindow
modalDelegate: (id)delegate
didEndSelector: (SEL)didEndSelector
contextInfo: (void *)contextInfo
{
[self _setupForDirectory: path file: filename];
[NSApp beginSheet: self
modalForWindow: docWindow
modalDelegate: delegate
didEndSelector: didEndSelector
contextInfo: contextInfo];
}
- (NSString*) directory
{
if (_directory)
@ -735,6 +763,11 @@ static BOOL _gs_display_reading_progress = NO;
return [_fullFileName stringByAppendingPathExtension: _requiredFileType];
}
- (NSURL *) URL
{
return [NSURL fileURLWithPath: [self filename]];
}
- (void) cancel: (id)sender
{
_fullFileName = nil;
@ -1077,16 +1110,7 @@ createRowsForColumn: (int)column
shouldShowFilename: pathAndFile];
}
if (_treatsFilePackagesAsDirectories == NO && isDir == YES && exists
&& ![extension isEqualToString: @""])
{
// Ones with more chance first
if ([self isMemberOfClass: [NSSavePanel class]] == YES)
if ([extension isEqualToString: _requiredFileType] == YES)
isDir = NO;
}
if (_selfHasShowExtensionFilter && exists)
if (exists)
{
exists = [self _shouldShowExtension: extension isDir: &isDir];
}