Order in Tab instead TabViewModel, Utf8 char handling

This commit is contained in:
2023-08-16 09:04:36 +02:00
parent d175c7bf7e
commit 3ca2fc181f
21 changed files with 286 additions and 189 deletions

View File

@@ -62,16 +62,16 @@ public class Timeline
{
ForegroundColor = _progressBarTheme?.ForegroundColor,
UnfilledForeground = _progressBarTheme?.UnfilledForeground,
FilledCharacter = '\u2594',
UnfilledCharacter = '\u2594',
Fraction1Per8Character = '\u2594',
Fraction2Per8Character = '\u2594',
Fraction3Per8Character = '\u2594',
Fraction4Per8Character = '\u2594',
Fraction5Per8Character = '\u2594',
Fraction6Per8Character = '\u2594',
Fraction7Per8Character = '\u2594',
FractionFull = '\u2594',
FilledCharacter = new('\u2594', '█'),
UnfilledCharacter = new('\u2594', '█'),
Fraction1Per8Character = new('\u2594', ' '),
Fraction2Per8Character = new('\u2594', ' '),
Fraction3Per8Character = new('\u2594', ' '),
Fraction4Per8Character = new('\u2594', ' '),
Fraction5Per8Character = new('\u2594', '█'),
Fraction6Per8Character = new('\u2594', '█'),
Fraction7Per8Character = new('\u2594', '█'),
FractionFull = new('\u2594', '█'),
},
Extensions =
{

View File

@@ -1,8 +1,11 @@
using FileTime.App.Core.Models.Enums;
using System.Globalization;
using FileTime.App.Core.Models.Enums;
using FileTime.App.Core.ViewModels;
using FileTime.ConsoleUI.App.Controls;
using FileTime.ConsoleUI.App.Styling;
using FileTime.Core.Enums;
using FileTime.Core.Models;
using Humanizer.Bytes;
using TerminalUI;
using TerminalUI.Color;
using TerminalUI.Controls;
@@ -14,6 +17,16 @@ namespace FileTime.ConsoleUI.App;
public class MainWindow
{
private readonly struct ItemViewRenderOptions
{
public readonly bool ShowAttributes;
public ItemViewRenderOptions(bool showAttributes = false)
{
ShowAttributes = showAttributes;
}
}
private readonly IRootViewModel _rootViewModel;
private readonly IApplicationContext _applicationContext;
private readonly ITheme _theme;
@@ -251,30 +264,11 @@ public class MainWindow
{
var list = new ListView<IRootViewModel, IItemViewModel>
{
ListPadding = 8
ListPadding = 8,
Margin = "1 0 1 0"
};
list.ItemTemplate = item =>
{
var textBlock = item.CreateChild<TextBlock<IItemViewModel>>();
textBlock.Bind(
textBlock,
dc => dc == null ? string.Empty : dc.DisplayNameText,
tb => tb.Text
);
textBlock.Bind(
textBlock,
dc => dc == null ? _theme.DefaultForegroundColor : ToForegroundColor(dc.ViewMode.Value, dc.BaseItem.Type),
tb => tb.Foreground
);
textBlock.Bind(
textBlock,
dc => dc == null ? _theme.DefaultBackgroundColor : ToBackgroundColor(dc.ViewMode.Value, dc.BaseItem.Type),
tb => tb.Background
);
return textBlock;
};
list.ItemTemplate = item => ItemItemTemplate(item, new ItemViewRenderOptions(true));
list.Bind(
list,
@@ -296,27 +290,7 @@ public class MainWindow
ListPadding = 8
};
list.ItemTemplate = item =>
{
var textBlock = item.CreateChild<TextBlock<IItemViewModel>>();
textBlock.Bind(
textBlock,
dc => dc == null ? string.Empty : dc.DisplayNameText,
tb => tb.Text
);
textBlock.Bind(
textBlock,
dc => dc == null ? _theme.DefaultForegroundColor : ToForegroundColor(dc.ViewMode.Value, dc.BaseItem.Type),
tb => tb.Foreground
);
textBlock.Bind(
textBlock,
dc => dc == null ? _theme.DefaultBackgroundColor : ToBackgroundColor(dc.ViewMode.Value, dc.BaseItem.Type),
tb => tb.Background
);
return textBlock;
};
list.ItemTemplate = item => ItemItemTemplate(item, new ItemViewRenderOptions());
list.Bind(
list,
@@ -333,28 +307,7 @@ public class MainWindow
ListPadding = 8
};
list.ItemTemplate = item =>
{
var textBlock = item.CreateChild<TextBlock<IItemViewModel>>();
textBlock.Bind(
textBlock,
dc => dc == null ? string.Empty : dc.DisplayNameText,
tb => tb.Text
);
textBlock.Bind(
textBlock,
dc => dc == null ? _theme.DefaultForegroundColor : ToForegroundColor(dc.ViewMode.Value, dc.BaseItem.Type),
tb => tb.Foreground,
v => v
);
textBlock.Bind(
textBlock,
dc => dc == null ? _theme.DefaultBackgroundColor : ToBackgroundColor(dc.ViewMode.Value, dc.BaseItem.Type),
tb => tb.Background
);
return textBlock;
};
list.ItemTemplate = item => ItemItemTemplate(item, new ItemViewRenderOptions());
list.Bind(
list,
@@ -364,6 +317,98 @@ public class MainWindow
return list;
}
private IView<IItemViewModel> ItemItemTemplate(
ListViewItem<IItemViewModel, IRootViewModel> item,
ItemViewRenderOptions options
)
{
var root = new Grid<IItemViewModel>
{
ChildInitializer =
{
new Rectangle<IItemViewModel>(),
new Grid<IItemViewModel>
{
Margin = "1 0 1 0",
ColumnDefinitionsObject = "* Auto",
ChildInitializer =
{
new TextBlock<IItemViewModel>()
.Setup(t =>
{
t.Bind(
t,
dc => dc == null ? string.Empty : dc.DisplayNameText,
tb => tb.Text
);
}),
new StackPanel<IItemViewModel>
{
Extensions = {new GridPositionExtension(1, 0)},
ChildInitializer =
{
new TextBlock<IItemViewModel>()
.Setup(t =>
{
if (!options.ShowAttributes) return;
t.Bind(
t,
dc => ((IContainer) dc.BaseItem).Items.Count,
tb => tb.Text,
t => $" {t}");
})
}
}
.Setup(s => s.Bind(
s,
dc => dc.BaseItem.Type == AbsolutePathType.Container,
s => s.IsVisible)),
new StackPanel<IItemViewModel>
{
Extensions = {new GridPositionExtension(1, 0)},
ChildInitializer =
{
new TextBlock<IItemViewModel>()
.Setup(t =>
{
if (!options.ShowAttributes) return;
t.Bind(
t,
dc => ((IElementViewModel) dc).Size.Value,
tb => tb.Text,
v =>
{
var b = ByteSize.FromBytes(v);
return $"{b.LargestWholeNumberValue:0.#} " + b.GetLargestWholeNumberSymbol(NumberFormatInfo.CurrentInfo).First();
});
})
}
}
.Setup(s => s.Bind(
s,
dc => dc.BaseItem.Type == AbsolutePathType.Element,
s => s.IsVisible))
}
}
}
};
root.Bind(
root,
dc => dc == null ? _theme.DefaultForegroundColor : ToForegroundColor(dc.ViewMode.Value, dc.BaseItem.Type),
tb => tb.Foreground
);
root.Bind(
root,
dc => dc == null ? _theme.DefaultBackgroundColor : ToBackgroundColor(dc.ViewMode.Value, dc.BaseItem.Type),
tb => tb.Background
);
return root;
}
private IColor? ToForegroundColor(ItemViewMode viewMode, AbsolutePathType absolutePathType) =>
(viewMode, absolutePathType) switch
{