Skip to content

Commit

Permalink
Minor improvements (#535)
Browse files Browse the repository at this point in the history
  • Loading branch information
Serg-Norseman committed Feb 28, 2024
1 parent bf82fdc commit 72dfaee
Show file tree
Hide file tree
Showing 23 changed files with 503 additions and 155 deletions.
64 changes: 30 additions & 34 deletions projects/GKCore/GDModel/GDMDate.cs
Original file line number Diff line number Diff line change
Expand Up @@ -200,7 +200,7 @@ public override string ParseString(string strValue)
/// <summary>
/// Internal helper method for parser
/// </summary>
internal void SetRawData(GDMApproximated approximated, GDMCalendar calendar,
internal void SetRawData(GDMApproximated approximated, GDMCalendar calendar,
short year, bool yearBC, string yearModifier, byte month, byte day)
{
fApproximated = approximated;
Expand All @@ -219,8 +219,7 @@ internal void SetRawData(GDMApproximated approximated, GDMCalendar calendar,
public static string[] GetMonthNames(GDMCalendar calendar)
{
string[] monthes;
switch (calendar)
{
switch (calendar) {
case GDMCalendar.dcGregorian:
case GDMCalendar.dcJulian:
case GDMCalendar.dcRoman:
Expand Down Expand Up @@ -267,22 +266,23 @@ private static string CheckGEDCOMMonth(GDMCalendar calendar, string str)

protected override string GetStringValue()
{
var parts = new List<string>(5);
var parts = new string[5];
int pIdx = 0;
if (fApproximated != GDMApproximated.daExact) {
parts.Add(GEDCOMConsts.GEDCOMDateApproximatedArray[(int)fApproximated]);
parts[pIdx++] = GEDCOMConsts.GEDCOMDateApproximatedArray[(int)fApproximated];
}

if (fCalendar != GDMCalendar.dcGregorian) {
parts.Add(GEDCOMConsts.GEDCOMDateEscapeArray[(int)fCalendar]);
parts[pIdx++] = GEDCOMConsts.GEDCOMDateEscapeArray[(int)fCalendar];
}

if (fDay > 0) {
parts.Add(fDay.ToString("D2"));
parts[pIdx++] = fDay.ToString("D2");
}

if (fMonth > 0) {
string[] months = GetMonthNames(fCalendar);
parts.Add(months[fMonth - 1]);
parts[pIdx++] = months[fMonth - 1];
}

if (fYear != UNKNOWN_YEAR) {
Expand All @@ -295,10 +295,10 @@ protected override string GetStringValue()
yearStr += GEDCOMConsts.YearBC;
}

parts.Add(yearStr);
parts[pIdx++] = yearStr;
}

return string.Join(" ", parts);
return string.Join(" ", parts, 0, pIdx);
}

private static byte GetMonthNumber(GDMCalendar calendar, string strMonth)
Expand Down Expand Up @@ -526,7 +526,8 @@ public static UDN GetUDNByFormattedStr(string dateStr, GDMCalendar calendar, boo

public string GetDisplayString(DateFormat format, bool includeBC = false, bool showCalendar = false)
{
string result = "";
var parts = new string[5];
int pIdx = 0;

int year = fYear;
int month = fMonth;
Expand All @@ -536,44 +537,39 @@ public string GetDisplayString(DateFormat format, bool includeBC = false, bool s
if (year > 0 || month > 0 || day > 0) {
switch (format) {
case DateFormat.dfDD_MM_YYYY:
result += day > 0 ? ConvertHelper.AdjustNumber(day, 2) + "." : "__.";
result += month > 0 ? ConvertHelper.AdjustNumber(month, 2) + "." : "__.";
result += year > 0 ? year.ToString().PadLeft(4, '_') : "____";
parts[pIdx++] = day > 0 ? ConvertHelper.AdjustNumber(day, 2) + "." : "__.";
parts[pIdx++] = month > 0 ? ConvertHelper.AdjustNumber(month, 2) + "." : "__.";
parts[pIdx++] = year > 0 ? year.ToString().PadLeft(4, '_') : "____";
if (includeBC && ybc) {
parts[pIdx++] = " BC";
}
break;

case DateFormat.dfYYYY_MM_DD:
result += year > 0 ? year.ToString().PadLeft(4, '_') + "." : "____.";
result += month > 0 ? ConvertHelper.AdjustNumber(month, 2) + "." : "__.";
result += day > 0 ? ConvertHelper.AdjustNumber(day, 2) : "__";
if (includeBC && ybc) {
parts[pIdx++] = "BC ";
}
parts[pIdx++] = year > 0 ? year.ToString().PadLeft(4, '_') + "." : "____.";
parts[pIdx++] = month > 0 ? ConvertHelper.AdjustNumber(month, 2) + "." : "__.";
parts[pIdx++] = day > 0 ? ConvertHelper.AdjustNumber(day, 2) : "__";
break;

case DateFormat.dfYYYY:
if (year > 0) {
result = year.ToString().PadLeft(4, '_');
if (includeBC && ybc) {
parts[pIdx++] = "BC ";
}
parts[pIdx++] = year.ToString().PadLeft(4, '_');
}
break;
}
}

if (includeBC && ybc) {
switch (format) {
case DateFormat.dfDD_MM_YYYY:
result = result + " BC";
break;
case DateFormat.dfYYYY_MM_DD:
result = "BC " + result;
break;
case DateFormat.dfYYYY:
result = "BC " + result;
break;
}
}

if (showCalendar) {
result = result + GKUtils.GetCalendarSign(fCalendar);
parts[pIdx] = GKUtils.GetCalendarSign(fCalendar);
}

return result;
return string.Concat(parts);
}

public override string GetDisplayStringExt(DateFormat format, bool sign, bool showCalendar, bool shorten = false)
Expand Down
46 changes: 32 additions & 14 deletions projects/GKCore/GDModel/GDMDatePeriod.cs
Original file line number Diff line number Diff line change
Expand Up @@ -61,30 +61,40 @@ internal override void TrimExcess()
protected override string GetStringValue()
{
string result;
if (!fDateFrom.IsEmpty() && !fDateTo.IsEmpty()) {

bool frEmpty = fDateFrom.IsEmpty();
bool toEmpty = fDateTo.IsEmpty();

if (!frEmpty && !toEmpty) {
result = string.Concat("FROM ", fDateFrom.StringValue, " TO ", fDateTo.StringValue);
} else if (!fDateFrom.IsEmpty()) {
} else if (!frEmpty) {
result = "FROM " + fDateFrom.StringValue;
} else if (!fDateTo.IsEmpty()) {
} else if (!toEmpty) {
result = "TO " + fDateTo.StringValue;
} else {
result = "";
}

return result;
}

public override DateTime GetDateTime()
{
DateTime result;
if (fDateFrom.IsEmpty()) {

bool frEmpty = fDateFrom.IsEmpty();
bool toEmpty = fDateTo.IsEmpty();

if (frEmpty) {
result = fDateTo.GetDateTime();
} else if (fDateTo.IsEmpty()) {
} else if (toEmpty) {
result = fDateFrom.GetDateTime();
} else if (fDateFrom.GetDateTime() == fDateTo.GetDateTime()) {
result = fDateFrom.GetDateTime();
} else {
result = new DateTime(0);
}

return result;
}

Expand Down Expand Up @@ -126,12 +136,15 @@ public override UDN GetUDN()
{
UDN result;

if (fDateFrom.StringValue != "" && fDateTo.StringValue == "") {
bool frEmpty = fDateFrom.IsEmpty();
bool toEmpty = fDateTo.IsEmpty();

if (!frEmpty && !toEmpty) {
result = UDN.CreateBetween(fDateFrom.GetUDN(), fDateTo.GetUDN(), false);
} else if (!frEmpty) {
result = UDN.CreateAfter(fDateFrom.GetUDN());
} else if (fDateFrom.StringValue == "" && fDateTo.StringValue != "") {
} else if (!toEmpty) {
result = UDN.CreateBefore(fDateTo.GetUDN());
} else if (fDateFrom.StringValue != "" && fDateTo.StringValue != "") {
result = UDN.CreateBetween(fDateFrom.GetUDN(), fDateTo.GetUDN(), false);
} else {
result = UDN.CreateUnknown();
}
Expand All @@ -141,16 +154,21 @@ public override UDN GetUDN()

public override string GetDisplayStringExt(DateFormat format, bool sign, bool showCalendar, bool shorten = false)
{
string result = "";
string result;

if (fDateFrom.StringValue != "" && fDateTo.StringValue == "") {
bool frEmpty = fDateFrom.IsEmpty();
bool toEmpty = fDateTo.IsEmpty();

if (!frEmpty && !toEmpty) {
result = fDateFrom.GetDisplayString(format, true, showCalendar) + " - " + fDateTo.GetDisplayString(format, true, showCalendar);
} else if (!frEmpty) {
result = fDateFrom.GetDisplayString(format, true, showCalendar);
if (sign) result += " >";
} else if (fDateFrom.StringValue == "" && fDateTo.StringValue != "") {
} else if (!toEmpty) {
result = fDateTo.GetDisplayString(format, true, showCalendar);
if (sign) result = "< " + result;
} else if (fDateFrom.StringValue != "" && fDateTo.StringValue != "") {
result = fDateFrom.GetDisplayString(format, true, showCalendar) + " - " + fDateTo.GetDisplayString(format, true, showCalendar);
} else {
result = "";
}

return result;
Expand Down
53 changes: 35 additions & 18 deletions projects/GKCore/GDModel/GDMDateRange.cs
Original file line number Diff line number Diff line change
Expand Up @@ -61,24 +61,33 @@ internal override void TrimExcess()
protected override string GetStringValue()
{
string result;
if (!fDateAfter.IsEmpty() && !fDateBefore.IsEmpty()) {

bool aftEmpty = fDateAfter.IsEmpty();
bool befEmpty = fDateBefore.IsEmpty();

if (!aftEmpty && !befEmpty) {
result = string.Concat(GEDCOMConsts.GEDCOMDateRangeArray[2], " ", fDateAfter.StringValue, " ", GEDCOMConsts.GEDCOMDateRangeArray[3], " ", fDateBefore.StringValue);
} else if (!fDateAfter.IsEmpty()) {
} else if (!aftEmpty) {
result = GEDCOMConsts.GEDCOMDateRangeArray[0] + " " + fDateAfter.StringValue;
} else if (!fDateBefore.IsEmpty()) {
} else if (!befEmpty) {
result = GEDCOMConsts.GEDCOMDateRangeArray[1] + " " + fDateBefore.StringValue;
} else {
result = "";
}

return result;
}

public override DateTime GetDateTime()
{
DateTime result;
if (fDateAfter.IsEmpty()) {

bool aftEmpty = fDateAfter.IsEmpty();
bool befEmpty = fDateBefore.IsEmpty();

if (aftEmpty) {
result = fDateBefore.GetDateTime();
} else if (fDateBefore.IsEmpty()) {
} else if (befEmpty) {
result = fDateAfter.GetDateTime();
} else {
result = new DateTime(0);
Expand Down Expand Up @@ -125,12 +134,15 @@ public override UDN GetUDN()
{
UDN result;

if (fDateAfter.StringValue == "" && fDateBefore.StringValue != "") {
result = UDN.CreateBefore(fDateBefore.GetUDN());
} else if (fDateAfter.StringValue != "" && fDateBefore.StringValue == "") {
result = UDN.CreateAfter(fDateAfter.GetUDN());
} else if (fDateAfter.StringValue != "" && fDateBefore.StringValue != "") {
bool aftEmpty = fDateAfter.IsEmpty();
bool befEmpty = fDateBefore.IsEmpty();

if (!aftEmpty && !befEmpty) {
result = UDN.CreateBetween(fDateAfter.GetUDN(), fDateBefore.GetUDN(), false);
} else if (!aftEmpty) {
result = UDN.CreateAfter(fDateAfter.GetUDN());
} else if (!befEmpty) {
result = UDN.CreateBefore(fDateBefore.GetUDN());
} else {
result = UDN.CreateUnknown();
}
Expand All @@ -140,15 +152,12 @@ public override UDN GetUDN()

public override string GetDisplayStringExt(DateFormat format, bool sign, bool showCalendar, bool shorten = false)
{
string result = "";
string result;

if (fDateAfter.StringValue == "" && fDateBefore.StringValue != "") {
result = fDateBefore.GetDisplayString(format, true, showCalendar);
if (sign) result = "< " + result;
} else if (fDateAfter.StringValue != "" && fDateBefore.StringValue == "") {
result = fDateAfter.GetDisplayString(format, true, showCalendar);
if (sign) result += " >";
} else if (fDateAfter.StringValue != "" && fDateBefore.StringValue != "") {
bool aftEmpty = fDateAfter.IsEmpty();
bool befEmpty = fDateBefore.IsEmpty();

if (!aftEmpty && !befEmpty) {
var dateAfter = fDateAfter.GetDisplayString(format, true, showCalendar);
var dateBefore = fDateBefore.GetDisplayString(format, true, showCalendar);

Expand All @@ -164,6 +173,14 @@ public override string GetDisplayStringExt(DateFormat format, bool sign, bool sh
} else {
result = dateAfter + " - " + dateBefore;
}
} else if (!aftEmpty) {
result = fDateAfter.GetDisplayString(format, true, showCalendar);
if (sign) result += " >";
} else if (!befEmpty) {
result = fDateBefore.GetDisplayString(format, true, showCalendar);
if (sign) result = "< " + result;
} else {
result = "";
}

return result;
Expand Down
4 changes: 4 additions & 0 deletions projects/GKCore/GKCore/AppHost.cs
Original file line number Diff line number Diff line change
Expand Up @@ -104,6 +104,10 @@ protected AppHost()
fTips = new StringList();
}

protected virtual void ApplicationExit()
{
}

private void AutosaveTimer_Tick(object sender, EventArgs e)
{
try {
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
/*
* "GEDKeeper", the personal genealogical database editor.
* Copyright (C) 2009-2023 by Sergey V. Zhdanovskih.
* Copyright (C) 2009-2024 by Sergey V. Zhdanovskih.
*
* This file is part of "GEDKeeper".
*
Expand Down Expand Up @@ -82,6 +82,13 @@ public PersonEditDlgController(T view) : base(view)
}
}

protected override void Dispose(bool disposing)
{
if (disposing) {
}
base.Dispose(disposing);
}

public override void Init(IBaseWindow baseWin)
{
base.Init(baseWin);
Expand Down
2 changes: 2 additions & 0 deletions projects/GKCore/GKCore/Design/Graphics/IGraphicsProvider.cs
Original file line number Diff line number Diff line change
Expand Up @@ -48,6 +48,8 @@ public interface IGraphicsProvider

IFont CreateFont(string fontName, float size, bool bold);

void FreeImage(ref IImage image);

IImage LoadImage(Stream stream, int thumbWidth, int thumbHeight, ExtRect cutoutArea, string cachedFile);

/// <summary>
Expand Down
Loading

0 comments on commit 72dfaee

Please sign in to comment.