mirror of
https://github.com/microsoft/PowerToys.git
synced 2026-02-24 04:00:02 +01:00
code cleanup
This commit is contained in:
@@ -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);
|
||||
}
|
||||
}
|
||||
@@ -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);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -28,49 +28,10 @@
|
||||
TargetType="x:Boolean"
|
||||
Value="{x:Bind ViewModel.ShowCommand, Mode=OneWay}">
|
||||
<controls:Case Value="False">
|
||||
<!--<controls:SwitchPresenter
|
||||
HorizontalAlignment="Stretch"
|
||||
TargetType="x:Boolean"
|
||||
Value="{x:Bind ViewModel.IsGridView, Mode=OneWay}">
|
||||
<controls:Case Value="False">
|
||||
<ListView
|
||||
x:Name="ItemsList"
|
||||
Padding="0,2,0,0"
|
||||
ContextCanceled="Items_OnContextCanceled"
|
||||
ContextRequested="Items_OnContextRequested"
|
||||
DoubleTapped="Items_DoubleTapped"
|
||||
IsDoubleTapEnabled="True"
|
||||
IsItemClickEnabled="True"
|
||||
ItemClick="Items_ItemClick"
|
||||
ItemTemplate="{StaticResource ListItemViewModelTemplate}"
|
||||
ItemsSource="{x:Bind ViewModel.FilteredItems, Mode=OneWay}"
|
||||
RightTapped="Items_RightTapped"
|
||||
SelectionChanged="Items_SelectionChanged">
|
||||
<ListView.ItemContainerTransitions>
|
||||
<TransitionCollection />
|
||||
</ListView.ItemContainerTransitions>
|
||||
</ListView>
|
||||
</controls:Case>
|
||||
<controls:Case Value="True">
|
||||
<GridView
|
||||
x:Name="ItemsGrid"
|
||||
Padding="8"
|
||||
ContextCanceled="Items_OnContextCanceled"
|
||||
ContextRequested="Items_OnContextRequested"
|
||||
DoubleTapped="Items_DoubleTapped"
|
||||
IsDoubleTapEnabled="True"
|
||||
IsItemClickEnabled="True"
|
||||
ItemClick="Items_ItemClick"
|
||||
ItemTemplateSelector="{StaticResource GridItemTemplateSelector}"
|
||||
ItemsSource="{x:Bind ViewModel.FilteredItems, Mode=OneWay}"
|
||||
RightTapped="Items_RightTapped"
|
||||
SelectionChanged="Items_SelectionChanged">
|
||||
<GridView.ItemContainerTransitions>
|
||||
<TransitionCollection />
|
||||
</GridView.ItemContainerTransitions>
|
||||
</GridView>
|
||||
</controls:Case>
|
||||
</controls:SwitchPresenter>-->
|
||||
<!--
|
||||
what kind of content do we want on this page before it
|
||||
has a command? Anything? Nothing?
|
||||
-->
|
||||
</controls:Case>
|
||||
<controls:Case Value="True">
|
||||
<StackPanel
|
||||
|
||||
@@ -19,7 +19,7 @@ public partial class ActionsCommandsProvider : CommandProvider
|
||||
|
||||
public ActionsCommandsProvider()
|
||||
{
|
||||
DisplayName = "Agents for Windows";
|
||||
DisplayName = "Windows Actions Framework";
|
||||
Icon = IconHelpers.FromRelativePath("Assets\\Actions.png");
|
||||
Id = "Actions";
|
||||
|
||||
|
||||
@@ -297,61 +297,6 @@ internal sealed partial class PhotoFilePicker : FilePickerParameterRun
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
// [System.Diagnostics.CodeAnalysis.SuppressMessage("StyleCop.CSharp.MaintainabilityRules", "SA1402:File may only contain a single type", Justification = "meh")]
|
||||
// public partial class ImageParameter : CommandParameter
|
||||
// {
|
||||
// private string? _filePath;
|
||||
|
||||
// public ImageParameter(string name = "", bool required = true)
|
||||
// : base(name, required, ParameterType.Custom)
|
||||
// {
|
||||
// }
|
||||
|
||||
// public override void ShowPicker(ulong hostHwnd)
|
||||
// {
|
||||
// var picker = new FileOpenPicker
|
||||
// {
|
||||
// SuggestedStartLocation = PickerLocationId.PicturesLibrary,
|
||||
// };
|
||||
// picker.FileTypeFilter.Add(".jpg");
|
||||
// picker.FileTypeFilter.Add(".jpeg");
|
||||
// picker.FileTypeFilter.Add(".png");
|
||||
// picker.FileTypeFilter.Add(".gif");
|
||||
// picker.FileTypeFilter.Add(".bmp");
|
||||
// picker.FileTypeFilter.Add(".tiff");
|
||||
// picker.FileTypeFilter.Add(".webp");
|
||||
|
||||
// // Initialize the picker with the window handle
|
||||
// WinRT.Interop.InitializeWithWindow.Initialize(picker, (IntPtr)hostHwnd);
|
||||
|
||||
// _ = Task.Run(async () =>
|
||||
// {
|
||||
// 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
|
||||
|
||||
@@ -40,10 +40,12 @@
|
||||
<CopyToOutputDirectory>PreserveNewest</CopyToOutputDirectory>
|
||||
</Content>
|
||||
|
||||
<!-- Don't include the actions icon - it gets into our package via the actions extension -->
|
||||
<!--<Content Update="Assets\Actions.png">
|
||||
<!-- Don't include the actions icon - it gets into our package via the actions extension -->
|
||||
<!--
|
||||
<Content Update="Assets\Actions.png">
|
||||
<CopyToOutputDirectory>PreserveNewest</CopyToOutputDirectory>
|
||||
</Content>-->
|
||||
</Content>
|
||||
-->
|
||||
</ItemGroup>
|
||||
|
||||
<ItemGroup>
|
||||
|
||||
@@ -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.
|
||||
|
||||
Reference in New Issue
Block a user