InputHandler, CreateContainer user command

This commit is contained in:
2022-05-19 22:46:25 +02:00
parent 40f36ed845
commit ced0c88a10
28 changed files with 358 additions and 52 deletions

View File

@@ -0,0 +1,7 @@
namespace FileTime.Core.Interactions;
public interface IInputElement
{
InputType Type { get; }
string Label { get; }
}

View File

@@ -0,0 +1,6 @@
namespace FileTime.Core.Interactions;
public interface IInputInterface
{
Task<bool> ReadInputs(IEnumerable<IInputElement> fields);
}

View File

@@ -0,0 +1,7 @@
namespace FileTime.Core.Interactions;
public interface IOptionElement
{
string Text { get; }
object? Value { get; }
}

View File

@@ -0,0 +1,7 @@
namespace FileTime.Core.Interactions;
public interface IOptionsInputElement : IInputElement
{
object Value { get; set; }
IEnumerable<IOptionElement> Options { get; }
}

View File

@@ -0,0 +1,13 @@
namespace FileTime.Core.Interactions;
public abstract class InputElementBase : IInputElement
{
public InputType Type { get; }
public string Label { get; }
protected InputElementBase(string label, InputType type)
{
Label = label;
Type = type;
}
}

View File

@@ -0,0 +1,8 @@
namespace FileTime.Core.Interactions;
public enum InputType
{
Options,
Password,
Text,
}

View File

@@ -0,0 +1,17 @@
namespace FileTime.Core.Interactions;
public class OptionElement<T> : IOptionElement
{
public string Text { get; }
public T Value { get; }
object IOptionElement.Value => Value;
public OptionElement(string text, T value)
{
ArgumentNullException.ThrowIfNull(value);
Text = text;
Value = value;
}
}

View File

@@ -0,0 +1,23 @@
using System.ComponentModel;
using PropertyChanged.SourceGenerator;
namespace FileTime.Core.Interactions;
public partial class OptionsInputElement<T> : InputElementBase, IOptionsInputElement, INotifyPropertyChanged
{
public IEnumerable<OptionElement<T>> Options { get; }
[Notify] private T? _value;
IEnumerable<IOptionElement> IOptionsInputElement.Options => Options;
object? IOptionsInputElement.Value
{
get => Value;
set => Value = (T?)value;
}
public OptionsInputElement(string label, IEnumerable<OptionElement<T>> options) : base(label, InputType.Options)
{
Options = options;
}
}

View File

@@ -0,0 +1,17 @@
using System.ComponentModel;
using PropertyChanged.SourceGenerator;
namespace FileTime.Core.Interactions;
public partial class PasswordInputElement : InputElementBase, INotifyPropertyChanged
{
public char PasswordChar { get; }
[Notify] private string? _value;
public PasswordInputElement(string label, string? value = null, char passwordChar = '*') : base(label, InputType.Password)
{
PasswordChar = passwordChar;
_value = value;
}
}

View File

@@ -0,0 +1,14 @@
using System.ComponentModel;
using PropertyChanged.SourceGenerator;
namespace FileTime.Core.Interactions;
public partial class TextInputElement : InputElementBase, INotifyPropertyChanged
{
[Notify] private string? _value;
public TextInputElement(string label, string? value = null) : base(label, InputType.Text)
{
_value = value;
}
}