[SHELL32] Give opportunity to rename file/folder on its creation (#5139)

* [SHELL32] Fix issue when creating a new file or folder. No chance to rename the displayed name.

The CNewMenu::SelectNewItem method starts with a request to notify the View object about a new item by calling SHChangeNotify.
After creating and obtaining the new PIDL by calling ILFindLastID, the CDefView::SelectItem method is called.
This method fails right from the start when calling LV_FindItemByPidl which returns -1, thus preventing the user from being given the opportunity to change the name displayed by default.

This failure is due to the fact that this object has not yet been added to the CDefView::m_ListView list. This is caused by the asynchronous nature of SHChangeNotify.

Thanks to Giannis Adamopoulos for the big help.
This commit is contained in:
Jose Carlos Jesus 2023-03-14 18:27:14 -03:00 committed by GitHub
parent 9b6b1b3513
commit b8c4d589b1
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
3 changed files with 2 additions and 3 deletions

View File

@ -990,7 +990,6 @@ BOOLEAN CDefView::LV_ProdItem(PCUITEMID_CHILD pidl)
lvItem.iImage = SHMapPIDLToSystemImageListIndex(m_pSFParent, pidl, 0);
m_ListView.SetItem(&lvItem);
m_ListView.Update(nItem);
m_ListView.EditLabel(nItem);
return TRUE;
}

View File

@ -926,7 +926,7 @@ CDefaultContextMenu::DoCreateNewFolder(
CComPtr<IShellView> psv;
/* Notify the view object about the new item */
SHChangeNotify(SHCNE_MKDIR, SHCNF_PATHW, (LPCVOID)wszName, NULL);
SHChangeNotify(SHCNE_MKDIR, SHCNF_PATHW | SHCNF_FLUSH, (LPCVOID)wszName, NULL);
if (!m_site)
return S_OK;

View File

@ -418,7 +418,7 @@ HRESULT CNewMenu::SelectNewItem(LONG wEventId, UINT uFlags, LPWSTR pszName, BOOL
dwSelectFlags |= SVSI_EDIT;
/* Notify the view object about the new item */
SHChangeNotify(wEventId, uFlags, (LPCVOID) pszName, NULL);
SHChangeNotify(wEventId, uFlags | SHCNF_FLUSH, (LPCVOID)pszName, NULL);
if (!m_pSite)
return S_OK;