浏览代码

dialog: fix default file name on Cocoa

Anon Ymous 2 月之前
父节点
当前提交
b2d152e51f
共有 1 个文件被更改,包括 8 次插入1 次删除
  1. 8 1
      src/dialog/cocoa/SDL_cocoadialog.m

+ 8 - 1
src/dialog/cocoa/SDL_cocoadialog.m

@@ -158,7 +158,14 @@ void SDL_SYS_ShowFileDialogWithProperties(SDL_FileDialogType type, SDL_DialogFil
     [dialog setAllowsOtherFileTypes:YES];
 
     if (default_location) {
-        [dialog setDirectoryURL:[NSURL fileURLWithPath:[NSString stringWithUTF8String:default_location]]];
+        char last = default_location[SDL_strlen(default_location) - 1];
+        NSURL* url = [NSURL fileURLWithPath:[NSString stringWithUTF8String:default_location]];
+        if (last == '/') {
+            [dialog setDirectoryURL:url];
+        } else {
+            [dialog setDirectoryURL:[url URLByDeletingLastPathComponent]];
+            [dialog setNameFieldStringValue:[url lastPathComponent]];
+        }
     }
 
     NSWindow *w = NULL;