Command palette with Title, style

This commit is contained in:
2023-07-29 16:01:25 +02:00
parent 604294fd2a
commit 05301f09c8
7 changed files with 77 additions and 39 deletions

View File

@@ -40,8 +40,9 @@ public partial class CommandPaletteService : ICommandPaletteService
public IReadOnlyList<ICommandPaletteEntry> GetCommands() => public IReadOnlyList<ICommandPaletteEntry> GetCommands() =>
_identifiableUserCommandService _identifiableUserCommandService
.GetCommandIdentifiers() .IdentifiableUserCommands
.Select(c => new CommandPaletteEntry(c, c)) .Select(c => new CommandPaletteEntry(c.Key, c.Value.Title))
.OrderBy(c => c.Title)
.ToList() .ToList()
.AsReadOnly(); .AsReadOnly();
} }

View File

@@ -41,9 +41,8 @@ public class CommandPaletteViewModel : FuzzyPanelViewModel<ICommandPaletteEntryV
|| c.Identifier.Contains(SearchText, StringComparison.OrdinalIgnoreCase) || c.Identifier.Contains(SearchText, StringComparison.OrdinalIgnoreCase)
) )
.Select(c => .Select(c =>
(ICommandPaletteEntryViewModel) new CommandPaletteEntryViewModel(c.Identifier, c.Title)) (ICommandPaletteEntryViewModel) new CommandPaletteEntryViewModel(c.Identifier, c.Title)
.Take(30) // TODO remove magic number )
.OrderBy(c => c.Title)
.ToList(); .ToList();
public override async Task<bool> HandleKeyDown(KeyEventArgs keyEventArgs) public override async Task<bool> HandleKeyDown(KeyEventArgs keyEventArgs)

View File

@@ -4,7 +4,8 @@ namespace FileTime.App.Core.Services;
public interface IIdentifiableUserCommandService public interface IIdentifiableUserCommandService
{ {
void AddIdentifiableUserCommandFactory(string identifier, Func<IIdentifiableUserCommand> commandFactory); void AddIdentifiableUserCommandFactory(string identifier, IIdentifiableUserCommand commandFactory);
IIdentifiableUserCommand? GetCommand(string identifier); IIdentifiableUserCommand? GetCommand(string identifier);
IReadOnlyCollection<string> GetCommandIdentifiers(); IReadOnlyCollection<string> GetCommandIdentifiers();
IReadOnlyDictionary<string, IIdentifiableUserCommand> IdentifiableUserCommands { get; }
} }

View File

@@ -4,9 +4,15 @@ namespace FileTime.App.Core.Services.UserCommandHandler;
public class IdentifiableUserCommandService : IIdentifiableUserCommandService public class IdentifiableUserCommandService : IIdentifiableUserCommandService
{ {
private readonly Dictionary<string, Func<IIdentifiableUserCommand>> _identifiableUserCommands = new(); private readonly Dictionary<string, IIdentifiableUserCommand> _identifiableUserCommands = new();
public IReadOnlyDictionary<string, IIdentifiableUserCommand> IdentifiableUserCommands { get; }
public void AddIdentifiableUserCommandFactory(string identifier, Func<IIdentifiableUserCommand> commandFactory) public IdentifiableUserCommandService()
{
IdentifiableUserCommands = _identifiableUserCommands.AsReadOnly();
}
public void AddIdentifiableUserCommandFactory(string identifier, IIdentifiableUserCommand commandFactory)
=> _identifiableUserCommands.Add(identifier, commandFactory); => _identifiableUserCommands.Add(identifier, commandFactory);
public IIdentifiableUserCommand? GetCommand(string identifier) public IIdentifiableUserCommand? GetCommand(string identifier)
@@ -15,7 +21,7 @@ public class IdentifiableUserCommandService : IIdentifiableUserCommandService
if (!_identifiableUserCommands.ContainsKey(identifier)) if (!_identifiableUserCommands.ContainsKey(identifier))
throw new IndexOutOfRangeException($"No command factory is registered for command {identifier}"); throw new IndexOutOfRangeException($"No command factory is registered for command {identifier}");
return _identifiableUserCommands[identifier].Invoke(); return _identifiableUserCommands[identifier];
} }
public IReadOnlyCollection<string> GetCommandIdentifiers() => _identifiableUserCommands.Keys.ToList(); public IReadOnlyCollection<string> GetCommandIdentifiers() => _identifiableUserCommands.Keys.ToList();

View File

@@ -68,5 +68,5 @@ public class DefaultIdentifiableCommandHandlerRegister : IStartupHandler
public Task InitAsync() => Task.CompletedTask; public Task InitAsync() => Task.CompletedTask;
private void AddUserCommand(IIdentifiableUserCommand command) private void AddUserCommand(IIdentifiableUserCommand command)
=> _userCommandHandlerService.AddIdentifiableUserCommandFactory(command.UserCommandID, () => command); => _userCommandHandlerService.AddIdentifiableUserCommandFactory(command.UserCommandID, command);
} }

View File

@@ -3,6 +3,8 @@
d:DesignWidth="800" d:DesignWidth="800"
mc:Ignorable="d" mc:Ignorable="d"
x:Class="FileTime.GuiApp.Views.CommandPalette" x:Class="FileTime.GuiApp.Views.CommandPalette"
x:CompileBindings="True"
xmlns:vm="clr-namespace:FileTime.App.CommandPalette.ViewModels;assembly=FileTime.App.CommandPalette.Abstractions"
xmlns="https://github.com/avaloniaui" xmlns="https://github.com/avaloniaui"
xmlns:d="http://schemas.microsoft.com/expression/blend/2008" xmlns:d="http://schemas.microsoft.com/expression/blend/2008"
xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006" xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
@@ -10,7 +12,8 @@
<UserControl.Styles> <UserControl.Styles>
<StyleInclude Source="avares://FileTime.GuiApp/Resources/Styles.axaml" /> <StyleInclude Source="avares://FileTime.GuiApp/Resources/Styles.axaml" />
</UserControl.Styles> </UserControl.Styles>
<Grid RowDefinitions="Auto,*"> <Grid RowDefinitions="Auto,*"
x:DataType="vm:ICommandPaletteViewModel">
<TextBox <TextBox
KeyDown="Search_OnKeyDown" KeyDown="Search_OnKeyDown"
Text="{Binding SearchText, Mode=TwoWay}" Text="{Binding SearchText, Mode=TwoWay}"
@@ -21,9 +24,9 @@
ItemsSource="{Binding FilteredMatches}" ItemsSource="{Binding FilteredMatches}"
SelectedItem="{Binding SelectedItem}"> SelectedItem="{Binding SelectedItem}">
<ListBox.ItemTemplate> <ListBox.ItemTemplate>
<DataTemplate> <DataTemplate x:DataType="vm:ICommandPaletteEntryViewModel">
<Grid Margin="5"> <Grid Margin="5">
<TextBlock Text="{Binding Identifier}" /> <TextBlock Text="{Binding Title}" />
</Grid> </Grid>
</DataTemplate> </DataTemplate>
</ListBox.ItemTemplate> </ListBox.ItemTemplate>

View File

@@ -45,7 +45,8 @@
</Window.Styles> </Window.Styles>
<Grid Background="{DynamicResource AppBackgroundBrush}"> <Grid Background="{DynamicResource AppBackgroundBrush}">
<Grid IsVisible="{Binding Loading, Converter={x:Static BoolConverters.Not}, FallbackValue=False}" x:DataType="vm:IMainWindowViewModel"> <Grid IsVisible="{Binding Loading, Converter={x:Static BoolConverters.Not}, FallbackValue=False}"
x:DataType="vm:IMainWindowViewModel">
<Grid ColumnDefinitions="250,*" RowDefinitions="Auto,*"> <Grid ColumnDefinitions="250,*" RowDefinitions="Auto,*">
@@ -59,8 +60,10 @@
<Grid ColumnDefinitions="*, Auto"> <Grid ColumnDefinitions="*, Auto">
<StackPanel Margin="20,10" Orientation="Horizontal"> <StackPanel Margin="20,10" Orientation="Horizontal">
<local:PathPresenter DataContext="{Binding AppState.SelectedTab^.CurrentLocation^.FullName.Path, Converter={StaticResource PathPreformatter}}" /> <local:PathPresenter
<TextBlock Foreground="{StaticResource AccentBrush}" Text="{Binding AppState.SelectedTab^.CurrentSelectedItem.Value.DisplayNameText}" /> DataContext="{Binding AppState.SelectedTab^.CurrentLocation^.FullName.Path, Converter={StaticResource PathPreformatter}}" />
<TextBlock Foreground="{StaticResource AccentBrush}"
Text="{Binding AppState.SelectedTab^.CurrentSelectedItem.Value.DisplayNameText}" />
</StackPanel> </StackPanel>
<StackPanel <StackPanel
Grid.Column="1" Grid.Column="1"
@@ -360,7 +363,8 @@
Grid.Column="0" Grid.Column="0"
Grid.Row="1" Grid.Row="1"
Margin="0,5,5,5"> Margin="0,5,5,5">
<TextBlock Text="{Binding DisplayDetailLabel^}" TextAlignment="Right" /> <TextBlock Text="{Binding DisplayDetailLabel^}"
TextAlignment="Right" />
<ProgressBar <ProgressBar
Margin="0,5,0,0" Margin="0,5,0,0"
@@ -372,7 +376,9 @@
Grid.Column="1" Grid.Column="1"
Grid.Row="1" Grid.Row="1"
Margin="5,5,0,5"> Margin="5,5,0,5">
<TextBlock Text="{Binding TotalProgress^, StringFormat={}{0}%}" TextAlignment="Right" /> <TextBlock
Text="{Binding TotalProgress^, StringFormat={}{0}%}"
TextAlignment="Right" />
<ProgressBar <ProgressBar
Margin="0,5,0,0" Margin="0,5,0,0"
@@ -411,7 +417,8 @@
<Grid RowDefinitions="Auto,1"> <Grid RowDefinitions="Auto,1">
<StackPanel Margin="20,0,20,0" Orientation="Horizontal"> <StackPanel Margin="20,0,20,0" Orientation="Horizontal">
<TextBlock Text="{Binding TabNumber, StringFormat=({0})}" VerticalAlignment="Center" /> <TextBlock Text="{Binding TabNumber, StringFormat=({0})}"
VerticalAlignment="Center" />
<TextBlock <TextBlock
Margin="5,0,0,0" Margin="5,0,0,0"
@@ -457,7 +464,8 @@
Width="1" /> Width="1" />
<Grid Grid.Column="2" RowDefinitions="Auto,*"> <Grid Grid.Column="2" RowDefinitions="Auto,*">
<Grid IsVisible="{Binding AppState.SelectedTab^.CurrentLocation.Value.IsLoading^, FallbackValue=False}"> <Grid
IsVisible="{Binding AppState.SelectedTab^.CurrentLocation.Value.IsLoading^, FallbackValue=False}">
<Image <Image
Classes="LoadingAnimation" Classes="LoadingAnimation"
Height="40" Height="40"
@@ -476,7 +484,8 @@
x:Name="CurrentItems"> x:Name="CurrentItems">
<ListBox.ItemTemplate> <ListBox.ItemTemplate>
<DataTemplate x:DataType="corevm:IItemViewModel"> <DataTemplate x:DataType="corevm:IItemViewModel">
<local:ItemView HorizontalAlignment="Stretch" HorizontalContentAlignment="Stretch" /> <local:ItemView HorizontalAlignment="Stretch"
HorizontalContentAlignment="Stretch" />
</DataTemplate> </DataTemplate>
</ListBox.ItemTemplate> </ListBox.ItemTemplate>
</ListBox> </ListBox>
@@ -502,11 +511,14 @@
Width="1" /> Width="1" />
<Grid Grid.Column="4"> <Grid Grid.Column="4">
<Grid IsVisible="{Binding ItemPreviewService.ItemPreview^, Converter={x:Static ObjectConverters.IsNull}}"> <Grid
<Grid IsVisible="{Binding AppState.SelectedTab^.SelectedsChildren.Value, Converter={x:Static ObjectConverters.IsNotNull}, FallbackValue=False}"> IsVisible="{Binding ItemPreviewService.ItemPreview^, Converter={x:Static ObjectConverters.IsNull}}">
<Grid
IsVisible="{Binding AppState.SelectedTab^.SelectedsChildren.Value, Converter={x:Static ObjectConverters.IsNotNull}, FallbackValue=False}">
<Grid RowDefinitions="Auto, Auto, *"> <Grid RowDefinitions="Auto, Auto, *">
<Grid IsVisible="{Binding AppState.SelectedTab^.CurrentSelectedItemAsContainer.Value.Container.IsLoading^, FallbackValue=False}"> <Grid
IsVisible="{Binding AppState.SelectedTab^.CurrentSelectedItemAsContainer.Value.Container.IsLoading^, FallbackValue=False}">
<Image <Image
Classes="LoadingAnimation" Classes="LoadingAnimation"
Height="40" Height="40"
@@ -515,7 +527,8 @@
</Grid> </Grid>
<ItemsRepeater Grid.Row="1" ItemsSource="{Binding AppState.SelectedTab^.CurrentLocation.Value.Exceptions}"> <ItemsRepeater Grid.Row="1"
ItemsSource="{Binding AppState.SelectedTab^.CurrentLocation.Value.Exceptions}">
<ItemsRepeater.ItemTemplate> <ItemsRepeater.ItemTemplate>
<DataTemplate> <DataTemplate>
<TextBlock <TextBlock
@@ -552,7 +565,9 @@
</TextBlock> </TextBlock>
</Grid> </Grid>
<Grid IsVisible="{Binding AppState.SelectedTab^.SelectedsChildren.Value, Converter={x:Static ObjectConverters.IsNull}, ConverterParameter=0, FallbackValue=False}" RowDefinitions="Auto, Auto"> <Grid
IsVisible="{Binding AppState.SelectedTab^.SelectedsChildren.Value, Converter={x:Static ObjectConverters.IsNull}, ConverterParameter=0, FallbackValue=False}"
RowDefinitions="Auto, Auto">
<TextBlock <TextBlock
Foreground="{DynamicResource ErrorBrush}" Foreground="{DynamicResource ErrorBrush}"
HorizontalAlignment="Center" HorizontalAlignment="Center"
@@ -560,7 +575,8 @@
Text="There were some errors while opening container." Text="There were some errors while opening container."
TextWrapping="Wrap" /> TextWrapping="Wrap" />
<ItemsRepeater Grid.Row="1" ItemsSource="{Binding AppState.SelectedTab^.CurrentSelectedItem.Value.BaseItem.Exceptions}"> <ItemsRepeater Grid.Row="1"
ItemsSource="{Binding AppState.SelectedTab^.CurrentSelectedItem.Value.BaseItem.Exceptions}">
<ItemsRepeater.ItemTemplate> <ItemsRepeater.ItemTemplate>
<DataTemplate> <DataTemplate>
<TextBlock <TextBlock
@@ -572,7 +588,8 @@
</ItemsRepeater> </ItemsRepeater>
</Grid> </Grid>
</Grid> </Grid>
<Grid IsVisible="{Binding ItemPreviewService.ItemPreview^, Converter={x:Static ObjectConverters.IsNotNull}}"> <Grid
IsVisible="{Binding ItemPreviewService.ItemPreview^, Converter={x:Static ObjectConverters.IsNotNull}}">
<TextBlock <TextBlock
HorizontalAlignment="Center" HorizontalAlignment="Center"
IsVisible="{Binding ItemPreviewService.ItemPreview^.Mode, Converter={StaticResource EqualsConverter}, ConverterParameter={x:Static appCoreModels:ItemPreviewMode.Unknown}, FallbackValue={x:Static appCoreModels:ItemPreviewMode.Unknown}}" IsVisible="{Binding ItemPreviewService.ItemPreview^.Mode, Converter={StaticResource EqualsConverter}, ConverterParameter={x:Static appCoreModels:ItemPreviewMode.Unknown}, FallbackValue={x:Static appCoreModels:ItemPreviewMode.Unknown}}"
@@ -581,7 +598,9 @@
HorizontalAlignment="Center" HorizontalAlignment="Center"
IsVisible="{Binding ItemPreviewService.ItemPreview^.Mode, Converter={StaticResource EqualsConverter}, ConverterParameter={x:Static appCoreModels:ItemPreviewMode.Empty}, FallbackValue={x:Static appCoreModels:ItemPreviewMode.Unknown}}" IsVisible="{Binding ItemPreviewService.ItemPreview^.Mode, Converter={StaticResource EqualsConverter}, ConverterParameter={x:Static appCoreModels:ItemPreviewMode.Empty}, FallbackValue={x:Static appCoreModels:ItemPreviewMode.Unknown}}"
Text="Empty" /> Text="Empty" />
<Grid IsVisible="{Binding ItemPreviewService.ItemPreview^.Mode, Converter={StaticResource EqualsConverter}, ConverterParameter={x:Static appCoreModels:ItemPreviewMode.Text}, FallbackValue={x:Static appCoreModels:ItemPreviewMode.Unknown}}" RowDefinitions="*, Auto"> <Grid
IsVisible="{Binding ItemPreviewService.ItemPreview^.Mode, Converter={StaticResource EqualsConverter}, ConverterParameter={x:Static appCoreModels:ItemPreviewMode.Text}, FallbackValue={x:Static appCoreModels:ItemPreviewMode.Unknown}}"
RowDefinitions="*, Auto">
<ScrollViewer> <ScrollViewer>
<TextBox <TextBox
IsReadOnly="True" IsReadOnly="True"
@@ -635,7 +654,9 @@
</Grid> </Grid>
<Grid Grid.Row="3"> <Grid Grid.Row="3">
<Grid IsVisible="{Binding AppState.ViewMode^, Converter={StaticResource EqualsConverter}, ConverterParameter=RapidTravel}" RowDefinitions="1,Auto"> <Grid
IsVisible="{Binding AppState.ViewMode^, Converter={StaticResource EqualsConverter}, ConverterParameter=RapidTravel}"
RowDefinitions="1,Auto">
<Rectangle <Rectangle
Fill="{DynamicResource ContentSeparatorBrush}" Fill="{DynamicResource ContentSeparatorBrush}"
@@ -657,7 +678,8 @@
</StackPanel> </StackPanel>
</Grid> </Grid>
<Grid IsVisible="{Binding AppState.PossibleCommands.Count, Converter={StaticResource NotEqualsConverter}, ConverterParameter=0}"> <Grid
IsVisible="{Binding AppState.PossibleCommands.Count, Converter={StaticResource NotEqualsConverter}, ConverterParameter=0}">
<Grid.RowDefinitions> <Grid.RowDefinitions>
<RowDefinition Height="1" /> <RowDefinition Height="1" />
<RowDefinition Height="Auto" /> <RowDefinition Height="Auto" />
@@ -680,7 +702,8 @@
</Grid.ColumnDefinitions> </Grid.ColumnDefinitions>
<TextBlock Text="{Binding KeysDisplayText}" /> <TextBlock Text="{Binding KeysDisplayText}" />
<TextBlock Grid.Column="1" Text="{Binding Command, Converter={StaticResource CommandToCommandNameConverter}}" /> <TextBlock Grid.Column="1"
Text="{Binding Command, Converter={StaticResource CommandToCommandNameConverter}}" />
</Grid> </Grid>
</DataTemplate> </DataTemplate>
</ItemsRepeater.ItemTemplate> </ItemsRepeater.ItemTemplate>
@@ -749,8 +772,10 @@
<ItemsControl.ItemTemplate> <ItemsControl.ItemTemplate>
<DataTemplate> <DataTemplate>
<Grid> <Grid>
<Grid IsVisible="{Binding PreviewType, Converter={StaticResource EqualsConverter}, ConverterParameter={x:Static appInteractions:PreviewType.DoubleTextList}}"> <Grid
<ItemsControl ItemsSource="{Binding Items}" x:DataType="appInteractions:DoubleTextListPreview"> IsVisible="{Binding PreviewType, Converter={StaticResource EqualsConverter}, ConverterParameter={x:Static appInteractions:PreviewType.DoubleTextList}}">
<ItemsControl ItemsSource="{Binding Items}"
x:DataType="appInteractions:DoubleTextListPreview">
<ItemsControl.ItemTemplate> <ItemsControl.ItemTemplate>
<DataTemplate> <DataTemplate>
<Grid ColumnDefinitions="*,*"> <Grid ColumnDefinitions="*,*">
@@ -762,11 +787,13 @@
</ItemsControl.ItemsPanel> </ItemsControl.ItemsPanel>
<ItemsControl.ItemTemplate> <ItemsControl.ItemTemplate>
<DataTemplate> <DataTemplate>
<TextBlock Text="{Binding Text}" TextDecorations="{Binding IsSpecial, Converter={StaticResource TextDecorationConverter}}" /> <TextBlock Text="{Binding Text}"
TextDecorations="{Binding IsSpecial, Converter={StaticResource TextDecorationConverter}}" />
</DataTemplate> </DataTemplate>
</ItemsControl.ItemTemplate> </ItemsControl.ItemTemplate>
</ItemsControl> </ItemsControl>
<ItemsControl Grid.Column="1" ItemsSource="{Binding Text2^}"> <ItemsControl Grid.Column="1"
ItemsSource="{Binding Text2^}">
<ItemsControl.ItemsPanel> <ItemsControl.ItemsPanel>
<ItemsPanelTemplate> <ItemsPanelTemplate>
<StackPanel Orientation="Horizontal" /> <StackPanel Orientation="Horizontal" />
@@ -774,7 +801,8 @@
</ItemsControl.ItemsPanel> </ItemsControl.ItemsPanel>
<ItemsControl.ItemTemplate> <ItemsControl.ItemTemplate>
<DataTemplate> <DataTemplate>
<TextBlock Text="{Binding Text}" TextDecorations="{Binding IsSpecial, Converter={StaticResource TextDecorationConverter}}" /> <TextBlock Text="{Binding Text}"
TextDecorations="{Binding IsSpecial, Converter={StaticResource TextDecorationConverter}}" />
</DataTemplate> </DataTemplate>
</ItemsControl.ItemTemplate> </ItemsControl.ItemTemplate>
</ItemsControl> </ItemsControl>
@@ -880,7 +908,7 @@
HorizontalAlignment="Stretch" HorizontalAlignment="Stretch"
IsVisible="{Binding ShowWindow^, FallbackValue=False}" IsVisible="{Binding ShowWindow^, FallbackValue=False}"
VerticalAlignment="Stretch"> VerticalAlignment="Stretch">
<Grid Margin="100"> <Grid Margin="100" Background="{DynamicResource ContainerBackgroundColor}">
<local:FrequencyNavigation IsVisible="{Binding ShowWindow^, FallbackValue=False}" /> <local:FrequencyNavigation IsVisible="{Binding ShowWindow^, FallbackValue=False}" />
</Grid> </Grid>
</Border> </Border>
@@ -891,7 +919,7 @@
HorizontalAlignment="Stretch" HorizontalAlignment="Stretch"
IsVisible="{Binding ShowWindow^, FallbackValue=False}" IsVisible="{Binding ShowWindow^, FallbackValue=False}"
VerticalAlignment="Stretch"> VerticalAlignment="Stretch">
<Grid Margin="100"> <Grid Margin="100" Background="{DynamicResource ContainerBackgroundColor}">
<local:CommandPalette IsVisible="{Binding ShowWindow^, FallbackValue=False}" /> <local:CommandPalette IsVisible="{Binding ShowWindow^, FallbackValue=False}" />
</Grid> </Grid>
</Border> </Border>