diff --git a/src/AppCommon/FileTime.App.Core.Abstraction/ViewModels/ITabViewModel.cs b/src/AppCommon/FileTime.App.Core.Abstraction/ViewModels/ITabViewModel.cs index 2e9ef9f..9c85c09 100644 --- a/src/AppCommon/FileTime.App.Core.Abstraction/ViewModels/ITabViewModel.cs +++ b/src/AppCommon/FileTime.App.Core.Abstraction/ViewModels/ITabViewModel.cs @@ -19,6 +19,7 @@ public interface ITabViewModel : IInitable, IDisposable IDeclarativeProperty> MarkedItems { get; } IDeclarativeProperty> SelectedsChildren { get; } IDeclarativeProperty> ParentsChildren { get; } + IDeclarativeProperty CurrentSelectedItemIndex { get; set; } void ClearMarkedItems(); void RemoveMarkedItem(FullName fullName); diff --git a/src/AppCommon/FileTime.App.Core/ViewModels/TabViewModel.cs b/src/AppCommon/FileTime.App.Core/ViewModels/TabViewModel.cs index a7145ef..35a13b6 100644 --- a/src/AppCommon/FileTime.App.Core/ViewModels/TabViewModel.cs +++ b/src/AppCommon/FileTime.App.Core/ViewModels/TabViewModel.cs @@ -39,6 +39,7 @@ public partial class TabViewModel : ITabViewModel public IDeclarativeProperty CurrentLocation { get; private set; } public IDeclarativeProperty CurrentSelectedItem { get; private set; } + public IDeclarativeProperty CurrentSelectedItemIndex { get; set; } public IDeclarativeProperty CurrentSelectedItemAsContainer { get; private set; } public IDeclarativeProperty?> CurrentItems { get; private set; } public IDeclarativeProperty> MarkedItems { get; } @@ -98,6 +99,25 @@ public partial class TabViewModel : ITabViewModel } ); + CurrentSelectedItemIndex = DeclarativePropertyHelpers.CombineLatest( + tab.CurrentSelectedItem, + CurrentItems.Watch, IItemViewModel>(), + (currentSelectedItem, currentItems) => + { + if (currentItems is null || currentSelectedItem is null) + return Task.FromResult(-1); + + for (var i = 0; i < currentItems.Count; i++) + { + if (currentItems[i].BaseItem?.FullName?.Path == currentSelectedItem?.Path.Path) + { + return Task.FromResult(i); + } + } + + return Task.FromResult(-1); + }); + CurrentSelectedItem.Subscribe((v) => { _refreshSmoothnessCalculator.RegisterChange(); diff --git a/src/ConsoleApp/FileTime.ConsoleUI.App/MainWindow.cs b/src/ConsoleApp/FileTime.ConsoleUI.App/MainWindow.cs index c8eb1fd..beb9fad 100644 --- a/src/ConsoleApp/FileTime.ConsoleUI.App/MainWindow.cs +++ b/src/ConsoleApp/FileTime.ConsoleUI.App/MainWindow.cs @@ -11,6 +11,7 @@ using TerminalUI.Color; using TerminalUI.Controls; using TerminalUI.Extensions; using TerminalUI.Models; +using TerminalUI.TextFormat; using TerminalUI.ViewExtensions; namespace FileTime.ConsoleUI.App; @@ -215,43 +216,47 @@ public class MainWindow } }, _timeline.View().WithExtension(new GridPositionExtension(0, 4)), - new Grid + StatusLine().WithExtension(new GridPositionExtension(0, 5)), + } + }; + + private IView StatusLine() + => new Grid + { + ColumnDefinitionsObject = "* Auto", + ChildInitializer = + { + new StackPanel { - ColumnDefinitionsObject = "* Auto", - Extensions = - { - new GridPositionExtension(0, 5) - }, + Orientation = Orientation.Horizontal, ChildInitializer = { - new StackPanel - { - Orientation = Orientation.Horizontal, - ChildInitializer = - { - new TextBlock - { - Margin = "0 0 1 0", - } - .Setup(t => t.Bind( - t, - dc => dc.AppState.SelectedTab.Value.CurrentSelectedItem.Value.Attributes, - tb => tb.Text)), - new TextBlock - { - Margin = "0 0 1 0", - } - .Setup(t => t.Bind( - t, - dc => dc.AppState.SelectedTab.Value.CurrentSelectedItem.Value.ModifiedAt, - tb => tb.Text, - v => v.ToString())) - } - }, new TextBlock { - Extensions = {new GridPositionExtension(1, 0)} + Margin = "0 0 1 0", } + .Setup(t => t.Bind( + t, + dc => dc.AppState.SelectedTab.Value.CurrentSelectedItem.Value.Attributes, + tb => tb.Text)), + new TextBlock + { + Margin = "0 0 1 0", + } + .Setup(t => t.Bind( + t, + dc => dc.AppState.SelectedTab.Value.CurrentSelectedItem.Value.ModifiedAt, + tb => tb.Text, + v => v.ToString())) + } + }, + new StackPanel() + { + Orientation = Orientation.Horizontal, + Extensions = {new GridPositionExtension(1, 0)}, + ChildInitializer = + { + new TextBlock() .Setup(t => { t.Bind( @@ -268,9 +273,54 @@ public class MainWindow ? $"{ByteSize.FromBytes(v.Value.FreeSize)} / {ByteSize.FromBytes(v.Value.TotalSize)} free" : string.Empty ); - }) + }), + new StackPanel + { + Margin = "2 0 0 0", + Orientation = Orientation.Horizontal, + ChildInitializer = + { + new TextBlock() + .Setup(t => t.Bind( + t, + dc => dc.AppState.SelectedTab.Value.CurrentSelectedItemIndex.Value, + tb => tb.Text, + v => v is null || v < 0 ? "?" : $"{v + 1}")), + new TextBlock + { + Foreground = _theme.MarkedItemForegroundColor, + TextFormat = new AnsiFormat + { + IsBold = true + } + } + .Setup(t => + { + t.Bind( + t, + dc => dc.AppState.SelectedTab.Value.MarkedItems.Value.Count, + tb => tb.Text, + v => $"/{v}"); + + t.Bind( + t, + dc => dc.AppState.SelectedTab.Value.MarkedItems.Value.Count > 0, + s => s.IsVisible); + }), + new TextBlock() + .Setup(t => t.Bind( + t, + dc => dc.AppState.SelectedTab.Value.CurrentItems.Value.Count, + tb => tb.Text, + v => $"/{v}")), + } + } + .Setup(s => s.Bind( + s, + dc => dc.AppState.SelectedTab.Value.CurrentItems.Value.Count > 0, + s => s.IsVisible)), } - }, + } } };