Skip to content

Commit

Permalink
Various improvements
Browse files Browse the repository at this point in the history
  • Loading branch information
Serg-Norseman committed Jul 15, 2024
1 parent b32efde commit 373d83e
Show file tree
Hide file tree
Showing 15 changed files with 143 additions and 152 deletions.
8 changes: 4 additions & 4 deletions projects/GKCore/GDModel/GDMList.cs
Original file line number Diff line number Diff line change
Expand Up @@ -95,7 +95,7 @@ public int Count
public T this[int index]
{
get {
return (fDataList == null) ? default(T) : fDataList[index];
return (fDataList == null) ? default : fDataList[index];
}
}

Expand Down Expand Up @@ -204,7 +204,7 @@ public void Exchange(int index1, int index2)

public T Extract(int index)
{
if (fDataList == null) return default(T);
if (fDataList == null) return default;

T result = fDataList[index];
fDataList.RemoveAt(index);
Expand All @@ -213,14 +213,14 @@ public T Extract(int index)

public T Extract(T item)
{
if (fDataList == null) return default(T);
if (fDataList == null) return default;

int index = fDataList.IndexOf(item);
if (index >= 0) {
fDataList.RemoveAt(index);
return item;
} else {
return default(T);
return default;
}
}

Expand Down
2 changes: 1 addition & 1 deletion projects/GKCore/GDModel/GDMLocationRecord.cs
Original file line number Diff line number Diff line change
Expand Up @@ -242,7 +242,7 @@ public GDMList<GDMLocationName> GetFullNames(GDMTree tree, ATDEnumeration atdEnu
}
}

if (topBuffer.Count == 0 || !locDate.IsEmpty()) {
if (topBuffer.Count == 0 || (locDate != null && !locDate.IsEmpty())) {
result.Add(new GDMLocationName(nVal, locDate));
}
}
Expand Down
6 changes: 3 additions & 3 deletions projects/GKCore/GKCore/GKData.cs
Original file line number Diff line number Diff line change
Expand Up @@ -390,12 +390,12 @@ static GKData()
new PredefinedEvent(LSID.PersonalProperty, GEDCOMTagName.PROP, EventKind.ekFact, EventTarget.etIndividual),
new PredefinedEvent(LSID.NobilityTitle, GEDCOMTagName.TITL, EventKind.ekFact, EventTarget.etIndividual),

new PredefinedEvent(LSID.Travel, GEDCOMTagName._TRAVEL, EventKind.ekFact, EventTarget.etIndividual),
new PredefinedEvent(LSID.Travel, GEDCOMTagName._TRAVEL, EventKind.ekFact, EventTarget.etIndividual, true),
new PredefinedEvent(LSID.Hobby, GEDCOMTagName._HOBBY, EventKind.ekFact, EventTarget.etIndividual),
new PredefinedEvent(LSID.Award, GEDCOMTagName._AWARD, EventKind.ekFact, EventTarget.etIndividual),
new PredefinedEvent(LSID.Mili, GEDCOMTagName._MILI, EventKind.ekFact, EventTarget.etIndividual),
new PredefinedEvent(LSID.MiliInd, GEDCOMTagName._MILI_IND, EventKind.ekFact, EventTarget.etIndividual),
new PredefinedEvent(LSID.MiliDis, GEDCOMTagName._MILI_DIS, EventKind.ekFact, EventTarget.etIndividual),
new PredefinedEvent(LSID.MiliInd, GEDCOMTagName._MILI_IND, EventKind.ekFact, EventTarget.etIndividual, true),
new PredefinedEvent(LSID.MiliDis, GEDCOMTagName._MILI_DIS, EventKind.ekFact, EventTarget.etIndividual, true),
new PredefinedEvent(LSID.MiliRank, GEDCOMTagName._MILI_RANK, EventKind.ekFact, EventTarget.etIndividual),

new PredefinedEvent(LSID.BloodGroup, GEDCOMTagName._BGRO, EventKind.ekFact, EventTarget.etIndividual),
Expand Down
2 changes: 1 addition & 1 deletion projects/GKCore/GKCore/Lists/ListSource.cs
Original file line number Diff line number Diff line change
Expand Up @@ -137,7 +137,7 @@ public void Clear()
fExternalFilter = null;
fFilter.Clear();

fFetchedRec = default(T);
fFetchedRec = default;

fColumnsMap.Clear();
fListColumns.Clear();
Expand Down
7 changes: 3 additions & 4 deletions projects/GKCore/GKCore/NetDiff/DiffUtil.cs
Original file line number Diff line number Diff line change
Expand Up @@ -132,8 +132,8 @@ private static IEnumerable<DiffResult<T>> MakeResults<T>(IEnumerable<Point> wayp
foreach (var pair in MakePairsWithNext(waypoints))
{
var status = GetStatus(pair.Item1, pair.Item2);
T obj1 = default(T);
T obj2 = default(T);
T obj1 = default;
T obj2 = default;
switch (status)
{
case DiffStatus.Equal:
Expand Down Expand Up @@ -276,8 +276,7 @@ internal class EditGraph<T>
private int offset;
private bool isEnd;

public EditGraph(
IEnumerable<T> seq1, IEnumerable<T> seq2)
public EditGraph(IEnumerable<T> seq1, IEnumerable<T> seq2)
{
this.seq1 = seq1.ToArray();
this.seq2 = seq2.ToArray();
Expand Down
190 changes: 102 additions & 88 deletions projects/GKCore/GKCore/ScriptEngine.cs
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 All @@ -18,13 +18,15 @@
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*/

#pragma warning disable IDE0060 // Remove unused parameter
#pragma warning disable IDE1006 // Naming Styles

#if !MOBILE

using System;
using System.Data;
using System.IO;
using System.Reflection;
using System.Text;
using BSLib;
using GDModel;
using GDModel.Providers.GEDCOM;
Expand Down Expand Up @@ -54,7 +56,7 @@ public ScriptException(string message) : base(message)
public class ScriptEngine
{
private IBaseWindow fBase;
private IScriptConsole fView;
private readonly IScriptConsole fView;

public ScriptEngine(IScriptConsole view)
{
Expand Down Expand Up @@ -92,15 +94,15 @@ private void lua_register(Lua lvm, string funcName)

private void lua_init(Lua lvm)
{
lua_register(lvm, "print");
lua_register(lvm, "progress_init");
lua_register(lvm, "progress_done");
lua_register(lvm, "progress_step");
lua_register(lvm, nameof(print));
lua_register(lvm, nameof(progress_init));
lua_register(lvm, nameof(progress_done));
lua_register(lvm, nameof(progress_step));

lua_register(lvm, "strpos");
lua_register(lvm, "update_view");
lua_register(lvm, "select_file");
lua_register(lvm, "select_new_file");
lua_register(lvm, nameof(strpos));
lua_register(lvm, nameof(update_view));
lua_register(lvm, nameof(select_file));
lua_register(lvm, nameof(select_new_file));

lvm["rtNone"] = (int)GDMRecordType.rtNone;
lvm["rtIndividual"] = (int)GDMRecordType.rtIndividual;
Expand All @@ -118,114 +120,115 @@ private void lua_init(Lua lvm)
lvm["rtSubmitter"] = (int)GDMRecordType.rtSubmitter;

// any records
lua_register(lvm, "get_records_count");
lua_register(lvm, "get_record");
lua_register(lvm, "get_record_type");
lua_register(lvm, "get_record_type_name");
lua_register(lvm, "get_record_xref");
lua_register(lvm, "get_record_uid");
lua_register(lvm, "delete_record");
lua_register(lvm, "record_is_filtered");
lua_register(lvm, "select_record");
lua_register(lvm, nameof(get_records_count));
lua_register(lvm, nameof(get_record));
lua_register(lvm, nameof(get_record_type));
lua_register(lvm, nameof(get_record_type_name));
lua_register(lvm, nameof(get_record_xref));
lua_register(lvm, nameof(get_record_uid));
lua_register(lvm, nameof(delete_record));
lua_register(lvm, nameof(record_is_filtered));
lua_register(lvm, nameof(select_record));

// any record : notes
lua_register(lvm, "get_record_notes_count");
lua_register(lvm, nameof(get_record_notes_count));

// any record : multimedia links
lua_register(lvm, "get_record_medialinks_count");
lua_register(lvm, "get_record_medialink");
lua_register(lvm, "set_medialink_primary");
lua_register(lvm, nameof(get_record_medialinks_count));
lua_register(lvm, nameof(get_record_medialink));
lua_register(lvm, nameof(set_medialink_primary));

// any record : bind notes, sources, multimedia
lua_register(lvm, "bind_record_note");
lua_register(lvm, "bind_record_source");
lua_register(lvm, nameof(bind_record_note));
lua_register(lvm, nameof(bind_record_source));

// individual records
lua_register(lvm, "create_individual");
lua_register(lvm, "get_individual_name");
lua_register(lvm, "define_sex");
lua_register(lvm, "get_individual_sex");
lua_register(lvm, "set_individual_sex");
lua_register(lvm, "define_patronymic");
lua_register(lvm, "get_individual_parents_family");
lua_register(lvm, "get_individual_spouses_count");
lua_register(lvm, "get_individual_spouse_family");
lua_register(lvm, "get_individual_primary_medialink");
lua_register(lvm, nameof(create_individual));
lua_register(lvm, nameof(get_individual_name));
lua_register(lvm, nameof(define_sex));
lua_register(lvm, nameof(get_individual_sex));
lua_register(lvm, nameof(set_individual_sex));
lua_register(lvm, nameof(define_patronymic));
lua_register(lvm, nameof(get_individual_parents_family));
lua_register(lvm, nameof(get_individual_spouses_count));
lua_register(lvm, nameof(get_individual_spouse_family));
lua_register(lvm, nameof(get_individual_primary_medialink));

// individual records : associations
lua_register(lvm, "get_individual_associations_count");
lua_register(lvm, "get_individual_association");
lua_register(lvm, "delete_individual_association");
lua_register(lvm, "add_individual_association");
lua_register(lvm, nameof(get_individual_associations_count));
lua_register(lvm, nameof(get_individual_association));
lua_register(lvm, nameof(delete_individual_association));
lua_register(lvm, nameof(add_individual_association));

// individual records : events
lua_register(lvm, "get_individual_events_count");
lua_register(lvm, "get_individual_event");
lua_register(lvm, "delete_individual_event");
lua_register(lvm, "get_individual_event_ex");
lua_register(lvm, nameof(get_individual_events_count));
lua_register(lvm, nameof(get_individual_event));
lua_register(lvm, nameof(delete_individual_event));
lua_register(lvm, nameof(get_individual_event_ex));

// individual records : groups
lua_register(lvm, "get_individual_groups_count");
lua_register(lvm, "get_individual_group");
lua_register(lvm, nameof(get_individual_groups_count));
lua_register(lvm, nameof(get_individual_group));

// family records
lua_register(lvm, "create_family");
lua_register(lvm, "bind_family_spouse");
lua_register(lvm, "bind_family_child");
lua_register(lvm, "get_family_husband");
lua_register(lvm, "get_family_wife");
lua_register(lvm, "get_family_childs_count");
lua_register(lvm, "get_family_child");
lua_register(lvm, nameof(create_family));
lua_register(lvm, nameof(bind_family_spouse));
lua_register(lvm, nameof(bind_family_child));
lua_register(lvm, nameof(get_family_husband));
lua_register(lvm, nameof(get_family_wife));
lua_register(lvm, nameof(get_family_childs_count));
lua_register(lvm, nameof(get_family_child));

// note records
lua_register(lvm, "create_note");
lua_register(lvm, "add_note_text");
lua_register(lvm, nameof(create_note));
lua_register(lvm, nameof(add_note_text));

// any record with events (individual / family)
lua_register(lvm, "create_event");
lua_register(lvm, nameof(create_event));

// events
lua_register(lvm, "get_event_value");
lua_register(lvm, "get_event_place");
lua_register(lvm, "get_event_date");
lua_register(lvm, "get_event_name");
lua_register(lvm, "set_event_value");
lua_register(lvm, "set_event_place");
lua_register(lvm, "set_event_date");
lua_register(lvm, "get_event_year");
lua_register(lvm, nameof(get_event_value));
lua_register(lvm, nameof(get_event_place));
lua_register(lvm, nameof(get_event_date));
lua_register(lvm, nameof(get_event_name));
lua_register(lvm, nameof(set_event_value));
lua_register(lvm, nameof(set_event_place));
lua_register(lvm, nameof(set_event_date));
lua_register(lvm, nameof(get_event_year));

// source records
lua_register(lvm, "create_source");
lua_register(lvm, "find_source");
lua_register(lvm, nameof(create_source));
lua_register(lvm, nameof(find_source));

// group records
lua_register(lvm, "create_group");
lua_register(lvm, "bind_group_member");
lua_register(lvm, "get_group_name");
lua_register(lvm, nameof(create_group));
lua_register(lvm, nameof(bind_group_member));
lua_register(lvm, nameof(get_group_name));

// location records
lua_register(lvm, "get_location_usages");
lua_register(lvm, nameof(create_location));
lua_register(lvm, nameof(get_location_usages));

// csv
lua_register(lvm, "csv_load");
lua_register(lvm, "csv_close");
lua_register(lvm, "csv_get_cols");
lua_register(lvm, "csv_get_rows");
lua_register(lvm, "csv_get_cell");
lua_register(lvm, "csv_create");
lua_register(lvm, "csv_write_cell");
lua_register(lvm, nameof(csv_load));
lua_register(lvm, nameof(csv_close));
lua_register(lvm, nameof(csv_get_cols));
lua_register(lvm, nameof(csv_get_rows));
lua_register(lvm, nameof(csv_get_cell));
lua_register(lvm, nameof(csv_create));
lua_register(lvm, nameof(csv_write_cell));

// experimental
lua_register(lvm, "ado_open");
lua_register(lvm, "ado_close");
lua_register(lvm, "ado_query_open");
lua_register(lvm, "ado_query_close");
lua_register(lvm, "ado_query_first");
lua_register(lvm, "ado_query_prev");
lua_register(lvm, "ado_query_next");
lua_register(lvm, "ado_query_last");
lua_register(lvm, "ado_get_query_field");
lua_register(lvm, "ado_dump");
lua_register(lvm, nameof(ado_open));
lua_register(lvm, nameof(ado_close));
lua_register(lvm, nameof(ado_query_open));
lua_register(lvm, nameof(ado_query_close));
lua_register(lvm, nameof(ado_query_first));
lua_register(lvm, nameof(ado_query_prev));
lua_register(lvm, nameof(ado_query_next));
lua_register(lvm, nameof(ado_query_last));
lua_register(lvm, nameof(ado_get_query_field));
lua_register(lvm, nameof(ado_dump));
}

#endregion
Expand Down Expand Up @@ -631,6 +634,17 @@ public object get_family_child(object recPtr, int childIndex)
return (fam == null) ? null : fBase.Context.Tree.GetPtrValue<GDMRecord>(fam.Children[childIndex]);
}

public object create_location(string name, string date)
{
var loc = fBase.Context.Tree.CreateLocation();
var locName = new GDMLocationName() {
StringValue = name,
Date = { StringValue = date }
};
loc.Names.Add(locName);
return loc;
}

public int get_location_usages(object recPtr)
{
GDMLocationRecord loc = recPtr as GDMLocationRecord;
Expand Down Expand Up @@ -725,7 +739,7 @@ public bool csv_load(string fileName, bool hasHeader)

public bool csv_create(string fileName, int columnsCount, int rowsCount)
{
bool result = false;
bool result;

try {
fCSVWriter = new CSVWriter();
Expand Down
Loading

0 comments on commit 373d83e

Please sign in to comment.