Console ItemPreview, select item after delete
This commit is contained in:
@@ -44,6 +44,12 @@ public abstract class ChildCollectionView<TConcrete, T>
|
||||
};
|
||||
}
|
||||
|
||||
public override void AddChild(IView child)
|
||||
{
|
||||
base.AddChild(child);
|
||||
_children.Add(child);
|
||||
}
|
||||
|
||||
public override TChild AddChild<TChild>(TChild child)
|
||||
{
|
||||
child = base.AddChild(child);
|
||||
|
||||
@@ -1,8 +1,11 @@
|
||||
using System.Collections;
|
||||
using System.Linq.Expressions;
|
||||
using TerminalUI.Extensions;
|
||||
|
||||
namespace TerminalUI.Controls;
|
||||
|
||||
public record ChildWithDataContextMapper<TSourceDataContext, TTargetDataContext>(IView<TTargetDataContext> Child, Func<TSourceDataContext?, TTargetDataContext?> DataContextMapper);
|
||||
public record ChildWithDataContextBinding<TSourceDataContext, TTargetDataContext>(IView<TTargetDataContext> Child, Expression<Func<TSourceDataContext?, TTargetDataContext?>> DataContextExpression);
|
||||
|
||||
public class ChildInitializer<T> : IEnumerable<IView>
|
||||
{
|
||||
@@ -17,6 +20,16 @@ public class ChildInitializer<T> : IEnumerable<IView>
|
||||
|
||||
public void Add<TDataContext>(ChildWithDataContextMapper<T, TDataContext> item)
|
||||
=> _childContainer.AddChild(item.Child, item.DataContextMapper);
|
||||
|
||||
public void Add<TDataContext>(ChildWithDataContextBinding<T, TDataContext> item)
|
||||
{
|
||||
item.Child.Bind(
|
||||
_childContainer,
|
||||
item.DataContextExpression,
|
||||
c => c.DataContext
|
||||
);
|
||||
_childContainer.AddChild(item.Child);
|
||||
}
|
||||
|
||||
public IEnumerator<IView> GetEnumerator() => _childContainer.Children.GetEnumerator();
|
||||
|
||||
|
||||
@@ -55,6 +55,7 @@ public interface IView<T> : IView
|
||||
TChild CreateChild<TChild, TDataContext>(Func<T?, TDataContext?> dataContextMapper)
|
||||
where TChild : IView<TDataContext>, new();
|
||||
|
||||
void AddChild(IView child);
|
||||
TChild AddChild<TChild>(TChild child) where TChild : IView<T>;
|
||||
|
||||
TChild AddChild<TChild, TDataContext>(TChild child, Func<T?, TDataContext?> dataContextMapper)
|
||||
|
||||
@@ -26,12 +26,14 @@ public sealed partial class TextBlock<T> : View<TextBlock<T>, T>, IDisplayView
|
||||
[Notify] private string? _text = string.Empty;
|
||||
[Notify] private TextAlignment _textAlignment = TextAlignment.Left;
|
||||
[Notify] private ITextFormat? _textFormat;
|
||||
[Notify] private int _textStartIndex;
|
||||
|
||||
public TextBlock()
|
||||
{
|
||||
RerenderProperties.Add(nameof(Text));
|
||||
RerenderProperties.Add(nameof(TextAlignment));
|
||||
RerenderProperties.Add(nameof(TextFormat));
|
||||
RerenderProperties.Add(nameof(TextStartIndex));
|
||||
|
||||
((INotifyPropertyChanged) this).PropertyChanged += (o, e) =>
|
||||
{
|
||||
@@ -78,7 +80,17 @@ public sealed partial class TextBlock<T> : View<TextBlock<T>, T>, IDisplayView
|
||||
|
||||
SetStyleColor(renderContext, foreground, background, _textFormat);
|
||||
|
||||
RenderText(_textLines, renderContext, position, size, skipRender, TransformText);
|
||||
var textLines = _textLines;
|
||||
if (_textStartIndex < _textLines.Length)
|
||||
{
|
||||
textLines = _textLines[_textStartIndex..];
|
||||
}
|
||||
else
|
||||
{
|
||||
_textStartIndex = _textLines.Length - size.Height;
|
||||
}
|
||||
|
||||
RenderText(textLines, renderContext, position, size, skipRender, TransformText);
|
||||
|
||||
return !skipRender;
|
||||
}
|
||||
|
||||
@@ -376,6 +376,12 @@ public abstract partial class View<TConcrete, T> : IView<T> where TConcrete : Vi
|
||||
return child;
|
||||
}
|
||||
|
||||
public virtual void AddChild(IView child)
|
||||
{
|
||||
Debug.Assert(child != null);
|
||||
SetupNewChild(child, null);
|
||||
}
|
||||
|
||||
public virtual TChild AddChild<TChild, TDataContext>(TChild child, Func<T?, TDataContext?> dataContextMapper)
|
||||
where TChild : IView<TDataContext>
|
||||
{
|
||||
@@ -387,15 +393,18 @@ public abstract partial class View<TConcrete, T> : IView<T> where TConcrete : Vi
|
||||
return child;
|
||||
}
|
||||
|
||||
private void SetupNewChild(IView child, IDisposable dataContextmapper)
|
||||
private void SetupNewChild(IView child, IDisposable? dataContextMapper)
|
||||
{
|
||||
child.ApplicationContext = ApplicationContext;
|
||||
child.Attached = Attached;
|
||||
child.VisualParent = this;
|
||||
VisualChildren.Add(child);
|
||||
|
||||
AddDisposable(dataContextmapper);
|
||||
child.AddDisposable(dataContextmapper);
|
||||
if (dataContextMapper is not null)
|
||||
{
|
||||
AddDisposable(dataContextMapper);
|
||||
child.AddDisposable(dataContextMapper);
|
||||
}
|
||||
}
|
||||
|
||||
public virtual void RemoveChild<TDataContext>(IView<TDataContext> child)
|
||||
|
||||
@@ -1,4 +1,5 @@
|
||||
using System.Linq.Expressions;
|
||||
using System.Collections;
|
||||
using System.Linq.Expressions;
|
||||
|
||||
namespace TerminalUI.ExpressionTrackers;
|
||||
|
||||
@@ -26,6 +27,10 @@ public class BinaryTracker : ExpressionTrackerBase
|
||||
{
|
||||
ExpressionType.Equal => (v1, v2) => Equals(v1, v2),
|
||||
ExpressionType.NotEqual => (v1, v2) => !Equals(v1, v2),
|
||||
ExpressionType.GreaterThan => (v1, v2) => Comparer.Default.Compare(v1, v2) > 0,
|
||||
ExpressionType.GreaterThanOrEqual => (v1, v2) => Comparer.Default.Compare(v1, v2) >= 0,
|
||||
ExpressionType.LessThan => (v1, v2) => Comparer.Default.Compare(v1, v2) < 0,
|
||||
ExpressionType.LessThanOrEqual => (v1, v2) => Comparer.Default.Compare(v1, v2) <= 0,
|
||||
_ => throw new NotImplementedException()
|
||||
};
|
||||
|
||||
|
||||
@@ -19,6 +19,11 @@ public static class ViewExtensions
|
||||
Func<TSourceDataContext?, TTargetDataContext?> dataContextMapper)
|
||||
=> new(view, dataContextMapper);
|
||||
|
||||
public static ChildWithDataContextBinding<TSourceDataContext, TTargetDataContext> WithDataContextBinding<TSourceDataContext, TTargetDataContext>(
|
||||
this IView<TTargetDataContext> view,
|
||||
Expression<Func<TSourceDataContext?, TTargetDataContext?>> dataContextMapper)
|
||||
=> new(view, dataContextMapper);
|
||||
|
||||
public static TView Setup<TView>(this TView view, Action<TView> action)
|
||||
{
|
||||
action(view);
|
||||
|
||||
Reference in New Issue
Block a user