Skip to content

Commit

Permalink
Use directory for last file to provide initial directory on open/save…
Browse files Browse the repository at this point in the history
… file dialog, issue #677.
  • Loading branch information
zufuliu committed Jul 6, 2023
1 parent 46496c4 commit 2aaa485
Showing 1 changed file with 28 additions and 38 deletions.
66 changes: 28 additions & 38 deletions src/Notepad2.c
Original file line number Diff line number Diff line change
Expand Up @@ -7862,28 +7862,35 @@ void EditApplyDefaultEncoding(PEDITLEXER pLex, BOOL bLexerChanged) {
// OpenFileDlg()
//
//
BOOL OpenFileDlg(LPWSTR lpstrFile, int cchFile, LPCWSTR lpstrInitialDir) {
WCHAR tchInitialDir[MAX_PATH] = L"";
if (!lpstrInitialDir) {
if (StrNotEmpty(szCurFile)) {
lstrcpy(tchInitialDir, szCurFile);
PathRemoveFileSpec(tchInitialDir);
} else if (StrNotEmpty(tchDefaultDir)) {
ExpandEnvironmentStrings(tchDefaultDir, tchInitialDir, COUNTOF(tchInitialDir));
if (PathIsRelative(tchInitialDir)) {
WCHAR tchModule[MAX_PATH];
GetModuleFileName(NULL, tchModule, COUNTOF(tchModule));
PathRemoveFileSpec(tchModule);
PathAppend(tchModule, tchInitialDir);
PathCanonicalize(tchInitialDir, tchModule);
}
} else {
lstrcpy(tchInitialDir, g_wchWorkingDirectory);
void SetupInitialOpenSaveDir(LPWSTR tchInitialDir, DWORD cchInitialDir, LPCWSTR lpstrInitialDir) {
tchInitialDir[0] = L'\0';
if (StrNotEmpty(lpstrInitialDir)) {
lstrcpy(tchInitialDir, lpstrInitialDir);
} else if (StrNotEmpty(szCurFile)) {
lstrcpy(tchInitialDir, szCurFile);
PathRemoveFileSpec(tchInitialDir);
} else if (StrNotEmpty(tchDefaultDir)) {
ExpandEnvironmentStrings(tchDefaultDir, tchInitialDir, cchInitialDir);
if (PathIsRelative(tchInitialDir)) {
WCHAR tchModule[MAX_PATH];
GetModuleFileName(NULL, tchModule, COUNTOF(tchModule));
PathRemoveFileSpec(tchModule);
PathAppend(tchModule, tchInitialDir);
PathCanonicalize(tchInitialDir, tchModule);
}
} else if (StrNotEmpty(pFileMRU->pszItems[0])) {
lstrcpy(tchInitialDir, pFileMRU->pszItems[0]);
PathRemoveFileSpec(tchInitialDir);
} else {
lstrcpy(tchInitialDir, g_wchWorkingDirectory);
}
}

BOOL OpenFileDlg(LPWSTR lpstrFile, int cchFile, LPCWSTR lpstrInitialDir) {
WCHAR tchInitialDir[MAX_PATH];
SetupInitialOpenSaveDir(tchInitialDir, COUNTOF(tchInitialDir), lpstrInitialDir);
WCHAR szFile[MAX_PATH];
StrCpyExW(szFile, L"");
szFile[0] = L'\0';
int lexers[1 + OPENDLG_MAX_LEXER_COUNT] = {0}; // 1-based filter index
LPWSTR szFilter = Style_GetOpenDlgFilterStr(true, szCurFile, lexers);

Expand All @@ -7893,7 +7900,7 @@ BOOL OpenFileDlg(LPWSTR lpstrFile, int cchFile, LPCWSTR lpstrInitialDir) {
ofn.hwndOwner = hwndMain;
ofn.lpstrFilter = szFilter;
ofn.lpstrFile = szFile;
ofn.lpstrInitialDir = (lpstrInitialDir) ? lpstrInitialDir : tchInitialDir;
ofn.lpstrInitialDir = tchInitialDir;
ofn.lpstrDefExt = L""; // auto add first extension from current filter
ofn.nMaxFile = COUNTOF(szFile);
ofn.Flags = OFN_FILEMUSTEXIST | OFN_HIDEREADONLY | /* OFN_NOCHANGEDIR |*/
Expand Down Expand Up @@ -7921,25 +7928,8 @@ BOOL OpenFileDlg(LPWSTR lpstrFile, int cchFile, LPCWSTR lpstrInitialDir) {
//
//
BOOL SaveFileDlg(bool Untitled, LPWSTR lpstrFile, int cchFile, LPCWSTR lpstrInitialDir) {
WCHAR tchInitialDir[MAX_PATH] = L"";
if (StrNotEmpty(lpstrInitialDir)) {
lstrcpy(tchInitialDir, lpstrInitialDir);
} else if (StrNotEmpty(szCurFile)) {
lstrcpy(tchInitialDir, szCurFile);
PathRemoveFileSpec(tchInitialDir);
} else if (StrNotEmpty(tchDefaultDir)) {
ExpandEnvironmentStrings(tchDefaultDir, tchInitialDir, COUNTOF(tchInitialDir));
if (PathIsRelative(tchInitialDir)) {
WCHAR tchModule[MAX_PATH];
GetModuleFileName(NULL, tchModule, COUNTOF(tchModule));
PathRemoveFileSpec(tchModule);
PathAppend(tchModule, tchInitialDir);
PathCanonicalize(tchInitialDir, tchModule);
}
} else {
lstrcpy(tchInitialDir, g_wchWorkingDirectory);
}

WCHAR tchInitialDir[MAX_PATH];
SetupInitialOpenSaveDir(tchInitialDir, COUNTOF(tchInitialDir), lpstrInitialDir);
WCHAR szNewFile[MAX_PATH];
lstrcpy(szNewFile, lpstrFile);
int lexers[1 + OPENDLG_MAX_LEXER_COUNT] = {0}; // 1-based filter index
Expand Down

0 comments on commit 2aaa485

Please sign in to comment.