Skip to content
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,8 @@
namespace Microsoft.CmdPal.UI.ViewModels;

public partial class ActionBarViewModel : ObservableObject,
IRecipient<UpdateActionBarMessage>
IRecipient<UpdateActionBarMessage>,
IRecipient<UpdateActionBarPage>
{
public ListItemViewModel? SelectedItem
{
Expand All @@ -23,11 +24,6 @@ public ListItemViewModel? SelectedItem
}
}

// [ObservableProperty]
// public partial string PrimaryActionName { get; set; } = string.Empty;

// [ObservableProperty]
// public partial string SecondaryActionName { get; set; } = string.Empty;
[ObservableProperty]
public partial CommandItemViewModel? PrimaryAction { get; set; }

Expand All @@ -49,10 +45,13 @@ public ListItemViewModel? SelectedItem
public ActionBarViewModel()
{
WeakReferenceMessenger.Default.Register<UpdateActionBarMessage>(this);
WeakReferenceMessenger.Default.Register<UpdateActionBarPage>(this);
}

public void Receive(UpdateActionBarMessage message) => SelectedItem = message.ViewModel;

public void Receive(UpdateActionBarPage message) => CurrentPage = message.Page;

private void SetSelectedItem(ListItemViewModel? value)
{
if (value != null)
Expand Down
4 changes: 0 additions & 4 deletions src/modules/cmdpal/Microsoft.CmdPal.UI/App.xaml.cs
Original file line number Diff line number Diff line change
Expand Up @@ -12,12 +12,10 @@
using Microsoft.CmdPal.Ext.WindowsSettings;
using Microsoft.CmdPal.Ext.WindowsTerminal;
using Microsoft.CmdPal.Extensions;
using Microsoft.CmdPal.UI.ExtViews;
using Microsoft.CmdPal.UI.ViewModels;
using Microsoft.CmdPal.UI.ViewModels.BuiltinCommands;
using Microsoft.CmdPal.UI.ViewModels.Models;
using Microsoft.Extensions.DependencyInjection;
using Microsoft.UI.Dispatching;
using Microsoft.UI.Xaml;

// To learn more about WinUI, the WinUI project structure,
Expand Down Expand Up @@ -73,8 +71,6 @@ private static ServiceProvider ConfigureServices()

// Root services
services.AddSingleton(TaskScheduler.FromCurrentSynchronizationContext());
services.AddSingleton(DispatcherQueue.GetForCurrentThread());
services.AddSingleton<IIconCacheService, IconCacheService>();

// Built-in Commands
services.AddSingleton<ICommandProvider, AllAppsCommandProvider>();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,6 @@
x:Key="StringNotEmptyToVisibilityConverter"
EmptyValue="Collapsed"
NotEmptyValue="Visible" />
<converters:TaskResultConverter x:Key="TaskConverter"/>

<!-- Template for actions in the mode actions dropdown button -->
<DataTemplate x:Key="ContextMenuViewModelTemplate" x:DataType="viewmodels:CommandContextItemViewModel">
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,24 +2,19 @@
// The Microsoft Corporation licenses this file to you under the MIT license.
// See the LICENSE file in the project root for more information.

using CommunityToolkit.Mvvm.Messaging;
using Microsoft.CmdPal.UI.ViewModels;
using Microsoft.CmdPal.UI.ViewModels.Messages;
using Microsoft.UI.Xaml.Controls;
using Microsoft.UI.Xaml.Input;

namespace Microsoft.CmdPal.UI.Controls;

public sealed partial class ActionBar : UserControl,
IRecipient<UpdateActionBarPage>
public sealed partial class ActionBar : UserControl
{
public ActionBarViewModel ViewModel { get; set; } = new();

public ActionBar()
{
this.InitializeComponent();

WeakReferenceMessenger.Default.Register<UpdateActionBarPage>(this);
}

[System.Diagnostics.CodeAnalysis.SuppressMessage("CodeQuality", "IDE0051:Remove unused private members", Justification = "VS has a tendency to delete XAML bound methods over-agressively")]
Expand All @@ -43,6 +38,4 @@ private void ActionListViewItem_Tapped(object sender, TappedRoutedEventArgs e)
ViewModel?.InvokeItemCommand.Execute(item);
}
}

public void Receive(UpdateActionBarPage message) => ViewModel.CurrentPage = message.Page;
}
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@

namespace Microsoft.CmdPal.UI.ExtViews;

public sealed class IconCacheService(DispatcherQueue dispatcherQueue) : IIconCacheService
public sealed class IconCacheService(DispatcherQueue dispatcherQueue)
{
public Task<IconSource?> GetIconSource(IconDataType icon) =>

Expand Down
35 changes: 17 additions & 18 deletions src/modules/cmdpal/Microsoft.CmdPal.UI/ExtViews/ListPage.xaml
Original file line number Diff line number Diff line change
Expand Up @@ -33,30 +33,29 @@

<DataTemplate x:Key="TagTemplate" x:DataType="viewmodels:TagViewModel">
<!-- TODO: Actually colorize the tags again -->
<Border
<StackPanel
Padding="4,2,4,2"
VerticalAlignment="Center"
BorderBrush="{ThemeResource TextBoxBorderThemeBrush}"
BorderThickness="1"
Orientation="Horizontal"
CornerRadius="4">
<StackPanel Orientation="Horizontal">
<Border x:Name="IconBorder"
Width="12"
Height="12"
Margin="0,0,4,0"
Visibility="{x:Bind HasIcon, Mode=OneWay}">
<!-- LoadIconBehavior will magically fill this border up with an icon -->
<Interactivity:Interaction.Behaviors>
<local:LoadIconBehavior Source="{x:Bind Icon, Mode=OneWay}"/>
</Interactivity:Interaction.Behaviors>
</Border>
<Border x:Name="IconBorder"
Width="12"
Height="12"
Margin="0,0,4,0"
Visibility="{x:Bind HasIcon, Mode=OneWay}">
<!-- LoadIconBehavior will magically fill this border up with an icon -->
<Interactivity:Interaction.Behaviors>
<local:LoadIconBehavior Source="{x:Bind Icon, Mode=OneWay}"/>
</Interactivity:Interaction.Behaviors>
</Border>

<TextBlock
VerticalAlignment="Center"
FontSize="12"
Text="{x:Bind Text, Mode=OneWay}" />
</StackPanel>
</Border>
<TextBlock
VerticalAlignment="Center"
FontSize="12"
Text="{x:Bind Text, Mode=OneWay}" />
</StackPanel>
</DataTemplate>

<!-- https://learn.microsoft.com/windows/apps/design/controls/itemsview#specify-the-look-of-the-items -->
Expand Down
15 changes: 0 additions & 15 deletions src/modules/cmdpal/Microsoft.CmdPal.UI/IIconCacheService.cs

This file was deleted.

10 changes: 5 additions & 5 deletions src/modules/cmdpal/Microsoft.CmdPal.UI/LoadIconBehavior.xaml.cs
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
// See the LICENSE file in the project root for more information.

using Microsoft.CmdPal.Extensions;
using Microsoft.Extensions.DependencyInjection;
using Microsoft.CmdPal.UI.ExtViews;
using Microsoft.UI.Xaml;
using Microsoft.UI.Xaml.Controls;
using Microsoft.Xaml.Interactivity;
Expand All @@ -12,6 +12,8 @@ namespace Microsoft.CmdPal.UI;

public partial class LoadIconBehavior : DependencyObject, IBehavior
{
private static readonly IconCacheService IconService = new(Microsoft.UI.Dispatching.DispatcherQueue.GetForCurrentThread());

public IconDataType Source
{
get => (IconDataType)GetValue(SourceProperty);
Expand All @@ -24,7 +26,7 @@ public IconDataType Source

// Using a DependencyProperty as the backing store for Source. This enables animation, styling, binding, etc...
public static readonly DependencyProperty SourceProperty =
DependencyProperty.Register("Source", typeof(IconDataType), typeof(LoadIconBehavior), new PropertyMetadata(new IconDataType(string.Empty)));
DependencyProperty.Register(nameof(Source), typeof(IconDataType), typeof(LoadIconBehavior), new PropertyMetadata(new IconDataType(string.Empty)));

public DependencyObject? AssociatedObject { get; private set; }

Expand All @@ -34,9 +36,7 @@ public IconDataType Source

public async void OnSourcePropertyChanged()
{
var iconService = App.Current.Services.GetService<IIconCacheService>()!;

var icoSource = await iconService.GetIconSource(Source ?? new(string.Empty));
var icoSource = await IconService.GetIconSource(Source ?? new(string.Empty));

if (AssociatedObject is Border border)
{
Expand Down