mirror of
https://github.com/gnustep/libs-gui.git
synced 2025-05-29 20:37:39 +00:00
Implement support for document types with multiple allowed file
extensions in NSSavePanel. git-svn-id: svn+ssh://svn.gna.org/svn/gnustep/libs/gui/trunk@27228 72102866-910b-0410-8b05-ffd578937521
This commit is contained in:
parent
51ae4e18a6
commit
02bce68800
4 changed files with 106 additions and 73 deletions
|
@ -412,7 +412,7 @@ setPath(NSBrowser *browser, NSString *path)
|
|||
[self _setDefaultDirectory];
|
||||
[self setPrompt: @"Name:"];
|
||||
[self setTitle: @"Save"];
|
||||
[self setRequiredFileType: @""];
|
||||
[self setAllowedFileTypes: nil];
|
||||
[self setTreatsFilePackagesAsDirectories: NO];
|
||||
[self setDelegate: nil];
|
||||
[self setAccessoryView: nil];
|
||||
|
@ -588,8 +588,9 @@ selectCellWithString: (NSString*)title
|
|||
{
|
||||
if (*isDir == NO)
|
||||
{
|
||||
if (_requiredFileType != nil && [_requiredFileType length] != 0
|
||||
&& [extension isEqualToString: _requiredFileType] == NO)
|
||||
if (_allowedFileTypes != nil
|
||||
&& [_allowedFileTypes indexOfObject: extension] == NSNotFound
|
||||
&& [_allowedFileTypes indexOfObject: @""] != NSNotFound)
|
||||
return NO;
|
||||
}
|
||||
else if ([extension length] == 0)
|
||||
|
@ -598,9 +599,9 @@ selectCellWithString: (NSString*)title
|
|||
}
|
||||
else if (_treatsFilePackagesAsDirectories == NO)
|
||||
{
|
||||
if (_requiredFileType == nil || [_requiredFileType length] == 0
|
||||
|| [extension isEqualToString: _requiredFileType] == YES)
|
||||
*isDir = NO;
|
||||
if (_allowedFileTypes == nil
|
||||
|| [_allowedFileTypes indexOfObject: extension] != NSNotFound)
|
||||
*isDir = NO;
|
||||
}
|
||||
|
||||
return YES;
|
||||
|
@ -687,7 +688,7 @@ selectCellWithString: (NSString*)title
|
|||
[[NSNotificationCenter defaultCenter] removeObserver: self];
|
||||
TEST_RELEASE (_fullFileName);
|
||||
TEST_RELEASE (_directory);
|
||||
TEST_RELEASE (_requiredFileType);
|
||||
TEST_RELEASE (_allowedFileTypes);
|
||||
|
||||
[super dealloc];
|
||||
}
|
||||
|
@ -703,7 +704,7 @@ selectCellWithString: (NSString*)title
|
|||
* All these are set automatically
|
||||
_directory = nil;
|
||||
_fullFileName = nil;
|
||||
_requiredFileType = nil;
|
||||
_allowedFileTypes = nil;
|
||||
_delegate = nil;
|
||||
|
||||
_treatsFilePackagesAsDirectories = NO;
|
||||
|
@ -928,24 +929,55 @@ selectCellWithString: (NSString*)title
|
|||
is used for another file type within the application. If
|
||||
you do not invoke it, or set it to empty string or nil, no
|
||||
extension will be appended, indicated by an empty string
|
||||
returned from -requiredFileType .</p><p>See Also: -requiredFileType</p>
|
||||
returned from -requiredFileType.</p><p>This method is equivalent
|
||||
to calling -setAllowedFileTypes: with an array containing only
|
||||
fileType.</p><p>See Also: -requiredFileType</p>
|
||||
*/
|
||||
- (void) setRequiredFileType: (NSString*)fileType
|
||||
{
|
||||
ASSIGN(_requiredFileType, fileType);
|
||||
if ([fileType length] == 0)
|
||||
DESTROY(_allowedFileTypes);
|
||||
else
|
||||
ASSIGN(_allowedFileTypes, [NSArray arrayWithObject: fileType]);
|
||||
}
|
||||
|
||||
/**<p>Returns the required file type. The default, indicated by empty string,
|
||||
* is no required file type.</p><p>See Also: -setRequiredFileType:</p>
|
||||
/**<p>Returns the required file type. The default, indicated by an empty
|
||||
* string, is no required file type.</p><p>This method is equivalent to
|
||||
* calling -allowedFileTypes and returning the first element of the list
|
||||
* of allowed types, or the empty string if there are none.</p>
|
||||
* <p>See Also: -setRequiredFileType:</p>
|
||||
*/
|
||||
- (NSString*) requiredFileType
|
||||
{
|
||||
return _requiredFileType;
|
||||
if ([_allowedFileTypes count] > 0)
|
||||
return [_allowedFileTypes objectAtIndex: 0];
|
||||
else
|
||||
return @"";
|
||||
}
|
||||
|
||||
/**<p> Specifies the allowed types, i.e., file name extensions to
|
||||
be appended to any selected files that don't already have one
|
||||
of those extensions. The elements of the array should be strings
|
||||
that do not include the period that begins the extension. Invoke
|
||||
this method each time the Save panel is used for another file type
|
||||
within the application. If you do not invoke it, or set it to an
|
||||
empty array or nil, no extension will be appended, indicated by nil
|
||||
returned from -allowedFileTypes.</p><p>See Also: -allowedFileTypes</p>
|
||||
*/
|
||||
- (void) setAllowedFileTypes: (NSArray *)types
|
||||
{
|
||||
// FIXME
|
||||
if ([types count] == 0)
|
||||
DESTROY(_allowedFileTypes);
|
||||
else
|
||||
ASSIGN(_allowedFileTypes, types);
|
||||
}
|
||||
|
||||
/**<p>Returns an array of the allowed file types. The default, indicated by
|
||||
* nil, is any file type is allowed.</p><p>See Also: -setAllowedFileTypes:</p>
|
||||
*/
|
||||
- (NSArray *) allowedFileTypes
|
||||
{
|
||||
return _allowedFileTypes;
|
||||
}
|
||||
|
||||
- (void) setAllowsOtherFileTypes: (BOOL)flag
|
||||
|
@ -953,12 +985,6 @@ selectCellWithString: (NSString*)title
|
|||
_allowsOtherFileTypes = flag;
|
||||
}
|
||||
|
||||
- (NSArray *) allowedFileTypes
|
||||
{
|
||||
// FIXME
|
||||
return nil;
|
||||
}
|
||||
|
||||
- (BOOL) allowsOtherFileTypes
|
||||
{
|
||||
return _allowsOtherFileTypes;
|
||||
|
@ -1076,17 +1102,27 @@ selectCellWithString: (NSString*)title
|
|||
*/
|
||||
- (NSString*) filename
|
||||
{
|
||||
NSString *fileType;
|
||||
|
||||
if (_fullFileName == nil)
|
||||
return @"";
|
||||
|
||||
if (_requiredFileType == nil || [_requiredFileType isEqual: @""] == YES)
|
||||
if (_allowedFileTypes == nil ||
|
||||
[_allowedFileTypes indexOfObject: @""] != NSNotFound)
|
||||
return _fullFileName;
|
||||
|
||||
// add filetype extension only if the filename does not include it already
|
||||
if ([[_fullFileName pathExtension] isEqual: _requiredFileType] == YES)
|
||||
return _fullFileName;
|
||||
/* add filetype extension only if the filename does not include an
|
||||
allowed one already */
|
||||
fileType = [_fullFileName pathExtension];
|
||||
if ([_allowedFileTypes indexOfObject: fileType] != NSNotFound)
|
||||
{
|
||||
return _fullFileName;
|
||||
}
|
||||
else
|
||||
return [_fullFileName stringByAppendingPathExtension: _requiredFileType];
|
||||
{
|
||||
fileType = [_allowedFileTypes objectAtIndex: 0];
|
||||
return [_fullFileName stringByAppendingPathExtension: fileType];
|
||||
}
|
||||
}
|
||||
|
||||
- (NSURL *) URL
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue