ConsoleUI FrequencyNavigation
This commit is contained in:
@@ -28,6 +28,7 @@ public class CommandPalette
|
||||
if (k.Key == Keys.Escape)
|
||||
{
|
||||
_commandPaletteService.CloseCommandPalette();
|
||||
sender.Text = String.Empty;
|
||||
}
|
||||
|
||||
if (!k.Handled)
|
||||
|
||||
@@ -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;
|
||||
}
|
||||
}
|
||||
@@ -21,6 +21,7 @@
|
||||
|
||||
<ItemGroup>
|
||||
<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="..\FileTime.ConsoleUI.App.Abstractions\FileTime.ConsoleUI.App.Abstractions.csproj" />
|
||||
</ItemGroup>
|
||||
|
||||
@@ -31,6 +31,7 @@ public class MainWindow
|
||||
private readonly IApplicationContext _applicationContext;
|
||||
private readonly ITheme _theme;
|
||||
private readonly CommandPalette _commandPalette;
|
||||
private readonly FrequencyNavigation _frequencyNavigation;
|
||||
private readonly Dialogs _dialogs;
|
||||
private readonly Timeline _timeline;
|
||||
private readonly Lazy<IView> _root;
|
||||
@@ -41,6 +42,7 @@ public class MainWindow
|
||||
IApplicationContext applicationContext,
|
||||
ITheme theme,
|
||||
CommandPalette commandPalette,
|
||||
FrequencyNavigation frequencyNavigation,
|
||||
Dialogs dialogs,
|
||||
Timeline timeline)
|
||||
{
|
||||
@@ -48,6 +50,7 @@ public class MainWindow
|
||||
_applicationContext = applicationContext;
|
||||
_theme = theme;
|
||||
_commandPalette = commandPalette;
|
||||
_frequencyNavigation = frequencyNavigation;
|
||||
_dialogs = dialogs;
|
||||
_timeline = timeline;
|
||||
_root = new Lazy<IView>(Initialize);
|
||||
@@ -70,6 +73,7 @@ public class MainWindow
|
||||
{
|
||||
MainContent(),
|
||||
_commandPalette.View(),
|
||||
_frequencyNavigation.View(),
|
||||
_dialogs.View(),
|
||||
}
|
||||
};
|
||||
|
||||
@@ -2,6 +2,7 @@
|
||||
using FileTime.App.CommandPalette.ViewModels;
|
||||
using FileTime.App.Core.ViewModels;
|
||||
using FileTime.App.Core.ViewModels.Timeline;
|
||||
using FileTime.App.FrequencyNavigation.ViewModels;
|
||||
using FileTime.ConsoleUI.App.Services;
|
||||
using FileTime.Core.Interactions;
|
||||
using FileTime.Core.Models;
|
||||
@@ -15,6 +16,7 @@ public class RootViewModel : IRootViewModel
|
||||
public IPossibleCommandsViewModel PossibleCommands { get; }
|
||||
public IConsoleAppState AppState { get; }
|
||||
public ICommandPaletteViewModel CommandPalette { get; }
|
||||
public IFrequencyNavigationViewModel FrequencyNavigation { get; }
|
||||
public IDialogService DialogService { get; }
|
||||
public ITimelineViewModel TimelineViewModel { get; }
|
||||
public IDeclarativeProperty<VolumeSizeInfo?> VolumeSizeInfo { get;}
|
||||
@@ -26,13 +28,15 @@ public class RootViewModel : IRootViewModel
|
||||
IPossibleCommandsViewModel possibleCommands,
|
||||
ICommandPaletteViewModel commandPalette,
|
||||
IDialogService dialogService,
|
||||
ITimelineViewModel timelineViewModel)
|
||||
ITimelineViewModel timelineViewModel,
|
||||
IFrequencyNavigationViewModel frequencyNavigation)
|
||||
{
|
||||
AppState = appState;
|
||||
PossibleCommands = possibleCommands;
|
||||
CommandPalette = commandPalette;
|
||||
DialogService = dialogService;
|
||||
TimelineViewModel = timelineViewModel;
|
||||
FrequencyNavigation = frequencyNavigation;
|
||||
|
||||
DialogService.ReadInput.PropertyChanged += (o, e) =>
|
||||
{
|
||||
|
||||
@@ -38,6 +38,7 @@ public static class Startup
|
||||
services.TryAddSingleton<CommandPalette>();
|
||||
services.TryAddSingleton<Dialogs>();
|
||||
services.TryAddSingleton<Timeline>();
|
||||
services.TryAddSingleton<FrequencyNavigation>();
|
||||
return services;
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user