From 39eb8abdffb697efb94f88497af5a3d6c29db93a Mon Sep 17 00:00:00 2001 From: Mike Griese Date: Thu, 20 Nov 2025 16:45:05 -0600 Subject: [PATCH] code cleanup --- .../ParameterRunTemplateSelector.xaml.cs | 48 ++++++++++++++++ .../Controls/SearchBar.xaml.cs | 27 --------- .../ExtViews/ParametersPage.xaml | 47 ++-------------- .../ActionsCommandsProvider.cs | 2 +- .../Pages/ActionsTestPage.cs | 55 ------------------- .../Microsoft.CmdPal.Ext.Indexer.csproj | 8 ++- .../SamplePagesExtension/SamplesListPage.cs | 11 ++-- 7 files changed, 64 insertions(+), 134 deletions(-) create mode 100644 src/modules/cmdpal/Microsoft.CmdPal.UI/Controls/ParameterRunTemplateSelector.xaml.cs diff --git a/src/modules/cmdpal/Microsoft.CmdPal.UI/Controls/ParameterRunTemplateSelector.xaml.cs b/src/modules/cmdpal/Microsoft.CmdPal.UI/Controls/ParameterRunTemplateSelector.xaml.cs new file mode 100644 index 0000000000..bda50e1345 --- /dev/null +++ b/src/modules/cmdpal/Microsoft.CmdPal.UI/Controls/ParameterRunTemplateSelector.xaml.cs @@ -0,0 +1,48 @@ +// Copyright (c) Microsoft Corporation +// The Microsoft Corporation licenses this file to you under the MIT license. +// See the LICENSE file in the project root for more information. + +using System.Collections.ObjectModel; +using System.ComponentModel; +using CommunityToolkit.Mvvm.Messaging; +using CommunityToolkit.WinUI; +using Microsoft.CmdPal.Core.Common; +using Microsoft.CmdPal.Core.ViewModels; +using Microsoft.CmdPal.Core.ViewModels.Commands; +using Microsoft.CmdPal.Core.ViewModels.Messages; +using Microsoft.CmdPal.UI.Views; +using Microsoft.CommandPalette.Extensions.Toolkit; +using Microsoft.UI.Dispatching; +using Microsoft.UI.Input; +using Microsoft.UI.Xaml; +using Microsoft.UI.Xaml.Controls; +using Microsoft.UI.Xaml.Input; +using CoreVirtualKeyStates = Windows.UI.Core.CoreVirtualKeyStates; +using VirtualKey = Windows.System.VirtualKey; + +namespace Microsoft.CmdPal.UI.Controls; + +public sealed partial class ParameterRunTemplateSelector : DataTemplateSelector +{ + public DataTemplate? LabelRunTemplate { get; set; } + + public DataTemplate? StringParamTemplate { get; set; } + + public DataTemplate? ButtonParamTemplate { get; set; } + + protected override DataTemplate? SelectTemplateCore(object item) + { + return item switch + { + LabelRunViewModel => LabelRunTemplate, + StringParameterRunViewModel => StringParamTemplate, + CommandParameterRunViewModel => ButtonParamTemplate, + _ => base.SelectTemplateCore(item), + }; + } + + protected override DataTemplate? SelectTemplateCore(object item, DependencyObject container) + { + return SelectTemplateCore(item); + } +} diff --git a/src/modules/cmdpal/Microsoft.CmdPal.UI/Controls/SearchBar.xaml.cs b/src/modules/cmdpal/Microsoft.CmdPal.UI/Controls/SearchBar.xaml.cs index 6b28814c7b..f6cee9f002 100644 --- a/src/modules/cmdpal/Microsoft.CmdPal.UI/Controls/SearchBar.xaml.cs +++ b/src/modules/cmdpal/Microsoft.CmdPal.UI/Controls/SearchBar.xaml.cs @@ -575,30 +575,3 @@ public sealed partial class SearchBar : UserControl, } } } - -#pragma warning disable SA1402 // File may only contain a single type -public sealed partial class ParameterRunTemplateSelector : DataTemplateSelector -#pragma warning restore SA1402 // File may only contain a single type -{ - public DataTemplate? LabelRunTemplate { get; set; } - - public DataTemplate? StringParamTemplate { get; set; } - - public DataTemplate? ButtonParamTemplate { get; set; } - - protected override DataTemplate? SelectTemplateCore(object item) - { - return item switch - { - LabelRunViewModel => LabelRunTemplate, - StringParameterRunViewModel => StringParamTemplate, - CommandParameterRunViewModel => ButtonParamTemplate, - _ => base.SelectTemplateCore(item), - }; - } - - protected override DataTemplate? SelectTemplateCore(object item, DependencyObject container) - { - return SelectTemplateCore(item); - } -} diff --git a/src/modules/cmdpal/Microsoft.CmdPal.UI/ExtViews/ParametersPage.xaml b/src/modules/cmdpal/Microsoft.CmdPal.UI/ExtViews/ParametersPage.xaml index 91d1982bd9..44095a442a 100644 --- a/src/modules/cmdpal/Microsoft.CmdPal.UI/ExtViews/ParametersPage.xaml +++ b/src/modules/cmdpal/Microsoft.CmdPal.UI/ExtViews/ParametersPage.xaml @@ -28,49 +28,10 @@ TargetType="x:Boolean" Value="{x:Bind ViewModel.ShowCommand, Mode=OneWay}"> - + -// { -// try -// { -// var file = await picker.PickSingleFileAsync(); -// if (file != null) -// { -// _filePath = file.Path; -// Value = _filePath; -// Icon = new IconInfo(_filePath); - -// // TODO! update display name -// } -// } -// catch (Exception ex) -// { -// // Handle any exceptions that might occur during file picking -// System.Diagnostics.Debug.WriteLine($"Error picking image file: {ex.Message}"); -// } -// }); -// } - -// public override string? DisplayName -// { -// get { return string.IsNullOrEmpty(_filePath) ? null : Path.GetFileName(_filePath); } -// } -// } #pragma warning restore SA1649 // File name should match first type name #pragma warning restore SA1402 // File may only contain a single type #nullable disable diff --git a/src/modules/cmdpal/ext/Microsoft.CmdPal.Ext.Indexer/Microsoft.CmdPal.Ext.Indexer.csproj b/src/modules/cmdpal/ext/Microsoft.CmdPal.Ext.Indexer/Microsoft.CmdPal.Ext.Indexer.csproj index 90a496ea26..9427ce9f48 100644 --- a/src/modules/cmdpal/ext/Microsoft.CmdPal.Ext.Indexer/Microsoft.CmdPal.Ext.Indexer.csproj +++ b/src/modules/cmdpal/ext/Microsoft.CmdPal.Ext.Indexer/Microsoft.CmdPal.Ext.Indexer.csproj @@ -40,10 +40,12 @@ PreserveNewest - - + + + --> diff --git a/src/modules/cmdpal/ext/SamplePagesExtension/SamplesListPage.cs b/src/modules/cmdpal/ext/SamplePagesExtension/SamplesListPage.cs index e5092b0942..9d9eef6f80 100644 --- a/src/modules/cmdpal/ext/SamplePagesExtension/SamplesListPage.cs +++ b/src/modules/cmdpal/ext/SamplePagesExtension/SamplesListPage.cs @@ -122,11 +122,12 @@ public partial class SamplesListPage : ListPage Title = "Mixed parameter types (file first)", Subtitle = "A demo of a command that takes multiple types of parameters", }, - new ListItem(new CreateNoteParametersPage()) - { - Title = "Create note sample", - Subtitle = "A parameter page with both a string and list parameter", - }, + // List parameters aren't yet supported + // new ListItem(new CreateNoteParametersPage()) + // { + // Title = "Create note sample", + // Subtitle = "A parameter page with both a string and list parameter", + // }, // Evil edge cases // Anything weird that might break the palette - put that in here.