mirror of
https://github.com/gnustep/libs-gui.git
synced 2025-05-05 10:40:55 +00:00
Present a warning when the user enters a filename with a wrong
extension in NSSavePanel. git-svn-id: svn+ssh://svn.gna.org/svn/gnustep/libs/gui/trunk@29080 72102866-910b-0410-8b05-ffd578937521
This commit is contained in:
parent
9af6ab1c95
commit
ef0b67bc70
2 changed files with 72 additions and 13 deletions
|
@ -1,3 +1,8 @@
|
||||||
|
2009-11-29 Wolfgang Lux <wolfgang.lux@gmail.com>
|
||||||
|
|
||||||
|
* Source/NSSavePanel.m (-ok:): Present a warning when the user has
|
||||||
|
entered a filename with a wrong extension.
|
||||||
|
|
||||||
2009-11-29 Richard Frith-Macdonald <rfm@gnu.org>
|
2009-11-29 Richard Frith-Macdonald <rfm@gnu.org>
|
||||||
|
|
||||||
* Source/NSOutlineView.m: Improve display of insertion point for DnD
|
* Source/NSOutlineView.m: Improve display of insertion point for DnD
|
||||||
|
|
|
@ -117,6 +117,7 @@ setPath(NSBrowser *browser, NSString *path)
|
||||||
- (void) _unmountMedia;
|
- (void) _unmountMedia;
|
||||||
- (void) _selectTextInColumn: (int)column;
|
- (void) _selectTextInColumn: (int)column;
|
||||||
- (void) _selectCellName: (NSString *)title;
|
- (void) _selectCellName: (NSString *)title;
|
||||||
|
- (void) _setFileName: (NSString *)name;
|
||||||
- (void) _setupForDirectory: (NSString *)path file: (NSString *)name;
|
- (void) _setupForDirectory: (NSString *)path file: (NSString *)name;
|
||||||
- (BOOL) _shouldShowExtension: (NSString *)extension;
|
- (BOOL) _shouldShowExtension: (NSString *)extension;
|
||||||
- (void) _windowResized: (NSNotification*)n;
|
- (void) _windowResized: (NSNotification*)n;
|
||||||
|
@ -559,6 +560,14 @@ selectCellWithString: (NSString*)title
|
||||||
return YES;
|
return YES;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
- (void) _setFileName: (NSString *)filename
|
||||||
|
{
|
||||||
|
[self _selectCellName: filename];
|
||||||
|
[[_form cellAtIndex: 0] setStringValue: filename];
|
||||||
|
[_form selectTextAtIndex: 0];
|
||||||
|
[_form setNeedsDisplay: YES];
|
||||||
|
}
|
||||||
|
|
||||||
- (void) _setupForDirectory: (NSString *)path file: (NSString *)filename
|
- (void) _setupForDirectory: (NSString *)path file: (NSString *)filename
|
||||||
{
|
{
|
||||||
if (path == nil)
|
if (path == nil)
|
||||||
|
@ -576,13 +585,7 @@ selectCellWithString: (NSString*)title
|
||||||
filename = @"";
|
filename = @"";
|
||||||
ASSIGN(_fullFileName, [_directory stringByAppendingPathComponent: filename]);
|
ASSIGN(_fullFileName, [_directory stringByAppendingPathComponent: filename]);
|
||||||
setPath(_browser, _fullFileName);
|
setPath(_browser, _fullFileName);
|
||||||
|
[self _setFileName: filename];
|
||||||
[self _selectCellName: filename];
|
|
||||||
[_form abortEditing]; // FIXME This is necessary because we cannot set a
|
|
||||||
// cell's value while it is being edited.
|
|
||||||
[[_form cellAtIndex: 0] setStringValue: filename];
|
|
||||||
[_form selectTextAtIndex: 0];
|
|
||||||
[_form setNeedsDisplay: YES];
|
|
||||||
|
|
||||||
[self _browser: _browser
|
[self _browser: _browser
|
||||||
selectCellWithString: [[_browser selectedCell] stringValue]
|
selectCellWithString: [[_browser selectedCell] stringValue]
|
||||||
|
@ -1172,7 +1175,7 @@ selectCellWithString: (NSString*)title
|
||||||
{
|
{
|
||||||
NSMatrix *matrix;
|
NSMatrix *matrix;
|
||||||
NSBrowserCell *selectedCell;
|
NSBrowserCell *selectedCell;
|
||||||
NSString *filename;
|
NSString *filename, *ext, *req;
|
||||||
BOOL isDir = NO;
|
BOOL isDir = NO;
|
||||||
|
|
||||||
matrix = [_browser matrixInColumn: [_browser lastColumn]];
|
matrix = [_browser matrixInColumn: [_browser lastColumn]];
|
||||||
|
@ -1208,13 +1211,64 @@ selectCellWithString: (NSString*)title
|
||||||
ASSIGN (_directory, [filename stringByDeletingLastPathComponent]);
|
ASSIGN (_directory, [filename stringByDeletingLastPathComponent]);
|
||||||
ASSIGN (_fullFileName, filename);
|
ASSIGN (_fullFileName, filename);
|
||||||
setPath(_browser, _fullFileName);
|
setPath(_browser, _fullFileName);
|
||||||
|
[self _setFileName: [_fullFileName lastPathComponent]];
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
filename = [_fullFileName lastPathComponent];
|
/* Warn user if a wrong extension was entered */
|
||||||
|
req = [self requiredFileType];
|
||||||
|
ext = [_fullFileName pathExtension];
|
||||||
|
if ([req length] > 0 && ![ext isEqualToString: req])
|
||||||
|
{
|
||||||
|
int result;
|
||||||
|
NSString *msgFormat, *butFormat;
|
||||||
|
NSString *altExt;
|
||||||
|
|
||||||
[self _selectCellName: filename];
|
if ([self allowsOtherFileTypes])
|
||||||
[[_form cellAtIndex: 0] setStringValue: filename];
|
{
|
||||||
[_form selectTextAtIndex: 0];
|
msgFormat =
|
||||||
[_form setNeedsDisplay: YES];
|
_(@"You have used the extension '.%@'.\n"
|
||||||
|
@"The standard extension is '.%@'.'");
|
||||||
|
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"),
|
||||||
|
msgFormat,
|
||||||
|
[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];
|
||||||
|
|
||||||
|
ASSIGN (_fullFileName, filename);
|
||||||
|
setPath(_browser, _fullFileName);
|
||||||
|
[self _setFileName: [_fullFileName lastPathComponent]];
|
||||||
|
}
|
||||||
|
break;
|
||||||
|
default:
|
||||||
|
return;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
Loading…
Reference in a new issue