Skip to content

Commit

Permalink
Experimental development (29) (#182)
Browse files Browse the repository at this point in the history
  • Loading branch information
Serg-Norseman committed Oct 31, 2023
1 parent d93cb50 commit 3d5bb8d
Show file tree
Hide file tree
Showing 16 changed files with 142 additions and 133 deletions.
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -57,7 +57,7 @@ If your problem or idea is not addressed yet, please open a new issue.

- "GEDKeeper2", standard (NET4.7.1 & WinForms)
- "GEDKeeper3", cross-platform (NET6 & Eto.Forms)
- "GEDKeeperX", future mobile (NET Standard & Xamarin), prototype
- "GEDKeeperX", mobile (NET Standard & Xamarin), prototype


## Supported languages
Expand Down
6 changes: 6 additions & 0 deletions projects/GKCore/GKCore/AppHost.cs
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@
using System.IO;
using System.Net;
using System.Reflection;
using System.Threading.Tasks;
using BSLib;
using GDModel;
using GKCore.Design;
Expand Down Expand Up @@ -655,6 +656,11 @@ public virtual bool ShowModalX(ICommonDialog dialog, IView owner, bool keepModel
return (dialog != null && dialog.ShowModalX(owner));
}

public virtual async Task<bool> ShowModalAsync(ICommonDialog dialog, IView owner, bool keepModeless = false)

Check warning on line 659 in projects/GKCore/GKCore/AppHost.cs

View workflow job for this annotation

GitHub Actions / mac

This async method lacks 'await' operators and will run synchronously. Consider using the 'await' operator to await non-blocking API calls, or 'await Task.Run(...)' to do CPU-bound work on a background thread.

Check warning on line 659 in projects/GKCore/GKCore/AppHost.cs

View workflow job for this annotation

GitHub Actions / mac

This async method lacks 'await' operators and will run synchronously. Consider using the 'await' operator to await non-blocking API calls, or 'await Task.Run(...)' to do CPU-bound work on a background thread.
{
return false;
}

public void ShowHelpTopic(string topic)
{
string lngSign = AppHost.Options.GetLanguageSign();
Expand Down
23 changes: 21 additions & 2 deletions projects/GKCore/GKCore/Controllers/BaseController.cs
Original file line number Diff line number Diff line change
Expand Up @@ -18,18 +18,19 @@
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*/

using System.Threading.Tasks;
using GDModel;
using GDModel.Providers.GEDCOM;
using GKCore.Charts;
using GKCore.Design;
using GKCore.Design.Views;
using GKCore.Interfaces;
using GKCore.Lists;
using GKCore.Design.Views;
using GKCore.Names;
using GKCore.Operations;
using GKCore.Options;
using GKCore.Tools;
using GKCore.Types;
using GKCore.Design;

namespace GKCore.Controllers
{
Expand Down Expand Up @@ -617,6 +618,24 @@ public static bool ModifyName(IView owner, IBaseContext context, ref NameEntry n
return result;
}

public static async Task<bool> ModifyNameAsync(IView owner, IBaseContext context, NameEntry nameEntry)
{
bool result;

try {
context.BeginUpdate();

using (var dlg = AppHost.ResolveDialog<INameEditDlg>()) {
dlg.IName = nameEntry;
result = await AppHost.Instance.ShowModalAsync(dlg, owner, false);
}
} finally {
context.EndUpdate();
}

return result;
}

#endregion

#region Data modification functions for UI
Expand Down
6 changes: 1 addition & 5 deletions projects/GKCore/GKCore/Controllers/NameEditDlgController.cs
Original file line number Diff line number Diff line change
Expand Up @@ -92,11 +92,7 @@ public override void SetLocale()
GetControl<IButton>("btnCancel").Text = LangMan.LS(LSID.DlgCancel);
GetControl<ILabel>("lblName").Text = LangMan.LS(LSID.Name);
GetControl<ILabel>("lblSex").Text = LangMan.LS(LSID.Sex);
if (!AppHost.Instance.HasFeatureSupport(Feature.Mobile)) {
GetControl<IGroupBox>("grpPatronymics").Text = LangMan.LS(LSID.Patronymic);
} else {
GetControl<ILabel>("grpPatronymics").Text = LangMan.LS(LSID.Patronymic);
}
GetControl<IGroupBox>("grpPatronymics").Text = LangMan.LS(LSID.Patronymic);
GetControl<ILabel>("lblFemale").Text = LangMan.LS(LSID.PatFemale);
GetControl<ILabel>("lblMale").Text = LangMan.LS(LSID.PatMale);
}
Expand Down
12 changes: 3 additions & 9 deletions projects/GKCore/GKCore/Controllers/RecMergeController.cs
Original file line number Diff line number Diff line change
Expand Up @@ -137,15 +137,9 @@ public override void SetLocale()
{
fView.Title = LangMan.LS(LSID.MergeDuplicates);

if (!AppHost.Instance.HasFeatureSupport(Feature.Mobile)) {
GetControl<IGroupBox>("grpSearchPersons").Text = LangMan.LS(LSID.RM_SearchPersons);
GetControl<IGroupBox>("grpMergeOther").Text = LangMan.LS(LSID.Other);
GetControl<IGroupBox>("rgMode").Text = LangMan.LS(LSID.RM_Records);
} else {
GetControl<ILabel>("grpSearchPersons").Text = LangMan.LS(LSID.RM_SearchPersons);
GetControl<ILabel>("grpMergeOther").Text = LangMan.LS(LSID.Other);
GetControl<ILabel>("rgMode").Text = LangMan.LS(LSID.RM_Records);
}
GetControl<IGroupBox>("grpSearchPersons").Text = LangMan.LS(LSID.RM_SearchPersons);
GetControl<IGroupBox>("grpMergeOther").Text = LangMan.LS(LSID.Other);
GetControl<IGroupBox>("rgMode").Text = LangMan.LS(LSID.RM_Records);

GetControl<ITabPage>("pageMerge").Text = LangMan.LS(LSID.RecMerge);
GetControl<ITabPage>("pageMergeOptions").Text = LangMan.LS(LSID.MIOptions);
Expand Down
2 changes: 1 addition & 1 deletion projects/GKMap/GKMap.Xamarin/GMapControl.cs
Original file line number Diff line number Diff line change
Expand Up @@ -588,7 +588,7 @@ public GPoint FromLatLngToLocal(PointLatLng point)
/// <summary>
/// enqueue built-in thread safe invalidation
/// </summary>
public new void Invalidate()
public void Invalidate()
{
if (fCore.RefreshEvent != null && !HoldInvalidation) {
fCore.RefreshEvent.Set();
Expand Down
2 changes: 1 addition & 1 deletion projects/GKvX/GEDKeeperX/GKUI/Components/CircleChart.cs
Original file line number Diff line number Diff line change
Expand Up @@ -90,7 +90,7 @@ public int VisibleGenerations
}
}

public new float Zoom
public float Zoom
{
get {
return fZoom;
Expand Down
78 changes: 21 additions & 57 deletions projects/GKvX/GEDKeeperX/GKUI/Components/GroupBox.cs
Original file line number Diff line number Diff line change
Expand Up @@ -18,89 +18,53 @@
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*/

using System.Collections.Generic;
using Xamarin.Forms;
using Xamarin.Forms.Xaml;

namespace GKUI.Components
{
[ContentProperty("Contents")]
[XamlCompilation(XamlCompilationOptions.Compile)]
public class GroupBox : ContentView
{
private readonly Frame fContent;
private readonly StackLayout fContentLayout;
private readonly Label fTitle;

public new View Content
{
get {
return fContent.Content;
}
set {
fContent.Content = value;
}
}
public IList<View> Contents { get => fContentLayout.Children; }

public string Text
{
get { return fTitle.Text; }
set {
///fTitle.Text = value;
//ForceLayout();
}
set { fTitle.Text = value; }
}

public GroupBox()
{
fTitle = new Label() {
//HorizontalOptions = LayoutOptions.FillAndExpand,
//VerticalOptions = LayoutOptions.Start,
Text = "GroupBox",
};
fTitle = new Label();

fContentLayout = new StackLayout() {
Orientation = StackOrientation.Vertical,
HorizontalOptions = LayoutOptions.FillAndExpand,
VerticalOptions = LayoutOptions.FillAndExpand
VerticalOptions = LayoutOptions.FillAndExpand,
Padding = 0,
Spacing = 0
};

fContent = new Frame() {
//HorizontalOptions = LayoutOptions.FillAndExpand,
//VerticalOptions = LayoutOptions.FillAndExpand,
//Padding = 4
Content = fContentLayout
};

var contentGrid = new Grid() {
RowDefinitions = {
new RowDefinition() { Height = GridLength.Auto },
new RowDefinition() { Height = GridLength.Auto }
var content = new StackLayout() {
Orientation = StackOrientation.Vertical,
Padding = 0,
Spacing = 0,
Children = {
fTitle,
new Frame() {
Padding = 8,
Content = fContentLayout
}
}
//Padding = new Thickness(4),
//HorizontalOptions = LayoutOptions.FillAndExpand,
//VerticalOptions = LayoutOptions.FillAndExpand,
//Orientation = StackOrientation.Vertical,
//Children = { fTitle, fContent }
};
contentGrid.Children.Add(fTitle, 0, 0);
contentGrid.Children.Add(fContent, 0, 1);

base.Content = contentGrid;
base.Content = content;
}

/*protected override void OnChildAdded(Element child)
{
View childView = child as View;
if (childView != null) {
((Layout<View>)fContentLayout).Children.Add(childView);
base.OnChildAdded(child);
}
}
protected override void OnChildRemoved(Element child, int oldLogicalIndex)
{
View childView = child as View;
if (childView != null) {
((Layout<View>)fContentLayout).Children.Remove(childView);
base.OnChildRemoved(child, oldLogicalIndex);
}
}*/
}
}
23 changes: 16 additions & 7 deletions projects/GKvX/GEDKeeperX/GKUI/Forms/CommonForm.cs
Original file line number Diff line number Diff line change
Expand Up @@ -133,11 +133,18 @@ public class CommonWindow<TView, TController> : CommonWindow


/// <summary>
///
///
/// Ref: https://stackoverflow.com/questions/24174241/how-can-i-await-modal-form-dismissal-using-xamarin-forms
/// </summary>
public class CommonDialog : CommonForm, ICommonDialog
{
private DialogResult fResult;
private readonly TaskCompletionSource<bool> fTaskSource;

public Task<bool> DialogResultTask
{
get { return fTaskSource.Task; }
}

public DialogResult DialogResult
{
Expand All @@ -146,6 +153,7 @@ public DialogResult DialogResult

public CommonDialog()
{
fTaskSource = new TaskCompletionSource<bool>();
fResult = DialogResult.None;
}

Expand All @@ -160,22 +168,23 @@ public override void Close()
Navigation.PopModalAsync();
}

public void Close(DialogResult dialogResult)
protected async Task Close(DialogResult dialogResult)
{
fResult = dialogResult;
if (fResult != DialogResult.None) {
Navigation.PopModalAsync();
await Navigation.PopModalAsync();
fTaskSource.SetResult(dialogResult == DialogResult.Ok);
}
}

protected async virtual void AcceptClickHandler(object sender, EventArgs e)
{
Close(DialogResult.Ok);
await Close(DialogResult.Ok);
}

protected async virtual void CancelClickHandler(object sender, EventArgs e)
{
Close(DialogResult.Cancel);
await Close(DialogResult.Cancel);
}
}

Expand All @@ -193,7 +202,7 @@ protected async override void AcceptClickHandler(object sender, EventArgs e)
{
try {
if (fController.Accept())
Close(DialogResult.Ok);
await Close(DialogResult.Ok);
} catch (Exception ex) {
Logger.WriteError("CommonDialog<>.AcceptClickHandler()", ex);
}
Expand All @@ -206,7 +215,7 @@ protected async override void CancelClickHandler(object sender, EventArgs e)
return;

if (fController.Cancel())
Close(DialogResult.Cancel);
await Close(DialogResult.Cancel);
} catch (Exception ex) {
Logger.WriteError("CommonDialog<>.CancelClickHandler()", ex);
}
Expand Down
31 changes: 25 additions & 6 deletions projects/GKvX/GEDKeeperX/GKUI/Forms/LaunchPage.xaml.cs
Original file line number Diff line number Diff line change
Expand Up @@ -94,19 +94,32 @@ public LaunchPage()
var baseWin = AppHost.Instance.GetCurrentFile() as BaseWinSDI;
baseWin.Context.DefineSex(baseWin, "Ivan", "Ivanovich");
}),
new LaunchItem("Test", "NameEditDlg", async () => {
new LaunchItem("Test", "NameEditDlg (def)", async () => {
var baseWin = AppHost.Instance.GetCurrentFile() as BaseWinSDI;
var nameEntry = new NameEntry();
BaseController.ModifyName(baseWin, baseWin.Context, ref nameEntry);
if (BaseController.ModifyName(baseWin, baseWin.Context, ref nameEntry)) {
AppHost.StdDialogs.ShowMessage("True!");
} else {
AppHost.StdDialogs.ShowMessage("False!");
}
}),
new LaunchItem("Test", "NameEditDlg (ASYNC)", async () => {
var baseWin = AppHost.Instance.GetCurrentFile() as BaseWinSDI;
var nameEntry = new NameEntry();
bool res = await BaseController.ModifyNameAsync(baseWin, baseWin.Context, nameEntry);
if (res) {
AppHost.StdDialogs.ShowMessage("True!");
} else {
AppHost.StdDialogs.ShowMessage("False!");
}
}),
new LaunchItem("Test", "PortraitSelectDlg", async () => {
var baseWin = AppHost.Instance.GetCurrentFile() as BaseWinSDI;
XFAppHost.GetMainPage().NavigateAsync(new PortraitSelectDlg(baseWin));
}),
};

var groups = launchItems.GroupBy(p => p.Group).Select(g => new Grouping<string, LaunchItem>(g.Key, g));
LaunchItems = new ObservableCollection<Grouping<string, LaunchItem>>(groups);
LaunchItems = PrepareItems(launchItems);

var servicesItems = new List<LaunchItem>() {
new LaunchItem("Pedigree", "Maps", async () => {
Expand Down Expand Up @@ -167,17 +180,23 @@ public LaunchPage()
}),
};

var services = servicesItems.GroupBy(p => p.Group).Select(g => new Grouping<string, LaunchItem>(g.Key, g));
ServiceItems = new ObservableCollection<Grouping<string, LaunchItem>>(services);
ServiceItems = PrepareItems(servicesItems);

BindingContext = this;
}

private async void lv_ItemSelected(object sender, SelectedItemChangedEventArgs e)
{
var item = e.SelectedItem as LaunchItem;
((ListView)sender).SelectedItem = null;
item?.Action?.Invoke();
}

private static ObservableCollection<Grouping<string, LaunchItem>> PrepareItems(List<LaunchItem> items)
{
var groups = items.GroupBy(p => p.Group).Select(g => new Grouping<string, LaunchItem>(g.Key, g));
return new ObservableCollection<Grouping<string, LaunchItem>>(groups);
}
}

public class Grouping<K, T> : ObservableCollection<T>
Expand Down
Loading

0 comments on commit 3d5bb8d

Please sign in to comment.