Command palette with Title, style
This commit is contained in:
@@ -40,8 +40,9 @@ public partial class CommandPaletteService : ICommandPaletteService
|
||||
|
||||
public IReadOnlyList<ICommandPaletteEntry> GetCommands() =>
|
||||
_identifiableUserCommandService
|
||||
.GetCommandIdentifiers()
|
||||
.Select(c => new CommandPaletteEntry(c, c))
|
||||
.IdentifiableUserCommands
|
||||
.Select(c => new CommandPaletteEntry(c.Key, c.Value.Title))
|
||||
.OrderBy(c => c.Title)
|
||||
.ToList()
|
||||
.AsReadOnly();
|
||||
}
|
||||
@@ -41,9 +41,8 @@ public class CommandPaletteViewModel : FuzzyPanelViewModel<ICommandPaletteEntryV
|
||||
|| c.Identifier.Contains(SearchText, StringComparison.OrdinalIgnoreCase)
|
||||
)
|
||||
.Select(c =>
|
||||
(ICommandPaletteEntryViewModel) new CommandPaletteEntryViewModel(c.Identifier, c.Title))
|
||||
.Take(30) // TODO remove magic number
|
||||
.OrderBy(c => c.Title)
|
||||
(ICommandPaletteEntryViewModel) new CommandPaletteEntryViewModel(c.Identifier, c.Title)
|
||||
)
|
||||
.ToList();
|
||||
|
||||
public override async Task<bool> HandleKeyDown(KeyEventArgs keyEventArgs)
|
||||
|
||||
@@ -4,7 +4,8 @@ namespace FileTime.App.Core.Services;
|
||||
|
||||
public interface IIdentifiableUserCommandService
|
||||
{
|
||||
void AddIdentifiableUserCommandFactory(string identifier, Func<IIdentifiableUserCommand> commandFactory);
|
||||
void AddIdentifiableUserCommandFactory(string identifier, IIdentifiableUserCommand commandFactory);
|
||||
IIdentifiableUserCommand? GetCommand(string identifier);
|
||||
IReadOnlyCollection<string> GetCommandIdentifiers();
|
||||
IReadOnlyDictionary<string, IIdentifiableUserCommand> IdentifiableUserCommands { get; }
|
||||
}
|
||||
@@ -4,9 +4,15 @@ namespace FileTime.App.Core.Services.UserCommandHandler;
|
||||
|
||||
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);
|
||||
|
||||
public IIdentifiableUserCommand? GetCommand(string identifier)
|
||||
@@ -15,7 +21,7 @@ public class IdentifiableUserCommandService : IIdentifiableUserCommandService
|
||||
if (!_identifiableUserCommands.ContainsKey(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();
|
||||
|
||||
@@ -68,5 +68,5 @@ public class DefaultIdentifiableCommandHandlerRegister : IStartupHandler
|
||||
public Task InitAsync() => Task.CompletedTask;
|
||||
|
||||
private void AddUserCommand(IIdentifiableUserCommand command)
|
||||
=> _userCommandHandlerService.AddIdentifiableUserCommandFactory(command.UserCommandID, () => command);
|
||||
=> _userCommandHandlerService.AddIdentifiableUserCommandFactory(command.UserCommandID, command);
|
||||
}
|
||||
@@ -3,6 +3,8 @@
|
||||
d:DesignWidth="800"
|
||||
mc:Ignorable="d"
|
||||
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:d="http://schemas.microsoft.com/expression/blend/2008"
|
||||
xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
|
||||
@@ -10,7 +12,8 @@
|
||||
<UserControl.Styles>
|
||||
<StyleInclude Source="avares://FileTime.GuiApp/Resources/Styles.axaml" />
|
||||
</UserControl.Styles>
|
||||
<Grid RowDefinitions="Auto,*">
|
||||
<Grid RowDefinitions="Auto,*"
|
||||
x:DataType="vm:ICommandPaletteViewModel">
|
||||
<TextBox
|
||||
KeyDown="Search_OnKeyDown"
|
||||
Text="{Binding SearchText, Mode=TwoWay}"
|
||||
@@ -21,9 +24,9 @@
|
||||
ItemsSource="{Binding FilteredMatches}"
|
||||
SelectedItem="{Binding SelectedItem}">
|
||||
<ListBox.ItemTemplate>
|
||||
<DataTemplate>
|
||||
<DataTemplate x:DataType="vm:ICommandPaletteEntryViewModel">
|
||||
<Grid Margin="5">
|
||||
<TextBlock Text="{Binding Identifier}" />
|
||||
<TextBlock Text="{Binding Title}" />
|
||||
</Grid>
|
||||
</DataTemplate>
|
||||
</ListBox.ItemTemplate>
|
||||
|
||||
@@ -45,7 +45,8 @@
|
||||
</Window.Styles>
|
||||
|
||||
<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,*">
|
||||
|
||||
@@ -59,8 +60,10 @@
|
||||
|
||||
<Grid ColumnDefinitions="*, Auto">
|
||||
<StackPanel Margin="20,10" Orientation="Horizontal">
|
||||
<local:PathPresenter DataContext="{Binding AppState.SelectedTab^.CurrentLocation^.FullName.Path, Converter={StaticResource PathPreformatter}}" />
|
||||
<TextBlock Foreground="{StaticResource AccentBrush}" Text="{Binding AppState.SelectedTab^.CurrentSelectedItem.Value.DisplayNameText}" />
|
||||
<local:PathPresenter
|
||||
DataContext="{Binding AppState.SelectedTab^.CurrentLocation^.FullName.Path, Converter={StaticResource PathPreformatter}}" />
|
||||
<TextBlock Foreground="{StaticResource AccentBrush}"
|
||||
Text="{Binding AppState.SelectedTab^.CurrentSelectedItem.Value.DisplayNameText}" />
|
||||
</StackPanel>
|
||||
<StackPanel
|
||||
Grid.Column="1"
|
||||
@@ -360,7 +363,8 @@
|
||||
Grid.Column="0"
|
||||
Grid.Row="1"
|
||||
Margin="0,5,5,5">
|
||||
<TextBlock Text="{Binding DisplayDetailLabel^}" TextAlignment="Right" />
|
||||
<TextBlock Text="{Binding DisplayDetailLabel^}"
|
||||
TextAlignment="Right" />
|
||||
|
||||
<ProgressBar
|
||||
Margin="0,5,0,0"
|
||||
@@ -372,7 +376,9 @@
|
||||
Grid.Column="1"
|
||||
Grid.Row="1"
|
||||
Margin="5,5,0,5">
|
||||
<TextBlock Text="{Binding TotalProgress^, StringFormat={}{0}%}" TextAlignment="Right" />
|
||||
<TextBlock
|
||||
Text="{Binding TotalProgress^, StringFormat={}{0}%}"
|
||||
TextAlignment="Right" />
|
||||
|
||||
<ProgressBar
|
||||
Margin="0,5,0,0"
|
||||
@@ -411,7 +417,8 @@
|
||||
<Grid RowDefinitions="Auto,1">
|
||||
<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
|
||||
Margin="5,0,0,0"
|
||||
@@ -457,7 +464,8 @@
|
||||
Width="1" />
|
||||
|
||||
<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
|
||||
Classes="LoadingAnimation"
|
||||
Height="40"
|
||||
@@ -476,7 +484,8 @@
|
||||
x:Name="CurrentItems">
|
||||
<ListBox.ItemTemplate>
|
||||
<DataTemplate x:DataType="corevm:IItemViewModel">
|
||||
<local:ItemView HorizontalAlignment="Stretch" HorizontalContentAlignment="Stretch" />
|
||||
<local:ItemView HorizontalAlignment="Stretch"
|
||||
HorizontalContentAlignment="Stretch" />
|
||||
</DataTemplate>
|
||||
</ListBox.ItemTemplate>
|
||||
</ListBox>
|
||||
@@ -502,11 +511,14 @@
|
||||
Width="1" />
|
||||
|
||||
<Grid Grid.Column="4">
|
||||
<Grid IsVisible="{Binding ItemPreviewService.ItemPreview^, Converter={x:Static ObjectConverters.IsNull}}">
|
||||
<Grid IsVisible="{Binding AppState.SelectedTab^.SelectedsChildren.Value, Converter={x:Static ObjectConverters.IsNotNull}, FallbackValue=False}">
|
||||
<Grid
|
||||
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 IsVisible="{Binding AppState.SelectedTab^.CurrentSelectedItemAsContainer.Value.Container.IsLoading^, FallbackValue=False}">
|
||||
<Grid
|
||||
IsVisible="{Binding AppState.SelectedTab^.CurrentSelectedItemAsContainer.Value.Container.IsLoading^, FallbackValue=False}">
|
||||
<Image
|
||||
Classes="LoadingAnimation"
|
||||
Height="40"
|
||||
@@ -515,7 +527,8 @@
|
||||
</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>
|
||||
<DataTemplate>
|
||||
<TextBlock
|
||||
@@ -552,7 +565,9 @@
|
||||
</TextBlock>
|
||||
</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
|
||||
Foreground="{DynamicResource ErrorBrush}"
|
||||
HorizontalAlignment="Center"
|
||||
@@ -560,7 +575,8 @@
|
||||
Text="There were some errors while opening container."
|
||||
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>
|
||||
<DataTemplate>
|
||||
<TextBlock
|
||||
@@ -572,7 +588,8 @@
|
||||
</ItemsRepeater>
|
||||
</Grid>
|
||||
</Grid>
|
||||
<Grid IsVisible="{Binding ItemPreviewService.ItemPreview^, Converter={x:Static ObjectConverters.IsNotNull}}">
|
||||
<Grid
|
||||
IsVisible="{Binding ItemPreviewService.ItemPreview^, Converter={x:Static ObjectConverters.IsNotNull}}">
|
||||
<TextBlock
|
||||
HorizontalAlignment="Center"
|
||||
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"
|
||||
IsVisible="{Binding ItemPreviewService.ItemPreview^.Mode, Converter={StaticResource EqualsConverter}, ConverterParameter={x:Static appCoreModels:ItemPreviewMode.Empty}, FallbackValue={x:Static appCoreModels:ItemPreviewMode.Unknown}}"
|
||||
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>
|
||||
<TextBox
|
||||
IsReadOnly="True"
|
||||
@@ -635,7 +654,9 @@
|
||||
</Grid>
|
||||
|
||||
<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
|
||||
Fill="{DynamicResource ContentSeparatorBrush}"
|
||||
@@ -657,7 +678,8 @@
|
||||
</StackPanel>
|
||||
</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>
|
||||
<RowDefinition Height="1" />
|
||||
<RowDefinition Height="Auto" />
|
||||
@@ -680,7 +702,8 @@
|
||||
</Grid.ColumnDefinitions>
|
||||
|
||||
<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>
|
||||
</DataTemplate>
|
||||
</ItemsRepeater.ItemTemplate>
|
||||
@@ -749,8 +772,10 @@
|
||||
<ItemsControl.ItemTemplate>
|
||||
<DataTemplate>
|
||||
<Grid>
|
||||
<Grid IsVisible="{Binding PreviewType, Converter={StaticResource EqualsConverter}, ConverterParameter={x:Static appInteractions:PreviewType.DoubleTextList}}">
|
||||
<ItemsControl ItemsSource="{Binding Items}" x:DataType="appInteractions:DoubleTextListPreview">
|
||||
<Grid
|
||||
IsVisible="{Binding PreviewType, Converter={StaticResource EqualsConverter}, ConverterParameter={x:Static appInteractions:PreviewType.DoubleTextList}}">
|
||||
<ItemsControl ItemsSource="{Binding Items}"
|
||||
x:DataType="appInteractions:DoubleTextListPreview">
|
||||
<ItemsControl.ItemTemplate>
|
||||
<DataTemplate>
|
||||
<Grid ColumnDefinitions="*,*">
|
||||
@@ -762,11 +787,13 @@
|
||||
</ItemsControl.ItemsPanel>
|
||||
<ItemsControl.ItemTemplate>
|
||||
<DataTemplate>
|
||||
<TextBlock Text="{Binding Text}" TextDecorations="{Binding IsSpecial, Converter={StaticResource TextDecorationConverter}}" />
|
||||
<TextBlock Text="{Binding Text}"
|
||||
TextDecorations="{Binding IsSpecial, Converter={StaticResource TextDecorationConverter}}" />
|
||||
</DataTemplate>
|
||||
</ItemsControl.ItemTemplate>
|
||||
</ItemsControl>
|
||||
<ItemsControl Grid.Column="1" ItemsSource="{Binding Text2^}">
|
||||
<ItemsControl Grid.Column="1"
|
||||
ItemsSource="{Binding Text2^}">
|
||||
<ItemsControl.ItemsPanel>
|
||||
<ItemsPanelTemplate>
|
||||
<StackPanel Orientation="Horizontal" />
|
||||
@@ -774,7 +801,8 @@
|
||||
</ItemsControl.ItemsPanel>
|
||||
<ItemsControl.ItemTemplate>
|
||||
<DataTemplate>
|
||||
<TextBlock Text="{Binding Text}" TextDecorations="{Binding IsSpecial, Converter={StaticResource TextDecorationConverter}}" />
|
||||
<TextBlock Text="{Binding Text}"
|
||||
TextDecorations="{Binding IsSpecial, Converter={StaticResource TextDecorationConverter}}" />
|
||||
</DataTemplate>
|
||||
</ItemsControl.ItemTemplate>
|
||||
</ItemsControl>
|
||||
@@ -880,7 +908,7 @@
|
||||
HorizontalAlignment="Stretch"
|
||||
IsVisible="{Binding ShowWindow^, FallbackValue=False}"
|
||||
VerticalAlignment="Stretch">
|
||||
<Grid Margin="100">
|
||||
<Grid Margin="100" Background="{DynamicResource ContainerBackgroundColor}">
|
||||
<local:FrequencyNavigation IsVisible="{Binding ShowWindow^, FallbackValue=False}" />
|
||||
</Grid>
|
||||
</Border>
|
||||
@@ -891,7 +919,7 @@
|
||||
HorizontalAlignment="Stretch"
|
||||
IsVisible="{Binding ShowWindow^, FallbackValue=False}"
|
||||
VerticalAlignment="Stretch">
|
||||
<Grid Margin="100">
|
||||
<Grid Margin="100" Background="{DynamicResource ContainerBackgroundColor}">
|
||||
<local:CommandPalette IsVisible="{Binding ShowWindow^, FallbackValue=False}" />
|
||||
</Grid>
|
||||
</Border>
|
||||
|
||||
Reference in New Issue
Block a user