Skip to content
Merged
Show file tree
Hide file tree
Changes from 7 commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,6 @@
namespace Microsoft.CmdPal.UI.ViewModels;

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

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

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

[ObservableProperty]
public partial string SecondaryActionName { get; set; } = string.Empty;
[NotifyPropertyChangedFor(nameof(HasSecondaryCommand))]
public partial CommandItemViewModel? SecondaryAction { get; set; }

public bool HasSecondaryCommand => SecondaryAction != null;

[ObservableProperty]
public partial bool ShouldShowContextMenu { get; set; } = false;

[ObservableProperty]
public partial PageViewModel? CurrentPage { get; private set; }
public partial PageViewModel? CurrentPage { get; set; }

[ObservableProperty]
public partial ObservableCollection<CommandContextItemViewModel> ContextActions { get; set; } = [];

public ActionBarViewModel()
{
WeakReferenceMessenger.Default.Register<UpdateActionBarPage>(this);
WeakReferenceMessenger.Default.Register<UpdateActionBarMessage>(this);
}

Expand All @@ -51,8 +57,8 @@ private void SetSelectedItem(ListItemViewModel? value)
{
if (value != null)
{
PrimaryActionName = value.Name;
SecondaryActionName = value.SecondaryCommandName;
PrimaryAction = value;
SecondaryAction = value.SecondaryCommand;

if (value.MoreCommands.Count > 1)
{
Expand All @@ -66,15 +72,13 @@ private void SetSelectedItem(ListItemViewModel? value)
}
else
{
PrimaryActionName = string.Empty;
SecondaryActionName = string.Empty;
PrimaryAction = null;
SecondaryAction = null;
ShouldShowContextMenu = false;
}
}

// InvokeItemCommand is what this will be in Xaml due to source generator
[RelayCommand]
private void InvokeItem(CommandContextItemViewModel item) => WeakReferenceMessenger.Default.Send<PerformCommandMessage>(new(item.Command));

public void Receive(UpdateActionBarPage message) => CurrentPage = message.Page;
}
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ public partial class CommandItemViewModel : ExtensionObjectViewModel

public string Subtitle { get; private set; } = string.Empty;

public string IconUri { get; private set; } = string.Empty;
public IconDataType Icon { get; private set; } = new(string.Empty);

public ExtensionObject<ICommand> Command { get; private set; } = new(null);

Expand All @@ -36,6 +36,8 @@ public partial class CommandItemViewModel : ExtensionObjectViewModel

public string SecondaryCommandName => HasMoreCommands ? MoreCommands[0].Name : string.Empty;

public CommandItemViewModel? SecondaryCommand => HasMoreCommands ? MoreCommands[0] : null;

public List<CommandContextItemViewModel> AllCommands
{
get
Expand All @@ -49,7 +51,7 @@ public List<CommandContextItemViewModel> AllCommands
Name = Name,
Title = Name,
Subtitle = Subtitle,
IconUri = IconUri,
Icon = Icon,

// TODO this probably should just be a CommandContextItemViewModel(CommandItemViewModel) ctor, or a copy ctor or whatever
};
Expand Down Expand Up @@ -79,7 +81,7 @@ public override void InitializeProperties()
Name = model.Command?.Name ?? string.Empty;
Title = model.Title;
Subtitle = model.Subtitle;
IconUri = model.Icon.Icon;
Icon = model.Icon;
MoreCommands = model.MoreCommands
.Where(contextItem => contextItem is ICommandContextItem)
.Select(contextItem => (contextItem as ICommandContextItem)!)
Expand Down Expand Up @@ -129,6 +131,9 @@ protected virtual void FetchProperty(string propertyName)
case nameof(Subtitle):
this.Subtitle = model.Subtitle;
break;
case nameof(Icon):
this.Icon = model.Icon;
break;

// TODO! Icon
// TODO! MoreCommands array, which needs to also raise HasMoreCommands
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,8 @@ public partial class PageViewModel : ExtensionObjectViewModel

public bool IsLoading { get; private set; } = true;

public IconDataType Icon { get; private set; } = new(string.Empty);

public PageViewModel(IPage model, TaskScheduler scheduler)
{
_pageModel = new(model);
Expand Down Expand Up @@ -70,10 +72,12 @@ public override void InitializeProperties()

Name = page.Name;
IsLoading = page.IsLoading;
Icon = page.Icon;

// Let the UI know about our initial properties too.
UpdateProperty(nameof(Name));
UpdateProperty(nameof(IsLoading));
UpdateProperty(nameof(Icon));

page.PropChanged += Model_PropChanged;
}
Expand Down Expand Up @@ -107,6 +111,9 @@ protected virtual void FetchProperty(string propertyName)
case nameof(IsLoading):
this.IsLoading = model.IsLoading;
break;
case nameof(Icon):
this.Icon = model.Icon;
break;
}

UpdateProperty(propertyName);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,10 @@ public partial class TagViewModel(ITag _tag, TaskScheduler Scheduler) : Extensio

public OptionalColor Color { get; private set; }

// TODO Icon
public IconDataType Icon { get; private set; } = new(string.Empty);

public bool HasIcon => !string.IsNullOrEmpty(Icon.Icon);

public ExtensionObject<ICommand> Command { get; private set; } = new(null);

public override void InitializeProperties()
Expand All @@ -34,10 +37,12 @@ public override void InitializeProperties()
Text = model.Text;
Color = model.Color;
Tooltip = model.ToolTip;
Icon = model.Icon;

UpdateProperty(nameof(Text));
UpdateProperty(nameof(Color));
UpdateProperty(nameof(Tooltip));
UpdateProperty(nameof(Icon));
}

protected void UpdateProperty(string propertyName) => Task.Factory.StartNew(() => { OnPropertyChanged(propertyName); }, CancellationToken.None, TaskCreationOptions.None, Scheduler);
Expand Down
5 changes: 4 additions & 1 deletion src/modules/cmdpal/Microsoft.CmdPal.UI/App.xaml.cs
Original file line number Diff line number Diff line change
Expand Up @@ -12,11 +12,12 @@
using Microsoft.CmdPal.Ext.WindowsSettings;
using Microsoft.CmdPal.Ext.WindowsTerminal;
using Microsoft.CmdPal.Extensions;
using Microsoft.CmdPal.UI.Pages;
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 @@ -72,6 +73,8 @@ 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
72 changes: 50 additions & 22 deletions src/modules/cmdpal/Microsoft.CmdPal.UI/Controls/ActionBar.xaml
Original file line number Diff line number Diff line change
Expand Up @@ -5,10 +5,12 @@
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
xmlns:converters="using:CommunityToolkit.WinUI.Converters"
xmlns:d="http://schemas.microsoft.com/expression/blend/2008"
xmlns:cmdpalUI="using:Microsoft.CmdPal.UI"
xmlns:local="using:Microsoft.CmdPal.UI.Controls"
xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
xmlns:ui="using:CommunityToolkit.WinUI"
xmlns:viewmodels="using:Microsoft.CmdPal.UI.ViewModels"
xmlns:Interactivity="using:Microsoft.Xaml.Interactivity"
Background="Transparent"
mc:Ignorable="d">

Expand All @@ -18,25 +20,28 @@
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">
<ListViewItem KeyDown="ActionListViewItem_KeyDown" Tapped="ActionListViewItem_Tapped">
<Grid ColumnSpacing="8">
<Grid.ColumnDefinitions>
<ColumnDefinition Width="24" />
<ColumnDefinition Width="20" />
<ColumnDefinition Width="Auto" />
</Grid.ColumnDefinitions>

<Viewbox Width="16" Height="16">
<!-- TODO bind to icon -->
<ContentControl
<Border x:Name="IconBorder"
Grid.Column="0"
Width="24"
Height="24">
<!--<SymbolIcon Symbol="Emoji" />-->
</ContentControl>
</Viewbox>
Width="16"
Height="16"
Margin="0,0,0,0">
<!-- LoadIconBehavior will magically fill this border up with an icon -->
<Interactivity:Interaction.Behaviors>
<cmdpalUI:LoadIconBehavior Source="{x:Bind Icon, Mode=OneWay}"/>
</Interactivity:Interaction.Behaviors>
</Border>

<TextBlock Grid.Column="1" Text="{x:Bind Title}" />
</Grid>
</ListViewItem>
Expand All @@ -51,13 +56,17 @@
<ColumnDefinition Width="*" />
</Grid.ColumnDefinitions>

<!-- TO DO: Placeholder, needs to be replaced with extension info -->
<Border
Width="20"
Height="20"
Margin="12,0,0,0"
Background="{ThemeResource AccentFillColorDefaultBrush}"
CornerRadius="{StaticResource ControlCornerRadius}" />

<Border x:Name="IconBorder"
Width="20"
Height="20"
Margin="12,0,0,0"
CornerRadius="{StaticResource ControlCornerRadius}">
<!-- LoadIconBehavior will magically fill this border up with an icon -->
<Interactivity:Interaction.Behaviors>
<cmdpalUI:LoadIconBehavior Source="{x:Bind ViewModel.CurrentPage.Icon, Mode=OneWay}"/>
</Interactivity:Interaction.Behaviors>
</Border>

<TextBlock
Grid.Column="1"
Expand All @@ -73,15 +82,24 @@
<Button
Height="40"
Padding="8,4,8,4"
Visibility="{x:Bind ViewModel.PrimaryActionName, Converter={StaticResource StringNotEmptyToVisibilityConverter}, Mode=OneWay}">
Visibility="{x:Bind ViewModel.PrimaryAction.Name, Converter={StaticResource StringNotEmptyToVisibilityConverter}, Mode=OneWay}">

<StackPanel Orientation="Horizontal" Spacing="8">
<FontIcon Glyph="&#xEA3A;" />
<!-- <FontIcon Glyph="&#xEA3A;" /> -->
<Border Width="16"
Height="16"
Margin="4,4,4,4">
<!-- LoadIconBehavior will magically fill this border up with an icon -->
<Interactivity:Interaction.Behaviors>
<cmdpalUI:LoadIconBehavior Source="{x:Bind ViewModel.PrimaryAction.Icon, Mode=OneWay}"/>
</Interactivity:Interaction.Behaviors>
</Border>

<StackPanel Orientation="Vertical" Spacing="2">
<TextBlock
FontSize="12"
Style="{StaticResource CaptionTextBlockStyle}"
Text="{x:Bind ViewModel.PrimaryActionName, Mode=OneWay}" />
Text="{x:Bind ViewModel.PrimaryAction.Name, Mode=OneWay}" />
<FontIcon
HorizontalAlignment="Left"
VerticalAlignment="Center"
Expand All @@ -94,14 +112,24 @@
<Button
Height="40"
Padding="8,4,8,4"
Visibility="{x:Bind ViewModel.SecondaryActionName, Converter={StaticResource StringNotEmptyToVisibilityConverter}, Mode=OneWay}">
Visibility="{x:Bind ViewModel.HasSecondaryCommand, Mode=OneWay}">
<StackPanel Orientation="Horizontal" Spacing="8">
<FontIcon Glyph="&#xEA3A;" />
<!-- <FontIcon Glyph="&#xEA3A;" /> -->

<Border Width="16"
Height="16"
Margin="4,4,4,4">
<!-- LoadIconBehavior will magically fill this border up with an icon -->
<Interactivity:Interaction.Behaviors>
<cmdpalUI:LoadIconBehavior Source="{x:Bind ViewModel.SecondaryAction.Icon, Mode=OneWay}"/>
</Interactivity:Interaction.Behaviors>
</Border>

<StackPanel Orientation="Vertical" Spacing="1">
<TextBlock
FontSize="12"
Style="{StaticResource CaptionTextBlockStyle}"
Text="{x:Bind ViewModel.SecondaryActionName, Mode=OneWay}" />
Text="{x:Bind ViewModel.SecondaryAction.Name, Mode=OneWay}" />
<TextBlock
FontSize="10"
Foreground="{ThemeResource TextFillColorSecondaryBrush}"
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,26 +2,33 @@
// 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
public sealed partial class ActionBar : UserControl,
IRecipient<UpdateActionBarPage>
{
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")]
private void ActionListViewItem_KeyDown(object sender, KeyRoutedEventArgs e)
{
// TODO
}

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

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