Console: Selected and marked items in statusbar

This commit is contained in:
2023-08-19 21:49:03 +02:00
parent aa16b49b4d
commit ac2a34d897
3 changed files with 104 additions and 33 deletions

View File

@@ -19,6 +19,7 @@ public interface ITabViewModel : IInitable<ITab, int>, IDisposable
IDeclarativeProperty<ObservableCollection<FullName>> MarkedItems { get; } IDeclarativeProperty<ObservableCollection<FullName>> MarkedItems { get; }
IDeclarativeProperty<ObservableCollection<IItemViewModel>> SelectedsChildren { get; } IDeclarativeProperty<ObservableCollection<IItemViewModel>> SelectedsChildren { get; }
IDeclarativeProperty<ObservableCollection<IItemViewModel>> ParentsChildren { get; } IDeclarativeProperty<ObservableCollection<IItemViewModel>> ParentsChildren { get; }
IDeclarativeProperty<int?> CurrentSelectedItemIndex { get; set; }
void ClearMarkedItems(); void ClearMarkedItems();
void RemoveMarkedItem(FullName fullName); void RemoveMarkedItem(FullName fullName);

View File

@@ -39,6 +39,7 @@ public partial class TabViewModel : ITabViewModel
public IDeclarativeProperty<IContainer?> CurrentLocation { get; private set; } public IDeclarativeProperty<IContainer?> CurrentLocation { get; private set; }
public IDeclarativeProperty<IItemViewModel?> CurrentSelectedItem { get; private set; } public IDeclarativeProperty<IItemViewModel?> CurrentSelectedItem { get; private set; }
public IDeclarativeProperty<int?> CurrentSelectedItemIndex { get; set; }
public IDeclarativeProperty<IContainerViewModel?> CurrentSelectedItemAsContainer { get; private set; } public IDeclarativeProperty<IContainerViewModel?> CurrentSelectedItemAsContainer { get; private set; }
public IDeclarativeProperty<ObservableCollection<IItemViewModel>?> CurrentItems { get; private set; } public IDeclarativeProperty<ObservableCollection<IItemViewModel>?> CurrentItems { get; private set; }
public IDeclarativeProperty<ObservableCollection<FullName>> MarkedItems { get; } public IDeclarativeProperty<ObservableCollection<FullName>> MarkedItems { get; }
@@ -98,6 +99,25 @@ public partial class TabViewModel : ITabViewModel
} }
); );
CurrentSelectedItemIndex = DeclarativePropertyHelpers.CombineLatest(
tab.CurrentSelectedItem,
CurrentItems.Watch<ObservableCollection<IItemViewModel>, IItemViewModel>(),
(currentSelectedItem, currentItems) =>
{
if (currentItems is null || currentSelectedItem is null)
return Task.FromResult<int?>(-1);
for (var i = 0; i < currentItems.Count; i++)
{
if (currentItems[i].BaseItem?.FullName?.Path == currentSelectedItem?.Path.Path)
{
return Task.FromResult<int?>(i);
}
}
return Task.FromResult<int?>(-1);
});
CurrentSelectedItem.Subscribe((v) => CurrentSelectedItem.Subscribe((v) =>
{ {
_refreshSmoothnessCalculator.RegisterChange(); _refreshSmoothnessCalculator.RegisterChange();

View File

@@ -11,6 +11,7 @@ using TerminalUI.Color;
using TerminalUI.Controls; using TerminalUI.Controls;
using TerminalUI.Extensions; using TerminalUI.Extensions;
using TerminalUI.Models; using TerminalUI.Models;
using TerminalUI.TextFormat;
using TerminalUI.ViewExtensions; using TerminalUI.ViewExtensions;
namespace FileTime.ConsoleUI.App; namespace FileTime.ConsoleUI.App;
@@ -215,43 +216,47 @@ public class MainWindow
} }
}, },
_timeline.View().WithExtension(new GridPositionExtension(0, 4)), _timeline.View().WithExtension(new GridPositionExtension(0, 4)),
new Grid<IRootViewModel> StatusLine().WithExtension(new GridPositionExtension(0, 5)),
}
};
private IView<IRootViewModel> StatusLine()
=> new Grid<IRootViewModel>
{
ColumnDefinitionsObject = "* Auto",
ChildInitializer =
{
new StackPanel<IRootViewModel>
{ {
ColumnDefinitionsObject = "* Auto", Orientation = Orientation.Horizontal,
Extensions =
{
new GridPositionExtension(0, 5)
},
ChildInitializer = ChildInitializer =
{ {
new StackPanel<IRootViewModel>
{
Orientation = Orientation.Horizontal,
ChildInitializer =
{
new TextBlock<IRootViewModel>
{
Margin = "0 0 1 0",
}
.Setup(t => t.Bind(
t,
dc => dc.AppState.SelectedTab.Value.CurrentSelectedItem.Value.Attributes,
tb => tb.Text)),
new TextBlock<IRootViewModel>
{
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<IRootViewModel> new TextBlock<IRootViewModel>
{ {
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<IRootViewModel>
{
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<IRootViewModel>()
{
Orientation = Orientation.Horizontal,
Extensions = {new GridPositionExtension(1, 0)},
ChildInitializer =
{
new TextBlock<IRootViewModel>()
.Setup(t => .Setup(t =>
{ {
t.Bind( t.Bind(
@@ -268,9 +273,54 @@ public class MainWindow
? $"{ByteSize.FromBytes(v.Value.FreeSize)} / {ByteSize.FromBytes(v.Value.TotalSize)} free" ? $"{ByteSize.FromBytes(v.Value.FreeSize)} / {ByteSize.FromBytes(v.Value.TotalSize)} free"
: string.Empty : string.Empty
); );
}) }),
new StackPanel<IRootViewModel>
{
Margin = "2 0 0 0",
Orientation = Orientation.Horizontal,
ChildInitializer =
{
new TextBlock<IRootViewModel>()
.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<IRootViewModel>
{
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<IRootViewModel>()
.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)),
} }
}, }
} }
}; };