Use current file directory in File Rename dialog

and fix "Remember last used directory" unexpected behaviour.

Fix #10095, fix #10115, close #10100
This commit is contained in:
mere-human 2021-07-03 20:17:52 +03:00 committed by Don Ho
parent 80c285ee2d
commit a0472fd7f2
3 changed files with 21 additions and 10 deletions

View File

@ -1348,6 +1348,7 @@ You can re-activate this dialog in Preferences dialog later." /> <!-- HowToRepro
<cloud-select-folder value="Select a folder from/to where Notepad++ reads/writes its settings"/> <!-- HowToReproduce: In "Cloud" section of Preferences dialog, check "Set your cloud location path here: ", then click the button "...". This message is displayed in the "Browse For Folder" dialog. -->
<shift-change-direction-tip value="Use Shift+Enter to search in the opposite direction"/>
<two-find-buttons-tip value="2 find buttons mode"/>
<file-rename-title value="Rename"/>
<find-in-files-filter-tip value="Find in cpp, cxx, h, hxx &amp;&amp; hpp:
*.cpp *.cxx *.h *.hxx *.hpp

View File

@ -1753,8 +1753,12 @@ bool Notepad_plus::fileRename(BufferID id)
fDlg.setExtFilter(TEXT("All types"), TEXT(".*"));
setFileOpenSaveDlgFilters(fDlg, false);
fDlg.setFolder(buf->getFullPathName());
fDlg.setDefFileName(buf->getFileName());
generic_string title = _nativeLangSpeaker.getLocalizedStrFromID("file-rename-title", TEXT("Rename"));
fDlg.setTitle(title.c_str());
generic_string fn = fDlg.doSaveDlg();
if (!fn.empty())
@ -1769,10 +1773,10 @@ bool Notepad_plus::fileRename(BufferID id)
// Reserved characters: < > : " / \ | ? *
std::wstring reservedChars = TEXT("<>:\"/\\|\?*");
generic_string title = _nativeLangSpeaker.getLocalizedStrFromID("tabrename-title", TEXT("Rename Current Tab"));
generic_string staticName = _nativeLangSpeaker.getLocalizedStrFromID("tabrename-newname", TEXT("New Name: "));
StringDlg strDlg;
generic_string title = _nativeLangSpeaker.getLocalizedStrFromID("tabrename-title", TEXT("Rename Current Tab"));
strDlg.init(_pPublicInterface->getHinst(), _pPublicInterface->getHSelf(), title.c_str(), staticName.c_str(), buf->getFileName(), 0, reservedChars.c_str(), true);
TCHAR *tabNewName = reinterpret_cast<TCHAR *>(strDlg.doDialog());

View File

@ -137,15 +137,21 @@ namespace // anonymous
return result;
}
bool setDialogFolder(IFileDialog* dialog, const TCHAR* folder)
bool setDialogFolder(IFileDialog* dialog, const TCHAR* path)
{
IShellItem* psi = nullptr;
HRESULT hr = SHCreateItemFromParsingName(folder,
0,
IID_IShellItem,
reinterpret_cast<void**>(&psi));
com_ptr<IShellItem> shellItem;
HRESULT hr = SHCreateItemFromParsingName(path,
nullptr,
IID_PPV_ARGS(&shellItem));
if (SUCCEEDED(hr) && shellItem && !::PathIsDirectory(path))
{
com_ptr<IShellItem> parentItem;
hr = shellItem->GetParent(&parentItem);
if (SUCCEEDED(hr))
hr = dialog->SetFolder(psi);
shellItem = parentItem;
}
if (SUCCEEDED(hr))
hr = dialog->SetFolder(shellItem);
return SUCCEEDED(hr);
}
@ -738,7 +744,7 @@ public:
okPressed = SUCCEEDED(hr);
NppParameters& params = NppParameters::getInstance();
if (params.getNppGUI()._openSaveDir == dir_last)
if (okPressed && params.getNppGUI()._openSaveDir == dir_last)
{
// Note: IFileDialog doesn't modify the current directory.
// At least, after it is hidden, the current directory is the same as before it was shown.