Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix: Refactored ContextMenu #12217

Merged
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
35 changes: 14 additions & 21 deletions src/Files.App/Shell/ContextMenu.cs
Expand Up @@ -165,15 +165,7 @@ public async Task InvokeItem(int itemID)

public static async Task WarmUpQueryContextMenuAsync()
{
var thread = new ThreadWithMessageQueue();
await thread.PostMethod(() =>
{
// Create a dummy context menu for warming up
var shellItem = ShellFolderExtensions.GetShellItemFromPathOrPidl("C:\\");
Shell32.IContextMenu menu = shellItem.Parent.GetChildrenUIObjects<Shell32.IContextMenu>(default, shellItem);
menu.QueryContextMenu(User32.CreatePopupMenu(), 0, 1, 0x7FFF, Shell32.CMF.CMF_NORMAL);
});
thread.Dispose();
using var cMenu = await GetContextMenuForFiles(new string[] { "C:\\" }, Shell32.CMF.CMF_NORMAL);
}

#endregion FactoryMethods
Expand Down Expand Up @@ -262,18 +254,18 @@ public static async Task WarmUpQueryContextMenuAsync()

if (loadSubenus)
{
LoadSubMenu(hSubMenu);
LoadSubMenu();
}
else
{
loadSubMenuActions.Add(subItems, () => LoadSubMenu(hSubMenu));
loadSubMenuActions.Add(subItems, LoadSubMenu);
}

menuItem.SubItems = subItems;

Debug.WriteLine("Item {0}: done submenu", ii);

void LoadSubMenu(HMENU hSubMenu)
void LoadSubMenu()
{
try
{
Expand All @@ -300,24 +292,25 @@ void LoadSubMenu(HMENU hSubMenu)

public async Task<bool> LoadSubMenu(List<Win32ContextMenuItem> subItems)
{
return await owningThread.PostMethod<bool>(() =>
if (loadSubMenuActions.Remove(subItems, out var loadSubMenuAction))
{
var result = loadSubMenuActions.Remove(subItems, out var loadSubMenuAction);

if (result)
return await owningThread.PostMethod<bool>(() =>
{
try
{
loadSubMenuAction!();
return true;
}
catch (COMException)
{
result = false;
return false;
}
}

return result;
});
});
}
else
{
return false;
}
}

private static string? GetCommandString(Shell32.IContextMenu cMenu, uint offset, Shell32.GCS flags = Shell32.GCS.GCS_VERBW)
Expand Down