2025-05-28 14:35:26 -05:00
|
|
|
|
// 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.
|
|
|
|
|
|
|
2025-07-15 12:21:44 -05:00
|
|
|
|
using Microsoft.CmdPal.Core.ViewModels;
|
2025-05-28 14:35:26 -05:00
|
|
|
|
using Microsoft.UI.Xaml;
|
|
|
|
|
|
using Microsoft.UI.Xaml.Controls;
|
2025-07-09 14:53:47 -05:00
|
|
|
|
using Microsoft.UI.Xaml.Controls.Primitives;
|
|
|
|
|
|
using Microsoft.UI.Xaml.Data;
|
2025-05-28 14:35:26 -05:00
|
|
|
|
|
|
|
|
|
|
namespace Microsoft.CmdPal.UI;
|
|
|
|
|
|
|
|
|
|
|
|
internal sealed partial class ContextItemTemplateSelector : DataTemplateSelector
|
|
|
|
|
|
{
|
|
|
|
|
|
public DataTemplate? Default { get; set; }
|
|
|
|
|
|
|
|
|
|
|
|
public DataTemplate? Critical { get; set; }
|
|
|
|
|
|
|
2025-07-09 14:53:47 -05:00
|
|
|
|
public DataTemplate? Separator { get; set; }
|
|
|
|
|
|
|
|
|
|
|
|
protected override DataTemplate? SelectTemplateCore(object item, DependencyObject dependencyObject)
|
2025-05-28 14:35:26 -05:00
|
|
|
|
{
|
2025-07-09 14:53:47 -05:00
|
|
|
|
DataTemplate? dataTemplate = Default;
|
|
|
|
|
|
|
|
|
|
|
|
if (dependencyObject is ListViewItem li)
|
|
|
|
|
|
{
|
|
|
|
|
|
li.IsEnabled = true;
|
|
|
|
|
|
|
|
|
|
|
|
if (item is SeparatorContextItemViewModel)
|
|
|
|
|
|
{
|
|
|
|
|
|
li.IsEnabled = false;
|
|
|
|
|
|
li.AllowFocusWhenDisabled = false;
|
|
|
|
|
|
li.AllowFocusOnInteraction = false;
|
|
|
|
|
|
dataTemplate = Separator;
|
|
|
|
|
|
}
|
2025-07-17 17:03:54 +08:00
|
|
|
|
else if (item is CommandContextItemViewModel commandItem)
|
|
|
|
|
|
{
|
|
|
|
|
|
dataTemplate = commandItem.IsCritical ? Critical : Default;
|
|
|
|
|
|
}
|
2025-07-09 14:53:47 -05:00
|
|
|
|
else
|
|
|
|
|
|
{
|
2025-07-17 17:03:54 +08:00
|
|
|
|
// Fallback for unknown types
|
|
|
|
|
|
dataTemplate = Default;
|
2025-07-09 14:53:47 -05:00
|
|
|
|
}
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
return dataTemplate;
|
2025-05-28 14:35:26 -05:00
|
|
|
|
}
|
|
|
|
|
|
}
|