cmdpal: unset the command if we don't find a command (#39208)

On a reload, the system commands fallback would leave the "restart"
fallback behind, for the same reason as what we found around
e40372c & ef264d9 in #38455
This commit is contained in:
Mike Griese
2025-05-04 06:03:01 -05:00
committed by GitHub
parent 2c555e2c2b
commit 15ef9189ba
6 changed files with 23 additions and 9 deletions

View File

@@ -190,7 +190,7 @@ public partial class CommandItemViewModel : ExtensionObjectViewModel, ICommandBa
contextItem.SlowInitializeProperties(); contextItem.SlowInitializeProperties();
}); });
if (!string.IsNullOrEmpty(model.Command.Name)) if (!string.IsNullOrEmpty(model.Command?.Name))
{ {
_defaultCommandContextItem = new(new CommandContextItem(model.Command!), PageContext) _defaultCommandContextItem = new(new CommandContextItem(model.Command!), PageContext)
{ {

View File

@@ -32,6 +32,7 @@ internal sealed partial class FallbackSystemCommandItem : FallbackCommandItem
{ {
if (string.IsNullOrWhiteSpace(query)) if (string.IsNullOrWhiteSpace(query))
{ {
Command = null;
Title = string.Empty; Title = string.Empty;
Subtitle = string.Empty; Subtitle = string.Empty;
return; return;
@@ -58,6 +59,7 @@ internal sealed partial class FallbackSystemCommandItem : FallbackCommandItem
if (result == null) if (result == null)
{ {
Command = null;
Title = string.Empty; Title = string.Empty;
Subtitle = string.Empty; Subtitle = string.Empty;

View File

@@ -10,12 +10,12 @@ namespace Microsoft.CmdPal.Ext.System.Pages;
public sealed partial class SystemCommandPage : ListPage public sealed partial class SystemCommandPage : ListPage
{ {
private SettingsManager _settingsManager; private readonly SettingsManager _settingsManager;
public SystemCommandPage(SettingsManager settingsManager) public SystemCommandPage(SettingsManager settingsManager)
{ {
Title = Resources.Microsoft_plugin_ext_system_page_name; Title = Resources.Microsoft_plugin_ext_system_page_title;
Name = Resources.Microsoft_plugin_ext_system_page_name; Name = Resources.Microsoft_plugin_command_name_open;
Icon = IconHelpers.FromRelativePath("Assets\\SystemCommand.svg"); Icon = IconHelpers.FromRelativePath("Assets\\SystemCommand.svg");
_settingsManager = settingsManager; _settingsManager = settingsManager;
ShowDetails = true; ShowDetails = true;

View File

@@ -205,7 +205,7 @@ namespace Microsoft.CmdPal.Ext.System {
} }
/// <summary> /// <summary>
/// Looks up a localized string similar to Windows System Command. /// Looks up a localized string similar to System Commands.
/// </summary> /// </summary>
public static string Microsoft_plugin_ext_system_page_name { public static string Microsoft_plugin_ext_system_page_name {
get { get {
@@ -213,6 +213,15 @@ namespace Microsoft.CmdPal.Ext.System {
} }
} }
/// <summary>
/// Looks up a localized string similar to Windows System Commands.
/// </summary>
public static string Microsoft_plugin_ext_system_page_title {
get {
return ResourceManager.GetString("Microsoft_plugin_ext_system_page_title", resourceCulture);
}
}
/// <summary> /// <summary>
/// Looks up a localized string similar to Adapter name. /// Looks up a localized string similar to Adapter name.
/// </summary> /// </summary>

View File

@@ -160,8 +160,11 @@
<data name="Microsoft_plugin_ext_settings_hideDisconnectedNetworkInfo" xml:space="preserve"> <data name="Microsoft_plugin_ext_settings_hideDisconnectedNetworkInfo" xml:space="preserve">
<value>Hide disconnected network info</value> <value>Hide disconnected network info</value>
</data> </data>
<data name="Microsoft_plugin_ext_system_page_title" xml:space="preserve">
<value>Windows System Commands</value>
</data>
<data name="Microsoft_plugin_ext_system_page_name" xml:space="preserve"> <data name="Microsoft_plugin_ext_system_page_name" xml:space="preserve">
<value>Windows System Command</value> <value>System Commands</value>
</data> </data>
<data name="Microsoft_plugin_sys_AdapterName" xml:space="preserve"> <data name="Microsoft_plugin_sys_AdapterName" xml:space="preserve">
<value>Adapter name</value> <value>Adapter name</value>

View File

@@ -14,7 +14,7 @@ public partial class SystemCommandExtensionProvider : CommandProvider
private readonly ICommandItem[] _commands; private readonly ICommandItem[] _commands;
private static readonly SettingsManager _settingsManager = new(); private static readonly SettingsManager _settingsManager = new();
public static readonly SystemCommandPage Page = new(_settingsManager); public static readonly SystemCommandPage Page = new(_settingsManager);
private readonly FallbackSystemCommandItem _fallbackFileItem = new(_settingsManager); private readonly FallbackSystemCommandItem _fallbackSystemItem = new(_settingsManager);
public SystemCommandExtensionProvider() public SystemCommandExtensionProvider()
{ {
@@ -23,7 +23,7 @@ public partial class SystemCommandExtensionProvider : CommandProvider
_commands = [ _commands = [
new CommandItem(Page) new CommandItem(Page)
{ {
Title = Resources.Microsoft_plugin_ext_system_page_name, Title = Resources.Microsoft_plugin_ext_system_page_title,
Icon = Page.Icon, Icon = Page.Icon,
MoreCommands = [new CommandContextItem(_settingsManager.Settings.SettingsPage)], MoreCommands = [new CommandContextItem(_settingsManager.Settings.SettingsPage)],
}, },
@@ -38,5 +38,5 @@ public partial class SystemCommandExtensionProvider : CommandProvider
return _commands; return _commands;
} }
public override IFallbackCommandItem[] FallbackCommands() => [_fallbackFileItem]; public override IFallbackCommandItem[] FallbackCommands() => [_fallbackSystemItem];
} }