97 lines
2.4 KiB
C#
97 lines
2.4 KiB
C#
using NStack;
|
|
using Terminal.Gui;
|
|
|
|
namespace Akari.Provider.WaveshareUART.Views
|
|
{
|
|
public class NewUserDialog : Dialog
|
|
{
|
|
private bool _success;
|
|
|
|
private TextField _nameEntry;
|
|
private TextField _tokenEntry;
|
|
|
|
public NewUserDialog() : base("New User", 60, 8)
|
|
{
|
|
ColorScheme = Colors.ColorSchemes["Menu"];
|
|
}
|
|
|
|
public bool TryShow(out ustring name, out ustring token)
|
|
{
|
|
_success = false;
|
|
|
|
var nameLabel = new Label("Name: ")
|
|
{
|
|
X = 1,
|
|
Y = 2
|
|
};
|
|
_nameEntry = new TextField("")
|
|
{
|
|
X = Pos.Right(nameLabel),
|
|
Y = Pos.Top(nameLabel),
|
|
Width = Dim.Fill() - 1,
|
|
Height = 1
|
|
};
|
|
|
|
var tokenLabel = new Label("Token: ")
|
|
{
|
|
X = 1,
|
|
Y = 3
|
|
};
|
|
_tokenEntry = new TextField("")
|
|
{
|
|
X = Pos.Right(tokenLabel),
|
|
Y = Pos.Top(tokenLabel),
|
|
Width = Dim.Fill() - 1,
|
|
Height = 1
|
|
};
|
|
|
|
var cancelButton = new Button("_Cancel")
|
|
{
|
|
X = Pos.Percent(82),
|
|
Y = Pos.Percent(95)
|
|
};
|
|
cancelButton.Clicked += () => Application.RequestStop();
|
|
|
|
var okButton = new Button("_Ok")
|
|
{
|
|
X = Pos.Percent(70),
|
|
Y = Pos.Percent(95)
|
|
};
|
|
okButton.Clicked += () => CheckInput();
|
|
|
|
Add(nameLabel, _nameEntry, tokenLabel, _tokenEntry, okButton, cancelButton);
|
|
|
|
_nameEntry.SetFocus();
|
|
|
|
Application.Run(this);
|
|
|
|
if (_success)
|
|
{
|
|
name = _nameEntry.Text;
|
|
token = _tokenEntry.Text;
|
|
|
|
return true;
|
|
}
|
|
|
|
name = default;
|
|
token = default;
|
|
|
|
return false;
|
|
}
|
|
|
|
private void CheckInput()
|
|
{
|
|
if (!string.IsNullOrWhiteSpace(_nameEntry.Text.ToString()) && !string.IsNullOrWhiteSpace(_tokenEntry.Text.ToString()))
|
|
{
|
|
_success = true;
|
|
|
|
Application.RequestStop();
|
|
}
|
|
else
|
|
{
|
|
MessageBox.ErrorQuery("New User", "Name and Token can't be empty", "Ok");
|
|
}
|
|
}
|
|
}
|
|
}
|