OSDN Git Service

Fix sf.net ticket #2163: Save As: default directory should be file's original directory
authorTakashi Sawanaka <sdottaka@users.sourceforge.net>
Thu, 14 Mar 2019 07:46:28 +0000 (16:46 +0900)
committerTakashi Sawanaka <sdottaka@users.sourceforge.net>
Thu, 14 Mar 2019 07:46:28 +0000 (16:46 +0900)
Src/FileOrFolderSelect.cpp

index ca8d3d9..5ea6285 100644 (file)
@@ -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)