From af56b87dfb5ca7caba7f92c106d644dd7f6da96f Mon Sep 17 00:00:00 2001 From: Takashi Sawanaka Date: Thu, 14 Mar 2019 16:46:28 +0900 Subject: [PATCH] Fix sf.net ticket #2163: Save As: default directory should be file's original directory --HG-- branch : stable --- Src/FileOrFolderSelect.cpp | 8 +++++++- 1 file changed, 7 insertions(+), 1 deletion(-) diff --git a/Src/FileOrFolderSelect.cpp b/Src/FileOrFolderSelect.cpp index ca8d3d918..5ea628517 100644 --- a/Src/FileOrFolderSelect.cpp +++ b/Src/FileOrFolderSelect.cpp @@ -70,6 +70,7 @@ bool SelectFile(HWND parent, String& path, bool is_open /*= true*/, // This will tell common file dialog what to show // and also this will hold its return value TCHAR sSelectedFile[MAX_PATH_FULL] = {0}; + String sInitialDir; // check if specified path is a file if (initialPath && initialPath[0]) @@ -82,6 +83,11 @@ bool SelectFile(HWND parent, String& path, bool is_open /*= true*/, String temp; paths::SplitFilename(initialPath, 0, &temp, 0); lstrcpy(sSelectedFile, temp.c_str()); + sInitialDir = paths::GetParentPath(initialPath); + } + else + { + sInitialDir = initialPath; } } @@ -105,7 +111,7 @@ bool SelectFile(HWND parent, String& path, bool is_open /*= true*/, ofn.nFilterIndex = 1; ofn.lpstrFile = sSelectedFile; ofn.nMaxFile = MAX_PATH_FULL; - ofn.lpstrInitialDir = initialPath; + ofn.lpstrInitialDir = sInitialDir.empty() ? nullptr : sInitialDir.c_str(); ofn.lpstrTitle = title.c_str(); ofn.lpstrFileTitle = nullptr; if (defaultExtension) -- 2.11.0