Skip to content

Commit

Permalink
[macOS] Dialog::SaveFile のデフォルトファイル名 #1199
Browse files Browse the repository at this point in the history
  • Loading branch information
Reputeless committed Jun 30, 2024
1 parent 7be009e commit 3adfe86
Showing 1 changed file with 20 additions and 2 deletions.
22 changes: 20 additions & 2 deletions Siv3D/src/Siv3D-Platform/macOS/Siv3D/Dialog/SivDialog_macOS.mm
Original file line number Diff line number Diff line change
Expand Up @@ -53,6 +53,24 @@ static bool SetDefaultPath(NSSavePanel* dialog, const FilePathView defaultPath)

return true;
}

static bool SetDefaultPath(NSSavePanel* dialog, const FilePathView defaultPath, const StringView defaultFileName)
{
if (defaultPath)
{
NSString* defaultPathStr = [NSString stringWithUTF8String: defaultPath.toUTF8().c_str()];
NSURL* url = [NSURL fileURLWithPath:defaultPathStr isDirectory:YES];
[dialog setDirectoryURL:url];
}

if (defaultFileName)
{
NSString* defaultFileNameStr = [NSString stringWithUTF8String: defaultFileName.toUTF8().c_str()];
[dialog setNameFieldStringValue:defaultFileNameStr];
}

return true;
}
}

namespace Dialog
Expand Down Expand Up @@ -155,7 +173,7 @@ static bool SetDefaultPath(NSSavePanel* dialog, const FilePathView defaultPath)
}
}

Optional<FilePath> SaveFile(const Array<FileFilter>& filters, const FilePathView defaultPath, const StringView, const StringView)
Optional<FilePath> SaveFile(const Array<FileFilter>& filters, const FilePathView defaultPath, const StringView, const StringView defaultFileName)
{
@autoreleasepool
{
Expand All @@ -177,7 +195,7 @@ static bool SetDefaultPath(NSSavePanel* dialog, const FilePathView defaultPath)
[dialog setAllowedFileTypes:result];
}

if (!detail::SetDefaultPath(dialog, defaultPath))
if (!detail::SetDefaultPath(dialog, defaultPath, defaultFileName))
{
return none;
}
Expand Down

0 comments on commit 3adfe86

Please sign in to comment.