Commit 8006fd41 authored by Vincent Povirk's avatar Vincent Povirk Committed by Alexandre Julliard

explorer: Hide empty folders in the start menu.

parent 69caad44
...@@ -131,6 +131,50 @@ static HRESULT pidl_to_shellfolder(LPITEMIDLIST pidl, LPWSTR *displayname, IShel ...@@ -131,6 +131,50 @@ static HRESULT pidl_to_shellfolder(LPITEMIDLIST pidl, LPWSTR *displayname, IShel
return hr; return hr;
} }
static BOOL shell_folder_is_empty(IShellFolder* folder)
{
IEnumIDList* enumidl;
LPITEMIDLIST pidl=NULL;
if (IShellFolder_EnumObjects(folder, NULL, SHCONTF_NONFOLDERS, &enumidl) == S_OK)
{
if (IEnumIDList_Next(enumidl, 1, &pidl, NULL) == S_OK)
{
CoTaskMemFree(pidl);
IEnumIDList_Release(enumidl);
return FALSE;
}
IEnumIDList_Release(enumidl);
}
if (IShellFolder_EnumObjects(folder, NULL, SHCONTF_FOLDERS, &enumidl) == S_OK)
{
BOOL found = FALSE;
IShellFolder *child_folder;
while (!found && IEnumIDList_Next(enumidl, 1, &pidl, NULL) == S_OK)
{
if (IShellFolder_BindToObject(folder, pidl, NULL, &IID_IShellFolder, (void *)&child_folder) == S_OK)
{
if (!shell_folder_is_empty(child_folder))
found = TRUE;
IShellFolder_Release(child_folder);
}
CoTaskMemFree(pidl);
}
IEnumIDList_Release(enumidl);
if (found)
return FALSE;
}
return TRUE;
}
/* add an individual file or folder to the menu, takes ownership of pidl */ /* add an individual file or folder to the menu, takes ownership of pidl */
static struct menu_item* add_shell_item(struct menu_item* parent, LPITEMIDLIST pidl) static struct menu_item* add_shell_item(struct menu_item* parent, LPITEMIDLIST pidl)
{ {
...@@ -161,6 +205,15 @@ static struct menu_item* add_shell_item(struct menu_item* parent, LPITEMIDLIST p ...@@ -161,6 +205,15 @@ static struct menu_item* add_shell_item(struct menu_item* parent, LPITEMIDLIST p
IShellFolder_BindToObject(parent->folder, pidl, NULL, &IID_IShellFolder, (void *)&item->folder); IShellFolder_BindToObject(parent->folder, pidl, NULL, &IID_IShellFolder, (void *)&item->folder);
} }
if (item->folder && shell_folder_is_empty(item->folder))
{
IShellFolder_Release(item->folder);
HeapFree(GetProcessHeap(), 0, item->displayname);
HeapFree(GetProcessHeap(), 0, item);
CoTaskMemFree(pidl);
return NULL;
}
parent_menu = parent->menuhandle; parent_menu = parent->menuhandle;
item->parent = parent; item->parent = parent;
...@@ -411,9 +464,13 @@ void do_startmenu(HWND hwnd) ...@@ -411,9 +464,13 @@ void do_startmenu(HWND hwnd)
if (!public_startmenu.folder) if (!public_startmenu.folder)
pidl_to_shellfolder(public_startmenu.pidl, NULL, &public_startmenu.folder); pidl_to_shellfolder(public_startmenu.pidl, NULL, &public_startmenu.folder);
fill_menu(&user_startmenu); if (!shell_folder_is_empty(user_startmenu.folder) ||
!shell_folder_is_empty(public_startmenu.folder))
{
fill_menu(&user_startmenu);
AppendMenuW(root_menu.menuhandle, MF_SEPARATOR, 0, NULL); AppendMenuW(root_menu.menuhandle, MF_SEPARATOR, 0, NULL);
}
if (SUCCEEDED(SHGetSpecialFolderLocation(NULL, CSIDL_CONTROLS, &pidl))) if (SUCCEEDED(SHGetSpecialFolderLocation(NULL, CSIDL_CONTROLS, &pidl)))
add_shell_item(&root_menu, pidl); add_shell_item(&root_menu, pidl);
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment