Console ItemPreview, select item after delete
This commit is contained in:
@@ -117,6 +117,8 @@ public class App : IApplication
|
||||
|
||||
Thread.Sleep(10);
|
||||
}
|
||||
|
||||
Task.Run(async () => await _lifecycleService.ExitAsync()).Wait();
|
||||
}
|
||||
|
||||
private void Render() => _applicationContext.RenderEngine.Run();
|
||||
|
||||
110
src/ConsoleApp/FileTime.ConsoleUI.App/Controls/ItemPreviews.cs
Normal file
110
src/ConsoleApp/FileTime.ConsoleUI.App/Controls/ItemPreviews.cs
Normal file
@@ -0,0 +1,110 @@
|
||||
using FileTime.App.Core.Models;
|
||||
using FileTime.App.Core.Services;
|
||||
using FileTime.App.Core.ViewModels.ItemPreview;
|
||||
using FileTime.ConsoleUI.App.Styling;
|
||||
using TerminalUI.Controls;
|
||||
using TerminalUI.Extensions;
|
||||
using TerminalUI.Models;
|
||||
using TerminalUI.ViewExtensions;
|
||||
|
||||
namespace FileTime.ConsoleUI.App.Controls;
|
||||
|
||||
public class ItemPreviews
|
||||
{
|
||||
private readonly ITheme _theme;
|
||||
|
||||
public ItemPreviews(ITheme theme)
|
||||
{
|
||||
_theme = theme;
|
||||
}
|
||||
|
||||
public IView<IRootViewModel> View()
|
||||
{
|
||||
var view = new Grid<IRootViewModel>()
|
||||
{
|
||||
ChildInitializer =
|
||||
{
|
||||
new TextBlock<IRootViewModel>
|
||||
{
|
||||
TextAlignment = TextAlignment.Center,
|
||||
Text = "Empty",
|
||||
Foreground = _theme.ErrorForegroundColor,
|
||||
}.Setup(t => t.Bind(
|
||||
t,
|
||||
dc => dc.AppState.SelectedTab.Value.SelectedsChildren.Value.Count == 0,
|
||||
t => t.IsVisible,
|
||||
fallbackValue: false)),
|
||||
ElementPreviews()
|
||||
.WithDataContextBinding<IRootViewModel, IElementPreviewViewModel>(
|
||||
dc => (IElementPreviewViewModel)dc.ItemPreviewService.ItemPreview.Value
|
||||
)
|
||||
}
|
||||
};
|
||||
|
||||
return view;
|
||||
}
|
||||
|
||||
private IView<IElementPreviewViewModel> ElementPreviews()
|
||||
{
|
||||
var view = new Grid<IElementPreviewViewModel>
|
||||
{
|
||||
ChildInitializer =
|
||||
{
|
||||
new TextBlock<IElementPreviewViewModel>
|
||||
{
|
||||
TextAlignment = TextAlignment.Center,
|
||||
Text = "Don't know how to preview this item.",
|
||||
}.Setup(t => t.Bind(
|
||||
t,
|
||||
dc => dc.Mode == ItemPreviewMode.Unknown,
|
||||
t => t.IsVisible,
|
||||
v => v,
|
||||
fallbackValue: false)),
|
||||
new TextBlock<IElementPreviewViewModel>
|
||||
{
|
||||
TextAlignment = TextAlignment.Center,
|
||||
Text = "Empty",
|
||||
}.Setup(t => t.Bind(
|
||||
t,
|
||||
dc => dc.Mode == ItemPreviewMode.Empty,
|
||||
t => t.IsVisible,
|
||||
v => v,
|
||||
fallbackValue: false)),
|
||||
new Grid<IElementPreviewViewModel>
|
||||
{
|
||||
RowDefinitionsObject = "* Auto",
|
||||
ChildInitializer =
|
||||
{
|
||||
new TextBlock<IElementPreviewViewModel>()
|
||||
.Setup(t => t.Bind(
|
||||
t,
|
||||
dc => dc.TextContent,
|
||||
t => t.Text)),
|
||||
new TextBlock<IElementPreviewViewModel>
|
||||
{
|
||||
Extensions = {new GridPositionExtension(0, 1)}
|
||||
}.Setup(t => t.Bind(
|
||||
t,
|
||||
dc => dc.TextEncoding,
|
||||
t => t.Text,
|
||||
v => $"Encoding: {v}"))
|
||||
}
|
||||
}.Setup(t => t.Bind(
|
||||
t,
|
||||
dc => dc.Mode == ItemPreviewMode.Text,
|
||||
t => t.IsVisible,
|
||||
v => v,
|
||||
fallbackValue: false)),
|
||||
}
|
||||
};
|
||||
|
||||
view.Bind(
|
||||
view,
|
||||
dc => dc.Name == ElementPreviewViewModel.PreviewName,
|
||||
v => v.IsVisible,
|
||||
v => v
|
||||
);
|
||||
|
||||
return view;
|
||||
}
|
||||
}
|
||||
@@ -34,6 +34,7 @@ public class MainWindow
|
||||
private readonly FrequencyNavigation _frequencyNavigation;
|
||||
private readonly Dialogs _dialogs;
|
||||
private readonly Timeline _timeline;
|
||||
private readonly ItemPreviews _itemPreviews;
|
||||
private readonly Lazy<IView> _root;
|
||||
|
||||
|
||||
@@ -44,7 +45,8 @@ public class MainWindow
|
||||
CommandPalette commandPalette,
|
||||
FrequencyNavigation frequencyNavigation,
|
||||
Dialogs dialogs,
|
||||
Timeline timeline)
|
||||
Timeline timeline,
|
||||
ItemPreviews itemPreviews)
|
||||
{
|
||||
_rootViewModel = rootViewModel;
|
||||
_applicationContext = applicationContext;
|
||||
@@ -53,6 +55,7 @@ public class MainWindow
|
||||
_frequencyNavigation = frequencyNavigation;
|
||||
_dialogs = dialogs;
|
||||
_timeline = timeline;
|
||||
_itemPreviews = itemPreviews;
|
||||
_root = new Lazy<IView>(Initialize);
|
||||
}
|
||||
|
||||
@@ -141,7 +144,18 @@ public class MainWindow
|
||||
{
|
||||
ParentsItemsView().WithExtension(new GridPositionExtension(0, 0)),
|
||||
SelectedItemsView().WithExtension(new GridPositionExtension(1, 0)),
|
||||
SelectedsItemsView().WithExtension(new GridPositionExtension(2, 0)),
|
||||
new Grid<IRootViewModel>
|
||||
{
|
||||
Extensions =
|
||||
{
|
||||
new GridPositionExtension(2, 0)
|
||||
},
|
||||
ChildInitializer =
|
||||
{
|
||||
SelectedsItemsView(),
|
||||
_itemPreviews.View()
|
||||
}
|
||||
}
|
||||
}
|
||||
},
|
||||
new ItemsControl<IRootViewModel, string>
|
||||
@@ -347,15 +361,21 @@ public class MainWindow
|
||||
{
|
||||
var list = new ListView<IRootViewModel, IItemViewModel>
|
||||
{
|
||||
ListPadding = 8
|
||||
ListPadding = 8,
|
||||
ItemTemplate = item => ItemItemTemplate(item, new ItemViewRenderOptions())
|
||||
};
|
||||
|
||||
list.ItemTemplate = item => ItemItemTemplate(item, new ItemViewRenderOptions());
|
||||
|
||||
list.Bind(
|
||||
list,
|
||||
root => root.AppState.SelectedTab.Value.SelectedsChildren.Value,
|
||||
v => v.ItemsSource);
|
||||
dc => dc.AppState.SelectedTab.Value.SelectedsChildren.Value.Count > 0,
|
||||
l => l.IsVisible,
|
||||
fallbackValue: false);
|
||||
|
||||
list.Bind(
|
||||
list,
|
||||
dc => dc.AppState.SelectedTab.Value.SelectedsChildren.Value,
|
||||
v => v.ItemsSource,
|
||||
fallbackValue: null);
|
||||
|
||||
return list;
|
||||
}
|
||||
@@ -364,14 +384,13 @@ public class MainWindow
|
||||
{
|
||||
var list = new ListView<IRootViewModel, IItemViewModel>
|
||||
{
|
||||
ListPadding = 8
|
||||
ListPadding = 8,
|
||||
ItemTemplate = item => ItemItemTemplate(item, new ItemViewRenderOptions())
|
||||
};
|
||||
|
||||
list.ItemTemplate = item => ItemItemTemplate(item, new ItemViewRenderOptions());
|
||||
|
||||
list.Bind(
|
||||
list,
|
||||
root => root.AppState.SelectedTab.Value.ParentsChildren.Value,
|
||||
dc => dc.AppState.SelectedTab.Value.ParentsChildren.Value,
|
||||
v => v.ItemsSource);
|
||||
|
||||
return list;
|
||||
|
||||
@@ -1,5 +1,6 @@
|
||||
using DeclarativeProperty;
|
||||
using FileTime.App.CommandPalette.ViewModels;
|
||||
using FileTime.App.Core.Services;
|
||||
using FileTime.App.Core.ViewModels;
|
||||
using FileTime.App.Core.ViewModels.Timeline;
|
||||
using FileTime.App.FrequencyNavigation.ViewModels;
|
||||
@@ -17,6 +18,7 @@ public class RootViewModel : IRootViewModel
|
||||
public IConsoleAppState AppState { get; }
|
||||
public ICommandPaletteViewModel CommandPalette { get; }
|
||||
public IFrequencyNavigationViewModel FrequencyNavigation { get; }
|
||||
public IItemPreviewService ItemPreviewService { get; }
|
||||
public IDialogService DialogService { get; }
|
||||
public ITimelineViewModel TimelineViewModel { get; }
|
||||
public IDeclarativeProperty<VolumeSizeInfo?> VolumeSizeInfo { get;}
|
||||
@@ -29,7 +31,8 @@ public class RootViewModel : IRootViewModel
|
||||
ICommandPaletteViewModel commandPalette,
|
||||
IDialogService dialogService,
|
||||
ITimelineViewModel timelineViewModel,
|
||||
IFrequencyNavigationViewModel frequencyNavigation)
|
||||
IFrequencyNavigationViewModel frequencyNavigation,
|
||||
IItemPreviewService itemPreviewService)
|
||||
{
|
||||
AppState = appState;
|
||||
PossibleCommands = possibleCommands;
|
||||
@@ -37,6 +40,7 @@ public class RootViewModel : IRootViewModel
|
||||
DialogService = dialogService;
|
||||
TimelineViewModel = timelineViewModel;
|
||||
FrequencyNavigation = frequencyNavigation;
|
||||
ItemPreviewService = itemPreviewService;
|
||||
|
||||
DialogService.ReadInput.PropertyChanged += (o, e) =>
|
||||
{
|
||||
|
||||
@@ -45,6 +45,7 @@ public static class Startup
|
||||
services.TryAddSingleton<Dialogs>();
|
||||
services.TryAddSingleton<Timeline>();
|
||||
services.TryAddSingleton<FrequencyNavigation>();
|
||||
services.TryAddSingleton<ItemPreviews>();
|
||||
return services;
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user