From 42178a894a410727193d29564eb6199834bd778b Mon Sep 17 00:00:00 2001 From: "Sergey V. Zhdanovskih" Date: Tue, 7 Nov 2023 00:32:18 +0300 Subject: [PATCH 01/20] Switching total UI to async/await --- CODINGSTYLE.md | 341 ------------------ CONTRIBUTING.md | 2 +- README.md | 27 +- projects/GKCore/GKCore/AppHost.cs | 4 +- projects/GKCore/GKCore/BaseContext.cs | 33 +- .../AssociationEditDlgController.cs | 4 +- .../GKCore/Controllers/BaseController.cs | 58 +-- .../GKCore/Controllers/BaseWinController.cs | 52 +-- .../CommunicationEditDlgController.cs | 4 +- .../Controllers/EventEditDlgController.cs | 8 +- .../Controllers/FamilyEditDlgController.cs | 8 +- .../FilePropertiesDlgController.cs | 4 +- .../Controllers/ParentsEditDlgController.cs | 8 +- .../Controllers/PersonEditDlgController.cs | 16 +- .../Controllers/PlacesManagerController.cs | 4 +- .../GKCore/Controllers/RecMergeController.cs | 8 +- .../RelationshipCalculatorDlgController.cs | 8 +- .../RepositoryEditDlgController.cs | 4 +- .../Controllers/SourceCitEditDlgController.cs | 4 +- .../Controllers/TaskEditDlgController.cs | 8 +- .../Controllers/TreeChartWinController.cs | 20 +- .../Controllers/TreeFilterDlgController.cs | 4 +- .../GKCore/GKCore/Interfaces/IBaseContext.cs | 19 +- .../GKCore/Lists/AssociationsListModel.cs | 4 +- .../GKCore/GKCore/Lists/ChildrenListModel.cs | 10 +- .../GKCore/GKCore/Lists/EventsListModel.cs | 4 +- .../GKCore/GKCore/Lists/GroupListModel.cs | 4 +- .../GKCore/Lists/IndividualListModel.cs | 18 +- .../GKCore/Lists/MediaLinksListModel.cs | 6 +- .../GKCore/GKCore/Lists/NoteLinksListModel.cs | 4 +- .../GKCore/GKCore/Lists/ResearchListModel.cs | 12 +- .../GKCore/GKCore/Lists/SourceListModel.cs | 4 +- projects/GKCore/GKCore/ScriptEngine.cs | 11 +- .../GEDKeeper2/GKUI/Platform/WFAppHost.cs | 11 + .../GKComponents/GKUI/Forms/CommonForm.cs | 51 ++- .../GKv2/GKTestsUI2/UITests/MainSDITests.cs | 4 +- .../GEDKeeper3/GKUI/Platform/EtoAppHost.cs | 11 + .../GKComponents/GKUI/Forms/CommonForm.cs | 47 ++- .../GEDKeeperX/GKUI/Forms/LaunchPage.xaml.cs | 13 +- projects/plugins/GEDmill/MainForm.cs | 4 +- .../plugins/GKFlowInputPlugin/FlowInput.cs | 25 +- .../plugins/GKFlowInputPlugin/FlowInputDlg.cs | 6 +- 42 files changed, 303 insertions(+), 594 deletions(-) delete mode 100644 CODINGSTYLE.md diff --git a/CODINGSTYLE.md b/CODINGSTYLE.md deleted file mode 100644 index fec0026b1..000000000 --- a/CODINGSTYLE.md +++ /dev/null @@ -1,341 +0,0 @@ -# Target .NET platform - --- under revision -- - -# Language Integrated Query (LINQ) - -Using of LINQ in the project is not desirable, but is permissible in a limited scope (exceptionally not in the Core). - -# Non-portable features - -To develop a program feature, that is known to be non-portable between Linux and Microsoft Windows, -you **must** get project's owner (@Serg-Norseman) approval before doing that. - -# C# features - -# `foreach` operator - -We do not recommend to use operator `foreach` in the code. One can use it in some GUI implementations, -but we still strongly advise against it. Using the operator in the main classes of the core is -completely unacceptable, to avoid performance degradation. - -## Use of var - -You can use "var" on the left-hand side of an assignment when the type name is repeated on the right hand side. -Otherwise, the use of "var" is prohibited. Exception: primitive types (int, string, double, etc) use predefined names. - -## Use flags and directives - -Use flags and directives in code, so that you can come back later and work on it. - -You can use the #warning and #error directives, - -```csharp -#warning This is dirty code... -#error Fix this before everything explodes! -``` - -Also you can mark it with "//TODO:" or "//FIXME:" comments that show up in the task pane in IDE or for fast search. - -# Naming - -## Namespace names - -Namespaces are named using Pascal Case (also called `UpperCamelCase`) with no underscores. -This means the first letter of every word in the name is capitalized. For example: `MyNewNamespace`. -However, are allowed capitalized acronyms (`MyXMLNamespace`). - -## Assemblies - -If an assembly contains only one namespace, they should use the same name. -Otherwise, assemblies should follow the normal Pascal Case format. - -## Classes and structures - -Pascal Case, no underscores or leading C, cls, or I. Classes should not have the same name as the namespace -in which they reside. Allowed capitalized acronyms. Try to avoid abbreviations, and try to always use nouns. - -### Properties and public fields, constants and readonly fields - -Pascal Case, no underscores. Try to avoid abbreviations. - -### Private and protected fields - -Pascal Case with a leading `f`-char. Always indicate protected or private in the declaration. -The leading character helps to prevent name collisions in constructors (a parameter and a private field -having the same name). - -Using of "m_" and "_" as prefixes for instance members is highly discouraged. - -## Exception classes - -Follow class naming conventions, but add suffix `Exception` to the end of the name. - -## Interfaces - -Follow class naming conventions, but start the name with `I` and capitalize the letter following the `I`. -Example: `IFoo`. - -The `I` prefix helps to differentiate between interfaces and classes, and also to avoid name collisions. - -## Methods - -Pascal Case, no underscores except in the event handlers. Please, try to avoid abbreviations. Since the latter may -dramatically affect on code readability, we strongly advise against using abbreviations, except ones that are -widely known. - -## Method arguments and local variables - -Camel Case (or `lowerCamelCase`). Try to avoid abbreviations. -Camel Case is the same as Pascal case, but the first letter of the first word is lowercased. - -## Controls on Forms - -Pascal Case with a prefix that identifies it as being part of the UI instead of a purely coded control -(example a temporary variable). Many developers use `ui` as the prefix followed by a descriptive name such as -`txtUserName` or `lblUserNickName` ("txt" stands for TextBox control and "lbl" for Label control) - -Some samples: - -``` -Control Prefix Example -Label lbl lblSurname -TextBox txt txtSurname -DataGrid grid gridResults -Button btn btnSave -ListBox lst lstCompany -Checkbox chk chkMailList -CheckBoxList lst lstAddress -RadioButton rad radSex -Image img imgLogo -Panel pnl pnlSevtion -Table tbl tblResults -``` - -# Classes - -## Declaration order - -Declare all member variables at the top of class declaration, with static variables at the very top: - -- private static fields; -- protected and public static fields; -- private and public consts; -- private member fields; -- protected member fields (private and protected may be mixed); -- public member fields; -- properties; -- instance's control (constructor, destructor, static create methods if needs); -- private methods and public methods usually are mixed grouped by meaning and functions. - -In old and very old classes, the order of the sections may be absent, for example constructors can be at the end of class. -But this is valid only before the refactoring. Not supposed to do in the new classes. - -# Formatting - -## Indentation - -Use spaces (and configure your IDE to show a size of 4 spaces for them) for writing your code. -If you are modifying someone else’s code, try to keep the coding style similar. - -Switch statements have the "case" at the additional indentation. - -``` -switch (x) { - case 'a': - ... - case 'b': - ... -} -``` - -## Blank lines - -Blank lines improve readability and create logical blocks of code. - -Two blank lines should always be used between: - -- Logical sections of a source file -- Class and interface definitions (try one class/interface per file to prevent this case) - -One blank line should always be used between: - -- Methods -- Properties -- Local variables in a method and its first statement (necessarily only if the variable is in front of a large block of logically related statements) -- Logical sections inside a method to improve readability. - -## Wrapping Lines - -Preferred line length is 80 characters, taking into consideration the recommendations below: - -- Break after a comma. -- Break after an operator. -- Prefer higher-level breaks to lower-level breaks. -- Align the new line with the beginning of the expression at the same level on the previous line. - -## Where to put spaces - -Don't use a space before an opening parenthesis when calling functions, or indexing, like this: - -bad: - -```csharp -method (a); -b [10]; -``` - -Don't put a space after the opening parenthesis and the closing one, ie: - -bad: - -```csharp -method ( a ); -array[ 10 ]; -``` - -Don't put a space between the generic types, ie: - -bad: - -```csharp -var list = new List (); -``` - -good: - -```csharp -var list = new List(); -``` - -## Where to put braces - -Inside a code block, put the opening brace on the same line as the statement: - -good: - -```csharp -if (a) { - code(); - code(); -} -``` - -bad: - -```csharp -if (a) -{ - code(); - code(); -} -``` - -Avoid using unnecessary open/close braces, vertical space is usually limited: - -good: - -```sharp -if (a) - code(); -``` - -bad: - -```sharp -if (a) { - code(); -} -``` - -Unless there are either multiple hierarchical conditions being used, or the condition cannot fit into a single line. - -good: - -```csharp -if (a) { - if (b) - code(); -} -``` - -bad: - -```csharp -if (a) - if (b) - code(); -``` - -If statements with else clauses are formatted like this: - -good: - -```csharp -if (dingus) { - ... -} else { - ... -} -``` - -bad: - -```csharp -if (dingus) -{ - ... -} -else -{ - ... -} -``` - -bad: - -```csharp -if (dingus) { - ... -} -else { - ... -} -``` - -When defining namespaces and classes, method (including constructor), properties and indexers, use a new line for the brace. -For very small properties, you can compress things: - -passable: - -```csharp -int Property -{ - get { return value; } - set { x = value; } -} -``` - -Empty methods: they should have the body of code using two lines (if it's temporary stub), or all in one line (if it will never be implemented). - -## Use whitespace for clarity - -Use white space in expressions liberally, except in the presence of parenthesis. - -good: - -```csharp -if (a + 5 > method(blah() + 4)) -``` - -bad: - -```scharp -if (a + 5 > method (blah ()+4)) -``` - -bad: - -```csharp -if (a+5>method(blah()+4)) -``` diff --git a/CONTRIBUTING.md b/CONTRIBUTING.md index 58e8e5f42..71558c1c9 100644 --- a/CONTRIBUTING.md +++ b/CONTRIBUTING.md @@ -15,7 +15,7 @@ No code is perfect and we always welcome third-party patches. This document desc ## Making changes - Create a topic branch from where you want to base your work, -- Make your changes taking [style guide](CODINGSTYLE.md) into account, +- Make your changes taking style of sources into account, - Check for whitespace errors issuing `git diff --check`, `git diff --cached --check` or `git diff HEAD --check`, - Make commits writing good [commit messages](http://chris.beams.io/posts/git-commit/), diff --git a/README.md b/README.md index a5a0d73d7..8b5730545 100644 --- a/README.md +++ b/README.md @@ -62,23 +62,8 @@ If your problem or idea is not addressed yet, please open a new issue. ## Supported languages -- Belarusian, initial -- Chinese (simplified) -- Czech -- Dutch -- English -- French -- German -- Hungarian -- Icelandic, partial -- Italian -- Kazakh (Cyrillic), partial -- Polish -- Portuguese, initial -- Russian -- Serbian (Latin), partial -- Spanish, initial -- Ukrainian +Belarusian, Chinese (simplified), Czech, Dutch, English, French, German, Hungarian, Icelandic, +Italian, Kazakh (Cyrillic), Polish, Portuguese, Russian, Serbian (Latin), Spanish, Ukrainian. Platform for project localization: [Crowdin](https://crowdin.com/project/gedkeeper) @@ -86,12 +71,4 @@ Platform for project localization: [Crowdin](https://crowdin.com/project/gedkeep ## Docs & Help - [Contributing and Development guide](/CONTRIBUTING.md) -- [Coding style guide](/CODINGSTYLE.md) - [Changelog](/CHANGELOG.md) - - -## Links - -https://gedkeeper.net/ - -https://sourceforge.net/projects/gedkeeper/ diff --git a/projects/GKCore/GKCore/AppHost.cs b/projects/GKCore/GKCore/AppHost.cs index d2763087a..04641cb64 100644 --- a/projects/GKCore/GKCore/AppHost.cs +++ b/projects/GKCore/GKCore/AppHost.cs @@ -1042,12 +1042,12 @@ public void ShowOptions(IView owner) ShowOptions(owner, page); } - public void ShowOptions(IView owner, OptionsPage page) + public async void ShowOptions(IView owner, OptionsPage page) { using (var dlg = AppHost.ResolveDialog(AppHost.Instance)) { dlg.SetPage(page); - if (AppHost.Instance.ShowModalX(dlg, owner)) { + if (await AppHost.Instance.ShowModalAsync(dlg, owner)) { AppHost.Instance.ApplyOptions(); } } diff --git a/projects/GKCore/GKCore/BaseContext.cs b/projects/GKCore/GKCore/BaseContext.cs index e8df6283f..6886087c2 100644 --- a/projects/GKCore/GKCore/BaseContext.cs +++ b/projects/GKCore/GKCore/BaseContext.cs @@ -24,6 +24,7 @@ using System.Security.Cryptography; using System.Text; using System.Text.RegularExpressions; +using System.Threading.Tasks; using BSLib; using GDModel; using GDModel.Providers; @@ -604,7 +605,7 @@ public void CollectTips(StringList tipsList) #region Name and sex functions - public string DefinePatronymic(IView owner, string name, GDMSex sex, bool confirm) + public async Task DefinePatronymic(IView owner, string name, GDMSex sex, bool confirm) { ICulture culture = this.Culture; if (!culture.HasPatronymic) return string.Empty; @@ -637,7 +638,7 @@ public string DefinePatronymic(IView owner, string name, GDMSex sex, bool confir return result; } - BaseController.ModifyName(owner, this, ref n); + await BaseController.ModifyName(owner, this, n); } switch (sex) { @@ -653,7 +654,7 @@ public string DefinePatronymic(IView owner, string name, GDMSex sex, bool confir return result; } - public GDMSex DefineSex(IView owner, string iName, string iPatr) + public async Task DefineSex(IView owner, string iName, string iPatr) { INamesTable namesTable = AppHost.NamesTable; @@ -665,7 +666,7 @@ public GDMSex DefineSex(IView owner, string iName, string iPatr) result = this.Culture.GetSex(iName, iPatr, false); dlg.Sex = result; - if (AppHost.Instance.ShowModalX(dlg, owner, false)) { + if (await AppHost.Instance.ShowModalAsync(dlg, owner, false)) { result = dlg.Sex; if (result != GDMSex.svUnknown) { @@ -678,7 +679,7 @@ public GDMSex DefineSex(IView owner, string iName, string iPatr) return result; } - public void CheckPersonSex(IView owner, GDMIndividualRecord iRec) + public async void CheckPersonSex(IView owner, GDMIndividualRecord iRec) { if (iRec == null) throw new ArgumentNullException("iRec"); @@ -688,7 +689,7 @@ public void CheckPersonSex(IView owner, GDMIndividualRecord iRec) if (iRec.Sex != GDMSex.svMale && iRec.Sex != GDMSex.svFemale) { var parts = GKUtils.GetNameParts(fTree, iRec); - iRec.Sex = DefineSex(owner, parts.Name, parts.Patronymic); + iRec.Sex = await DefineSex(owner, parts.Name, parts.Patronymic); } } finally { EndUpdate(); @@ -1763,7 +1764,7 @@ public bool IsAvailableRecord(GDMRecord record) #region UI control functions - public GDMFamilyRecord SelectFamily(IView owner, GDMIndividualRecord target, TargetMode targetMode = TargetMode.tmFamilyChild) + public async Task SelectFamily(IView owner, GDMIndividualRecord target, TargetMode targetMode = TargetMode.tmFamilyChild) { GDMFamilyRecord result; @@ -1771,7 +1772,7 @@ public GDMFamilyRecord SelectFamily(IView owner, GDMIndividualRecord target, Tar using (var dlg = AppHost.ResolveDialog(fViewer, GDMRecordType.rtFamily)) { dlg.SetTarget(targetMode, target, GDMSex.svUnknown); - if (AppHost.Instance.ShowModalX(dlg, owner, false)) { + if (await AppHost.Instance.ShowModalAsync(dlg, owner, false)) { result = (dlg.ResultRecord as GDMFamilyRecord); } else { result = null; @@ -1785,7 +1786,7 @@ public GDMFamilyRecord SelectFamily(IView owner, GDMIndividualRecord target, Tar return result; } - public GDMIndividualRecord SelectPerson(IView owner, GDMIndividualRecord target, TargetMode targetMode, GDMSex needSex) + public async Task SelectPerson(IView owner, GDMIndividualRecord target, TargetMode targetMode, GDMSex needSex) { GDMIndividualRecord result; @@ -1793,7 +1794,7 @@ public GDMIndividualRecord SelectPerson(IView owner, GDMIndividualRecord target, using (var dlg = AppHost.ResolveDialog(fViewer, GDMRecordType.rtIndividual)) { dlg.SetTarget(targetMode, target, needSex); - if (AppHost.Instance.ShowModalX(dlg, owner, false)) { + if (await AppHost.Instance.ShowModalAsync(dlg, owner, false)) { result = (dlg.ResultRecord as GDMIndividualRecord); } else { result = null; @@ -1807,7 +1808,7 @@ public GDMIndividualRecord SelectPerson(IView owner, GDMIndividualRecord target, return result; } - public GDMRecord SelectRecord(IView owner, GDMRecordType mode, params object[] args) + public async Task SelectRecord(IView owner, GDMRecordType mode, params object[] args) { GDMRecord result; @@ -1816,7 +1817,7 @@ public GDMRecord SelectRecord(IView owner, GDMRecordType mode, params object[] a var flt = (args != null && args.Length > 0) ? (args[0] as string) : "*"; dlg.SetTarget(TargetMode.tmNone, null, GDMSex.svUnknown, flt); - if (AppHost.Instance.ShowModalX(dlg, owner, false)) { + if (await AppHost.Instance.ShowModalAsync(dlg, owner, false)) { result = dlg.ResultRecord; } else { result = null; @@ -1898,7 +1899,7 @@ public GDMFamilyRecord AddFamilyForSpouse(GDMIndividualRecord spouse) return family; } - public GDMIndividualRecord AddChildForParent(IView owner, GDMIndividualRecord parent, GDMSex needSex) + public async Task AddChildForParent(IView owner, GDMIndividualRecord parent, GDMSex needSex) { GDMIndividualRecord resultChild = null; @@ -1917,7 +1918,7 @@ public GDMIndividualRecord AddChildForParent(IView owner, GDMIndividualRecord pa family = fTree.GetPtrValue(parent.SpouseToFamilyLinks[0]); } - GDMIndividualRecord child = SelectPerson(owner, fTree.GetPtrValue(family.Husband), TargetMode.tmParent, needSex); + GDMIndividualRecord child = await SelectPerson(owner, fTree.GetPtrValue(family.Husband), TargetMode.tmParent, needSex); if (child != null && family.AddChild(child)) { // this repetition necessary, because the call of CreatePersonDialog only works if person already has a father, @@ -1932,7 +1933,7 @@ public GDMIndividualRecord AddChildForParent(IView owner, GDMIndividualRecord pa return resultChild; } - public GDMIndividualRecord SelectSpouseFor(IView owner, GDMIndividualRecord iRec) + public async Task SelectSpouseFor(IView owner, GDMIndividualRecord iRec) { if (iRec == null) throw new ArgumentNullException(@"iRec"); @@ -1952,7 +1953,7 @@ public GDMIndividualRecord SelectSpouseFor(IView owner, GDMIndividualRecord iRec return null; } - return SelectPerson(owner, iRec, TargetMode.tmSpouse, needSex); + return await SelectPerson(owner, iRec, TargetMode.tmSpouse, needSex); } public void ProcessFamily(GDMFamilyRecord famRec) diff --git a/projects/GKCore/GKCore/Controllers/AssociationEditDlgController.cs b/projects/GKCore/GKCore/Controllers/AssociationEditDlgController.cs index 0471e170b..48a90ffee 100644 --- a/projects/GKCore/GKCore/Controllers/AssociationEditDlgController.cs +++ b/projects/GKCore/GKCore/Controllers/AssociationEditDlgController.cs @@ -78,9 +78,9 @@ public override void UpdateView() fView.Person.Text = (fTempPerson == null) ? "" : GKUtils.GetNameString(fTempPerson, false); } - public void SetPerson() + public async void SetPerson() { - fTempPerson = fBase.Context.SelectPerson(fView, null, TargetMode.tmNone, GDMSex.svUnknown); + fTempPerson = await fBase.Context.SelectPerson(fView, null, TargetMode.tmNone, GDMSex.svUnknown); fView.Person.Text = (fTempPerson == null) ? "" : GKUtils.GetNameString(fTempPerson, false); } diff --git a/projects/GKCore/GKCore/Controllers/BaseController.cs b/projects/GKCore/GKCore/Controllers/BaseController.cs index 75710e53d..938a67e30 100644 --- a/projects/GKCore/GKCore/Controllers/BaseController.cs +++ b/projects/GKCore/GKCore/Controllers/BaseController.cs @@ -39,13 +39,13 @@ namespace GKCore.Controllers /// public static class BaseController { - public static void ViewRecordInfo(IView owner, IBaseWindow baseWin, GDMRecord record) + public static async void ViewRecordInfo(IView owner, IBaseWindow baseWin, GDMRecord record) { if (record == null) return; using (var dlg = AppHost.ResolveDialog(baseWin)) { dlg.Record = record; - AppHost.Instance.ShowModalX(dlg, owner, false); + await AppHost.Instance.ShowModalAsync(dlg, owner, false); } } @@ -582,7 +582,7 @@ public static bool ModifyFamily(IView owner, IBaseWindow baseWin, ref GDMFamilyR return result; } - public static bool ModifyAddress(IView owner, IBaseWindow baseWin, GDMAddress address) + public static async Task ModifyAddress(IView owner, IBaseWindow baseWin, GDMAddress address) { bool result; @@ -591,7 +591,7 @@ public static bool ModifyAddress(IView owner, IBaseWindow baseWin, GDMAddress ad using (var dlg = AppHost.ResolveDialog(baseWin)) { dlg.Address = address; - result = (AppHost.Instance.ShowModalX(dlg, owner, false)); + result = await AppHost.Instance.ShowModalAsync(dlg, owner, false); } } finally { baseWin.Context.EndUpdate(); @@ -600,25 +600,7 @@ public static bool ModifyAddress(IView owner, IBaseWindow baseWin, GDMAddress ad return result; } - public static bool ModifyName(IView owner, IBaseContext context, ref NameEntry nameEntry) - { - bool result; - - try { - context.BeginUpdate(); - - using (var dlg = AppHost.ResolveDialog()) { - dlg.IName = nameEntry; - result = AppHost.Instance.ShowModalX(dlg, owner, false); - } - } finally { - context.EndUpdate(); - } - - return result; - } - - public static async Task ModifyNameAsync(IView owner, IBaseContext context, NameEntry nameEntry) + public static async Task ModifyName(IView owner, IBaseContext context, NameEntry nameEntry) { bool result; @@ -888,11 +870,11 @@ public static bool DeleteRecord(IBaseWindow baseWin, GDMRecord record, bool conf return result; } - public static bool AddIndividualFather(IView owner, IBaseWindow baseWin, ChangeTracker localUndoman, GDMIndividualRecord person) + public static async Task AddIndividualFather(IView owner, IBaseWindow baseWin, ChangeTracker localUndoman, GDMIndividualRecord person) { bool result = false; - GDMIndividualRecord father = baseWin.Context.SelectPerson(owner, person, TargetMode.tmChild, GDMSex.svMale); + GDMIndividualRecord father = await baseWin.Context.SelectPerson(owner, person, TargetMode.tmChild, GDMSex.svMale); if (father == null) return result; if (father == person) { @@ -931,11 +913,11 @@ public static bool DeleteIndividualFather(IBaseWindow baseWin, ChangeTracker loc return result; } - public static bool AddIndividualMother(IView owner, IBaseWindow baseWin, ChangeTracker localUndoman, GDMIndividualRecord person) + public static async Task AddIndividualMother(IView owner, IBaseWindow baseWin, ChangeTracker localUndoman, GDMIndividualRecord person) { bool result = false; - GDMIndividualRecord mother = baseWin.Context.SelectPerson(owner, person, TargetMode.tmChild, GDMSex.svFemale); + GDMIndividualRecord mother = await baseWin.Context.SelectPerson(owner, person, TargetMode.tmChild, GDMSex.svFemale); if (mother == null) return result; if (mother == person) { @@ -974,12 +956,12 @@ public static bool DeleteIndividualMother(IBaseWindow baseWin, ChangeTracker loc } - public static bool AddFamilyHusband(IView owner, IBaseWindow baseWin, ChangeTracker localUndoman, GDMFamilyRecord family) + public static async Task AddFamilyHusband(IView owner, IBaseWindow baseWin, ChangeTracker localUndoman, GDMFamilyRecord family) { bool result = false; var wife = baseWin.Context.Tree.GetPtrValue(family.Wife); - GDMIndividualRecord husband = baseWin.Context.SelectPerson(owner, wife, TargetMode.tmSpouse, GDMSex.svMale); + GDMIndividualRecord husband = await baseWin.Context.SelectPerson(owner, wife, TargetMode.tmSpouse, GDMSex.svMale); if (husband != null && family.Husband.IsEmpty()) { result = localUndoman.DoOrdinaryOperation(OperationType.otFamilySpouseAttach, family, husband); } @@ -1001,12 +983,12 @@ public static bool DeleteFamilyHusband(IBaseWindow baseWin, ChangeTracker localU return result; } - public static bool AddFamilyWife(IView owner, IBaseWindow baseWin, ChangeTracker localUndoman, GDMFamilyRecord family) + public static async Task AddFamilyWife(IView owner, IBaseWindow baseWin, ChangeTracker localUndoman, GDMFamilyRecord family) { bool result = false; var husband = baseWin.Context.Tree.GetPtrValue(family.Husband); - GDMIndividualRecord wife = baseWin.Context.SelectPerson(owner, husband, TargetMode.tmSpouse, GDMSex.svFemale); + GDMIndividualRecord wife = await baseWin.Context.SelectPerson(owner, husband, TargetMode.tmSpouse, GDMSex.svFemale); if (wife != null && family.Wife.IsEmpty()) { result = localUndoman.DoOrdinaryOperation(OperationType.otFamilySpouseAttach, family, wife); } @@ -1028,21 +1010,21 @@ public static bool DeleteFamilyWife(IBaseWindow baseWin, ChangeTracker localUndo return result; } - public static bool SelectPortraitRegion(IView owner, IBaseWindow baseWin, GDMMultimediaLink mmLink) + public static async Task SelectPortraitRegion(IView owner, IBaseWindow baseWin, GDMMultimediaLink mmLink) { bool result; using (var dlg = AppHost.ResolveDialog(baseWin)) { dlg.MultimediaLink = mmLink; - result = AppHost.Instance.ShowModalX(dlg, owner, false); + result = await AppHost.Instance.ShowModalAsync(dlg, owner, false); } return result; } - public static bool AddIndividualPortrait(IView owner, IBaseWindow baseWin, ChangeTracker localUndoman, GDMIndividualRecord iRec) + public static async Task AddIndividualPortrait(IView owner, IBaseWindow baseWin, ChangeTracker localUndoman, GDMIndividualRecord iRec) { bool result = false; - GDMMultimediaRecord mmRec = baseWin.Context.SelectRecord(owner, GDMRecordType.rtMultimedia, null) as GDMMultimediaRecord; + GDMMultimediaRecord mmRec = await baseWin.Context.SelectRecord(owner, GDMRecordType.rtMultimedia, null) as GDMMultimediaRecord; if (mmRec == null) return false; // remove previous portrait link @@ -1055,7 +1037,7 @@ public static bool AddIndividualPortrait(IView owner, IBaseWindow baseWin, Chang mmLink = iRec.SetPrimaryMultimediaLink(mmRec); // select portrait area - result = SelectPortraitRegion(owner, baseWin, mmLink); + result = await SelectPortraitRegion(owner, baseWin, mmLink); if (result) { result = localUndoman.DoOrdinaryOperation(OperationType.otIndividualPortraitAttach, iRec, mmLink); @@ -1073,14 +1055,14 @@ public static bool DeleteIndividualPortrait(IBaseWindow baseWin, ChangeTracker l return false; } - public static void ShowRecMerge(IView owner, IBaseWindow baseWin, GDMRecord rec1, GDMRecord rec2) + public static async void ShowRecMerge(IView owner, IBaseWindow baseWin, GDMRecord rec1, GDMRecord rec2) { try { baseWin.Context.BeginUpdate(); using (var dlg = AppHost.Container.Resolve(baseWin)) { dlg.SetRec1(rec1); dlg.SetRec2(rec2); - AppHost.Instance.ShowModalX(dlg, owner, false); + await AppHost.Instance.ShowModalAsync(dlg, owner, false); } } finally { baseWin.Context.EndUpdate(); diff --git a/projects/GKCore/GKCore/Controllers/BaseWinController.cs b/projects/GKCore/GKCore/Controllers/BaseWinController.cs index e1e8de729..da699ced9 100644 --- a/projects/GKCore/GKCore/Controllers/BaseWinController.cs +++ b/projects/GKCore/GKCore/Controllers/BaseWinController.cs @@ -1034,20 +1034,20 @@ public override void ApplyTheme() #region Dialogs - private void ShowCommonFilter(GDMRecordType rt, IRecordsListModel listMan) + private async void ShowCommonFilter(GDMRecordType rt, IRecordsListModel listMan) { using (var dlg = AppHost.Container.Resolve(fView, listMan)) { - if (AppHost.Instance.ShowModalX(dlg, fView, false)) { + if (await AppHost.Instance.ShowModalAsync(dlg, fView, false)) { AppHost.Instance.NotifyFilter(fView, rt, listMan, listMan.Filter); ApplyFilter(rt); } } } - private void ShowPersonsFilter(GDMRecordType rt, IRecordsListModel listMan) + private async void ShowPersonsFilter(GDMRecordType rt, IRecordsListModel listMan) { using (var dlg = AppHost.Container.Resolve(fView, listMan)) { - if (AppHost.Instance.ShowModalX(dlg, fView, false)) { + if (await AppHost.Instance.ShowModalAsync(dlg, fView, false)) { ApplyFilter(rt, listMan); } } @@ -1077,98 +1077,98 @@ public void ExportTable() } } - public void ShowFileProperties() + public async void ShowFileProperties() { try { fContext.BeginUpdate(); using (var dlg = AppHost.ResolveDialog(fView)) { - AppHost.Instance.ShowModalX(dlg, fView, false); + await AppHost.Instance.ShowModalAsync(dlg, fView, false); } } finally { fContext.EndUpdate(); } } - public void ShowScripts() + public async void ShowScripts() { try { fContext.BeginUpdate(); using (var dlg = AppHost.Container.Resolve(fView)) { - AppHost.Instance.ShowModalX(dlg, fView, false); + await AppHost.Instance.ShowModalAsync(dlg, fView, false); } } finally { fContext.EndUpdate(); } } - public void ShowTreeSplit() + public async void ShowTreeSplit() { try { fContext.BeginUpdate(); using (var dlg = AppHost.Container.Resolve(fView)) { - AppHost.Instance.ShowModalX(dlg, fView, false); + await AppHost.Instance.ShowModalAsync(dlg, fView, false); } } finally { fContext.EndUpdate(); } } - public void ShowTreeMerge() + public async void ShowTreeMerge() { try { fContext.BeginUpdate(); using (var dlg = AppHost.Container.Resolve(fView)) { - AppHost.Instance.ShowModalX(dlg, fView, false); + await AppHost.Instance.ShowModalAsync(dlg, fView, false); } } finally { fContext.EndUpdate(); } } - public void ShowTreeCompare() + public async void ShowTreeCompare() { try { fContext.BeginUpdate(); using (var dlg = AppHost.Container.Resolve(fView)) { - AppHost.Instance.ShowModalX(dlg, fView, false); + await AppHost.Instance.ShowModalAsync(dlg, fView, false); } } finally { fContext.EndUpdate(); } } - public void ShowTreeCheck() + public async void ShowTreeCheck() { try { fContext.BeginUpdate(); using (var dlg = AppHost.Container.Resolve(fView)) { - AppHost.Instance.ShowModalX(dlg, fView, false); + await AppHost.Instance.ShowModalAsync(dlg, fView, false); } } finally { fContext.EndUpdate(); } } - public void ShowPlacesManager() + public async void ShowPlacesManager() { try { fContext.BeginUpdate(); using (var dlg = AppHost.Container.Resolve(fView)) { - AppHost.Instance.ShowModalX(dlg, fView, false); + await AppHost.Instance.ShowModalAsync(dlg, fView, false); } } finally { fContext.EndUpdate(); } } - public void ShowPatSearch() + public async void ShowPatSearch() { try { fContext.BeginUpdate(); using (var dlg = AppHost.Container.Resolve(fView)) { - AppHost.Instance.ShowModalX(dlg, fView, false); + await AppHost.Instance.ShowModalAsync(dlg, fView, false); } } finally { fContext.EndUpdate(); @@ -1198,17 +1198,17 @@ public void ShowMap() AppHost.Instance.ShowWindow(mapsWin); } - public void ShowOrganizer() + public async void ShowOrganizer() { using (var dlg = AppHost.Container.Resolve(fView)) { - AppHost.Instance.ShowModalX(dlg, fView, false); + await AppHost.Instance.ShowModalAsync(dlg, fView, false); } } - public void ShowRelationshipCalculator() + public async void ShowRelationshipCalculator() { using (var dlg = AppHost.Container.Resolve(fView)) { - AppHost.Instance.ShowModalX(dlg, fView, false); + await AppHost.Instance.ShowModalAsync(dlg, fView, false); } } @@ -1286,10 +1286,10 @@ public void ShowLog() GKUtils.LoadExtFile(AppHost.GetLogFilename()); } - public void ShowAbout() + public async void ShowAbout() { using (var dlg = AppHost.Container.Resolve()) { - AppHost.Instance.ShowModalX(dlg, fView, false); + await AppHost.Instance.ShowModalAsync(dlg, fView, false); } } diff --git a/projects/GKCore/GKCore/Controllers/CommunicationEditDlgController.cs b/projects/GKCore/GKCore/Controllers/CommunicationEditDlgController.cs index 73c90b959..84726d868 100644 --- a/projects/GKCore/GKCore/Controllers/CommunicationEditDlgController.cs +++ b/projects/GKCore/GKCore/Controllers/CommunicationEditDlgController.cs @@ -124,9 +124,9 @@ public override void UpdateView() } } - public void SetPerson() + public async void SetPerson() { - fTempInd = fBase.Context.SelectPerson(fView, null, TargetMode.tmNone, GDMSex.svUnknown); + fTempInd = await fBase.Context.SelectPerson(fView, null, TargetMode.tmNone, GDMSex.svUnknown); fView.Corresponder.Text = ((fTempInd == null) ? "" : GKUtils.GetNameString(fTempInd, false)); } diff --git a/projects/GKCore/GKCore/Controllers/EventEditDlgController.cs b/projects/GKCore/GKCore/Controllers/EventEditDlgController.cs index d31d1fb0d..67ab94a05 100644 --- a/projects/GKCore/GKCore/Controllers/EventEditDlgController.cs +++ b/projects/GKCore/GKCore/Controllers/EventEditDlgController.cs @@ -198,9 +198,9 @@ private void SetLocationMode(bool active) } } - public void AddPlace() + public async void AddPlace() { - fTempLocation = fBase.Context.SelectRecord(fView, GDMRecordType.rtLocation, new object[] { fView.Place.Text }) as GDMLocationRecord; + fTempLocation = await fBase.Context.SelectRecord(fView, GDMRecordType.rtLocation, new object[] { fView.Place.Text }) as GDMLocationRecord; UpdatePlace(); } @@ -210,9 +210,9 @@ public void RemovePlace() UpdatePlace(); } - public void ModifyAddress() + public async void ModifyAddress() { - BaseController.ModifyAddress(fView, fBase, fEvent.Address); + await BaseController.ModifyAddress(fView, fBase, fEvent.Address); } private void SetAttributeMode(bool active) diff --git a/projects/GKCore/GKCore/Controllers/FamilyEditDlgController.cs b/projects/GKCore/GKCore/Controllers/FamilyEditDlgController.cs index 61de4aaeb..319d8143d 100644 --- a/projects/GKCore/GKCore/Controllers/FamilyEditDlgController.cs +++ b/projects/GKCore/GKCore/Controllers/FamilyEditDlgController.cs @@ -157,9 +157,9 @@ private void UpdateControls() fView.SourcesList.UpdateSheet(); } - public void AddHusband() + public async void AddHusband() { - if (BaseController.AddFamilyHusband(fView, fBase, fLocalUndoman, fFamilyRecord)) { + if (await BaseController.AddFamilyHusband(fView, fBase, fLocalUndoman, fFamilyRecord)) { UpdateControls(); } } @@ -171,9 +171,9 @@ public void DeleteHusband() } } - public void AddWife() + public async void AddWife() { - if (BaseController.AddFamilyWife(fView, fBase, fLocalUndoman, fFamilyRecord)) { + if (await BaseController.AddFamilyWife(fView, fBase, fLocalUndoman, fFamilyRecord)) { UpdateControls(); } } diff --git a/projects/GKCore/GKCore/Controllers/FilePropertiesDlgController.cs b/projects/GKCore/GKCore/Controllers/FilePropertiesDlgController.cs index f8a7c892a..a9c455d90 100644 --- a/projects/GKCore/GKCore/Controllers/FilePropertiesDlgController.cs +++ b/projects/GKCore/GKCore/Controllers/FilePropertiesDlgController.cs @@ -98,7 +98,7 @@ public override void UpdateView() } } - public void ChangeLanguage() + public async void ChangeLanguage() { if (AppHost.Instance.HasFeatureSupport(Feature.Mobile)) return; @@ -106,7 +106,7 @@ public void ChangeLanguage() using (var dlg = AppHost.ResolveDialog()) { dlg.LanguageID = fBase.Context.Tree.Header.Language; - if (dlg.ShowModalX(fView)) { + if (await AppHost.Instance.ShowModalAsync(dlg, fView)) { // Assignment in control, instead of the header's property to work Cancel. fView.Language.Text = GEDCOMUtils.GetLanguageStr(dlg.LanguageID); } diff --git a/projects/GKCore/GKCore/Controllers/ParentsEditDlgController.cs b/projects/GKCore/GKCore/Controllers/ParentsEditDlgController.cs index da0be72d5..e5ee542bb 100644 --- a/projects/GKCore/GKCore/Controllers/ParentsEditDlgController.cs +++ b/projects/GKCore/GKCore/Controllers/ParentsEditDlgController.cs @@ -130,9 +130,9 @@ public void EditParents() } } - public void AddFather() + public async void AddFather() { - if (BaseController.AddIndividualFather(fView, fBase, fLocalUndoman, fIndividualRecord)) { + if (await BaseController.AddIndividualFather(fView, fBase, fLocalUndoman, fIndividualRecord)) { UpdateControls(); } } @@ -144,9 +144,9 @@ public void DeleteFather() } } - public void AddMother() + public async void AddMother() { - if (BaseController.AddIndividualMother(fView, fBase, fLocalUndoman, fIndividualRecord)) { + if (await BaseController.AddIndividualMother(fView, fBase, fLocalUndoman, fIndividualRecord)) { UpdateControls(); } } diff --git a/projects/GKCore/GKCore/Controllers/PersonEditDlgController.cs b/projects/GKCore/GKCore/Controllers/PersonEditDlgController.cs index efcf61717..c3f63e1fc 100644 --- a/projects/GKCore/GKCore/Controllers/PersonEditDlgController.cs +++ b/projects/GKCore/GKCore/Controllers/PersonEditDlgController.cs @@ -385,9 +385,9 @@ private void SetMarriedSurname(ICulture culture, string husbSurname) } } - public void AddPortrait() + public async void AddPortrait() { - if (BaseController.AddIndividualPortrait(fView, fBase, fLocalUndoman, fIndividualRecord)) { + if (await BaseController.AddIndividualPortrait(fView, fBase, fLocalUndoman, fIndividualRecord)) { fView.MediaList.UpdateSheet(); UpdatePortrait(true); } @@ -400,11 +400,11 @@ public void DeletePortrait() } } - public void AddParents() + public async void AddParents() { AcceptTempData(); - GDMFamilyRecord family = fBase.Context.SelectFamily(fView, fIndividualRecord); + GDMFamilyRecord family = await fBase.Context.SelectFamily(fView, fIndividualRecord); if (family != null && family.IndexOfChild(fIndividualRecord) < 0) { fLocalUndoman.DoOrdinaryOperation(OperationType.otIndividualParentsAttach, fIndividualRecord, family); } @@ -434,11 +434,11 @@ public void DeleteParents() UpdateControls(); } - public void AddFather() + public async void AddFather() { AcceptTempData(); - if (BaseController.AddIndividualFather(fView, fBase, fLocalUndoman, fIndividualRecord)) { + if (await BaseController.AddIndividualFather(fView, fBase, fLocalUndoman, fIndividualRecord)) { UpdateControls(); } } @@ -452,11 +452,11 @@ public void DeleteFather() } } - public void AddMother() + public async void AddMother() { AcceptTempData(); - if (BaseController.AddIndividualMother(fView, fBase, fLocalUndoman, fIndividualRecord)) { + if (await BaseController.AddIndividualMother(fView, fBase, fLocalUndoman, fIndividualRecord)) { UpdateControls(); } } diff --git a/projects/GKCore/GKCore/Controllers/PlacesManagerController.cs b/projects/GKCore/GKCore/Controllers/PlacesManagerController.cs index 1e53fb5ac..039dc2965 100644 --- a/projects/GKCore/GKCore/Controllers/PlacesManagerController.cs +++ b/projects/GKCore/GKCore/Controllers/PlacesManagerController.cs @@ -73,7 +73,7 @@ public void CheckPlaces() } } - public void CreateLocationRecord(IList placesList) + public async void CreateLocationRecord(IList placesList) { PlaceObj pObj = placesList.Count > 0 ? (PlaceObj) placesList[0] : null; if (pObj == null) return; @@ -81,7 +81,7 @@ public void CreateLocationRecord(IList placesList) if (pObj.Name.IndexOf("[*]") == 0) { AppHost.StdDialogs.ShowMessage(LangMan.LS(LSID.PlaceAlreadyInBook)); } else { - GDMLocationRecord locRec = fBase.Context.SelectRecord(fView, GDMRecordType.rtLocation, new object[] { pObj.Name }) as GDMLocationRecord; + GDMLocationRecord locRec = await fBase.Context.SelectRecord(fView, GDMRecordType.rtLocation, new object[] { pObj.Name }) as GDMLocationRecord; if (locRec == null) return; for (var pi = 0; pi < placesList.Count; pi++) { diff --git a/projects/GKCore/GKCore/Controllers/RecMergeController.cs b/projects/GKCore/GKCore/Controllers/RecMergeController.cs index 276c3d1a3..77a2c0f5b 100644 --- a/projects/GKCore/GKCore/Controllers/RecMergeController.cs +++ b/projects/GKCore/GKCore/Controllers/RecMergeController.cs @@ -211,16 +211,16 @@ public void SetRec2(GDMRecord value) } } - public void SelectRec1() + public async void SelectRec1() { - GDMRecord irec = fBase.Context.SelectRecord(fView, fMergeMode, null); + GDMRecord irec = await fBase.Context.SelectRecord(fView, fMergeMode, null); if (irec != null) SetRec1(irec); } - public void SelectRec2() + public async void SelectRec2() { - GDMRecord irec = fBase.Context.SelectRecord(fView, fMergeMode, null); + GDMRecord irec = await fBase.Context.SelectRecord(fView, fMergeMode, null); if (irec != null) SetRec2(irec); } diff --git a/projects/GKCore/GKCore/Controllers/RelationshipCalculatorDlgController.cs b/projects/GKCore/GKCore/Controllers/RelationshipCalculatorDlgController.cs index e180bb0ac..60cbf2df8 100644 --- a/projects/GKCore/GKCore/Controllers/RelationshipCalculatorDlgController.cs +++ b/projects/GKCore/GKCore/Controllers/RelationshipCalculatorDlgController.cs @@ -40,15 +40,15 @@ public RelationshipCalculatorDlgController(IRelationshipCalculatorDlg view) : ba { } - public void SelectRec1() + public async void SelectRec1() { - GDMIndividualRecord iRec = fBase.Context.SelectRecord(fView, GDMRecordType.rtIndividual, null) as GDMIndividualRecord; + GDMIndividualRecord iRec = await fBase.Context.SelectRecord(fView, GDMRecordType.rtIndividual, null) as GDMIndividualRecord; if (iRec != null) SetRec1(iRec); } - public void SelectRec2() + public async void SelectRec2() { - GDMIndividualRecord iRec = fBase.Context.SelectRecord(fView, GDMRecordType.rtIndividual, null) as GDMIndividualRecord; + GDMIndividualRecord iRec = await fBase.Context.SelectRecord(fView, GDMRecordType.rtIndividual, null) as GDMIndividualRecord; if (iRec != null) SetRec2(iRec); } diff --git a/projects/GKCore/GKCore/Controllers/RepositoryEditDlgController.cs b/projects/GKCore/GKCore/Controllers/RepositoryEditDlgController.cs index d28db0cc2..a0fa56bca 100644 --- a/projects/GKCore/GKCore/Controllers/RepositoryEditDlgController.cs +++ b/projects/GKCore/GKCore/Controllers/RepositoryEditDlgController.cs @@ -83,9 +83,9 @@ public override void UpdateView() fView.NotesList.ListModel.DataOwner = fRepositoryRecord; } - public void ModifyAddress() + public async void ModifyAddress() { - BaseController.ModifyAddress(fView, fBase, fRepositoryRecord.Address); + await BaseController.ModifyAddress(fView, fBase, fRepositoryRecord.Address); } public override void SetLocale() diff --git a/projects/GKCore/GKCore/Controllers/SourceCitEditDlgController.cs b/projects/GKCore/GKCore/Controllers/SourceCitEditDlgController.cs index e985c9b01..d01a4b415 100644 --- a/projects/GKCore/GKCore/Controllers/SourceCitEditDlgController.cs +++ b/projects/GKCore/GKCore/Controllers/SourceCitEditDlgController.cs @@ -96,10 +96,10 @@ public override void UpdateView() fView.DataText.Text = fSourceCitation.Data.Text.Lines.Text.Trim(); } - public void AddSource() + public async void AddSource() { object[] anArgs = new object[0]; - GDMSourceRecord src = fBase.Context.SelectRecord(fView, GDMRecordType.rtSource, anArgs) as GDMSourceRecord; + GDMSourceRecord src = await fBase.Context.SelectRecord(fView, GDMRecordType.rtSource, anArgs) as GDMSourceRecord; if (src == null) return; fBase.Context.GetSourcesList(fSourcesList); diff --git a/projects/GKCore/GKCore/Controllers/TaskEditDlgController.cs b/projects/GKCore/GKCore/Controllers/TaskEditDlgController.cs index e1b006798..4580031c7 100644 --- a/projects/GKCore/GKCore/Controllers/TaskEditDlgController.cs +++ b/projects/GKCore/GKCore/Controllers/TaskEditDlgController.cs @@ -141,22 +141,22 @@ public override void UpdateView() ChangeGoalType(); } - public void SelectGoal() + public async void SelectGoal() { GDMGoalType gt = (GDMGoalType)fView.GoalType.SelectedIndex; switch (gt) { case GDMGoalType.gtIndividual: - fTempRec = fBase.Context.SelectPerson(fView, null, TargetMode.tmNone, GDMSex.svUnknown); + fTempRec = await fBase.Context.SelectPerson(fView, null, TargetMode.tmNone, GDMSex.svUnknown); fView.Goal.Text = GKUtils.GetGoalStr(fBase.Context.Tree, gt, fTempRec); break; case GDMGoalType.gtFamily: - fTempRec = fBase.Context.SelectRecord(fView, GDMRecordType.rtFamily, new object[0]); + fTempRec = await fBase.Context.SelectRecord(fView, GDMRecordType.rtFamily, new object[0]); fView.Goal.Text = GKUtils.GetGoalStr(fBase.Context.Tree, gt, fTempRec); break; case GDMGoalType.gtSource: - fTempRec = fBase.Context.SelectRecord(fView, GDMRecordType.rtSource, new object[0]); + fTempRec = await fBase.Context.SelectRecord(fView, GDMRecordType.rtSource, new object[0]); fView.Goal.Text = GKUtils.GetGoalStr(fBase.Context.Tree, gt, fTempRec); break; diff --git a/projects/GKCore/GKCore/Controllers/TreeChartWinController.cs b/projects/GKCore/GKCore/Controllers/TreeChartWinController.cs index 51e74a0a6..cb355ac5e 100644 --- a/projects/GKCore/GKCore/Controllers/TreeChartWinController.cs +++ b/projects/GKCore/GKCore/Controllers/TreeChartWinController.cs @@ -90,12 +90,12 @@ public void AddFamily() UpdateChart(); } - private void InternalChildAdd(GDMSex needSex) + private async void InternalChildAdd(GDMSex needSex) { TreeChartPerson p = fView.TreeBox.Selected; if (p == null || p.Rec == null) return; - GDMIndividualRecord child = fBase.Context.AddChildForParent(fView, p.Rec, needSex); + GDMIndividualRecord child = await fBase.Context.AddChildForParent(fView, p.Rec, needSex); if (child == null) return; UpdateChart(); @@ -111,13 +111,13 @@ public void AddDaughter() InternalChildAdd(GDMSex.svFemale); } - public void AddSpouse() + public async void AddSpouse() { TreeChartPerson p = fView.TreeBox.Selected; if (p == null || p.Rec == null) return; GDMIndividualRecord iRec = p.Rec; - GDMIndividualRecord iSpouse = fBase.Context.SelectSpouseFor(fView, iRec); + GDMIndividualRecord iSpouse = await fBase.Context.SelectSpouseFor(fView, iRec); if (iSpouse == null) return; GDMFamilyRecord fam = fBase.Context.Tree.CreateFamily(); @@ -126,7 +126,7 @@ public void AddSpouse() UpdateChart(); } - private void ParentAdd(GDMSex needSex) + private async void ParentAdd(GDMSex needSex) { TreeChartPerson p = fView.TreeBox.Selected; if (p == null || p.Rec == null) return; @@ -147,7 +147,7 @@ private void ParentAdd(GDMSex needSex) } if (needParent) { - GDMIndividualRecord parent = fBase.Context.SelectPerson(fView, p.Rec, TargetMode.tmChild, needSex); + GDMIndividualRecord parent = await fBase.Context.SelectPerson(fView, p.Rec, TargetMode.tmChild, needSex); if (parent != null) { if (!familyExist) { fam = fBase.Context.Tree.CreateFamily(); @@ -191,7 +191,7 @@ public void Delete() UpdateChart(); } - public void ModifyPerson(TreeChartPerson person) + public async void ModifyPerson(TreeChartPerson person) { if (person == null) return; @@ -207,7 +207,7 @@ public void ModifyPerson(TreeChartPerson person) GDMFamilyRecord baseFamily = person.BaseFamily; if (baseSpouse != null && baseFamily != null) { - GDMIndividualRecord iSpouse = fBase.Context.SelectSpouseFor(fView, person.BaseSpouse.Rec); + GDMIndividualRecord iSpouse = await fBase.Context.SelectSpouseFor(fView, person.BaseSpouse.Rec); if (iSpouse != null) { modified = baseFamily.AddSpouse(iSpouse); @@ -285,12 +285,12 @@ public void SaveSnapshot() } } - public void SetFilter() + public async void SetFilter() { using (var dlgFilter = AppHost.Container.Resolve(fBase)) { dlgFilter.Filter = fView.TreeBox.Model.Filter; - if (dlgFilter.ShowModalX(fView)) { + if (await AppHost.Instance.ShowModalAsync(dlgFilter, fView)) { fView.GenChart(); } } diff --git a/projects/GKCore/GKCore/Controllers/TreeFilterDlgController.cs b/projects/GKCore/GKCore/Controllers/TreeFilterDlgController.cs index bfa6666f8..77eba5726 100644 --- a/projects/GKCore/GKCore/Controllers/TreeFilterDlgController.cs +++ b/projects/GKCore/GKCore/Controllers/TreeFilterDlgController.cs @@ -130,13 +130,13 @@ public void UpdateControls() } } - public void ModifyPersons(RecordAction action, object itemData) + public async void ModifyPersons(RecordAction action, object itemData) { GDMIndividualRecord iRec = itemData as GDMIndividualRecord; switch (action) { case RecordAction.raAdd: - iRec = fBase.Context.SelectPerson(fView, null, TargetMode.tmNone, GDMSex.svUnknown); + iRec = await fBase.Context.SelectPerson(fView, null, TargetMode.tmNone, GDMSex.svUnknown); if (iRec != null) { fTemp = fTemp + iRec.XRef + ";"; } diff --git a/projects/GKCore/GKCore/Interfaces/IBaseContext.cs b/projects/GKCore/GKCore/Interfaces/IBaseContext.cs index ffa2a5d5e..aa166d293 100644 --- a/projects/GKCore/GKCore/Interfaces/IBaseContext.cs +++ b/projects/GKCore/GKCore/Interfaces/IBaseContext.cs @@ -21,6 +21,7 @@ using System; using System.Collections.Generic; using System.IO; +using System.Threading.Tasks; using BSLib; using GDModel; using GKCore.Design; @@ -112,19 +113,17 @@ public interface IBaseContext : IDisposable GDMSourceRecord FindSource(string sourceName); void GetSourcesList(StringList sources); - string DefinePatronymic(IView owner, string name, GDMSex sex, bool confirm); - GDMSex DefineSex(IView owner, string iName, string iPatr); + Task DefinePatronymic(IView owner, string name, GDMSex sex, bool confirm); + Task DefineSex(IView owner, string iName, string iPatr); void CheckPersonSex(IView owner, GDMIndividualRecord iRec); - GDMFamilyRecord SelectFamily(IView owner, GDMIndividualRecord target, TargetMode targetMode = TargetMode.tmFamilyChild); - GDMIndividualRecord SelectPerson(IView owner, GDMIndividualRecord target, TargetMode targetMode, GDMSex needSex); - GDMRecord SelectRecord(IView owner, GDMRecordType mode, params object[] args); - GDMFamilyRecord GetChildFamily(GDMIndividualRecord iChild, - bool canCreate, - GDMIndividualRecord newParent); + Task SelectFamily(IView owner, GDMIndividualRecord target, TargetMode targetMode = TargetMode.tmFamilyChild); + Task SelectPerson(IView owner, GDMIndividualRecord target, TargetMode targetMode, GDMSex needSex); + Task SelectRecord(IView owner, GDMRecordType mode, params object[] args); + GDMFamilyRecord GetChildFamily(GDMIndividualRecord iChild, bool canCreate, GDMIndividualRecord newParent); GDMFamilyRecord AddFamilyForSpouse(GDMIndividualRecord spouse); - GDMIndividualRecord AddChildForParent(IView owner, GDMIndividualRecord parent, GDMSex needSex); - GDMIndividualRecord SelectSpouseFor(IView owner, GDMIndividualRecord iRec); + Task AddChildForParent(IView owner, GDMIndividualRecord parent, GDMSex needSex); + Task SelectSpouseFor(IView owner, GDMIndividualRecord iRec); void ProcessFamily(GDMFamilyRecord famRec); void ProcessIndividual(GDMIndividualRecord indiRec); diff --git a/projects/GKCore/GKCore/Lists/AssociationsListModel.cs b/projects/GKCore/GKCore/Lists/AssociationsListModel.cs index 9e890aac4..53c08f760 100644 --- a/projects/GKCore/GKCore/Lists/AssociationsListModel.cs +++ b/projects/GKCore/GKCore/Lists/AssociationsListModel.cs @@ -80,7 +80,7 @@ public override void UpdateContents() } } - public override void Modify(object sender, ModifyEventArgs eArgs) + public override async void Modify(object sender, ModifyEventArgs eArgs) { var person = fDataOwner as GDMIndividualRecord; if (fBaseWin == null || person == null) return; @@ -99,7 +99,7 @@ public override void Modify(object sender, ModifyEventArgs eArgs) } dlg.Association = ast; - result = AppHost.Instance.ShowModalX(dlg, fOwner, false); + result = await AppHost.Instance.ShowModalAsync(dlg, fOwner, false); if (!exists) { if (result) { diff --git a/projects/GKCore/GKCore/Lists/ChildrenListModel.cs b/projects/GKCore/GKCore/Lists/ChildrenListModel.cs index 01b720121..485716da7 100644 --- a/projects/GKCore/GKCore/Lists/ChildrenListModel.cs +++ b/projects/GKCore/GKCore/Lists/ChildrenListModel.cs @@ -90,7 +90,7 @@ public override void UpdateContents() } } - public override void Modify(object sender, ModifyEventArgs eArgs) + public override async void Modify(object sender, ModifyEventArgs eArgs) { var family = fDataOwner as GDMFamilyRecord; if (fBaseWin == null || family == null) return; @@ -102,7 +102,7 @@ public override void Modify(object sender, ModifyEventArgs eArgs) switch (eArgs.Action) { case RecordAction.raAdd: - child = fBaseWin.Context.SelectPerson(fOwner, tree.GetPtrValue(family.Husband), TargetMode.tmParent, GDMSex.svUnknown); + child = await fBaseWin.Context.SelectPerson(fOwner, tree.GetPtrValue(family.Husband), TargetMode.tmParent, GDMSex.svUnknown); result = (child != null && fBaseWin.Context.IsAvailableRecord(child) && !family.HasChild(child)); if (result) { result = fUndoman.DoOrdinaryOperation(OperationType.otIndividualParentsAttach, child, family); @@ -161,7 +161,7 @@ public override void UpdateContents() } } - public override void Modify(object sender, ModifyEventArgs eArgs) + public override async void Modify(object sender, ModifyEventArgs eArgs) { var indiRec = fDataOwner as GDMIndividualRecord; if (fBaseWin == null || indiRec == null) return; @@ -173,10 +173,10 @@ public override void Modify(object sender, ModifyEventArgs eArgs) switch (eArgs.Action) { case RecordAction.raAdd: - GDMFamilyRecord family = fBaseWin.Context.SelectFamily(fOwner, indiRec, TargetMode.tmFamilySpouse); + GDMFamilyRecord family = await fBaseWin.Context.SelectFamily(fOwner, indiRec, TargetMode.tmFamilySpouse); if (family != null && fBaseWin.Context.IsAvailableRecord(family)) { GDMIndividualRecord target = (indiRec.Sex == GDMSex.svMale) ? indiRec : null; - child = fBaseWin.Context.SelectPerson(fOwner, target, TargetMode.tmParent, GDMSex.svUnknown); + child = await fBaseWin.Context.SelectPerson(fOwner, target, TargetMode.tmParent, GDMSex.svUnknown); result = (child != null && fBaseWin.Context.IsAvailableRecord(child)); if (result) { result = fUndoman.DoOrdinaryOperation(OperationType.otIndividualParentsAttach, child, family); diff --git a/projects/GKCore/GKCore/Lists/EventsListModel.cs b/projects/GKCore/GKCore/Lists/EventsListModel.cs index 928d6ad74..334094929 100644 --- a/projects/GKCore/GKCore/Lists/EventsListModel.cs +++ b/projects/GKCore/GKCore/Lists/EventsListModel.cs @@ -96,7 +96,7 @@ public override void UpdateContents() } } - public override void Modify(object sender, ModifyEventArgs eArgs) + public override async void Modify(object sender, ModifyEventArgs eArgs) { GDMRecordWithEvents record = fDataOwner as GDMRecordWithEvents; if (fBaseWin == null || record == null) return; @@ -124,7 +124,7 @@ public override void Modify(object sender, ModifyEventArgs eArgs) } dlg.Event = newEvent; - result = AppHost.Instance.ShowModalX(dlg, fOwner, true); + result = await AppHost.Instance.ShowModalAsync(dlg, fOwner, true); if (!result) { if (!exists) { diff --git a/projects/GKCore/GKCore/Lists/GroupListModel.cs b/projects/GKCore/GKCore/Lists/GroupListModel.cs index 30f4c4a95..e63227a62 100644 --- a/projects/GKCore/GKCore/Lists/GroupListModel.cs +++ b/projects/GKCore/GKCore/Lists/GroupListModel.cs @@ -133,7 +133,7 @@ public override void UpdateContents() } } - public override void Modify(object sender, ModifyEventArgs eArgs) + public override async void Modify(object sender, ModifyEventArgs eArgs) { var grp = fDataOwner as GDMGroupRecord; if (fBaseWin == null || grp == null) return; @@ -144,7 +144,7 @@ public override void Modify(object sender, ModifyEventArgs eArgs) switch (eArgs.Action) { case RecordAction.raAdd: - member = fBaseWin.Context.SelectPerson(fOwner, null, TargetMode.tmNone, GDMSex.svUnknown); + member = await fBaseWin.Context.SelectPerson(fOwner, null, TargetMode.tmNone, GDMSex.svUnknown); if (member != null) { result = fUndoman.DoOrdinaryOperation(OperationType.otGroupMemberAttach, grp, member); } diff --git a/projects/GKCore/GKCore/Lists/IndividualListModel.cs b/projects/GKCore/GKCore/Lists/IndividualListModel.cs index 6fb7b780e..5b3dfdab7 100644 --- a/projects/GKCore/GKCore/Lists/IndividualListModel.cs +++ b/projects/GKCore/GKCore/Lists/IndividualListModel.cs @@ -737,7 +737,7 @@ public override void UpdateContents() } } - public override void Modify(object sender, ModifyEventArgs eArgs) + public override async void Modify(object sender, ModifyEventArgs eArgs) { var iRec = fDataOwner as GDMIndividualRecord; if (fBaseWin == null || iRec == null) return; @@ -748,7 +748,7 @@ public override void Modify(object sender, ModifyEventArgs eArgs) switch (eArgs.Action) { case RecordAction.raAdd: - groupRec = fBaseWin.Context.SelectRecord(fOwner, GDMRecordType.rtGroup, null) as GDMGroupRecord; + groupRec = await fBaseWin.Context.SelectRecord(fOwner, GDMRecordType.rtGroup, null) as GDMGroupRecord; if (groupRec != null) { result = fUndoman.DoOrdinaryOperation(OperationType.otGroupMemberAttach, groupRec, iRec); } @@ -819,7 +819,7 @@ public override void UpdateContents() } } - public override void Modify(object sender, ModifyEventArgs eArgs) + public override async void Modify(object sender, ModifyEventArgs eArgs) { var iRec = fDataOwner as GDMIndividualRecord; if (fBaseWin == null || iRec == null) return; @@ -839,7 +839,7 @@ public override void Modify(object sender, ModifyEventArgs eArgs) dlg.IndividualRecord = iRec; dlg.PersonalName = persName; - result = AppHost.Instance.ShowModalX(dlg, fOwner, false); + result = await AppHost.Instance.ShowModalAsync(dlg, fOwner, false); if (!exists) { if (result) { @@ -940,7 +940,7 @@ public override void UpdateContents() } } - public override void Modify(object sender, ModifyEventArgs eArgs) + public override async void Modify(object sender, ModifyEventArgs eArgs) { var iRec = fDataOwner as GDMIndividualRecord; if (fBaseWin == null || iRec == null) return; @@ -951,7 +951,7 @@ public override void Modify(object sender, ModifyEventArgs eArgs) switch (eArgs.Action) { case RecordAction.raAdd: - GDMFamilyRecord family = fBaseWin.Context.SelectFamily(fOwner, iRec); + GDMFamilyRecord family = await fBaseWin.Context.SelectFamily(fOwner, iRec); if (family != null && family.IndexOfChild(iRec) < 0) { result = fUndoman.DoOrdinaryOperation(OperationType.otIndividualParentsAttach, iRec, family); } @@ -962,7 +962,7 @@ public override void Modify(object sender, ModifyEventArgs eArgs) using (var dlg = AppHost.ResolveDialog(fBaseWin)) { dlg.IndividualRecord = iRec; dlg.ChildLink = cfLink; - result = AppHost.Instance.ShowModalX(dlg, fOwner, false); + result = await AppHost.Instance.ShowModalAsync(dlg, fOwner, false); } } break; @@ -1171,7 +1171,7 @@ public override void UpdateContents() } } - public override void Modify(object sender, ModifyEventArgs eArgs) + public override async void Modify(object sender, ModifyEventArgs eArgs) { var iRec = fDataOwner as GDMIndividualRecord; if (fBaseWin == null || iRec == null) return; @@ -1190,7 +1190,7 @@ public override void Modify(object sender, ModifyEventArgs eArgs) } dlg.UserReference = userRef; - result = AppHost.Instance.ShowModalX(dlg, fOwner, false); + result = await AppHost.Instance.ShowModalAsync(dlg, fOwner, false); if (!exists) { if (result) { diff --git a/projects/GKCore/GKCore/Lists/MediaLinksListModel.cs b/projects/GKCore/GKCore/Lists/MediaLinksListModel.cs index 7b777394f..f0e8b5663 100644 --- a/projects/GKCore/GKCore/Lists/MediaLinksListModel.cs +++ b/projects/GKCore/GKCore/Lists/MediaLinksListModel.cs @@ -82,7 +82,7 @@ public override void UpdateContents() } } - public override void Modify(object sender, ModifyEventArgs eArgs) + public override async void Modify(object sender, ModifyEventArgs eArgs) { var dataOwner = fDataOwner as IGDMStructWithMultimediaLinks; if (fBaseWin == null || dataOwner == null) return; @@ -94,13 +94,13 @@ public override void Modify(object sender, ModifyEventArgs eArgs) GDMMultimediaRecord mmRec; switch (eArgs.Action) { case RecordAction.raAdd: - mmRec = fBaseWin.Context.SelectRecord(fOwner, GDMRecordType.rtMultimedia, new object[0]) as GDMMultimediaRecord; + mmRec = await fBaseWin.Context.SelectRecord(fOwner, GDMRecordType.rtMultimedia, new object[0]) as GDMMultimediaRecord; if (mmRec != null) { result = fUndoman.DoOrdinaryOperation(OperationType.otRecordMediaAdd, (GDMObject)dataOwner, mmRec); mmLink = dataOwner.FindMultimediaLink(mmRec); if (result && mmLink != null && (dataOwner is GDMIndividualRecord) && GKUtils.MayContainPortrait(mmRec)) { - BaseController.SelectPortraitRegion(fOwner, fBaseWin, mmLink); + await BaseController.SelectPortraitRegion(fOwner, fBaseWin, mmLink); } } break; diff --git a/projects/GKCore/GKCore/Lists/NoteLinksListModel.cs b/projects/GKCore/GKCore/Lists/NoteLinksListModel.cs index 125145246..2a777be31 100644 --- a/projects/GKCore/GKCore/Lists/NoteLinksListModel.cs +++ b/projects/GKCore/GKCore/Lists/NoteLinksListModel.cs @@ -76,7 +76,7 @@ public override void UpdateContents() } } - public override void Modify(object sender, ModifyEventArgs eArgs) + public override async void Modify(object sender, ModifyEventArgs eArgs) { var dataOwner = fDataOwner as IGDMStructWithNotes; if (fBaseWin == null || dataOwner == null) return; @@ -88,7 +88,7 @@ public override void Modify(object sender, ModifyEventArgs eArgs) GDMNoteRecord noteRec; switch (eArgs.Action) { case RecordAction.raAdd: - noteRec = fBaseWin.Context.SelectRecord(fOwner, GDMRecordType.rtNote, null) as GDMNoteRecord; + noteRec = await fBaseWin.Context.SelectRecord(fOwner, GDMRecordType.rtNote, null) as GDMNoteRecord; if (noteRec != null) { result = fUndoman.DoOrdinaryOperation(OperationType.otRecordNoteAdd, (GDMObject)dataOwner, noteRec); notes = dataOwner.FindNotes(noteRec); diff --git a/projects/GKCore/GKCore/Lists/ResearchListModel.cs b/projects/GKCore/GKCore/Lists/ResearchListModel.cs index 04ff7e183..e05e1197c 100644 --- a/projects/GKCore/GKCore/Lists/ResearchListModel.cs +++ b/projects/GKCore/GKCore/Lists/ResearchListModel.cs @@ -176,7 +176,7 @@ public override void UpdateContents() } } - public override void Modify(object sender, ModifyEventArgs eArgs) + public override async void Modify(object sender, ModifyEventArgs eArgs) { var research = fDataOwner as GDMResearchRecord; if (fBaseWin == null || research == null) return; @@ -187,7 +187,7 @@ public override void Modify(object sender, ModifyEventArgs eArgs) switch (eArgs.Action) { case RecordAction.raAdd: - task = fBaseWin.Context.SelectRecord(fOwner, GDMRecordType.rtTask, null) as GDMTaskRecord; + task = await fBaseWin.Context.SelectRecord(fOwner, GDMRecordType.rtTask, null) as GDMTaskRecord; if (task != null) { result = fUndoman.DoOrdinaryOperation(OperationType.otResearchTaskAdd, research, task); } @@ -269,7 +269,7 @@ public override void UpdateContents() } } - public override void Modify(object sender, ModifyEventArgs eArgs) + public override async void Modify(object sender, ModifyEventArgs eArgs) { var research = fDataOwner as GDMResearchRecord; if (fBaseWin == null || research == null) return; @@ -280,7 +280,7 @@ public override void Modify(object sender, ModifyEventArgs eArgs) switch (eArgs.Action) { case RecordAction.raAdd: - comm = fBaseWin.Context.SelectRecord(fOwner, GDMRecordType.rtCommunication, null) as GDMCommunicationRecord; + comm = await fBaseWin.Context.SelectRecord(fOwner, GDMRecordType.rtCommunication, null) as GDMCommunicationRecord; if (comm != null) { result = fUndoman.DoOrdinaryOperation(OperationType.otResearchCommunicationAdd, research, comm); } @@ -350,7 +350,7 @@ public override void UpdateContents() } } - public override void Modify(object sender, ModifyEventArgs eArgs) + public override async void Modify(object sender, ModifyEventArgs eArgs) { var research = fDataOwner as GDMResearchRecord; if (fBaseWin == null || research == null) return; @@ -361,7 +361,7 @@ public override void Modify(object sender, ModifyEventArgs eArgs) switch (eArgs.Action) { case RecordAction.raAdd: - group = fBaseWin.Context.SelectRecord(fOwner, GDMRecordType.rtGroup, null) as GDMGroupRecord; + group = await fBaseWin.Context.SelectRecord(fOwner, GDMRecordType.rtGroup, null) as GDMGroupRecord; if (group != null) { result = fUndoman.DoOrdinaryOperation(OperationType.otResearchGroupAdd, research, group); } diff --git a/projects/GKCore/GKCore/Lists/SourceListModel.cs b/projects/GKCore/GKCore/Lists/SourceListModel.cs index f14bd2748..3d1409cfa 100644 --- a/projects/GKCore/GKCore/Lists/SourceListModel.cs +++ b/projects/GKCore/GKCore/Lists/SourceListModel.cs @@ -152,7 +152,7 @@ public override void UpdateContents() } } - public override void Modify(object sender, ModifyEventArgs eArgs) + public override async void Modify(object sender, ModifyEventArgs eArgs) { var source = fDataOwner as GDMSourceRecord; if (fBaseWin == null || source == null) return; @@ -164,7 +164,7 @@ public override void Modify(object sender, ModifyEventArgs eArgs) switch (eArgs.Action) { case RecordAction.raAdd: - repoRec = fBaseWin.Context.SelectRecord(fOwner, GDMRecordType.rtRepository, null) as GDMRepositoryRecord; + repoRec = await fBaseWin.Context.SelectRecord(fOwner, GDMRecordType.rtRepository, null) as GDMRepositoryRecord; if (repoRec != null) { result = fUndoman.DoOrdinaryOperation(OperationType.otSourceRepositoryCitationAdd, source, repoRec); } diff --git a/projects/GKCore/GKCore/ScriptEngine.cs b/projects/GKCore/GKCore/ScriptEngine.cs index b844f2e35..15e2081d6 100644 --- a/projects/GKCore/GKCore/ScriptEngine.cs +++ b/projects/GKCore/GKCore/ScriptEngine.cs @@ -25,6 +25,7 @@ using System.IO; using System.Reflection; using System.Text; +using System.Threading.Tasks; using BSLib; using GDModel; using GDModel.Providers.GEDCOM; @@ -565,11 +566,11 @@ public void bind_family_child(object familyPtr, object childPtr) fRec.AddChild(chRec); } - public string define_sex(string name, string patr) + public async Task define_sex(string name, string patr) { - GDMSex sx = fBase.Context.DefineSex(fView, name, patr); + GDMSex sx = await fBase.Context.DefineSex(fView, name, patr); - return (GKData.SexData[(int)sx].Sign); + return GKData.SexData[(int)sx].Sign; } public object find_source(string name) @@ -584,11 +585,11 @@ public object create_event(object recPtr, string sign) return evt; } - public string define_patronymic(string fatherName, string childSex, bool confirm) + public async Task define_patronymic(string fatherName, string childSex, bool confirm) { GDMSex sex = (childSex.Length == 1) ? GKUtils.GetSexBySign(childSex[0]) : GDMSex.svUnknown; - return fBase.Context.DefinePatronymic(fView, fatherName, sex, confirm); + return await fBase.Context.DefinePatronymic(fView, fatherName, sex, confirm); } public object get_individual_parents_family(object recPtr) diff --git a/projects/GKv2/GEDKeeper2/GKUI/Platform/WFAppHost.cs b/projects/GKv2/GEDKeeper2/GKUI/Platform/WFAppHost.cs index 96600e107..98d72ab52 100644 --- a/projects/GKv2/GEDKeeper2/GKUI/Platform/WFAppHost.cs +++ b/projects/GKv2/GEDKeeper2/GKUI/Platform/WFAppHost.cs @@ -24,6 +24,7 @@ using System.Runtime.InteropServices; using System.Security; using System.Threading; +using System.Threading.Tasks; using System.Windows.Forms; using BSLib; using GKCore; @@ -39,6 +40,7 @@ using GKUI.Forms; using GKUI.Platform.Handlers; using GKUI.Themes; +using CommonDialog = GKUI.Forms.CommonDialog; namespace GKUI.Platform { @@ -125,6 +127,15 @@ public override bool ShowModalX(ICommonDialog dialog, IView owner, bool keepMode return base.ShowModalX(dialog, owner, keepModeless); } + public override async Task ShowModalAsync(ICommonDialog dialog, IView owner, bool keepModeless = false) + { + var wfModal = dialog as CommonDialog; + if (wfModal == null) return false; + + wfModal.ShowDialog(owner as IWin32Window); + return await wfModal.DialogResultTask; + } + public override void EnableWindow(IWidgetForm form, bool value) { Form frm = form as Form; diff --git a/projects/GKv2/GKComponents/GKUI/Forms/CommonForm.cs b/projects/GKv2/GKComponents/GKUI/Forms/CommonForm.cs index e78a14474..6ca2e2c78 100644 --- a/projects/GKv2/GKComponents/GKUI/Forms/CommonForm.cs +++ b/projects/GKv2/GKComponents/GKUI/Forms/CommonForm.cs @@ -21,6 +21,7 @@ using System; using System.ComponentModel; using System.Reflection; +using System.Threading.Tasks; using System.Windows.Forms; using GKCore; using GKCore.Design; @@ -171,14 +172,48 @@ public override void ApplyTheme() /// public class CommonDialog : CommonForm, ICommonDialog { + private readonly TaskCompletionSource fTaskSource; + + public Task DialogResultTask + { + get { return fTaskSource.Task; } + } + + public CommonDialog() + { + fTaskSource = new TaskCompletionSource(); + } + public virtual bool ShowModalX(IView owner) { return (ShowDialog(owner as IWin32Window) == DialogResult.OK); } - protected virtual void CancelClickHandler(object sender, EventArgs e) + protected async Task Close(DialogResult dialogResult) + { + if (dialogResult != DialogResult.None) { + base.DialogResult = dialogResult; + fTaskSource.SetResult(dialogResult == DialogResult.OK); + } + } + + protected async virtual void AcceptClickHandler(object sender, EventArgs e) { - DialogResult = DialogResult.Cancel; + await Close(DialogResult.OK); + } + + protected async virtual void CancelClickHandler(object sender, EventArgs e) + { + await Close(DialogResult.Cancel); + } + + protected override void OnClosing(CancelEventArgs e) + { + // To correctly close the dialog using the button in the dialog header. + if (!e.Cancel && !fTaskSource.Task.IsCompleted) + fTaskSource.SetResult(false); + + base.OnClosing(e); } } @@ -192,19 +227,21 @@ public class CommonDialog : CommonDialog { protected TController fController; - protected virtual void AcceptClickHandler(object sender, EventArgs e) + protected async override void AcceptClickHandler(object sender, EventArgs e) { try { - DialogResult = fController.Accept() ? DialogResult.OK : DialogResult.None; + if (fController.Accept()) + await Close(DialogResult.OK); } catch (Exception ex) { Logger.WriteError("CommonDialog<>.AcceptClickHandler()", ex); } } - protected override void CancelClickHandler(object sender, EventArgs e) + protected async override void CancelClickHandler(object sender, EventArgs e) { try { - DialogResult = fController.Cancel() ? DialogResult.Cancel : DialogResult.None; + if (fController.Cancel()) + await Close(DialogResult.Cancel); } catch (Exception ex) { Logger.WriteError("CommonDialog<>.CancelClickHandler()", ex); } @@ -212,8 +249,8 @@ protected override void CancelClickHandler(object sender, EventArgs e) protected override void OnClosing(CancelEventArgs e) { - base.OnClosing(e); e.Cancel = fController.CheckChangesPersistence(); + base.OnClosing(e); } /// diff --git a/projects/GKv2/GKTestsUI2/UITests/MainSDITests.cs b/projects/GKv2/GKTestsUI2/UITests/MainSDITests.cs index 146bfb911..ac4f106f3 100644 --- a/projects/GKv2/GKTestsUI2/UITests/MainSDITests.cs +++ b/projects/GKv2/GKTestsUI2/UITests/MainSDITests.cs @@ -167,7 +167,7 @@ public void Test_Exit() } [Test] - public void Test_TabsAndLists() + public async void Test_TabsAndLists() { // calls to the different Editors for (GDMRecordType rt = GDMRecordType.rtIndividual; rt <= GDMRecordType.rtLocation; rt++) { @@ -228,7 +228,7 @@ public void Test_TabsAndLists() fCurBase.ApplyFilter(); // default lang for tests is English - string patr = fCurBase.Context.DefinePatronymic(null, "Ivan", GDMSex.svMale, false); + string patr = await fCurBase.Context.DefinePatronymic(null, "Ivan", GDMSex.svMale, false); Assert.AreEqual("", patr); } diff --git a/projects/GKv3/GEDKeeper3/GKUI/Platform/EtoAppHost.cs b/projects/GKv3/GEDKeeper3/GKUI/Platform/EtoAppHost.cs index 209f201c6..6f13e0d90 100644 --- a/projects/GKv3/GEDKeeper3/GKUI/Platform/EtoAppHost.cs +++ b/projects/GKv3/GEDKeeper3/GKUI/Platform/EtoAppHost.cs @@ -25,6 +25,7 @@ using System.Linq; using System.Text; using System.Threading; +using System.Threading.Tasks; using BSLib; using Eto.Drawing; using Eto.Forms; @@ -44,6 +45,7 @@ namespace GKUI.Platform { + using CommonDialog = Forms.CommonDialog; using FormWindowState = Eto.Forms.WindowState; /// @@ -201,6 +203,15 @@ public override bool ShowModalX(ICommonDialog dialog, IView owner, bool keepMode return (dialog != null && dialog.ShowModalX(owner)); } + public override async Task ShowModalAsync(ICommonDialog dialog, IView owner, bool keepModeless = false) + { + var efModal = dialog as CommonDialog; + if (efModal == null) return false; + + efModal.ShowModal(owner as Control); + return await efModal.DialogResultTask; + } + public override void EnableWindow(IWidgetForm form, bool value) { Form frm = form as Form; diff --git a/projects/GKv3/GKComponents/GKUI/Forms/CommonForm.cs b/projects/GKv3/GKComponents/GKUI/Forms/CommonForm.cs index b12a5136c..0f8ca2d77 100644 --- a/projects/GKv3/GKComponents/GKUI/Forms/CommonForm.cs +++ b/projects/GKv3/GKComponents/GKUI/Forms/CommonForm.cs @@ -21,6 +21,7 @@ using System; using System.ComponentModel; using System.Reflection; +using System.Threading.Tasks; using Eto.Forms; using GKCore; using GKCore.Design; @@ -155,6 +156,12 @@ public override void ApplyTheme() public class CommonDialog : Dialog, ICommonDialog, IThemedView { private readonly ControlsManager fControlsManager; + private readonly TaskCompletionSource fTaskSource; + + public Task DialogResultTask + { + get { return fTaskSource.Task; } + } #region View Interface @@ -188,6 +195,8 @@ public CommonDialog() fControlsManager = new ControlsManager(this); + fTaskSource = new TaskCompletionSource(); + // Option: Enter in dialogs is always the "Accept/Apply/Ok" button /*Styles.Add public interface ICommonDialog : IForm { - bool ShowModalX(IView owner); } } diff --git a/projects/GKCore/GKCore/Interfaces/IHost.cs b/projects/GKCore/GKCore/Interfaces/IHost.cs index 082bac025..4a4ca249e 100644 --- a/projects/GKCore/GKCore/Interfaces/IHost.cs +++ b/projects/GKCore/GKCore/Interfaces/IHost.cs @@ -18,6 +18,7 @@ * along with this program. If not, see . */ +using System.Threading.Tasks; using GDModel; using GKCore.Design; using GKCore.Options; @@ -36,8 +37,8 @@ public interface IHost string GetAppDataPath(); string GetUserFilesPath(string filePath); - IBaseWindow CreateBase(string fileName); - void LoadBase(IBaseWindow baseWin, string fileName); + Task CreateBase(string fileName); + Task LoadBase(IBaseWindow baseWin, string fileName); IBaseWindow FindBase(string fileName); void BaseChanged(IBaseWindow baseWin); void BaseClosed(IBaseWindow baseWin); @@ -56,7 +57,7 @@ public interface IHost void EnableWindow(IWidgetForm form, bool value); MRUFile GetMRUFile(IBaseWindow baseWin); - bool ShowModalX(ICommonDialog dialog, IView owner, bool keepModeless = false); + Task ShowModalAsync(ICommonDialog dialog, IView owner, bool keepModeless = false); void ShowWindow(IWindow window); ILangMan CreateLangMan(object sender); diff --git a/projects/GKCore/GKCore/Lists/ChildrenListModel.cs b/projects/GKCore/GKCore/Lists/ChildrenListModel.cs index 485716da7..54dc1d556 100644 --- a/projects/GKCore/GKCore/Lists/ChildrenListModel.cs +++ b/projects/GKCore/GKCore/Lists/ChildrenListModel.cs @@ -109,8 +109,10 @@ public override async void Modify(object sender, ModifyEventArgs eArgs) } break; - case RecordAction.raEdit: - result = (BaseController.ModifyIndividual(fOwner, fBaseWin, ref child, null, TargetMode.tmNone, GDMSex.svUnknown)); + case RecordAction.raEdit: { + var indiRes = await BaseController.ModifyIndividual(fOwner, fBaseWin, child, null, TargetMode.tmNone, GDMSex.svUnknown); + result = indiRes.Result; + } break; case RecordAction.raDelete: @@ -184,8 +186,10 @@ public override async void Modify(object sender, ModifyEventArgs eArgs) } break; - case RecordAction.raEdit: - result = (BaseController.ModifyIndividual(fOwner, fBaseWin, ref child, null, TargetMode.tmNone, GDMSex.svUnknown)); + case RecordAction.raEdit: { + var indiRes = await BaseController.ModifyIndividual(fOwner, fBaseWin, child, null, TargetMode.tmNone, GDMSex.svUnknown); + result = indiRes.Result; + } break; case RecordAction.raDelete: diff --git a/projects/GKCore/GKCore/Lists/IndividualListModel.cs b/projects/GKCore/GKCore/Lists/IndividualListModel.cs index 5b3dfdab7..de4511c1a 100644 --- a/projects/GKCore/GKCore/Lists/IndividualListModel.cs +++ b/projects/GKCore/GKCore/Lists/IndividualListModel.cs @@ -1074,7 +1074,7 @@ public override void UpdateContents() } } - public override void Modify(object sender, ModifyEventArgs eArgs) + public override async void Modify(object sender, ModifyEventArgs eArgs) { var iRec = fDataOwner as GDMIndividualRecord; if (fBaseWin == null || iRec == null) return; @@ -1084,15 +1084,19 @@ public override void Modify(object sender, ModifyEventArgs eArgs) bool result = false; switch (eArgs.Action) { - case RecordAction.raAdd: - result = (BaseController.ModifyFamily(fOwner, fBaseWin, ref family, TargetMode.tmSpouse, iRec)); - if (result) { - eArgs.ItemData = family; + case RecordAction.raAdd: { + var famRes = await BaseController.ModifyFamily(fOwner, fBaseWin, family, TargetMode.tmSpouse, iRec); + result = famRes.Result; + if (result) { + eArgs.ItemData = famRes.Record; + } } break; - case RecordAction.raEdit: - result = (BaseController.ModifyFamily(fOwner, fBaseWin, ref family, TargetMode.tmNone, null)); + case RecordAction.raEdit: { + var famRes = await BaseController.ModifyFamily(fOwner, fBaseWin, family, TargetMode.tmNone, null); + result = famRes.Result; + } break; case RecordAction.raDelete: diff --git a/projects/GKCore/GKCore/Lists/MediaLinksListModel.cs b/projects/GKCore/GKCore/Lists/MediaLinksListModel.cs index f0e8b5663..1e36b2207 100644 --- a/projects/GKCore/GKCore/Lists/MediaLinksListModel.cs +++ b/projects/GKCore/GKCore/Lists/MediaLinksListModel.cs @@ -108,7 +108,8 @@ public override async void Modify(object sender, ModifyEventArgs eArgs) case RecordAction.raEdit: if (mmLink != null) { mmRec = fBaseContext.Tree.GetPtrValue(mmLink); - result = BaseController.ModifyMedia(fOwner, fBaseWin, ref mmRec); + var mmRes = await BaseController.ModifyMedia(fOwner, fBaseWin, mmRec); + result = mmRes.Result; } break; diff --git a/projects/GKCore/GKCore/Lists/NoteLinksListModel.cs b/projects/GKCore/GKCore/Lists/NoteLinksListModel.cs index 2a777be31..3b13a6095 100644 --- a/projects/GKCore/GKCore/Lists/NoteLinksListModel.cs +++ b/projects/GKCore/GKCore/Lists/NoteLinksListModel.cs @@ -98,7 +98,8 @@ public override async void Modify(object sender, ModifyEventArgs eArgs) case RecordAction.raEdit: if (notes != null) { noteRec = fBaseContext.Tree.GetPtrValue(notes); - result = BaseController.ModifyNote(fOwner, fBaseWin, ref noteRec); + var noteRes = await BaseController.ModifyNote(fOwner, fBaseWin, noteRec); + result = noteRes.Result; } break; diff --git a/projects/GKCore/GKCore/Lists/ResearchListModel.cs b/projects/GKCore/GKCore/Lists/ResearchListModel.cs index e05e1197c..afe2f4320 100644 --- a/projects/GKCore/GKCore/Lists/ResearchListModel.cs +++ b/projects/GKCore/GKCore/Lists/ResearchListModel.cs @@ -194,7 +194,10 @@ public override async void Modify(object sender, ModifyEventArgs eArgs) break; case RecordAction.raEdit: - result = (task != null && BaseController.ModifyTask(fOwner, fBaseWin, ref task)); + if (task != null) { + var taskRes = await BaseController.ModifyTask(fOwner, fBaseWin, task); + result = taskRes.Result; + } break; case RecordAction.raDelete: @@ -287,7 +290,10 @@ public override async void Modify(object sender, ModifyEventArgs eArgs) break; case RecordAction.raEdit: - result = (comm != null && BaseController.ModifyCommunication(fOwner, fBaseWin, ref comm)); + if (comm != null) { + var commRes = await BaseController.ModifyCommunication(fOwner, fBaseWin, comm); + result = commRes.Result; + } break; case RecordAction.raDelete: diff --git a/projects/GKCore/GKCore/Lists/SourceCitationsListModel.cs b/projects/GKCore/GKCore/Lists/SourceCitationsListModel.cs index 992781dd1..c191d0051 100644 --- a/projects/GKCore/GKCore/Lists/SourceCitationsListModel.cs +++ b/projects/GKCore/GKCore/Lists/SourceCitationsListModel.cs @@ -89,7 +89,7 @@ public override void UpdateContents() } } - public override void Modify(object sender, ModifyEventArgs eArgs) + public override async void Modify(object sender, ModifyEventArgs eArgs) { var dataOwner = fDataOwner as IGDMStructWithSourceCitations; if (fBaseWin == null || dataOwner == null) return; @@ -100,8 +100,11 @@ public override void Modify(object sender, ModifyEventArgs eArgs) switch (eArgs.Action) { case RecordAction.raAdd: - case RecordAction.raEdit: - result = BaseController.ModifySourceCitation(fOwner, fBaseWin, fUndoman, dataOwner, ref srcCit); + case RecordAction.raEdit: { + var srcCitRes = await BaseController.ModifySourceCitation(fOwner, fBaseWin, fUndoman, dataOwner, srcCit); + srcCit = srcCitRes.Record; + result = srcCitRes.Result; + } break; case RecordAction.raDelete: diff --git a/projects/GKCore/GKCore/Tools/TreeInspector.cs b/projects/GKCore/GKCore/Tools/TreeInspector.cs index cb37d779f..a5ce9569f 100644 --- a/projects/GKCore/GKCore/Tools/TreeInspector.cs +++ b/projects/GKCore/GKCore/Tools/TreeInspector.cs @@ -20,6 +20,7 @@ using System; using System.Collections.Generic; +using System.Threading.Tasks; using BSLib; using GDModel; using GDModel.Providers.GEDCOM; @@ -488,7 +489,7 @@ public static void CheckBase(IBaseWindow baseWin, List checksList, IPr } } - public static void RepairProblem(IView owner, IBaseWindow baseWin, CheckObj checkObj) + public static async Task RepairProblem(IView owner, IBaseWindow baseWin, CheckObj checkObj) { if (baseWin == null) throw new ArgumentNullException("baseWin"); @@ -508,7 +509,7 @@ public static void RepairProblem(IView owner, IBaseWindow baseWin, CheckObj chec case CheckDiag.cdPersonSexless: { var iRec = checkObj.Rec as GDMIndividualRecord; - baseWin.Context.CheckPersonSex(owner, iRec); + await baseWin.Context.CheckPersonSex(owner, iRec); baseWin.NotifyRecord(iRec, RecordAction.raEdit); } break; @@ -531,13 +532,13 @@ public static void RepairProblem(IView owner, IBaseWindow baseWin, CheckObj chec case CheckDiag.cdDuplicateChildren: if (checkObj.Solve == CheckSolve.csEdit) { - BaseController.EditRecord(owner, baseWin, checkObj.Rec); + await BaseController.EditRecord(owner, baseWin, checkObj.Rec); } break; case CheckDiag.csDateInvalid: if (checkObj.Solve == CheckSolve.csEdit) { - BaseController.EditRecord(owner, baseWin, checkObj.Rec); + await BaseController.EditRecord(owner, baseWin, checkObj.Rec); } break; diff --git a/projects/GKTests/GKCore/AppHostTests.cs b/projects/GKTests/GKCore/AppHostTests.cs index 63ea901a6..3a57387d9 100644 --- a/projects/GKTests/GKCore/AppHostTests.cs +++ b/projects/GKTests/GKCore/AppHostTests.cs @@ -41,7 +41,7 @@ public void Test_AppHost() Assert.IsNotEmpty(AppHost.Instance.GetAppDataPath()); - Assert.Throws(typeof(ArgumentNullException), () => { AppHost.Instance.LoadBase(null, null); }); + Assert.ThrowsAsync(typeof(ArgumentNullException), async () => { await AppHost.Instance.LoadBase(null, null); }); AppHost.Instance.SetArgs(new string[] { "" }); diff --git a/projects/GKTests/GKCore/BaseContextTests.cs b/projects/GKTests/GKCore/BaseContextTests.cs index 9eae11dd7..022c58c08 100644 --- a/projects/GKTests/GKCore/BaseContextTests.cs +++ b/projects/GKTests/GKCore/BaseContextTests.cs @@ -20,6 +20,7 @@ using System; using System.IO; +using System.Threading.Tasks; using BSLib; using GDModel; using GDModel.Providers.GEDCOM; @@ -548,7 +549,7 @@ public void Test_CollectTips() [Test] public void Test_CheckPersonSex() { - Assert.Throws(typeof(ArgumentNullException), () => { fContext.CheckPersonSex(null, null); }); + Assert.ThrowsAsync(typeof(ArgumentNullException), async () => { await fContext.CheckPersonSex(null, null); }); } [Test] @@ -593,16 +594,16 @@ public void Test_AddFamilyForSpouse() } [Test] - public void Test_AddChildForParent() + public async Task Test_AddChildForParent() { - var result = fContext.AddChildForParent(null, null, GDMSex.svMale); + var result = await fContext.AddChildForParent(null, null, GDMSex.svMale); Assert.IsNull(result); } [Test] public void Test_SelectSpouseFor() { - Assert.Throws(typeof(ArgumentNullException), () => { fContext.SelectSpouseFor(null, null); }); + Assert.ThrowsAsync(typeof(ArgumentNullException), async () => { await fContext.SelectSpouseFor(null, null); }); } } } diff --git a/projects/GKTests/GKCore/TreeToolsTests.cs b/projects/GKTests/GKCore/TreeToolsTests.cs index 9f7551f6b..09338472d 100644 --- a/projects/GKTests/GKCore/TreeToolsTests.cs +++ b/projects/GKTests/GKCore/TreeToolsTests.cs @@ -21,6 +21,7 @@ using System; using System.Collections.Generic; using System.IO; +using System.Threading.Tasks; using BSLib; using GDModel; using GDModel.Providers.GEDCOM; @@ -242,7 +243,7 @@ public void Test_CheckGEDCOMFormat() } [Test] - public void Test_CheckBaseAndRepairProblem() + public async Task Test_CheckBaseAndRepairProblem() { var progress = Substitute.For(); @@ -258,10 +259,10 @@ public void Test_CheckBaseAndRepairProblem() Assert.AreEqual(TreeInspector.CheckDiag.cdStrangeSpouse, checksList[1].Diag); Assert.AreEqual(TreeInspector.CheckDiag.cdPersonLonglived, checksList[2].Diag); - Assert.Throws(typeof(ArgumentNullException), () => { TreeInspector.RepairProblem(null, null, null); }); - Assert.Throws(typeof(ArgumentNullException), () => { TreeInspector.RepairProblem(null, fBaseWin, null); }); + Assert.ThrowsAsync(typeof(ArgumentNullException), async () => { await TreeInspector.RepairProblem(null, null, null); }); + Assert.ThrowsAsync(typeof(ArgumentNullException), async () => { await TreeInspector.RepairProblem(null, fBaseWin, null); }); - TreeInspector.RepairProblem(null, fBaseWin, checksList[2]); + await TreeInspector.RepairProblem(null, fBaseWin, checksList[2]); } [Test] diff --git a/projects/GKTests/Stubs/AppHostStub.cs b/projects/GKTests/Stubs/AppHostStub.cs index 302e44668..e4dbcf9ed 100644 --- a/projects/GKTests/Stubs/AppHostStub.cs +++ b/projects/GKTests/Stubs/AppHostStub.cs @@ -86,7 +86,7 @@ public override void ExecuteWork(ProgressStart proc) try { workerThread.Start(progressForm); - progressForm.ShowModalX(activeWnd); + //progressForm.ShowModalX(activeWnd); } catch (Exception ex) { Logger.WriteError("ExecuteWork()", ex); } diff --git a/projects/GKv2/GEDKeeper2/GKUI/Forms/BaseWinSDI.cs b/projects/GKv2/GEDKeeper2/GKUI/Forms/BaseWinSDI.cs index 9072ba03a..fe0d84f89 100644 --- a/projects/GKv2/GEDKeeper2/GKUI/Forms/BaseWinSDI.cs +++ b/projects/GKv2/GEDKeeper2/GKUI/Forms/BaseWinSDI.cs @@ -667,7 +667,7 @@ private void Form_DragEnter(object sender, DragEventArgs e) e.Effect = e.Data.GetDataPresent(DataFormats.FileDrop) ? DragDropEffects.Copy : DragDropEffects.None; } - private void Form_DragDrop(object sender, DragEventArgs e) + private async void Form_DragDrop(object sender, DragEventArgs e) { try { try { @@ -678,10 +678,11 @@ private void Form_DragDrop(object sender, DragEventArgs e) for (int i = 0; i < files.Length; i++) { string fn = files[i]; - AppHost.Instance.LoadBase(this, fn); + await AppHost.Instance.LoadBase(this, fn); } + + await AppHost.Instance.EndLoading(); } finally { - AppHost.Instance.EndLoading(); } } catch (Exception ex) { Logger.WriteError("BaseWinSDI.Form_DragDrop()", ex); @@ -690,8 +691,8 @@ private void Form_DragDrop(object sender, DragEventArgs e) void IBaseWindowView.LoadBase(string fileName) { - MethodInvoker invoker = delegate() { - AppHost.Instance.LoadBase(this, fileName); + MethodInvoker invoker = async delegate() { + await AppHost.Instance.LoadBase(this, fileName); }; if (InvokeRequired) { @@ -715,10 +716,10 @@ private void StatusBar_PanelClick(object sender, EventArgs e) UpdateShieldState(); } - private void MRUFileClick(object sender, EventArgs e) + private async void MRUFileClick(object sender, EventArgs e) { int idx = (int)((MenuItemEx)sender).Tag; - AppHost.Instance.LoadBase(this, AppHost.Options.MRUFiles[idx].FileName); + await AppHost.Instance.LoadBase(this, AppHost.Options.MRUFiles[idx].FileName); } public void UpdateMRU() diff --git a/projects/GKv2/GEDKeeper2/GKUI/Forms/RecordSelectDlg.cs b/projects/GKv2/GEDKeeper2/GKUI/Forms/RecordSelectDlg.cs index c2c61f80d..a0f48b8c9 100644 --- a/projects/GKv2/GEDKeeper2/GKUI/Forms/RecordSelectDlg.cs +++ b/projects/GKv2/GEDKeeper2/GKUI/Forms/RecordSelectDlg.cs @@ -105,7 +105,7 @@ private void btnSelect_Click(object sender, EventArgs e) { try { ResultRecord = fListRecords.GetSelectedData() as GDMRecord; - DialogResult = DialogResult.OK; + Close(DialogResult.OK); } catch (Exception ex) { Logger.WriteError("RecordSelectDlg.btnSelect_Click()", ex); ResultRecord = null; @@ -113,13 +113,13 @@ private void btnSelect_Click(object sender, EventArgs e) } } - private void btnCreate_Click(object sender, EventArgs e) + private async void btnCreate_Click(object sender, EventArgs e) { try { - GDMRecord rec = BaseController.AddRecord(this, fController.Base, fController.RecType, fController.Target); + GDMRecord rec = await BaseController.AddRecord(this, fController.Base, fController.RecType, fController.Target); if (rec != null) { ResultRecord = rec; - DialogResult = DialogResult.OK; + Close(DialogResult.OK); } } catch (Exception ex) { Logger.WriteError("RecordSelectDlg.btnCreate_Click()", ex); diff --git a/projects/GKv2/GEDKeeper2/GKUI/Platform/WFAppHost.cs b/projects/GKv2/GEDKeeper2/GKUI/Platform/WFAppHost.cs index 98d72ab52..3f5c88f85 100644 --- a/projects/GKv2/GEDKeeper2/GKUI/Platform/WFAppHost.cs +++ b/projects/GKv2/GEDKeeper2/GKUI/Platform/WFAppHost.cs @@ -65,9 +65,9 @@ private void OnApplicationExit(object sender, EventArgs e) //AppHost.Instance.SaveLastBases(); } - public override void Init(string[] args, bool isMDI) + public override async Task Init(string[] args, bool isMDI) { - base.Init(args, isMDI); + await base.Init(args, isMDI); Application.ApplicationExit += OnApplicationExit; } @@ -106,8 +106,11 @@ public override IntPtr GetTopWindowHandle() return (ownerForm == null) ? IntPtr.Zero : ownerForm.Handle; } - public override bool ShowModalX(ICommonDialog dialog, IView owner, bool keepModeless = false) + public override async Task ShowModalAsync(ICommonDialog dialog, IView owner, bool keepModeless = false) { + var wfModal = dialog as CommonDialog; + if (wfModal == null) return false; + IntPtr mainHandle = GetTopWindowHandle(); if (keepModeless) { @@ -115,23 +118,15 @@ public override bool ShowModalX(ICommonDialog dialog, IView owner, bool keepMode if (win is IBaseWindow) { IntPtr handle = ((Form)win).Handle; - #if !MONO +#if !MONO PostMessageExt(handle, WM_KEEPMODELESS, IntPtr.Zero, IntPtr.Zero); - #endif +#endif } } } UIHelper.CenterFormByParent((Form)dialog, mainHandle); - return base.ShowModalX(dialog, owner, keepModeless); - } - - public override async Task ShowModalAsync(ICommonDialog dialog, IView owner, bool keepModeless = false) - { - var wfModal = dialog as CommonDialog; - if (wfModal == null) return false; - wfModal.ShowDialog(owner as IWin32Window); return await wfModal.DialogResultTask; } @@ -193,7 +188,7 @@ public override void ExecuteWork(ProgressStart proc) try { workerThread.Start(progressForm); - progressForm.ShowModalX(activeWnd); + ((Form)progressForm).ShowDialog(activeWnd as IWin32Window); } catch (Exception ex) { Logger.WriteError("ExecuteWork()", ex); } diff --git a/projects/GKv2/GKComponents/GKUI/Forms/CommonForm.cs b/projects/GKv2/GKComponents/GKUI/Forms/CommonForm.cs index 6ca2e2c78..d2674e6c1 100644 --- a/projects/GKv2/GKComponents/GKUI/Forms/CommonForm.cs +++ b/projects/GKv2/GKComponents/GKUI/Forms/CommonForm.cs @@ -184,12 +184,7 @@ public CommonDialog() fTaskSource = new TaskCompletionSource(); } - public virtual bool ShowModalX(IView owner) - { - return (ShowDialog(owner as IWin32Window) == DialogResult.OK); - } - - protected async Task Close(DialogResult dialogResult) + protected void Close(DialogResult dialogResult) { if (dialogResult != DialogResult.None) { base.DialogResult = dialogResult; @@ -197,14 +192,14 @@ protected async Task Close(DialogResult dialogResult) } } - protected async virtual void AcceptClickHandler(object sender, EventArgs e) + protected virtual void AcceptClickHandler(object sender, EventArgs e) { - await Close(DialogResult.OK); + Close(DialogResult.OK); } - protected async virtual void CancelClickHandler(object sender, EventArgs e) + protected virtual void CancelClickHandler(object sender, EventArgs e) { - await Close(DialogResult.Cancel); + Close(DialogResult.Cancel); } protected override void OnClosing(CancelEventArgs e) @@ -227,21 +222,21 @@ public class CommonDialog : CommonDialog { protected TController fController; - protected async override void AcceptClickHandler(object sender, EventArgs e) + protected override void AcceptClickHandler(object sender, EventArgs e) { try { if (fController.Accept()) - await Close(DialogResult.OK); + Close(DialogResult.OK); } catch (Exception ex) { Logger.WriteError("CommonDialog<>.AcceptClickHandler()", ex); } } - protected async override void CancelClickHandler(object sender, EventArgs e) + protected override void CancelClickHandler(object sender, EventArgs e) { try { if (fController.Cancel()) - await Close(DialogResult.Cancel); + Close(DialogResult.Cancel); } catch (Exception ex) { Logger.WriteError("CommonDialog<>.CancelClickHandler()", ex); } diff --git a/projects/GKv2/GKTestsUI2/UITests/MainSDITests.cs b/projects/GKv2/GKTestsUI2/UITests/MainSDITests.cs index ac4f106f3..691ee7c5d 100644 --- a/projects/GKv2/GKTestsUI2/UITests/MainSDITests.cs +++ b/projects/GKv2/GKTestsUI2/UITests/MainSDITests.cs @@ -26,6 +26,7 @@ using System; using System.Collections.Generic; using System.Threading; +using System.Threading.Tasks; using System.Windows.Forms; using BSLib; using GDModel; @@ -56,7 +57,7 @@ public override bool UseHidden private Form fMainWin; private IBaseWindow fCurBase; - public override void Setup() + public override async void Setup() { TestUtilsUI.InitUITest(); @@ -65,7 +66,7 @@ public override void Setup() // prevent LanguageSelectDlg modal dialog from showing on first run AppHost.Options.InterfaceLang = LangMan.LS_DEF_CODE; - appHost.Init(null, false); + await appHost.Init(null, false); var indiCols = GlobalOptions.Instance.IndividualListColumns; for (int i = 0; i < indiCols.Count; i++) { @@ -167,7 +168,7 @@ public void Test_Exit() } [Test] - public async void Test_TabsAndLists() + public async Task Test_TabsAndLists() { // calls to the different Editors for (GDMRecordType rt = GDMRecordType.rtIndividual; rt <= GDMRecordType.rtLocation; rt++) { @@ -211,17 +212,12 @@ public async void Test_TabsAndLists() Assert.IsTrue(fCurBase.RecordIsFiltered(record)); Assert.Throws(typeof(ArgumentNullException), () => { fCurBase.ShowMedia(null, false); }); - Assert.Throws(typeof(ArgumentNullException), () => { fCurBase.Context.SelectSpouseFor(null, null); }); fCurBase.NotifyRecord(null, RecordAction.raAdd); IList search = fCurBase.FindAll("Maria"); Assert.AreEqual(1, search.Count); Assert.AreEqual(null, fCurBase.Context.GetChildFamily(null, false, null)); - Assert.AreEqual(null, fCurBase.Context.AddChildForParent(null, null, GDMSex.svUnknown)); - Assert.Throws(typeof(ArgumentNullException), () => { fCurBase.Context.AddFamilyForSpouse(null); }); - - Assert.Throws(typeof(ArgumentNullException), () => { fCurBase.Context.CheckPersonSex(null, null); }); fCurBase.NotifyRecord(null, RecordAction.raEdit); @@ -450,21 +446,21 @@ public void Test_ShowMapsViewerWin() } [Test] - public void Test_ShowLanguageSelectDlg() + public async Task Test_ShowLanguageSelectDlg() { ModalFormHandler = LanguageSelectDlgTests.LanguageSelectDlg_Accept_Handler; - AppHost.Instance.LoadLanguage(0); + await AppHost.Instance.LoadLanguage(0); } [Test] - public void Test_ShowDayTipsDlg() + public async Task Test_ShowDayTipsDlg() { Assert.Throws(typeof(ArgumentNullException), () => { fCurBase.Context.CollectTips(null); }); fCurBase.Context.CollectTips(new StringList()); // FIXME: don't show dialog because BirthDays is empty //ModalFormHandler = DayTipsDlgTests.CloseModalHandler; - AppHost.Instance.ShowTips(); + await AppHost.Instance.ShowTips(); } [Test] diff --git a/projects/GKv3/GEDKeeper3/GKUI/Forms/PersonsFilterDlg.cs b/projects/GKv3/GEDKeeper3/GKUI/Forms/PersonsFilterDlg.cs index eb2e17e89..6a2fd8544 100644 --- a/projects/GKv3/GEDKeeper3/GKUI/Forms/PersonsFilterDlg.cs +++ b/projects/GKv3/GEDKeeper3/GKUI/Forms/PersonsFilterDlg.cs @@ -214,7 +214,8 @@ private void rgLife_CheckedChanged(object sender, EventArgs e) private void btnAccept_Click(object sender, EventArgs e) { - DialogResult = (fCommonController.Accept() && fController.Accept()) ? DialogResult.Ok : DialogResult.None; + if (fCommonController.Accept() && fController.Accept()) + Close(DialogResult.Ok); } private void btnReset_Click(object sender, EventArgs e) diff --git a/projects/GKv3/GEDKeeper3/GKUI/Forms/RecordSelectDlg.cs b/projects/GKv3/GEDKeeper3/GKUI/Forms/RecordSelectDlg.cs index afdff01ff..c1a2d220f 100644 --- a/projects/GKv3/GEDKeeper3/GKUI/Forms/RecordSelectDlg.cs +++ b/projects/GKv3/GEDKeeper3/GKUI/Forms/RecordSelectDlg.cs @@ -109,7 +109,7 @@ private void btnSelect_Click(object sender, EventArgs e) { try { ResultRecord = fListRecords.GetSelectedData() as GDMRecord; - DialogResult = DialogResult.Ok; + Close(DialogResult.Ok); } catch (Exception ex) { Logger.WriteError("RecordSelectDlg.btnSelect_Click()", ex); ResultRecord = null; @@ -117,13 +117,13 @@ private void btnSelect_Click(object sender, EventArgs e) } } - private void btnCreate_Click(object sender, EventArgs e) + private async void btnCreate_Click(object sender, EventArgs e) { try { - GDMRecord rec = BaseController.AddRecord(this, fController.Base, fController.RecType, fController.Target); + GDMRecord rec = await BaseController.AddRecord(this, fController.Base, fController.RecType, fController.Target); if (rec != null) { ResultRecord = rec; - DialogResult = DialogResult.Ok; + Close(DialogResult.Ok); } } catch (Exception ex) { Logger.WriteError("RecordSelectDlg.btnCreate_Click()", ex); diff --git a/projects/GKv3/GEDKeeper3/GKUI/Forms/SexCheckDlg.cs b/projects/GKv3/GEDKeeper3/GKUI/Forms/SexCheckDlg.cs index 801eea60f..253de6114 100644 --- a/projects/GKv3/GEDKeeper3/GKUI/Forms/SexCheckDlg.cs +++ b/projects/GKv3/GEDKeeper3/GKUI/Forms/SexCheckDlg.cs @@ -18,7 +18,6 @@ * along with this program. If not, see . */ -using System; using Eto.Forms; using Eto.Serialization.Xaml; using GDModel; @@ -94,15 +93,5 @@ public GDMSex Sex } } } - - private void btnAccept_Click(object sender, EventArgs e) - { - DialogResult = DialogResult.Ok; - } - - private void btnCancel_Click(object sender, EventArgs e) - { - DialogResult = DialogResult.Cancel; - } } } diff --git a/projects/GKv3/GEDKeeper3/GKUI/Forms/SexCheckDlg.xeto b/projects/GKv3/GEDKeeper3/GKUI/Forms/SexCheckDlg.xeto index 192adcd7d..7a9513742 100644 --- a/projects/GKv3/GEDKeeper3/GKUI/Forms/SexCheckDlg.xeto +++ b/projects/GKv3/GEDKeeper3/GKUI/Forms/SexCheckDlg.xeto @@ -23,8 +23,8 @@ -