static void DoNewFolder(ContextMenu *This, IShellView *view) { ISFHelper *helper; IShellFolder_QueryInterface(This->parent, &IID_ISFHelper, (void**)&helper); if (helper) { WCHAR nameW[MAX_PATH]; LPITEMIDLIST pidl; ISFHelper_GetUniqueName(helper, nameW, MAX_PATH); ISFHelper_AddFolder(helper, 0, nameW, &pidl); if (view) { /* if we are in a shellview do labeledit */ IShellView_SelectItem(view, pidl,(SVSI_DESELECTOTHERS | SVSI_EDIT | SVSI_ENSUREVISIBLE |SVSI_FOCUSED|SVSI_SELECT)); } SHFree(pidl); ISFHelper_Release(helper); } }
static HRESULT create_folder(NewMenuImpl *This, IShellView *view) { IFolderView *folder_view = NULL; IShellFolder *desktop = NULL; IShellFolder *parent = NULL; ISFHelper *helper = NULL; LPITEMIDLIST pidl = NULL; WCHAR nameW[MAX_PATH]; HRESULT hr; if (view) { hr = IShellView_QueryInterface(view, &IID_IFolderView, (void **)&folder_view); if (FAILED(hr)) return hr; hr = IFolderView_GetFolder(folder_view, &IID_IShellFolder, (void **)&parent); if (FAILED(hr)) goto out; } else { hr = SHGetDesktopFolder(&desktop); if (FAILED(hr)) goto out; hr = IShellFolder_BindToObject(desktop, This->pidl, NULL, &IID_IShellFolder, (void **)&parent); if (FAILED(hr)) goto out; } IShellFolder_QueryInterface(parent, &IID_ISFHelper, (void **)&helper); if (FAILED(hr)) goto out; hr = ISFHelper_GetUniqueName(helper, nameW, MAX_PATH); if (FAILED(hr)) goto out; hr = ISFHelper_AddFolder(helper, 0, nameW, &pidl); if (FAILED(hr)) goto out; if (view) { IShellView_SelectItem(view, pidl, SVSI_DESELECTOTHERS | SVSI_EDIT | SVSI_ENSUREVISIBLE | SVSI_FOCUSED | SVSI_SELECT); } out: if (pidl) SHFree(pidl); if (helper) ISFHelper_Release(helper); if (parent) IShellFolder_Release(parent); if (desktop) IShellFolder_Release(desktop); if (folder_view) IFolderView_Release(folder_view); return hr; }
static HRESULT BrsFolder_NewFolder(browse_info *info) { DWORD flags = BrowseFlagsToSHCONTF(info->lpBrowseInfo->ulFlags); IShellFolder *desktop, *cur; ISFHelper *sfhelper; WCHAR name[MAX_PATH]; HTREEITEM parent, added; LPTV_ITEMDATA item_data; LPITEMIDLIST new_item; TVITEMW item; HRESULT hr; int len; if(!info->pidlRet) { ERR("Make new folder button should be disabled\n"); return E_FAIL; } /* Create new directory */ hr = SHGetDesktopFolder(&desktop); if(FAILED(hr)) return hr; hr = IShellFolder_BindToObject(desktop, info->pidlRet, 0, &IID_IShellFolder, (void**)&cur); IShellFolder_Release(desktop); if(FAILED(hr)) return hr; hr = IShellFolder_QueryInterface(cur, &IID_ISFHelper, (void**)&sfhelper); if(FAILED(hr)) return hr; hr = SHGetPathFromIDListW(info->pidlRet, name); if(FAILED(hr)) goto cleanup; len = strlenW(name); if(len<MAX_PATH) name[len++] = '\\'; hr = ISFHelper_GetUniqueName(sfhelper, &name[len], MAX_PATH-len); ISFHelper_Release(sfhelper); if(FAILED(hr)) goto cleanup; hr = E_FAIL; if(!CreateDirectoryW(name, NULL)) goto cleanup; /* Update parent of newly created directory */ parent = (HTREEITEM)SendMessageW(info->hwndTreeView, TVM_GETNEXTITEM, TVGN_CARET, 0); if(!parent) goto cleanup; SendMessageW(info->hwndTreeView, TVM_EXPAND, TVE_EXPAND, (LPARAM)parent); memset(&item, 0, sizeof(TVITEMW)); item.mask = TVIF_PARAM|TVIF_STATE; item.hItem = parent; SendMessageW(info->hwndTreeView, TVM_GETITEMW, 0, (LPARAM)&item); item_data = (LPTV_ITEMDATA)item.lParam; if(!item_data) goto cleanup; if(item_data->pEnumIL) IEnumIDList_Release(item_data->pEnumIL); hr = IShellFolder_EnumObjects(cur, info->hwndTreeView, flags, &item_data->pEnumIL); if(FAILED(hr)) goto cleanup; /* Update treeview */ if(!(item.state&TVIS_EXPANDEDONCE)) { item.mask = TVIF_STATE; item.state = TVIS_EXPANDEDONCE; item.stateMask = TVIS_EXPANDEDONCE; SendMessageW(info->hwndTreeView, TVM_SETITEMW, 0, (LPARAM)&item); } hr = IShellFolder_ParseDisplayName(cur, NULL, NULL, name+len, NULL, &new_item, NULL); if(FAILED(hr)) goto cleanup; added = InsertTreeViewItem(info, cur, new_item, item_data->lpifq, NULL, parent); IShellFolder_Release(cur); SHFree(new_item); SendMessageW(info->hwndTreeView, TVM_SORTCHILDREN, FALSE, (LPARAM)parent); return BrsFolder_Rename(info, added); cleanup: return hr; }