Skip to content

Commit

Permalink
Fix: Refactored ContextMenu (files-community#12217)
Browse files Browse the repository at this point in the history
  • Loading branch information
hishitetsu committed Apr 27, 2023
1 parent b179943 commit e7050da
Showing 1 changed file with 13 additions and 12 deletions.
25 changes: 13 additions & 12 deletions src/Files.App/Shell/ContextMenu.cs
Expand Up @@ -254,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 @@ -292,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

0 comments on commit e7050da

Please sign in to comment.