From 1d464cc3076a94ee10cb9294dc89a03f73fb19ec Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Ji=C5=99=C3=AD=20Pol=C3=A1=C5=A1ek?= Date: Sat, 12 Jul 2025 04:11:13 +0200 Subject: [PATCH] Use Empty content for empty Web search page (#40549) ## Summary of the Pull Request Display full page message when the Web Search extension page is empty image image ## PR Checklist - [x] **Closes:** #38969 - [x] **Communication:** I've discussed this with core contributors already. If the work hasn't been agreed, this work might be rejected - [x] **Tests:** yay - [x] **Localization:** nope - [x] **Dev docs:** none - [x] **New binaries:** zilch - [x] **Documentation updated:** no need ## Detailed Description of the Pull Request / Additional comments -- ## Validation Steps Performed Tested with and without enabled history. --- .../Pages/WebSearchListPage.cs | 39 ++++++++----------- 1 file changed, 16 insertions(+), 23 deletions(-) diff --git a/src/modules/cmdpal/ext/Microsoft.CmdPal.Ext.WebSearch/Pages/WebSearchListPage.cs b/src/modules/cmdpal/ext/Microsoft.CmdPal.Ext.WebSearch/Pages/WebSearchListPage.cs index 406f008a84..c96efe24c7 100644 --- a/src/modules/cmdpal/ext/Microsoft.CmdPal.Ext.WebSearch/Pages/WebSearchListPage.cs +++ b/src/modules/cmdpal/ext/Microsoft.CmdPal.Ext.WebSearch/Pages/WebSearchListPage.cs @@ -23,28 +23,31 @@ internal sealed partial class WebSearchListPage : DynamicListPage private readonly SettingsManager _settingsManager; private static readonly CompositeFormat PluginInBrowserName = System.Text.CompositeFormat.Parse(Properties.Resources.plugin_in_browser_name); private static readonly CompositeFormat PluginOpen = System.Text.CompositeFormat.Parse(Properties.Resources.plugin_open); - private List allItems; + private List _allItems; public WebSearchListPage(SettingsManager settingsManager) { Name = Resources.command_item_title; Title = Resources.command_item_title; - PlaceholderText = Resources.plugin_description; Icon = IconHelpers.FromRelativePath("Assets\\WebSearch.png"); - allItems = [new(new NoOpCommand()) - { - Icon = IconHelpers.FromRelativePath("Assets\\WebSearch.png"), - Title = Properties.Resources.plugin_description, - Subtitle = string.Format(CultureInfo.CurrentCulture, PluginOpen, BrowserInfo.Name ?? BrowserInfo.MSEdgeName), - } - ]; + _allItems = []; Id = "com.microsoft.cmdpal.websearch"; _settingsManager = settingsManager; _historyItems = _settingsManager.ShowHistory != Resources.history_none ? _settingsManager.LoadHistory() : null; if (_historyItems != null) { - allItems.AddRange(_historyItems); + _allItems.AddRange(_historyItems); } + + // It just looks viewer to have string twice on the page, and default placeholder is good enough + PlaceholderText = _allItems.Count > 0 ? Resources.plugin_description : string.Empty; + + EmptyContent = new CommandItem(new NoOpCommand()) + { + Icon = Icon, + Title = Properties.Resources.plugin_description, + Subtitle = string.Format(CultureInfo.CurrentCulture, PluginInBrowserName, BrowserInfo.Name ?? BrowserInfo.MSEdgeName), + }; } public List Query(string query) @@ -59,17 +62,7 @@ internal sealed partial class WebSearchListPage : DynamicListPage var results = new List(); - // empty query - if (string.IsNullOrEmpty(query)) - { - results.Add(new ListItem(new SearchWebCommand(string.Empty, _settingsManager)) - { - Title = Properties.Resources.plugin_description, - Subtitle = string.Format(CultureInfo.CurrentCulture, PluginInBrowserName, BrowserInfo.Name ?? BrowserInfo.MSEdgeName), - Icon = new IconInfo(_iconPath), - }); - } - else + if (!string.IsNullOrEmpty(query)) { var searchTerm = query; var result = new ListItem(new SearchWebCommand(searchTerm, _settingsManager)) @@ -91,9 +84,9 @@ internal sealed partial class WebSearchListPage : DynamicListPage public override void UpdateSearchText(string oldSearch, string newSearch) { - allItems = [.. Query(newSearch)]; + _allItems = [.. Query(newSearch)]; RaiseItemsChanged(0); } - public override IListItem[] GetItems() => [.. allItems]; + public override IListItem[] GetItems() => [.. _allItems]; }