ConsoleUI FrequencyNavigation

This commit is contained in:
2023-08-16 22:35:17 +02:00
parent 3c996f0c20
commit 92726f1af9
10 changed files with 156 additions and 3 deletions

View File

@@ -1,5 +1,4 @@
using DeclarativeProperty; using DeclarativeProperty;
using FileTime.App.Core.Models;
using FileTime.App.Core.ViewModels; using FileTime.App.Core.ViewModels;
using FileTime.App.FuzzyPanel; using FileTime.App.FuzzyPanel;
using GeneralInputKey; using GeneralInputKey;

View File

@@ -10,6 +10,7 @@
<ItemGroup> <ItemGroup>
<ProjectReference Include="..\..\AppCommon\FileTime.App.CommandPalette.Abstractions\FileTime.App.CommandPalette.Abstractions.csproj" /> <ProjectReference Include="..\..\AppCommon\FileTime.App.CommandPalette.Abstractions\FileTime.App.CommandPalette.Abstractions.csproj" />
<ProjectReference Include="..\..\AppCommon\FileTime.App.Core.Abstraction\FileTime.App.Core.Abstraction.csproj" /> <ProjectReference Include="..\..\AppCommon\FileTime.App.Core.Abstraction\FileTime.App.Core.Abstraction.csproj" />
<ProjectReference Include="..\..\AppCommon\FileTime.App.FrequencyNavigation.Abstractions\FileTime.App.FrequencyNavigation.Abstractions.csproj" />
<ProjectReference Include="..\..\Library\TerminalUI\TerminalUI.csproj" /> <ProjectReference Include="..\..\Library\TerminalUI\TerminalUI.csproj" />
</ItemGroup> </ItemGroup>

View File

@@ -2,6 +2,7 @@
using FileTime.App.CommandPalette.ViewModels; using FileTime.App.CommandPalette.ViewModels;
using FileTime.App.Core.ViewModels; using FileTime.App.Core.ViewModels;
using FileTime.App.Core.ViewModels.Timeline; using FileTime.App.Core.ViewModels.Timeline;
using FileTime.App.FrequencyNavigation.ViewModels;
using FileTime.ConsoleUI.App.Services; using FileTime.ConsoleUI.App.Services;
using FileTime.Core.Interactions; using FileTime.Core.Interactions;
using FileTime.Core.Models; using FileTime.Core.Models;
@@ -18,5 +19,6 @@ public interface IRootViewModel
IDialogService DialogService { get; } IDialogService DialogService { get; }
ITimelineViewModel TimelineViewModel { get; } ITimelineViewModel TimelineViewModel { get; }
IDeclarativeProperty<VolumeSizeInfo?> VolumeSizeInfo { get; } IDeclarativeProperty<VolumeSizeInfo?> VolumeSizeInfo { get; }
IFrequencyNavigationViewModel FrequencyNavigation { get; }
event Action<IInputElement>? FocusReadInputElement; event Action<IInputElement>? FocusReadInputElement;
} }

View File

@@ -28,6 +28,7 @@ public class CommandPalette
if (k.Key == Keys.Escape) if (k.Key == Keys.Escape)
{ {
_commandPaletteService.CloseCommandPalette(); _commandPaletteService.CloseCommandPalette();
sender.Text = String.Empty;
} }
if (!k.Handled) if (!k.Handled)

View File

@@ -0,0 +1,140 @@
using FileTime.App.FrequencyNavigation.Services;
using FileTime.ConsoleUI.App.Styling;
using GeneralInputKey;
using TerminalUI.Controls;
using TerminalUI.Extensions;
using TerminalUI.Models;
using TerminalUI.ViewExtensions;
namespace FileTime.ConsoleUI.App.Controls;
public class FrequencyNavigation
{
private readonly ITheme _theme;
private readonly IFrequencyNavigationService _frequencyNavigationService;
public FrequencyNavigation(ITheme theme, IFrequencyNavigationService frequencyNavigationService)
{
_theme = theme;
_frequencyNavigationService = frequencyNavigationService;
}
public IView<IRootViewModel> View()
{
var inputTextBox = new TextBox<IRootViewModel>()
.WithKeyHandler((sender, k) =>
{
if (k.Key == Keys.Escape)
{
_frequencyNavigationService.CloseNavigationWindow();
sender.Text = String.Empty;
}
if (!k.Handled)
{
sender.DataContext?.FrequencyNavigation.HandleKeyDown(k);
}
if (!k.Handled)
{
sender.DataContext?.FrequencyNavigation.HandleKeyUp(k);
}
if (k.Key == Keys.Enter)
{
sender.Text = String.Empty;
}
})
.WithTextHandler((sender, text) =>
{
if (sender.DataContext is not null)
{
sender.DataContext.FrequencyNavigation.SearchText = text;
}
});;
var root = new Border<IRootViewModel>
{
Margin = 5,
Padding = 1,
MaxWidth = 50,
Content = new Grid<IRootViewModel>
{
RowDefinitionsObject = "Auto *",
ChildInitializer =
{
new Border<IRootViewModel>
{
Margin = new Thickness(0, 0, 0, 1),
Content = inputTextBox
},
new ListView<IRootViewModel, string>
{
Extensions =
{
new GridPositionExtension(0, 1)
},
ItemTemplate = item =>
{
var root = new Grid<string>
{
ChildInitializer =
{
new TextBlock<string>()
.Setup(t => t.Bind(
t,
d => d,
t => t.Text)),
}
};
item.Bind(
item.Parent,
d => d.FrequencyNavigation.SelectedItem == item.DataContext ? _theme.ListViewItemTheme.SelectedBackgroundColor : null,
t => t.Background
);
item.Bind(
item.Parent,
d => d.FrequencyNavigation.SelectedItem == item.DataContext ? _theme.ListViewItemTheme.SelectedForegroundColor : null,
t => t.Foreground
);
return root;
}
}.Setup(t => t.Bind(
t,
d => d.FrequencyNavigation.FilteredMatches,
t => t.ItemsSource
))
.Setup(t => t.Bind(
t,
d => d.FrequencyNavigation.SelectedItem,
t => t.SelectedItem
))
}
}
};
root.WithPropertyChangedHandler(r => r.IsVisible,
(_, isVisible) =>
{
if (isVisible)
{
inputTextBox.Focus();
}
else
{
inputTextBox.UnFocus();
}
});
root.Bind(
root,
d => d.FrequencyNavigation.ShowWindow.Value,
t => t.IsVisible,
r => r);
return root;
}
}

View File

@@ -21,6 +21,7 @@
<ItemGroup> <ItemGroup>
<ProjectReference Include="..\..\AppCommon\FileTime.App.Core\FileTime.App.Core.csproj" /> <ProjectReference Include="..\..\AppCommon\FileTime.App.Core\FileTime.App.Core.csproj" />
<ProjectReference Include="..\..\AppCommon\FileTime.App.FrequencyNavigation\FileTime.App.FrequencyNavigation.csproj" />
<ProjectReference Include="..\..\Library\TerminalUI\TerminalUI.csproj" /> <ProjectReference Include="..\..\Library\TerminalUI\TerminalUI.csproj" />
<ProjectReference Include="..\FileTime.ConsoleUI.App.Abstractions\FileTime.ConsoleUI.App.Abstractions.csproj" /> <ProjectReference Include="..\FileTime.ConsoleUI.App.Abstractions\FileTime.ConsoleUI.App.Abstractions.csproj" />
</ItemGroup> </ItemGroup>

View File

@@ -31,6 +31,7 @@ public class MainWindow
private readonly IApplicationContext _applicationContext; private readonly IApplicationContext _applicationContext;
private readonly ITheme _theme; private readonly ITheme _theme;
private readonly CommandPalette _commandPalette; private readonly CommandPalette _commandPalette;
private readonly FrequencyNavigation _frequencyNavigation;
private readonly Dialogs _dialogs; private readonly Dialogs _dialogs;
private readonly Timeline _timeline; private readonly Timeline _timeline;
private readonly Lazy<IView> _root; private readonly Lazy<IView> _root;
@@ -41,6 +42,7 @@ public class MainWindow
IApplicationContext applicationContext, IApplicationContext applicationContext,
ITheme theme, ITheme theme,
CommandPalette commandPalette, CommandPalette commandPalette,
FrequencyNavigation frequencyNavigation,
Dialogs dialogs, Dialogs dialogs,
Timeline timeline) Timeline timeline)
{ {
@@ -48,6 +50,7 @@ public class MainWindow
_applicationContext = applicationContext; _applicationContext = applicationContext;
_theme = theme; _theme = theme;
_commandPalette = commandPalette; _commandPalette = commandPalette;
_frequencyNavigation = frequencyNavigation;
_dialogs = dialogs; _dialogs = dialogs;
_timeline = timeline; _timeline = timeline;
_root = new Lazy<IView>(Initialize); _root = new Lazy<IView>(Initialize);
@@ -70,6 +73,7 @@ public class MainWindow
{ {
MainContent(), MainContent(),
_commandPalette.View(), _commandPalette.View(),
_frequencyNavigation.View(),
_dialogs.View(), _dialogs.View(),
} }
}; };

View File

@@ -2,6 +2,7 @@
using FileTime.App.CommandPalette.ViewModels; using FileTime.App.CommandPalette.ViewModels;
using FileTime.App.Core.ViewModels; using FileTime.App.Core.ViewModels;
using FileTime.App.Core.ViewModels.Timeline; using FileTime.App.Core.ViewModels.Timeline;
using FileTime.App.FrequencyNavigation.ViewModels;
using FileTime.ConsoleUI.App.Services; using FileTime.ConsoleUI.App.Services;
using FileTime.Core.Interactions; using FileTime.Core.Interactions;
using FileTime.Core.Models; using FileTime.Core.Models;
@@ -15,6 +16,7 @@ public class RootViewModel : IRootViewModel
public IPossibleCommandsViewModel PossibleCommands { get; } public IPossibleCommandsViewModel PossibleCommands { get; }
public IConsoleAppState AppState { get; } public IConsoleAppState AppState { get; }
public ICommandPaletteViewModel CommandPalette { get; } public ICommandPaletteViewModel CommandPalette { get; }
public IFrequencyNavigationViewModel FrequencyNavigation { get; }
public IDialogService DialogService { get; } public IDialogService DialogService { get; }
public ITimelineViewModel TimelineViewModel { get; } public ITimelineViewModel TimelineViewModel { get; }
public IDeclarativeProperty<VolumeSizeInfo?> VolumeSizeInfo { get;} public IDeclarativeProperty<VolumeSizeInfo?> VolumeSizeInfo { get;}
@@ -26,13 +28,15 @@ public class RootViewModel : IRootViewModel
IPossibleCommandsViewModel possibleCommands, IPossibleCommandsViewModel possibleCommands,
ICommandPaletteViewModel commandPalette, ICommandPaletteViewModel commandPalette,
IDialogService dialogService, IDialogService dialogService,
ITimelineViewModel timelineViewModel) ITimelineViewModel timelineViewModel,
IFrequencyNavigationViewModel frequencyNavigation)
{ {
AppState = appState; AppState = appState;
PossibleCommands = possibleCommands; PossibleCommands = possibleCommands;
CommandPalette = commandPalette; CommandPalette = commandPalette;
DialogService = dialogService; DialogService = dialogService;
TimelineViewModel = timelineViewModel; TimelineViewModel = timelineViewModel;
FrequencyNavigation = frequencyNavigation;
DialogService.ReadInput.PropertyChanged += (o, e) => DialogService.ReadInput.PropertyChanged += (o, e) =>
{ {

View File

@@ -38,6 +38,7 @@ public static class Startup
services.TryAddSingleton<CommandPalette>(); services.TryAddSingleton<CommandPalette>();
services.TryAddSingleton<Dialogs>(); services.TryAddSingleton<Dialogs>();
services.TryAddSingleton<Timeline>(); services.TryAddSingleton<Timeline>();
services.TryAddSingleton<FrequencyNavigation>();
return services; return services;
} }
} }

View File

@@ -7,7 +7,7 @@
<TrimMode>copyused</TrimMode> <TrimMode>copyused</TrimMode>
<BuiltInComInteropSupport>true</BuiltInComInteropSupport> <BuiltInComInteropSupport>true</BuiltInComInteropSupport>
<ApplicationIcon>filetime.ico</ApplicationIcon> <ApplicationIcon>filetime.ico</ApplicationIcon>
<Version>0.2.1</Version> <Version>0.2.2</Version>
</PropertyGroup> </PropertyGroup>
<PropertyGroup> <PropertyGroup>