Skip to content
Merged
Show file tree
Hide file tree
Changes from 11 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 @@ -24,14 +24,20 @@ public ListItemViewModel? SelectedItem
}

[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; set; }

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

Expand All @@ -46,8 +52,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 @@ -61,8 +67,8 @@ private void SetSelectedItem(ListItemViewModel? value)
}
else
{
PrimaryActionName = string.Empty;
SecondaryActionName = string.Empty;
PrimaryAction = null;
SecondaryAction = null;
ShouldShowContextMenu = false;
}
}
Expand Down
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

This file was deleted.

Original file line number Diff line number Diff line change
Expand Up @@ -13,8 +13,8 @@ public partial class DetailsViewModel(IDetails _details, TaskScheduler Scheduler

// Remember - "observable" properties from the model (via PropChanged)
// cannot be marked [ObservableProperty]
public IconDataType HeroImage { get; private set; } = new(string.Empty);

// TODO: Icon
// TODO: Metadata is an array of IDetailsElement,
// where IDetailsElement = {IDetailsTags, IDetailsLink, IDetailsSeparator}
public string Title { get; private set; } = string.Empty;
Expand All @@ -31,9 +31,11 @@ public override void InitializeProperties()

Title = model.Title;
Body = model.Body;
HeroImage = model.HeroImage;

UpdateProperty(nameof(Title));
UpdateProperty(nameof(Body));
UpdateProperty(nameof(HeroImage));
}

protected void UpdateProperty(string propertyName) => Task.Factory.StartNew(() => { OnPropertyChanged(propertyName); }, CancellationToken.None, TaskCreationOptions.None, Scheduler);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,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 @@ -74,10 +76,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 @@ -119,6 +123,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
1 change: 0 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,7 +12,6 @@
using Microsoft.CmdPal.Ext.WindowsSettings;
using Microsoft.CmdPal.Ext.WindowsTerminal;
using Microsoft.CmdPal.Extensions;
using Microsoft.CmdPal.UI.Pages;
using Microsoft.CmdPal.UI.ViewModels;
using Microsoft.CmdPal.UI.ViewModels.BuiltinCommands;
using Microsoft.CmdPal.UI.ViewModels.Models;
Expand Down
71 changes: 49 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 @@ -24,19 +26,21 @@
<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 +55,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 +81,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 +111,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 @@ -29,11 +29,13 @@ public ActionBar()
this.InitializeComponent();
}

[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 Down
Loading