shell32: Implement folder renaming in SHBrowseForFolder.

This commit is contained in:
Piotr Caban 2011-07-03 14:42:26 +02:00 committed by Alexandre Julliard
parent 74c47d0a67
commit 1226422a08
2 changed files with 49 additions and 4 deletions

View File

@ -574,6 +574,46 @@ static HRESULT BrsFolder_Treeview_Changed( browse_info *info, NMTREEVIEWW *pnmtv
return 0;
}
static LRESULT BrsFolder_Treeview_Rename(browse_info *info, NMTVDISPINFOW *pnmtv)
{
LPTV_ITEMDATA item_data;
WCHAR old_path[MAX_PATH], new_path[MAX_PATH], *p;
NMTREEVIEWW nmtv;
TVITEMW item;
if(!pnmtv->item.pszText)
return 0;
item.mask = TVIF_HANDLE|TVIF_PARAM;
item.hItem = (HTREEITEM)SendMessageW(info->hwndTreeView, TVM_GETNEXTITEM, TVGN_CARET, 0);
SendMessageW(info->hwndTreeView, TVM_GETITEMW, 0, (LPARAM)&item);
item_data = (LPTV_ITEMDATA)item.lParam;
SHGetPathFromIDListW(item_data->lpifq, old_path);
if(!(p = strrchrW(old_path, '\\')))
return 0;
p = new_path+(p-old_path+1);
memcpy(new_path, old_path, (p-new_path)*sizeof(WCHAR));
strcpyW(p, pnmtv->item.pszText);
if(!MoveFileW(old_path, new_path))
return 0;
SHFree(item_data->lpifq);
SHFree(item_data->lpi);
item_data->lpifq = SHSimpleIDListFromPathW(new_path);
IShellFolder_ParseDisplayName(item_data->lpsfParent, NULL, NULL,
pnmtv->item.pszText, NULL, &item_data->lpi, NULL);
item.mask = TVIF_HANDLE|TVIF_TEXT;
item.pszText = pnmtv->item.pszText;
SendMessageW(info->hwndTreeView, TVM_SETITEMW, 0, (LPARAM)&item);
nmtv.itemNew.lParam = item.lParam;
BrsFolder_Treeview_Changed(info, &nmtv);
return 0;
}
static LRESULT BrsFolder_OnNotify( browse_info *info, UINT CtlID, LPNMHDR lpnmh )
{
NMTREEVIEWW *pnmtv = (NMTREEVIEWW *)lpnmh;
@ -597,6 +637,10 @@ static LRESULT BrsFolder_OnNotify( browse_info *info, UINT CtlID, LPNMHDR lpnmh
case TVN_SELCHANGEDW:
return BrsFolder_Treeview_Changed( info, pnmtv );
case TVN_ENDLABELEDITA:
case TVN_ENDLABELEDITW:
return BrsFolder_Treeview_Rename( info, (LPNMTVDISPINFOW)pnmtv );
default:
WARN("unhandled (%d)\n", pnmtv->hdr.code);
break;
@ -680,8 +724,9 @@ static BOOL BrsFolder_OnCreate( HWND hWnd, browse_info *info )
static HRESULT BrsFolder_Rename(browse_info *info, HTREEITEM rename)
{
FIXME("\n");
return E_NOTIMPL;
SendMessageW(info->hwndTreeView, TVM_SELECTITEM, TVGN_CARET, (LPARAM)rename);
SendMessageW(info->hwndTreeView, TVM_EDITLABELW, 0, (LPARAM)rename);
return S_OK;
}
static HRESULT BrsFolder_NewFolder(browse_info *info)

View File

@ -222,14 +222,14 @@ static void test_click_make_new_folder_button(void)
/* There should be a new folder foo inside the test folder */
strcpy(new_folder_path, test_folder_path);
strcat(new_folder_path, new_folder_name);
todo_wine ok(does_folder_or_file_exist(new_folder_path)
ok(does_folder_or_file_exist(new_folder_path)
|| broken(!does_folder_or_file_exist(new_folder_path)) /* W95, W98, XP, W2K3 */,
"The new folder did not get the name %s\n", new_folder_name);
/* Dialog should return a pidl pointing to the new folder */
ok(SHGetPathFromIDListA(pidl, new_folder_pidl_path),
"SHGetPathFromIDList failed for new folder.\n");
todo_wine ok(strcmp(new_folder_path, new_folder_pidl_path) == 0
ok(strcmp(new_folder_path, new_folder_pidl_path) == 0
|| broken(strcmp(new_folder_path, new_folder_pidl_path) != 0) /* earlier than Vista */,
"SHBrowseForFolder did not return the pidl for the new folder. "
"Expected '%s' got '%s'\n", new_folder_path, new_folder_pidl_path);