Skip to content

Commit

Permalink
Better setup default filename in windows save dialogs
Browse files Browse the repository at this point in the history
  • Loading branch information
hughsando committed Nov 30, 2023
1 parent a223416 commit 4642777
Showing 1 changed file with 27 additions and 2 deletions.
29 changes: 27 additions & 2 deletions project/src/windows/System.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -173,8 +173,33 @@ static unsigned __stdcall dialog_proc( void *inSpec )
ofn.nMaxFile = path.size();
ofn.lpstrDefExt = "*";

if (spec->defaultPath[0])
ofn.lpstrInitialDir = spec->defaultPath.c_str();
const char *path0 = spec->defaultPath.c_str();
if (*path0)
{
const char *lastWord = path0;
bool hasDot = false;
for(const char *p=lastWord; *p; p++)
{
if (*p=='\\' || *p=='/')
{
lastWord = p + 1;
hasDot = false;
}
else if (*p=='.')
hasDot = true;
}
if (lastWord && hasDot)
{
size_t len = spec->defaultPath.size();
memcpy(ofn.lpstrFile, spec->defaultPath.c_str(), len );
for(size_t i=0; i<len; i++)
if (ofn.lpstrFile[i]=='/')
ofn.lpstrFile[i]='\\';
ofn.nFileOffset = (WORD)(lastWord-path0);
}
else
ofn.lpstrInitialDir = path0;
}

bool result = (spec->flags & flagSave) ? GetSaveFileName(&ofn) : GetOpenFileName(&ofn);
if (result)
Expand Down

0 comments on commit 4642777

Please sign in to comment.