mirror of
https://github.com/gnustep/libs-gui.git
synced 2025-04-29 14:50:56 +00:00
Avoid a bogus warning that was shown when a Save panel requires a file
type extension and the user has entered a file name without an extension. In addition fix the filename method so that setting allowsOtherFileTypes to YES works as advertised. git-svn-id: svn+ssh://svn.gna.org/svn/gnustep/libs/gui/trunk@29126 72102866-910b-0410-8b05-ffd578937521
This commit is contained in:
parent
39a91b9021
commit
e93f94e5ab
2 changed files with 83 additions and 52 deletions
15
ChangeLog
15
ChangeLog
|
@ -1,3 +1,18 @@
|
||||||
|
2009-12-15 Wolfgang Lux <wolfgang.lux@gmail.com>
|
||||||
|
|
||||||
|
* Source/NSSavePanel.m (-ok:): Avoid the bogus warning that was
|
||||||
|
shown when the panel requires a file type extension and the user
|
||||||
|
has entered a file name without an extension.
|
||||||
|
|
||||||
|
* Source/NSSavePanel.m (-filename): Do not replace an existing
|
||||||
|
file type extension if allowsOtherFileTypes is set.
|
||||||
|
|
||||||
|
* Source/NSSavePanel.m (-runModalForDirectory:file,
|
||||||
|
-runModalForDirectory:file:relativeToWindow:,
|
||||||
|
-beginSheetForDirectory:file:modalForWindow:modalDelegate:...):
|
||||||
|
Initially enable the panel's OK button if a file name is provided
|
||||||
|
to the modal session.
|
||||||
|
|
||||||
2009-12-15 Riccardo Mottola <rmottola@users.sf.net>
|
2009-12-15 Riccardo Mottola <rmottola@users.sf.net>
|
||||||
|
|
||||||
* Source/NSOutlineView.m: removed c99-isms
|
* Source/NSOutlineView.m: removed c99-isms
|
||||||
|
|
|
@ -1082,6 +1082,8 @@ selectCellWithString: (NSString*)title
|
||||||
- (int) runModalForDirectory: (NSString*)path file: (NSString*)filename
|
- (int) runModalForDirectory: (NSString*)path file: (NSString*)filename
|
||||||
{
|
{
|
||||||
[self _setupForDirectory: path file: filename];
|
[self _setupForDirectory: path file: filename];
|
||||||
|
if ([filename length] > 0)
|
||||||
|
[_okButton setEnabled: YES];
|
||||||
return [NSApp runModalForWindow: self];
|
return [NSApp runModalForWindow: self];
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -1090,6 +1092,8 @@ selectCellWithString: (NSString*)title
|
||||||
relativeToWindow: (NSWindow*)window
|
relativeToWindow: (NSWindow*)window
|
||||||
{
|
{
|
||||||
[self _setupForDirectory: path file: filename];
|
[self _setupForDirectory: path file: filename];
|
||||||
|
if ([filename length] > 0)
|
||||||
|
[_okButton setEnabled: YES];
|
||||||
return [NSApp runModalForWindow: self
|
return [NSApp runModalForWindow: self
|
||||||
relativeToWindow: window];
|
relativeToWindow: window];
|
||||||
}
|
}
|
||||||
|
@ -1102,6 +1106,8 @@ selectCellWithString: (NSString*)title
|
||||||
contextInfo: (void *)contextInfo
|
contextInfo: (void *)contextInfo
|
||||||
{
|
{
|
||||||
[self _setupForDirectory: path file: filename];
|
[self _setupForDirectory: path file: filename];
|
||||||
|
if ([filename length] > 0)
|
||||||
|
[_okButton setEnabled: YES];
|
||||||
[NSApp beginSheet: self
|
[NSApp beginSheet: self
|
||||||
modalForWindow: docWindow
|
modalForWindow: docWindow
|
||||||
modalDelegate: delegate
|
modalDelegate: delegate
|
||||||
|
@ -1136,18 +1142,21 @@ selectCellWithString: (NSString*)title
|
||||||
[_allowedFileTypes indexOfObject: @""] != NSNotFound)
|
[_allowedFileTypes indexOfObject: @""] != NSNotFound)
|
||||||
return _fullFileName;
|
return _fullFileName;
|
||||||
|
|
||||||
/* add filetype extension only if the filename does not include an
|
/* add file type extension if the file name does not have an extension or
|
||||||
allowed one already */
|
the file name's extension is not one of the allowed extensions and the
|
||||||
|
save panel does not allow other extensions */
|
||||||
fileType = [_fullFileName pathExtension];
|
fileType = [_fullFileName pathExtension];
|
||||||
if ([_allowedFileTypes indexOfObject: fileType] != NSNotFound)
|
if ([fileType length] == 0 ||
|
||||||
{
|
((!_allowsOtherFileTypes &&
|
||||||
return _fullFileName;
|
[_allowedFileTypes indexOfObject: fileType] == NSNotFound)))
|
||||||
}
|
|
||||||
else
|
|
||||||
{
|
{
|
||||||
fileType = [_allowedFileTypes objectAtIndex: 0];
|
fileType = [_allowedFileTypes objectAtIndex: 0];
|
||||||
return [_fullFileName stringByAppendingPathExtension: fileType];
|
return [_fullFileName stringByAppendingPathExtension: fileType];
|
||||||
}
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
return _fullFileName;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
- (NSURL *) URL
|
- (NSURL *) URL
|
||||||
|
@ -1175,7 +1184,7 @@ selectCellWithString: (NSString*)title
|
||||||
{
|
{
|
||||||
NSMatrix *matrix;
|
NSMatrix *matrix;
|
||||||
NSBrowserCell *selectedCell;
|
NSBrowserCell *selectedCell;
|
||||||
NSString *filename, *ext, *req;
|
NSString *filename;
|
||||||
BOOL isDir = NO;
|
BOOL isDir = NO;
|
||||||
|
|
||||||
matrix = [_browser matrixInColumn: [_browser lastColumn]];
|
matrix = [_browser matrixInColumn: [_browser lastColumn]];
|
||||||
|
@ -1216,59 +1225,66 @@ selectCellWithString: (NSString*)title
|
||||||
}
|
}
|
||||||
|
|
||||||
/* Warn user if a wrong extension was entered */
|
/* Warn user if a wrong extension was entered */
|
||||||
req = [self requiredFileType];
|
if (_allowedFileTypes != nil &&
|
||||||
ext = [_fullFileName pathExtension];
|
[_allowedFileTypes indexOfObject: @""] == NSNotFound)
|
||||||
if ([req length] > 0 && ![ext isEqualToString: req])
|
|
||||||
{
|
{
|
||||||
int result;
|
NSString *fileType = [_fullFileName pathExtension];
|
||||||
NSString *msgFormat, *butFormat;
|
if ([fileType length] != 0 &&
|
||||||
NSString *altExt;
|
[_allowedFileTypes indexOfObject: fileType] == NSNotFound)
|
||||||
|
|
||||||
if ([self allowsOtherFileTypes])
|
|
||||||
{
|
{
|
||||||
msgFormat =
|
int result;
|
||||||
_(@"You have used the extension '.%@'.\n"
|
NSString *msgFormat, *butFormat;
|
||||||
@"The standard extension is '.%@'.'");
|
NSString *altType, *requiredType;
|
||||||
butFormat = _(@"Use .%@");
|
|
||||||
altExt = ext;
|
|
||||||
}
|
|
||||||
else
|
|
||||||
{
|
|
||||||
msgFormat =
|
|
||||||
_(@"You cannot save this document with extension '.%@'.\n"
|
|
||||||
@"The required extension is '.%@'.");
|
|
||||||
butFormat = _(@"Use .%@");
|
|
||||||
altExt = [ext stringByAppendingPathExtension: req];
|
|
||||||
}
|
|
||||||
|
|
||||||
result = NSRunAlertPanel(_(@"Save"),
|
requiredType = [self requiredFileType];
|
||||||
msgFormat,
|
if ([self allowsOtherFileTypes])
|
||||||
[NSString stringWithFormat: butFormat, req],
|
|
||||||
_(@"Cancel"),
|
|
||||||
[NSString stringWithFormat: butFormat, altExt],
|
|
||||||
ext, req);
|
|
||||||
switch (result)
|
|
||||||
{
|
|
||||||
case NSAlertDefaultReturn:
|
|
||||||
filename = [_fullFileName stringByDeletingPathExtension];
|
|
||||||
filename = [filename stringByAppendingPathExtension: req];
|
|
||||||
|
|
||||||
ASSIGN (_fullFileName, filename);
|
|
||||||
setPath(_browser, _fullFileName);
|
|
||||||
[self _setFileName: [_fullFileName lastPathComponent]];
|
|
||||||
break;
|
|
||||||
case NSAlertOtherReturn:
|
|
||||||
if (altExt != ext)
|
|
||||||
{
|
{
|
||||||
filename = [_fullFileName stringByAppendingPathExtension: req];
|
msgFormat =
|
||||||
|
_(@"You have used the extension '.%@'.\n"
|
||||||
|
@"The standard extension is '.%@'.'");
|
||||||
|
butFormat = _(@"Use .%@");
|
||||||
|
altType = fileType;
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
msgFormat =
|
||||||
|
_(@"You cannot save this document with extension '.%@'.\n"
|
||||||
|
@"The required extension is '.%@'.");
|
||||||
|
butFormat = _(@"Use .%@");
|
||||||
|
altType = [fileType stringByAppendingPathExtension: requiredType];
|
||||||
|
}
|
||||||
|
|
||||||
|
result = NSRunAlertPanel(_(@"Save"),
|
||||||
|
msgFormat,
|
||||||
|
[NSString stringWithFormat: butFormat, requiredType],
|
||||||
|
_(@"Cancel"),
|
||||||
|
[NSString stringWithFormat: butFormat, altType],
|
||||||
|
fileType, requiredType);
|
||||||
|
switch (result)
|
||||||
|
{
|
||||||
|
case NSAlertDefaultReturn:
|
||||||
|
filename = [_fullFileName stringByDeletingPathExtension];
|
||||||
|
filename =
|
||||||
|
[filename stringByAppendingPathExtension: requiredType];
|
||||||
|
|
||||||
ASSIGN (_fullFileName, filename);
|
ASSIGN (_fullFileName, filename);
|
||||||
setPath(_browser, _fullFileName);
|
setPath(_browser, _fullFileName);
|
||||||
[self _setFileName: [_fullFileName lastPathComponent]];
|
[self _setFileName: [_fullFileName lastPathComponent]];
|
||||||
|
break;
|
||||||
|
case NSAlertOtherReturn:
|
||||||
|
if (altType != fileType)
|
||||||
|
{
|
||||||
|
filename =
|
||||||
|
[_fullFileName stringByAppendingPathExtension: requiredType];
|
||||||
|
|
||||||
|
ASSIGN (_fullFileName, filename);
|
||||||
|
setPath(_browser, _fullFileName);
|
||||||
|
[self _setFileName: [_fullFileName lastPathComponent]];
|
||||||
|
}
|
||||||
|
break;
|
||||||
|
default:
|
||||||
|
return;
|
||||||
}
|
}
|
||||||
break;
|
|
||||||
default:
|
|
||||||
return;
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
Loading…
Reference in a new issue