Skip to content

Commit

Permalink
Added remembering and the feature to select from a list of causes and…
Browse files Browse the repository at this point in the history
… agencies of events (fix #565)
  • Loading branch information
Serg-Norseman committed Jun 21, 2024
1 parent 6c8641c commit 02e905d
Show file tree
Hide file tree
Showing 15 changed files with 80 additions and 63 deletions.
1 change: 1 addition & 0 deletions locales/help_enu/gkhHistory.html
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@ <h1>Change log</h1>

<p>
<b>14.06.2024 [v2.30.1 &amp; v3.6.1]</b><ul>
<li>Added remembering and the feature to select from a list of causes and agencies of events.
<li>Added an option to select list filtering methods (differences in speed).
<li>Added an option to display the full name in one line in trees, for countries with a short form of the full name (hieroglyphs).
<li>Added custom event types, the feature to turn off events and add custom ones.
Expand Down
1 change: 1 addition & 0 deletions locales/help_rus/gkhHistory.html
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@ <h1>История версий</h1>

<p>
<b>14.06.2024 [v2.30.1 &amp; v3.6.1]</b><ul>
<li>Добавлено запоминание и возможность выбора из списка причин и удостоверяющих организаций событий.
<li>Добавлена опция выбора методов фильтрации списков (различия по скорости).
<li>Добавлена опция вывода в деревьях полного имени в одну строку, для стран с короткой формой полного имени (иероглифы).
<li>Добавлены настраиваемые типы событий, возможность выключения событий и добавления пользовательских.
Expand Down
14 changes: 11 additions & 3 deletions projects/GKCore/GKCore/BaseContext.cs
Original file line number Diff line number Diff line change
Expand Up @@ -192,10 +192,18 @@ public void CollectEventValues(GDMCustomEvent evt)
{
if (evt == null) return;

string evName = evt.GetTagName();
string evKey = evt.GetEventKey();
string evVal = evt.StringValue;
if (!string.IsNullOrEmpty(evName) && !string.IsNullOrEmpty(evVal)) {
fValuesCollection.Add(evName, evVal, true);
if (!string.IsNullOrEmpty(evKey) && !string.IsNullOrEmpty(evVal)) {
fValuesCollection.Add(evKey, evVal);
}

if (!string.IsNullOrEmpty(evt.Cause)) {
fValuesCollection.Add(GEDCOMTagName.CAUS, evt.Cause);
}

if (!string.IsNullOrEmpty(evt.Agency)) {
fValuesCollection.Add(GEDCOMTagName.AGNC, evt.Agency);
}
}

Expand Down
28 changes: 17 additions & 11 deletions projects/GKCore/GKCore/Controllers/EventEditDlgController.cs
Original file line number Diff line number Diff line change
Expand Up @@ -160,8 +160,12 @@ public override void UpdateView()
ChangeEventType();

fView.Date.Date = fEvent.Date.Value;
fView.Cause.Text = fEvent.Cause;
fView.Agency.Text = fEvent.Agency;

var causVals = fBase.Context.ValuesCollection.GetValues(GEDCOMTagName.CAUS);
UpdateCombo(fView.Cause, true, false, causVals, fEvent.Cause);

var agncVals = fBase.Context.ValuesCollection.GetValues(GEDCOMTagName.AGNC);
UpdateCombo(fView.Agency, true, false, agncVals, fEvent.Agency);

fTempLocation = fBase.Context.Tree.GetPtrValue<GDMLocationRecord>(fEvent.Place.Location);
UpdatePlace(true);
Expand Down Expand Up @@ -238,27 +242,29 @@ public void ChangeEventType()
bool isFact = (evDef.Kind == EventKind.ekFact);
SetAttributeMode(isFact);

// TODO: It is necessary to provide the registrable list of values for different tag types.
string[] vals;
bool canbeSorted, fixedList;

if (evTag == GEDCOMTagName._BGRO) {
vals = GKData.BloodGroups.Split('|');
canbeSorted = false;
fixedList = true;
} else {
vals = fBase.Context.ValuesCollection.GetValues(evTag);
string evKey = evDef.Tag + ":" + evDef.Type;
vals = fBase.Context.ValuesCollection.GetValues(evKey);
canbeSorted = true;
fixedList = false;
}
UpdateCombo(fView.Attribute, canbeSorted, fixedList, vals, fView.Attribute.Text);
}

if (vals != null) {
string tmp = fView.Attribute.Text;
fView.Attribute.Clear();
fView.Attribute.AddRange(vals, canbeSorted);
fView.Attribute.Text = tmp;
fView.Attribute.ReadOnly = fixedList;
private void UpdateCombo(IComboBox combo, bool canbeSorted, bool readOnly, string[] values, string current)
{
combo.Clear();
if (values != null) {
combo.AddRange(values, canbeSorted);
}
combo.Text = current;
combo.ReadOnly = readOnly;
}

public void SendData(string signature, string data)
Expand Down
4 changes: 2 additions & 2 deletions projects/GKCore/GKCore/Design/Views/IEventEditDlg.cs
Original file line number Diff line number Diff line change
Expand Up @@ -35,8 +35,8 @@ public interface IEventEditDlg : ICommonDialog, IBaseEditor, IDataReceiver

IComboBox Attribute { get; }
ITextBox Place { get; }
ITextBox Cause { get; }
ITextBox Agency { get; }
IComboBox Cause { get; }
IComboBox Agency { get; }

ISheetList NotesList { get; }
ISheetList MediaList { get; }
Expand Down
9 changes: 8 additions & 1 deletion projects/GKCore/GKCore/GKExtensions.cs
Original file line number Diff line number Diff line change
@@ -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".
*
Expand All @@ -18,9 +18,16 @@
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*/

using GDModel;
using GDModel.Providers.GEDCOM;

namespace GKCore
{
public static class GKExtensions
{
public static string GetEventKey(this GDMCustomEvent customEvent)
{
return (customEvent == null) ? string.Empty : customEvent.GetTagName() + ":" + customEvent.Classification;
}
}
}
34 changes: 14 additions & 20 deletions projects/GKCore/GKCore/ValuesCollection.cs
Original file line number Diff line number Diff line change
@@ -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".
*
Expand All @@ -24,7 +24,7 @@ namespace GKCore
{
public sealed class ValuesCollection
{
private readonly Dictionary<string, List<string>> fValues;
private readonly Dictionary<string, SortedSet<string>> fValues;

public int Count
{
Expand All @@ -33,29 +33,24 @@ public int Count

public ValuesCollection()
{
fValues = new Dictionary<string, List<string>>();
fValues = new Dictionary<string, SortedSet<string>>();
}

public void Clear()
{
fValues.Clear();
}

public void Add(string name, string value, bool excludeDuplicates = false)
public void Add(string name, string value)
{
List<string> arrayList;
if (!fValues.TryGetValue(name, out arrayList)) {
arrayList = new List<string>(1);
fValues.Add(name, arrayList);
SortedSet<string> set;
if (!fValues.TryGetValue(name, out set)) {
set = new SortedSet<string>();
fValues.Add(name, set);
}

if (value == null) return;

if (!excludeDuplicates) {
arrayList.Add(value);
} else {
if (!arrayList.Contains(value)) arrayList.Add(value);
}
if (!string.IsNullOrEmpty(value))
set.Add(value);
}

public void Remove(string name)
Expand All @@ -65,15 +60,14 @@ public void Remove(string name)

public string[] GetValues(string name)
{
List<string> list;
if (!fValues.TryGetValue(name, out list)) {
SortedSet<string> set;
if (!fValues.TryGetValue(name, out set)) {
return new string[0];
}

int num = list.Count;
int num = set.Count;
string[] array = new string[num];
list.CopyTo(0, array, 0, num);

set.CopyTo(array, 0, num);
return array;
}
}
Expand Down
4 changes: 2 additions & 2 deletions projects/GKTests/GKCore/ControllerTests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -253,8 +253,8 @@ public void Test_EventEditDlgController()
view.Date.Returns(Substitute.For<IDateControl>());
view.Attribute.Returns(Substitute.For<IComboBox>());
view.Place.Returns(Substitute.For<ITextBox>());
view.Cause.Returns(Substitute.For<ITextBox>());
view.Agency.Returns(Substitute.For<ITextBox>());
view.Cause.Returns(Substitute.For<IComboBox>());
view.Agency.Returns(Substitute.For<IComboBox>());
view.NotesList.Returns(Substitute.For<ISheetList>());
view.MediaList.Returns(Substitute.For<ISheetList>());
view.SourcesList.Returns(Substitute.For<ISheetList>());
Expand Down
4 changes: 2 additions & 2 deletions projects/GKTests/GKCore/ValuesCollectionTests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -32,10 +32,10 @@ public void Test_Common()

valsCol.Add("red", "rojo");
valsCol.Add("green", "verde");
valsCol.Add("blue", "azul", true);
valsCol.Add("blue", "azul");
valsCol.Add("red", "rouge");
valsCol.Add("red", null);
valsCol.Add("red", "rouge", true);
valsCol.Add("red", "rouge");

Assert.AreEqual(3, valsCol.Count);

Expand Down
8 changes: 4 additions & 4 deletions projects/GKv2/GEDKeeper2/GKUI/Forms/EventEditDlg.Designer.cs

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

8 changes: 4 additions & 4 deletions projects/GKv2/GEDKeeper2/GKUI/Forms/EventEditDlg.cs
Original file line number Diff line number Diff line change
Expand Up @@ -80,14 +80,14 @@ ITextBox IEventEditDlg.Place
get { return GetControlHandler<ITextBox>(txtEventPlace); }
}

ITextBox IEventEditDlg.Cause
IComboBox IEventEditDlg.Cause
{
get { return GetControlHandler<ITextBox>(txtEventCause); }
get { return GetControlHandler<IComboBox>(txtEventCause); }
}

ITextBox IEventEditDlg.Agency
IComboBox IEventEditDlg.Agency
{
get { return GetControlHandler<ITextBox>(txtEventOrg); }
get { return GetControlHandler<IComboBox>(txtEventOrg); }
}

#endregion
Expand Down
12 changes: 6 additions & 6 deletions projects/GKv3/GEDKeeper3/GKUI/Forms/EventEditDlg.cs
Original file line number Diff line number Diff line change
Expand Up @@ -53,8 +53,8 @@ public sealed partial class EventEditDlg : CommonDialog<IEventEditDlg, EventEdit
private Label lblAttrValue;
private ComboBox cmbEventType;
private TextBox txtEventPlace;
private TextBox txtEventCause;
private TextBox txtEventOrg;
private ComboBox txtEventCause;
private ComboBox txtEventOrg;
private ComboBox txtAttribute;
private Button btnPlaceAdd;
private Button btnPlaceDelete;
Expand Down Expand Up @@ -109,14 +109,14 @@ ITextBox IEventEditDlg.Place
get { return GetControlHandler<ITextBox>(txtEventPlace); }
}

ITextBox IEventEditDlg.Cause
IComboBox IEventEditDlg.Cause
{
get { return GetControlHandler<ITextBox>(txtEventCause); }
get { return GetControlHandler<IComboBox>(txtEventCause); }
}

ITextBox IEventEditDlg.Agency
IComboBox IEventEditDlg.Agency
{
get { return GetControlHandler<ITextBox>(txtEventOrg); }
get { return GetControlHandler<IComboBox>(txtEventOrg); }
}

#endregion
Expand Down
4 changes: 2 additions & 2 deletions projects/GKv3/GEDKeeper3/GKUI/Forms/EventEditDlg.xeto
Original file line number Diff line number Diff line change
Expand Up @@ -40,12 +40,12 @@

<TableRow>
<Label x:Name="lblCause" />
<TextBox x:Name="txtEventCause" />
<ComboBox x:Name="txtEventCause" />
</TableRow>

<TableRow>
<Label x:Name="lblOrg" />
<TextBox x:Name="txtEventOrg" />
<ComboBox x:Name="txtEventOrg" />
</TableRow>

<TableRow ScaleHeight="True" />
Expand Down
4 changes: 2 additions & 2 deletions projects/GKvX/GEDKeeperX/GKUI/Forms/EventEditDlg.xaml
Original file line number Diff line number Diff line change
Expand Up @@ -51,10 +51,10 @@
<comcom:GKDateControl x:Name="dateCtl" Grid.Column="1" Grid.Row="3" />

<Label x:Name="lblCause" Grid.Column="0" Grid.Row="4" />
<Entry x:Name="txtEventCause" Grid.Column="1" Grid.Row="4" />
<comcom:GKComboBox x:Name="txtEventCause" Grid.Column="1" Grid.Row="4" />

<Label x:Name="lblOrg" Grid.Column="0" Grid.Row="5" />
<Entry x:Name="txtEventOrg" Grid.Column="1" Grid.Row="5" />
<comcom:GKComboBox x:Name="txtEventOrg" Grid.Column="1" Grid.Row="5" />
</Grid>

<Label VerticalOptions="FillAndExpand" />
Expand Down
8 changes: 4 additions & 4 deletions projects/GKvX/GEDKeeperX/GKUI/Forms/EventEditDlg.xaml.cs
Original file line number Diff line number Diff line change
Expand Up @@ -74,14 +74,14 @@ ITextBox IEventEditDlg.Place
get { return GetControlHandler<ITextBox>(txtEventPlace); }
}

ITextBox IEventEditDlg.Cause
IComboBox IEventEditDlg.Cause
{
get { return GetControlHandler<ITextBox>(txtEventCause); }
get { return GetControlHandler<IComboBox>(txtEventCause); }
}

ITextBox IEventEditDlg.Agency
IComboBox IEventEditDlg.Agency
{
get { return GetControlHandler<ITextBox>(txtEventOrg); }
get { return GetControlHandler<IComboBox>(txtEventOrg); }
}

#endregion
Expand Down

0 comments on commit 02e905d

Please sign in to comment.