From d41b4e1645f989f30e27e028ed96b2b41dba0400 Mon Sep 17 00:00:00 2001 From: mere-human <9664141+mere-human@users.noreply.github.com> Date: Sun, 22 Aug 2021 00:09:31 +0300 Subject: [PATCH] Fix current directory not applied bug after changing current directory option Refresh the working directory when changing Follow current document preference. Fix #10396, close #10426 --- PowerEditor/src/NppBigSwitch.cpp | 9 +++++++++ PowerEditor/src/WinControls/Preference/preferenceDlg.cpp | 2 ++ PowerEditor/src/resource.h | 1 + 3 files changed, 12 insertions(+) diff --git a/PowerEditor/src/NppBigSwitch.cpp b/PowerEditor/src/NppBigSwitch.cpp index 4ba7d1d93..21be19e51 100644 --- a/PowerEditor/src/NppBigSwitch.cpp +++ b/PowerEditor/src/NppBigSwitch.cpp @@ -2671,6 +2671,15 @@ LRESULT Notepad_plus::process(HWND hwnd, UINT message, WPARAM wParam, LPARAM lPa return TRUE; } + case NPPM_INTERNAL_REFRESHWORKDIR: + { + const Buffer* buf = _pEditView->getCurrentBuffer(); + generic_string path = buf ? buf->getFullPathName() : _T(""); + PathRemoveFileSpec(path); + setWorkingDir(path.c_str()); + return TRUE; + } + default: { if (message == WDN_NOTIFY) diff --git a/PowerEditor/src/WinControls/Preference/preferenceDlg.cpp b/PowerEditor/src/WinControls/Preference/preferenceDlg.cpp index c628886b8..760716b0e 100644 --- a/PowerEditor/src/WinControls/Preference/preferenceDlg.cpp +++ b/PowerEditor/src/WinControls/Preference/preferenceDlg.cpp @@ -2148,6 +2148,7 @@ INT_PTR CALLBACK DefaultDirectorySubDlg::run_dlgProc(UINT message, WPARAM wParam { case IDC_OPENSAVEDIR_FOLLOWCURRENT_RADIO: nppGUI._openSaveDir = dir_followCurrent; + ::SendMessage(::GetParent(_hParent), NPPM_INTERNAL_REFRESHWORKDIR, 0, 0); ::EnableWindow(::GetDlgItem(_hSelf, IDC_OPENSAVEDIR_ALWAYSON_EDIT), false); ::EnableWindow(::GetDlgItem(_hSelf, IDD_OPENSAVEDIR_ALWAYSON_BROWSE_BUTTON), false); return TRUE; @@ -2158,6 +2159,7 @@ INT_PTR CALLBACK DefaultDirectorySubDlg::run_dlgProc(UINT message, WPARAM wParam return TRUE; case IDC_OPENSAVEDIR_ALWAYSON_RADIO: nppGUI._openSaveDir = dir_userDef; + ::SendMessage(::GetParent(_hParent), NPPM_INTERNAL_REFRESHWORKDIR, 0, 0); ::EnableWindow(::GetDlgItem(_hSelf, IDC_OPENSAVEDIR_ALWAYSON_EDIT), true); ::EnableWindow(::GetDlgItem(_hSelf, IDD_OPENSAVEDIR_ALWAYSON_BROWSE_BUTTON), true); return TRUE; diff --git a/PowerEditor/src/resource.h b/PowerEditor/src/resource.h index e6e583c53..c70e9d811 100644 --- a/PowerEditor/src/resource.h +++ b/PowerEditor/src/resource.h @@ -632,6 +632,7 @@ #define NPPM_INTERNAL_UPDATETEXTZONEPADDING (NOTEPADPLUS_USER_INTERNAL + 58) #define NPPM_INTERNAL_REFRESHDARKMODE (NOTEPADPLUS_USER_INTERNAL + 59) #define NPPM_INTERNAL_SCINTILLAFINDERCOPYPATHS (NOTEPADPLUS_USER_INTERNAL + 60) + #define NPPM_INTERNAL_REFRESHWORKDIR (NOTEPADPLUS_USER_INTERNAL + 61) // See Notepad_plus_msgs.h //#define NOTEPADPLUS_USER (WM_USER + 1000)