Skip to content

Commit

Permalink
Leverage favorite system for recommended tool providers (#626)
Browse files Browse the repository at this point in the history
  • Loading branch information
C1rdec authored Aug 18, 2022
1 parent c409b9a commit e9df393
Showing 1 changed file with 19 additions and 3 deletions.
22 changes: 19 additions & 3 deletions src/dev/impl/DevToys/ViewModels/MainPageViewModel.cs
Original file line number Diff line number Diff line change
Expand Up @@ -666,8 +666,9 @@ ToolProviderViewItem[] newRecommendedTools

using (await _sempahore.WaitAsync(CancellationToken.None).ConfigureAwait(false))
{
if (newRecommendedTools.Length == 1
&& IsToolDisplayedInMenu(ToolsMenuItems.OfType<ToolProviderViewItem>(), newRecommendedTools[0]))
ToolProviderViewItem? toolProvider = GetRecommendedToolProvider(newRecommendedTools);
if (toolProvider != null
&& IsToolDisplayedInMenu(ToolsMenuItems.OfType<ToolProviderViewItem>(), toolProvider))
{
// One unique tool is recommended.
// The recommended tool is displayed in the top menu.
Expand All @@ -679,13 +680,28 @@ await ThreadHelper.RunOnUIThreadAsync(
{
if (!IsInCompactOverlayMode && _allowSelectAutomaticallyRecommendedTool)
{
SetSelectedMenuItem(newRecommendedTools[0], _clipboardContent);
SetSelectedMenuItem(toolProvider, _clipboardContent);
}
});
}
}
}

private ToolProviderViewItem? GetRecommendedToolProvider(ToolProviderViewItem[] items)
{
ToolProviderViewItem favoriteItem = items.FirstOrDefault(i => i.IsFavorite);
if (favoriteItem != null)
{
return favoriteItem;
}
else if (items.Length == 1)
{
return items[0];
}

return null;
}

private bool IsToolDisplayedInMenu(IEnumerable<ToolProviderViewItem> tools, ToolProviderViewItem ToolProviderViewItem)
{
Arguments.NotNull(tools, nameof(tools));
Expand Down

0 comments on commit e9df393

Please sign in to comment.