Fix Find-in-Files "Follow current doc" not working issue when absolute Default Directory set

This PR uses always current buffer's path in Find in Files dialog:
When "Follow current doc." is checked, then use current path first.
If that fails, fallback to the working directory as it was before.

Fix #8045, close #10387
This commit is contained in:
mere-human 2021-08-15 14:39:30 +03:00 committed by Don Ho
parent 302bab894f
commit 0c16f87a18
1 changed files with 14 additions and 4 deletions

View File

@ -14,7 +14,7 @@
// You should have received a copy of the GNU General Public License
// along with this program. If not, see <https://www.gnu.org/licenses/>.
#include <shlobj.h>
#include <shlwapi.h>
#include <uxtheme.h>
#include "FindReplaceDlg.h"
#include "ScintillaEditView.h"
@ -1822,9 +1822,19 @@ INT_PTR CALLBACK FindReplaceDlg::run_dlgProc(UINT message, WPARAM wParam, LPARAM
if (findHistory._isFolderFollowDoc)
{
NppParameters& nppParam = NppParameters::getInstance();
const TCHAR * dir = nppParam.getWorkingDir();
::SetDlgItemText(_hSelf, IDD_FINDINFILES_DIR_COMBO, dir);
// Working directory depends on "Default Directory" preferences.
// It might be set to an absolute path value.
// So try to get the current buffer's path first.
generic_string currPath;
const Buffer* buf = (*_ppEditView)->getCurrentBuffer();
if (!(buf->getStatus() & (DOC_UNNAMED | DOC_DELETED)))
{
currPath = buf->getFullPathName();
PathRemoveFileSpec(currPath);
}
if (currPath.empty() || !PathIsDirectory(currPath.c_str()))
currPath = NppParameters::getInstance().getWorkingDir();
::SetDlgItemText(_hSelf, IDD_FINDINFILES_DIR_COMBO, currPath.c_str());
}
}