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

<img width="786" height="473" alt="image"
src="https://github.com/user-attachments/assets/2d08d809-1127-44b3-9842-50969eb6bef7"
/>
<img width="786" height="473" alt="image"
src="https://github.com/user-attachments/assets/155374cc-3e13-4cc0-b7e5-b4fa2b371ba7"
/>

## 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.
This commit is contained in:
Jiří Polášek
2025-07-12 04:11:13 +02:00
committed by GitHub
parent 3686d6ac19
commit 1d464cc307

View File

@@ -23,28 +23,31 @@ internal sealed partial class WebSearchListPage : DynamicListPage
private readonly SettingsManager _settingsManager; private readonly SettingsManager _settingsManager;
private static readonly CompositeFormat PluginInBrowserName = System.Text.CompositeFormat.Parse(Properties.Resources.plugin_in_browser_name); 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 static readonly CompositeFormat PluginOpen = System.Text.CompositeFormat.Parse(Properties.Resources.plugin_open);
private List<ListItem> allItems; private List<ListItem> _allItems;
public WebSearchListPage(SettingsManager settingsManager) public WebSearchListPage(SettingsManager settingsManager)
{ {
Name = Resources.command_item_title; Name = Resources.command_item_title;
Title = Resources.command_item_title; Title = Resources.command_item_title;
PlaceholderText = Resources.plugin_description;
Icon = IconHelpers.FromRelativePath("Assets\\WebSearch.png"); Icon = IconHelpers.FromRelativePath("Assets\\WebSearch.png");
allItems = [new(new NoOpCommand()) _allItems = [];
{
Icon = IconHelpers.FromRelativePath("Assets\\WebSearch.png"),
Title = Properties.Resources.plugin_description,
Subtitle = string.Format(CultureInfo.CurrentCulture, PluginOpen, BrowserInfo.Name ?? BrowserInfo.MSEdgeName),
}
];
Id = "com.microsoft.cmdpal.websearch"; Id = "com.microsoft.cmdpal.websearch";
_settingsManager = settingsManager; _settingsManager = settingsManager;
_historyItems = _settingsManager.ShowHistory != Resources.history_none ? _settingsManager.LoadHistory() : null; _historyItems = _settingsManager.ShowHistory != Resources.history_none ? _settingsManager.LoadHistory() : null;
if (_historyItems != 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<ListItem> Query(string query) public List<ListItem> Query(string query)
@@ -59,17 +62,7 @@ internal sealed partial class WebSearchListPage : DynamicListPage
var results = new List<ListItem>(); var results = new List<ListItem>();
// empty query if (!string.IsNullOrEmpty(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
{ {
var searchTerm = query; var searchTerm = query;
var result = new ListItem(new SearchWebCommand(searchTerm, _settingsManager)) 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) public override void UpdateSearchText(string oldSearch, string newSearch)
{ {
allItems = [.. Query(newSearch)]; _allItems = [.. Query(newSearch)];
RaiseItemsChanged(0); RaiseItemsChanged(0);
} }
public override IListItem[] GetItems() => [.. allItems]; public override IListItem[] GetItems() => [.. _allItems];
} }