From 62b82d493dd33d1b4021d147e7289c3e651dcdb7 Mon Sep 17 00:00:00 2001 From: "Sergey V. Zhdanovskih" Date: Fri, 1 Mar 2024 21:59:47 +0300 Subject: [PATCH] Minor improvements (#535) --- locales/Hungarian.lng | 2 +- locales/Japanese.lng | 2 +- locales/german.lng | 2 +- projects/GKCore/GDModel/GDMDate.cs | 15 +++--- projects/GKCore/GDModel/GDMDatePeriod.cs | 32 +++++++----- projects/GKCore/GDModel/GDMDateRange.cs | 50 +++++++++++-------- projects/GKCore/GDModel/GDMDateValue.cs | 6 +-- projects/GKCore/GKCore/GKUtils.cs | 6 ++- .../GKCore/GKCore/Interfaces/IListFilter.cs | 3 +- .../GKCore/GKCore/Interfaces/IListSource.cs | 3 +- .../GKCore/Lists/IndividualListModel.cs | 10 ++-- projects/GKCore/GKCore/Lists/ListColumns.cs | 8 ++- projects/GKCore/GKCore/Lists/ListSource.cs | 23 +++++++-- .../GKCore/GKCore/Options/GlobalOptions.cs | 11 +++- .../GKComponents/GKUI/Components/UIHelper.cs | 6 ++- .../GKComponents/GKUI/Components/UIHelper.cs | 4 +- 16 files changed, 118 insertions(+), 65 deletions(-) diff --git a/locales/Hungarian.lng b/locales/Hungarian.lng index 1b6a55880..63935167a 100644 --- a/locales/Hungarian.lng +++ b/locales/Hungarian.lng @@ -950,4 +950,4 @@ 942={0} fotó hozzáadva innen: {1}. 943=Legfelső szintű linkek 944=Eltávolítja a legfelső szintű linket? -945=Help is not available for this language. An English help will be shown. +945=Ezen a nyelven nem érhető el súgó. Megjelenik egy angol nyelvű súgó. diff --git a/locales/Japanese.lng b/locales/Japanese.lng index eafb90070..83c234cba 100644 --- a/locales/Japanese.lng +++ b/locales/Japanese.lng @@ -950,4 +950,4 @@ 942={1} から {0} の写真を追加しました。 943=トップレベルのリンク 944=トップレベルのリンクを削除しますか? -945=Help is not available for this language. An English help will be shown. +945=この言語ではヘルプを利用できません。英語のヘルプが表示されます。 diff --git a/locales/german.lng b/locales/german.lng index 8a4d56171..c873b7478 100644 --- a/locales/german.lng +++ b/locales/german.lng @@ -950,4 +950,4 @@ 942={0} Fotografien von {1} hinzugefügt. 943=Verweise auf oberster Ebene 944=Verweis auf oberster Ebene löschen? -945=Help is not available for this language. An English help will be shown. +945=Hilfe ist für diese Sprache nicht verfügbar. Es wird eine englische Hilfe angezeigt. diff --git a/projects/GKCore/GDModel/GDMDate.cs b/projects/GKCore/GDModel/GDMDate.cs index edb5ec5e9..accf887a3 100644 --- a/projects/GKCore/GDModel/GDMDate.cs +++ b/projects/GKCore/GDModel/GDMDate.cs @@ -19,7 +19,6 @@ */ using System; -using System.Collections.Generic; using BSLib; using GDModel.Providers.GEDCOM; using GKCore; @@ -537,8 +536,8 @@ public string GetDisplayString(DateFormat format, bool includeBC = false, bool s if (year > 0 || month > 0 || day > 0) { switch (format) { case DateFormat.dfDD_MM_YYYY: - parts[pIdx++] = day > 0 ? ConvertHelper.AdjustNumber(day, 2) + "." : "__."; - parts[pIdx++] = month > 0 ? ConvertHelper.AdjustNumber(month, 2) + "." : "__."; + parts[pIdx++] = day > 0 ? day.ToString("D2", null) + "." : "__."; + parts[pIdx++] = month > 0 ? month.ToString("D2", null) + "." : "__."; parts[pIdx++] = year > 0 ? year.ToString().PadLeft(4, '_') : "____"; if (includeBC && ybc) { parts[pIdx++] = " BC"; @@ -550,8 +549,8 @@ public string GetDisplayString(DateFormat format, bool includeBC = false, bool s 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) : "__"; + parts[pIdx++] = month > 0 ? month.ToString("D2", null) + "." : "__."; + parts[pIdx++] = day > 0 ? day.ToString("D2", null) : "__"; break; case DateFormat.dfYYYY: @@ -563,10 +562,10 @@ public string GetDisplayString(DateFormat format, bool includeBC = false, bool s } break; } - } - if (showCalendar) { - parts[pIdx] = GKUtils.GetCalendarSign(fCalendar); + if (showCalendar) { + parts[pIdx] = GKUtils.GetCalendarSign(fCalendar); + } } return string.Concat(parts); diff --git a/projects/GKCore/GDModel/GDMDatePeriod.cs b/projects/GKCore/GDModel/GDMDatePeriod.cs index a96fc3096..c224a9504 100644 --- a/projects/GKCore/GDModel/GDMDatePeriod.cs +++ b/projects/GKCore/GDModel/GDMDatePeriod.cs @@ -65,10 +65,12 @@ protected override string GetStringValue() bool frEmpty = fDateFrom.IsEmpty(); bool toEmpty = fDateTo.IsEmpty(); - if (!frEmpty && !toEmpty) { - result = string.Concat("FROM ", fDateFrom.StringValue, " TO ", fDateTo.StringValue); - } else if (!frEmpty) { - result = "FROM " + fDateFrom.StringValue; + if (!frEmpty) { + if (!toEmpty) { + result = string.Concat("FROM ", fDateFrom.StringValue, " TO ", fDateTo.StringValue); + } else { + result = "FROM " + fDateFrom.StringValue; + } } else if (!toEmpty) { result = "TO " + fDateTo.StringValue; } else { @@ -139,10 +141,12 @@ public override UDN GetUDN() 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()); + if (!frEmpty) { + if (!toEmpty) { + result = UDN.CreateBetween(fDateFrom.GetUDN(), fDateTo.GetUDN(), false); + } else { + result = UDN.CreateAfter(fDateFrom.GetUDN()); + } } else if (!toEmpty) { result = UDN.CreateBefore(fDateTo.GetUDN()); } else { @@ -159,11 +163,13 @@ public override string GetDisplayStringExt(DateFormat format, bool sign, bool sh 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 += " >"; + if (!frEmpty) { + if (!toEmpty) { + result = fDateFrom.GetDisplayString(format, true, showCalendar) + " - " + fDateTo.GetDisplayString(format, true, showCalendar); + } else { + result = fDateFrom.GetDisplayString(format, true, showCalendar); + if (sign) result += " >"; + } } else if (!toEmpty) { result = fDateTo.GetDisplayString(format, true, showCalendar); if (sign) result = "< " + result; diff --git a/projects/GKCore/GDModel/GDMDateRange.cs b/projects/GKCore/GDModel/GDMDateRange.cs index c2e6102d5..99ad77325 100644 --- a/projects/GKCore/GDModel/GDMDateRange.cs +++ b/projects/GKCore/GDModel/GDMDateRange.cs @@ -65,10 +65,12 @@ protected override string GetStringValue() 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 (!aftEmpty) { - result = GEDCOMConsts.GEDCOMDateRangeArray[0] + " " + fDateAfter.StringValue; + if (!aftEmpty) { + if (!befEmpty) { + result = string.Concat(GEDCOMConsts.GEDCOMDateRangeArray[2], " ", fDateAfter.StringValue, " ", GEDCOMConsts.GEDCOMDateRangeArray[3], " ", fDateBefore.StringValue); + } else { + result = GEDCOMConsts.GEDCOMDateRangeArray[0] + " " + fDateAfter.StringValue; + } } else if (!befEmpty) { result = GEDCOMConsts.GEDCOMDateRangeArray[1] + " " + fDateBefore.StringValue; } else { @@ -137,10 +139,12 @@ public override UDN GetUDN() 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()); + if (!aftEmpty) { + if (!befEmpty) { + result = UDN.CreateBetween(fDateAfter.GetUDN(), fDateBefore.GetUDN(), false); + } else { + result = UDN.CreateAfter(fDateAfter.GetUDN()); + } } else if (!befEmpty) { result = UDN.CreateBefore(fDateBefore.GetUDN()); } else { @@ -157,25 +161,27 @@ public override string GetDisplayStringExt(DateFormat format, bool sign, bool sh 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); - - if (shorten) { - // FIXME: bad algorithm! - string dtA = dateAfter.Replace("__.__.", ""); - string dtB = dateBefore.Replace("__.__.", ""); - if (dtA.Length == 4 && dtB.Length == 4 && dtB.StartsWith(dtA.Substring(0, 2))) { - result = dtA + "/" + dtB.Substring(2); + if (!aftEmpty) { + if (!befEmpty) { + var dateAfter = fDateAfter.GetDisplayString(format, true, showCalendar); + var dateBefore = fDateBefore.GetDisplayString(format, true, showCalendar); + + if (shorten) { + // FIXME: bad algorithm! + string dtA = dateAfter.Replace("__.__.", ""); + string dtB = dateBefore.Replace("__.__.", ""); + if (dtA.Length == 4 && dtB.Length == 4 && dtB.StartsWith(dtA.Substring(0, 2))) { + result = dtA + "/" + dtB.Substring(2); + } else { + result = dateAfter + " - " + dateBefore; + } } else { result = dateAfter + " - " + dateBefore; } } else { - result = dateAfter + " - " + dateBefore; + result = fDateAfter.GetDisplayString(format, true, showCalendar); + if (sign) result += " >"; } - } 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; diff --git a/projects/GKCore/GDModel/GDMDateValue.cs b/projects/GKCore/GDModel/GDMDateValue.cs index 49cddb5cc..f8c7a76c9 100644 --- a/projects/GKCore/GDModel/GDMDateValue.cs +++ b/projects/GKCore/GDModel/GDMDateValue.cs @@ -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". * @@ -60,12 +60,12 @@ internal override void TrimExcess() protected override string GetStringValue() { - return ((fValue == null) ? "" : fValue.StringValue); + return (fValue == null) ? "" : fValue.StringValue; } public override DateTime GetDateTime() { - DateTime result = ((fValue == null) ? new DateTime(0) : fValue.GetDateTime()); + DateTime result = (fValue == null) ? new DateTime(0) : fValue.GetDateTime(); return result; } diff --git a/projects/GKCore/GKCore/GKUtils.cs b/projects/GKCore/GKCore/GKUtils.cs index 852ad72b6..e8b815883 100644 --- a/projects/GKCore/GKCore/GKUtils.cs +++ b/projects/GKCore/GKCore/GKUtils.cs @@ -3467,7 +3467,9 @@ public static string GetFmtSurname(GDMSex iSex, GDMPersonalName personalName, st string result; - WomanSurnameFormat wsFmt = GlobalOptions.Instance.WomanSurnameFormat; + var globOpts = GlobalOptions.Instance; + + WomanSurnameFormat wsFmt = globOpts.WomanSurnameFormat; if (iSex == GDMSex.svFemale && wsFmt != WomanSurnameFormat.wsfNotExtend) { string marriedSurname = personalName.MarriedName; switch (wsFmt) { @@ -3503,7 +3505,7 @@ public static string GetFmtSurname(GDMSex iSex, GDMPersonalName personalName, st result = defSurname; } - if (GlobalOptions.Instance.SurnameInCapitals) { + if (globOpts.SurnameInCapitals) { result = result.ToUpper(); } diff --git a/projects/GKCore/GKCore/Interfaces/IListFilter.cs b/projects/GKCore/GKCore/Interfaces/IListFilter.cs index 5ea277421..2fbd52392 100644 --- a/projects/GKCore/GKCore/Interfaces/IListFilter.cs +++ b/projects/GKCore/GKCore/Interfaces/IListFilter.cs @@ -1,6 +1,6 @@ /* * "GEDKeeper", the personal genealogical database editor. - * Copyright (C) 2009-2017 by Sergey V. Zhdanovskih. + * Copyright (C) 2009-2024 by Sergey V. Zhdanovskih. * * This file is part of "GEDKeeper". * @@ -81,6 +81,7 @@ public interface IListColumns ListColumn this[int index] { get; } IList OrderedColumns { get; } + void Clear(); void CopyTo(IListColumns target); bool MoveColumn(int idx, bool up); void ResetDefaults(); diff --git a/projects/GKCore/GKCore/Interfaces/IListSource.cs b/projects/GKCore/GKCore/Interfaces/IListSource.cs index 84cc6772d..0b3a0ea4e 100644 --- a/projects/GKCore/GKCore/Interfaces/IListSource.cs +++ b/projects/GKCore/GKCore/Interfaces/IListSource.cs @@ -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". * @@ -104,6 +104,7 @@ public interface IListSource int TotalCount { get; } QuickFilterParams QuickFilter { get; } + void Clear(); void AddCondition(byte columnId, ConditionKind condition, string value); void ChangeColumnWidth(int colIndex, int colWidth); string[] CreateFields(); diff --git a/projects/GKCore/GKCore/Lists/IndividualListModel.cs b/projects/GKCore/GKCore/Lists/IndividualListModel.cs index bed84501d..8e0ef1c95 100644 --- a/projects/GKCore/GKCore/Lists/IndividualListModel.cs +++ b/projects/GKCore/GKCore/Lists/IndividualListModel.cs @@ -400,13 +400,15 @@ private object GetNameValueEx(int colSubtype) if (colSubtype == -1) { result = GKUtils.GetNameString(fFetchedRec, false); } else { - NameFormat defNameFormat = (SimpleList) ? NameFormat.nfFNP : GlobalOptions.Instance.DefNameFormat; + var globOpts = GlobalOptions.Instance; + + NameFormat defNameFormat = (SimpleList) ? NameFormat.nfFNP : globOpts.DefNameFormat; NamePartsRet parts; GDMLanguageID defLang = fBaseContext.DefaultLanguage; switch (defNameFormat) { case NameFormat.nfFNP: - result = GKUtils.GetNameString(fFetchedRec, GlobalOptions.Instance.SurnameFirstInOrder, false, defLang); + result = GKUtils.GetNameString(fFetchedRec, globOpts.SurnameFirstInOrder, false, defLang); break; case NameFormat.nfF_NP: @@ -451,7 +453,7 @@ protected override object GetColumnValueEx(int colType, int colSubtype, bool isV break; case ColumnType.ctPatriarch: - result = ((fFetchedRec.Patriarch) ? "*" : " "); + result = fFetchedRec.Patriarch ? "*" : " "; break; case ColumnType.ctName: @@ -545,7 +547,7 @@ protected override object GetColumnValueEx(int colType, int colSubtype, bool isV break; case ColumnType.ctBookmark: - result = ((fFetchedRec.Bookmark) ? "*" : " "); + result = fFetchedRec.Bookmark ? "*" : " "; break; case ColumnType.ctTitle: diff --git a/projects/GKCore/GKCore/Lists/ListColumns.cs b/projects/GKCore/GKCore/Lists/ListColumns.cs index 13381f0dc..b08e1ec81 100644 --- a/projects/GKCore/GKCore/Lists/ListColumns.cs +++ b/projects/GKCore/GKCore/Lists/ListColumns.cs @@ -1,6 +1,6 @@ /* * "GEDKeeper", the personal genealogical database editor. - * Copyright (C) 2009-2022 by Sergey V. Zhdanovskih. + * Copyright (C) 2009-2024 by Sergey V. Zhdanovskih. * * This file is part of "GEDKeeper". * @@ -95,6 +95,12 @@ public ListColumns() ResetDefaults(); } + public void Clear() + { + fColumns.Clear(); + fOrderedColumns.Clear(); + } + public void AddColumn(LSID colName, int defWidth, bool autosize = false) { AddColumn(colName, DataType.dtString, defWidth, true, autosize, null, null); diff --git a/projects/GKCore/GKCore/Lists/ListSource.cs b/projects/GKCore/GKCore/Lists/ListSource.cs index 9d18da1cc..d3dfef848 100644 --- a/projects/GKCore/GKCore/Lists/ListSource.cs +++ b/projects/GKCore/GKCore/Lists/ListSource.cs @@ -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". * @@ -117,6 +117,23 @@ protected ListSource(IBaseContext baseContext, ListColumns defaultListColumns CreateFilter(); } + public void Clear() + { + fContentList.Clear(); + fTotalCount = 0; + + fMask = string.Empty; + fRegexMask = null; + fSimpleMask = string.Empty; + fExternalFilter = null; + fFilter.Clear(); + + fFetchedRec = null; + + fColumnsMap.Clear(); + fListColumns.Clear(); + } + #region Columns protected virtual void UpdateColumnsMap() @@ -514,8 +531,8 @@ protected static string ConvertColumnValue(object val, ListColumn cs) return ((double)val).ToString(cs.Format, cs.NumFmt); case DataType.dtDateTime: - DateTime dtx = ((DateTime)val); - return ((dtx.Ticks == 0) ? "" : dtx.ToString("yyyy.MM.dd HH:mm:ss", null)); + DateTime dtx = (DateTime)val; + return (dtx.Ticks == 0) ? "" : dtx.ToString("yyyy.MM.dd HH:mm:ss", null); case DataType.dtGEDCOMDate: return val.ToString(); diff --git a/projects/GKCore/GKCore/Options/GlobalOptions.cs b/projects/GKCore/GKCore/Options/GlobalOptions.cs index 7143b7975..475024cef 100644 --- a/projects/GKCore/GKCore/Options/GlobalOptions.cs +++ b/projects/GKCore/GKCore/Options/GlobalOptions.cs @@ -259,8 +259,14 @@ public StringList ResidenceFilters public bool ShowDatesSign { get; set; } + /// + /// Hidden option. + /// public bool ShowIndiAssociations { get; set; } + /// + /// Hidden option. + /// public bool ShowIndiNamesakes { get; set; } public bool ShowTips { get; set; } @@ -392,7 +398,6 @@ public void ResetDefaults_Interface() WomanSurnameFormat = WomanSurnameFormat.wsfNotExtend; UseSurnamesInPersonSelectionFilter = false; UseBirthDatesInPersonSelectionFilter = false; - ShowIndiAssociations = false; ShowIndiNamesakes = true; } @@ -820,6 +825,8 @@ public void LoadFromFile(IniFile ini) UseSurnamesInPersonSelectionFilter = ini.ReadBool("Common", "UseSurnamesInPersonSelectionFilter", false); UseBirthDatesInPersonSelectionFilter = ini.ReadBool("Common", "UseBirthDatesInPersonSelectionFilter", false); + ShowIndiAssociations = ini.ReadBool("Common", "ShowIndiAssociations", false); + ShowIndiNamesakes = ini.ReadBool("Common", "ShowIndiNamesakes", false); Theme = ini.ReadString("Common", "Theme", ""); @@ -966,6 +973,8 @@ public void SaveToFile(IniFile ini) ini.WriteBool("Common", "UseSurnamesInPersonSelectionFilter", UseSurnamesInPersonSelectionFilter); ini.WriteBool("Common", "UseBirthDatesInPersonSelectionFilter", UseBirthDatesInPersonSelectionFilter); + ini.WriteBool("Common", "ShowIndiAssociations", ShowIndiAssociations); + ini.WriteBool("Common", "ShowIndiNamesakes", ShowIndiNamesakes); ini.WriteString("Common", "Theme", Theme); diff --git a/projects/GKv2/GKComponents/GKUI/Components/UIHelper.cs b/projects/GKv2/GKComponents/GKUI/Components/UIHelper.cs index f1a596459..c34b6fdee 100644 --- a/projects/GKv2/GKComponents/GKUI/Components/UIHelper.cs +++ b/projects/GKv2/GKComponents/GKUI/Components/UIHelper.cs @@ -1,6 +1,6 @@ /* * "GEDKeeper", the personal genealogical database editor. - * Copyright (C) 2009-2023 by Sergey V. Zhdanovskih, Ruslan Garipov. + * Copyright (C) 2009-2024 by Sergey V. Zhdanovskih, Ruslan Garipov. * * This file is part of "GEDKeeper". * @@ -265,7 +265,9 @@ public static Color Lighter(Color color, float fraction) public static Bitmap LoadResourceImage(string resName) { - return new Bitmap(GKUtils.LoadResourceStream(resName)); + using (var stream = GKUtils.LoadResourceStream(resName)) { + return new Bitmap(stream); + } } public static void ProcessName(object sender) diff --git a/projects/GKv3/GKComponents/GKUI/Components/UIHelper.cs b/projects/GKv3/GKComponents/GKUI/Components/UIHelper.cs index 6da04e2d2..f939acd62 100644 --- a/projects/GKv3/GKComponents/GKUI/Components/UIHelper.cs +++ b/projects/GKv3/GKComponents/GKUI/Components/UIHelper.cs @@ -259,7 +259,9 @@ public static Color Lighter(Color color, float fraction) public static Bitmap LoadResourceImage(string resName) { - return new Bitmap(GKUtils.LoadResourceStream(resName)); + using (var stream = GKUtils.LoadResourceStream(resName)) { + return new Bitmap(stream); + } } public static void ProcessName(object sender)