Merge branch 'master' of tig:migueldeicaza/gui.cs

This commit is contained in:
Charlie Kindel
2020-05-23 19:40:57 -06:00
2 changed files with 44 additions and 16 deletions

View File

@@ -61,10 +61,15 @@ namespace Terminal.Gui {
void DateField_Changed (object sender, ustring e)
{
if (!DateTime.TryParseExact (Text.ToString (), Format, CultureInfo.CurrentCulture, DateTimeStyles.None, out DateTime result))
if (!DateTime.TryParseExact (GetDate (Text).ToString(), GetInvarianteFormat (), CultureInfo.CurrentCulture, DateTimeStyles.None, out DateTime result))
Text = e;
}
string GetInvarianteFormat ()
{
return $"MM{sepChar}dd{sepChar}yyyy";
}
string GetLongFormat (string lf)
{
ustring [] frm = ustring.Make (lf).Split (ustring.Make (sepChar));
@@ -191,6 +196,31 @@ namespace Terminal.Gui {
return date;
}
ustring GetDate (ustring text)
{
ustring [] vals = text.Split (ustring.Make (sepChar));
ustring [] frm = ustring.Make (Format).Split (ustring.Make (sepChar));
ustring [] date = { null, null, null };
for (int i = 0; i < frm.Length; i++) {
if (frm [i].Contains ("M")) {
date [0] = vals [i].TrimSpace ();
} else if (frm [i].Contains ("d")) {
date [1] = vals [i].TrimSpace ();
} else {
var year = vals [i].TrimSpace ();
if (year.Length == 2) {
var y = DateTime.Now.Year.ToString ();
date [2] = y.Substring (0, 2) + year.ToString ();
} else {
date [2] = vals [i].TrimSpace ();
}
}
}
return date [0] + ustring.Make (sepChar) + date [1] + ustring.Make (sepChar) + date [2];
}
int GetFormatIndex (ustring [] fm, string t)
{
int idx = -1;

View File

@@ -8,36 +8,34 @@ namespace UICatalog {
class TimeAndDate : Scenario {
public override void Setup ()
{
// NOTE: The TimeField control is not ready for prime-time. See #246
var longTime = new TimeField (0, 0, DateTime.Now, isShort: false) {
// BUGBUG: TimeField does not support Computed Layout
var longTime = new TimeField (DateTime.Now) {
X = Pos.Center (),
Y = 2,
IsShortFormat = false,
ReadOnly = false,
};
Win.Add (longTime);
var shortTime = new TimeField (0, 2, DateTime.Now, isShort: true) {
// BUGBUG: TimeField does not support Computed Layout
var shortTime = new TimeField (DateTime.Now) {
X = Pos.Center (),
Y = Pos.Bottom(longTime) + 1,
ReadOnly = true,
IsShortFormat = true,
ReadOnly = false,
};
Win.Add (shortTime);
var shortDate = new DateField (0, 2, DateTime.Now, isShort: true) {
// BUGBUG: TimeField does not support Computed Layout
var shortDate = new DateField (DateTime.Now) {
X = Pos.Center (),
Y = Pos.Bottom (shortTime) + 1,
IsShortFormat = true,
ReadOnly = true,
};
Win.Add (shortDate);
var longDate = new TimeField (0, 2, DateTime.Now, isShort: true) {
// BUGBUG: TimeField does not support Computed Layout
var longDate = new DateField (DateTime.Now) {
X = Pos.Center (),
Y = Pos.Bottom (shortDate) + 1,
IsShortFormat = false,
ReadOnly = true,
};
Win.Add (longDate);
@@ -49,14 +47,14 @@ namespace UICatalog {
longTime.ReadOnly = !longTime.ReadOnly;
shortTime.ReadOnly = !shortTime.ReadOnly;
//longTime.IsShortFormat = !longTime.IsShortFormat;
//shortTime.IsShortFormat = !shortTime.IsShortFormat;
longTime.IsShortFormat = !longTime.IsShortFormat;
shortTime.IsShortFormat = !shortTime.IsShortFormat;
longDate.ReadOnly = !longDate.ReadOnly;
shortDate.ReadOnly = !shortDate.ReadOnly;
//longDate.IsShortFormat = !longDate.IsShortFormat;
//shortDate.IsShortFormat = !shortDate.IsShortFormat;
longDate.IsShortFormat = !longDate.IsShortFormat;
shortDate.IsShortFormat = !shortDate.IsShortFormat;
}
});
}