Skip to content

Commit 3adfe86

Browse files
committed
[macOS] Dialog::SaveFile のデフォルトファイル名 #1199
1 parent 7be009e commit 3adfe86

File tree

1 file changed

+20
-2
lines changed

1 file changed

+20
-2
lines changed

Siv3D/src/Siv3D-Platform/macOS/Siv3D/Dialog/SivDialog_macOS.mm

+20-2
Original file line numberDiff line numberDiff line change
@@ -53,6 +53,24 @@ static bool SetDefaultPath(NSSavePanel* dialog, const FilePathView defaultPath)
5353

5454
return true;
5555
}
56+
57+
static bool SetDefaultPath(NSSavePanel* dialog, const FilePathView defaultPath, const StringView defaultFileName)
58+
{
59+
if (defaultPath)
60+
{
61+
NSString* defaultPathStr = [NSString stringWithUTF8String: defaultPath.toUTF8().c_str()];
62+
NSURL* url = [NSURL fileURLWithPath:defaultPathStr isDirectory:YES];
63+
[dialog setDirectoryURL:url];
64+
}
65+
66+
if (defaultFileName)
67+
{
68+
NSString* defaultFileNameStr = [NSString stringWithUTF8String: defaultFileName.toUTF8().c_str()];
69+
[dialog setNameFieldStringValue:defaultFileNameStr];
70+
}
71+
72+
return true;
73+
}
5674
}
5775

5876
namespace Dialog
@@ -155,7 +173,7 @@ static bool SetDefaultPath(NSSavePanel* dialog, const FilePathView defaultPath)
155173
}
156174
}
157175

158-
Optional<FilePath> SaveFile(const Array<FileFilter>& filters, const FilePathView defaultPath, const StringView, const StringView)
176+
Optional<FilePath> SaveFile(const Array<FileFilter>& filters, const FilePathView defaultPath, const StringView, const StringView defaultFileName)
159177
{
160178
@autoreleasepool
161179
{
@@ -177,7 +195,7 @@ static bool SetDefaultPath(NSSavePanel* dialog, const FilePathView defaultPath)
177195
[dialog setAllowedFileTypes:result];
178196
}
179197

180-
if (!detail::SetDefaultPath(dialog, defaultPath))
198+
if (!detail::SetDefaultPath(dialog, defaultPath, defaultFileName))
181199
{
182200
return none;
183201
}

0 commit comments

Comments
 (0)