Skip to content

Commit

Permalink
Preparations for AboutDialog
Browse files Browse the repository at this point in the history
  • Loading branch information
RolandKoenig committed Dec 4, 2020
1 parent 478e1bd commit 082fa84
Show file tree
Hide file tree
Showing 10 changed files with 128 additions and 12 deletions.
4 changes: 4 additions & 0 deletions MessageCommunicator.TestGui/MainWindow.xaml
Original file line number Diff line number Diff line change
Expand Up @@ -63,6 +63,10 @@
<MenuItem Header="Light" PointerPressed="OnMnuThemeLight_PointerPressed" />
<MenuItem Header="Dark" PointerPressed="OnMnuThemeDark_PointerPressed" />
</MenuItem>
<MenuItem Header="Info"
Classes="MainMenu">
<MenuItem Header="About" Command="{Binding Path=Command_ShowAboutDialog}" />
</MenuItem>
</Menu>

<GridSplitter Grid.Column="1" Grid.Row="1"
Expand Down
1 change: 1 addition & 0 deletions MessageCommunicator.TestGui/MainWindow.xaml.cs
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,7 @@ public MainWindow()
this.ViewServices.Add(new ImportViewService(ctrlDialogHost));
this.ViewServices.Add(new SaveFileDialogService(this));
this.ViewServices.Add(new OpenFileDialogService(this));
this.ViewServices.Add(new AboutDialogService(ctrlDialogHost));

// Load initial main view model
this.ViewModel = new MainWindowViewModel();
Expand Down
29 changes: 19 additions & 10 deletions MessageCommunicator.TestGui/MainWindowViewModel.cs
Original file line number Diff line number Diff line change
Expand Up @@ -51,13 +51,16 @@ public ConnectionProfileViewModel? SelectedProfile

public ReactiveCommand<object?, Unit> Command_DeleteProfile { get; }

public ReactiveCommand<object?, Unit> Command_ShowAboutDialog { get; }

public MainWindowViewModel()
{
this.Command_ImportProfiles = ReactiveCommand.CreateFromTask<object?>(this.ImportProfilesAsync);
this.Command_ExportProfiles = ReactiveCommand.CreateFromTask<object?>(this.ExportProfilesAsync);
this.Command_CreateProfile = ReactiveCommand.CreateFromTask<object?>(this.CreateProfileAsync);
this.Command_EditProfile = ReactiveCommand.CreateFromTask<object?>(this.EditProfileAsync);
this.Command_DeleteProfile = ReactiveCommand.CreateFromTask<object?>(this.DeleteSelectedProfile);
this.Command_ImportProfiles = ReactiveCommand.CreateFromTask<object?>(this.OnCommand_ImportProfiles_ExecuteAsync);
this.Command_ExportProfiles = ReactiveCommand.CreateFromTask<object?>(this.OnCommand_ExportProfiles_ExecuteAsync);
this.Command_CreateProfile = ReactiveCommand.CreateFromTask<object?>(this.OnCommand_CreateProfile_ExecuteAsync);
this.Command_EditProfile = ReactiveCommand.CreateFromTask<object?>(this.OnCommand_EditProfile_ExecuteAsync);
this.Command_DeleteProfile = ReactiveCommand.CreateFromTask<object?>(this.OnCommand_DeleteProfile_ExecuteAsync);
this.Command_ShowAboutDialog = ReactiveCommand.CreateFromTask<object?>(this.OnCommand_ShowAboutDialog_ExecuteAsync);

this.SendMessageVM = new SendMessageViewModel();

Expand Down Expand Up @@ -97,7 +100,7 @@ protected override void OnActivated(CompositeDisposable disposables)
disposables.Add(new DummyDisposable(() => timer.Stop()));
}

private async Task ImportProfilesAsync(object? arg, CancellationToken cancelToken)
private async Task OnCommand_ImportProfiles_ExecuteAsync(object? arg, CancellationToken cancelToken)
{
var connectionProfiles = this.Profiles
.Select(actProfile => actProfile.Model.Parameters)
Expand Down Expand Up @@ -135,7 +138,7 @@ private async Task ImportProfilesAsync(object? arg, CancellationToken cancelToke
}
}

private async Task ExportProfilesAsync(object? arg, CancellationToken cancelToken)
private async Task OnCommand_ExportProfiles_ExecuteAsync(object? arg, CancellationToken cancelToken)
{
if (this.Profiles.Count == 0)
{
Expand All @@ -154,7 +157,7 @@ await srvExportDlg.ExportAsync(
Constants.DATA_TYPE_CONNECTION_PROFILES);
}

private async Task CreateProfileAsync(object? arg, CancellationToken cancelToken)
private async Task OnCommand_CreateProfile_ExecuteAsync(object? arg, CancellationToken cancelToken)
{
var srvConnectionConfig = this.GetViewService<IConnectionConfigViewService>();
var connParams = await srvConnectionConfig.ConfigureConnectionAsync(null);
Expand All @@ -171,7 +174,7 @@ private async Task CreateProfileAsync(object? arg, CancellationToken cancelToken
}
}

private async Task EditProfileAsync(object? arg, CancellationToken cancelToken)
private async Task OnCommand_EditProfile_ExecuteAsync(object? arg, CancellationToken cancelToken)
{
var selectedProfileVM = this.SelectedProfile;
if (selectedProfileVM == null) { return; }
Expand Down Expand Up @@ -200,7 +203,7 @@ private async Task EditProfileAsync(object? arg, CancellationToken cancelToken)
}
}

private async Task DeleteSelectedProfile(object? arg, CancellationToken cancelToken)
private async Task OnCommand_DeleteProfile_ExecuteAsync(object? arg, CancellationToken cancelToken)
{
var selectedProfile = this.SelectedProfile;
if (selectedProfile == null) { return; }
Expand All @@ -222,5 +225,11 @@ private async Task DeleteSelectedProfile(object? arg, CancellationToken cancelTo
ConnectionProfileStore.Current.StoreConnectionProfiles(
this.Profiles.Select(actProfileVM => actProfileVM.Model));
}

private Task OnCommand_ShowAboutDialog_ExecuteAsync(object? arg, CancellationToken cancelToken)
{
var srvAboutDlg = this.GetViewService<IAboutDialogService>();
return srvAboutDlg.ShowAboutDialogAsync();
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,7 @@
<None Remove="Assets\MessageCommunicator.ico" />
<None Remove="Assets\Styles\Common.xaml" />
<None Remove="MessageCommunicator.TestGui.csproj.DotSettings" />
<None Remove="ViewServices\_AboutDialog\AboutDialogControl.xaml" />
<None Remove="ViewServices\_ExportDialog\ExportDialogControl.xaml" />
<None Remove="ViewServices\_ImportDialog\ImportDialogControl.xaml" />
<None Remove="Views\_SendMessage\SendMessageView.xaml" />
Expand All @@ -60,6 +61,9 @@
<AvaloniaResource Update="Assets\Icons.xaml">
<Generator>MSBuild:Compile</Generator>
</AvaloniaResource>
<AvaloniaResource Update="ViewServices\_AboutDialog\AboutDialogControl.xaml">
<Generator>MSBuild:Compile</Generator>
</AvaloniaResource>
<AvaloniaResource Update="ViewServices\_ExportDialog\ExportDialogControl.xaml">
<Generator>MSBuild:Compile</Generator>
</AvaloniaResource>
Expand All @@ -71,6 +75,9 @@
</AvaloniaResource>
</ItemGroup>
<ItemGroup>
<Compile Update="ViewServices\_AboutDialog\AboutDialogControl.xaml.cs">
<DependentUpon>%(Filename)</DependentUpon>
</Compile>
<Compile Update="ViewServices\_ExportDialog\ExportDialogControl.xaml.cs">
<DependentUpon>%(Filename)</DependentUpon>
</Compile>
Expand Down
3 changes: 3 additions & 0 deletions MessageCommunicator.TestGui/MessageCommunicator.TestGui.xml

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

12 changes: 12 additions & 0 deletions MessageCommunicator.TestGui/ViewServices/IAboutDialogService.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
using System;
using System.Collections.Generic;
using System.Text;
using System.Threading.Tasks;

namespace MessageCommunicator.TestGui.ViewServices
{
public interface IAboutDialogService : IViewService
{
Task ShowAboutDialogAsync();
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
<UserControl xmlns="https://github.com/avaloniaui"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
xmlns:d="http://schemas.microsoft.com/expression/blend/2008"
xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
xmlns:local="clr-namespace:MessageCommunicator.TestGui.ViewServices;assembly=MessageCommunicator.TestGui"
xmlns:localRoot="clr-namespace:MessageCommunicator.TestGui;assembly=MessageCommunicator.TestGui"
mc:Ignorable="d"
Width="610" Height="400"
x:Class="MessageCommunicator.TestGui.ViewServices.AboutDialogControl">

<Grid>
<TextBox>About ;)</TextBox>
</Grid>
</UserControl>
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
using System;
using System.ComponentModel;
using System.Reactive.Disposables;
using System.Runtime.InteropServices.ComTypes;
using System.Threading.Tasks;
using Avalonia;
using Avalonia.Controls;
using Avalonia.Markup.Xaml;
using Avalonia.Threading;

namespace MessageCommunicator.TestGui.ViewServices
{
public class AboutDialogControl : OwnUserControlDialog<OwnViewModelBase>
{
public AboutDialogControl()
{
AvaloniaXamlLoader.Load(this);
}
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
using System;
using System.Collections.Generic;
using System.Text;
using System.Threading.Tasks;

namespace MessageCommunicator.TestGui.ViewServices
{
public class AboutDialogService : ViewServiceBase, IAboutDialogService
{
private DialogHostControl _host;

public AboutDialogService(DialogHostControl host)
{
_host = host;
}

/// <inheritdoc />
public Task ShowAboutDialogAsync()
{
var aboutDialogControl = new AboutDialogControl();
return _host.ShowDialogAsync(aboutDialogControl, "About");
}
}
}
26 changes: 24 additions & 2 deletions MessageCommunicator.TestGui/_Util/_View/DialogHostControl.cs
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
using System;
using System.Collections.Generic;
using System.Text;
using System.Threading.Tasks;
using Avalonia;
using Avalonia.Controls;
using Avalonia.Controls.Primitives;
Expand Down Expand Up @@ -37,6 +38,11 @@ public DialogHostControl()
}

public void ShowDialog(Control controlToShow, string headerText)
{
this.ShowDialogAsync(controlToShow, headerText);
}

public Task ShowDialogAsync(Control controlToShow, string headerText)
{
var currentChild = controlToShow;
var currentChildInitialSize = new Size(currentChild.Width, currentChild.Height);
Expand All @@ -55,7 +61,11 @@ public void ShowDialog(Control controlToShow, string headerText)
var currentBackground = new Grid();
currentBackground.Background = _backgroundDialog;

_children.Push(new ChildInfo(currentChild, currentChildBorder, currentChildInitialSize, currentBackground));
var taskComplSource = new TaskCompletionSource<object?>();
_children.Push(new ChildInfo(
currentChild, currentChildBorder,
currentChildInitialSize, currentBackground,
taskComplSource));

this.Children.Add(currentBackground);
this.Children.Add(borderControl);
Expand All @@ -67,6 +77,8 @@ public void ShowDialog(Control controlToShow, string headerText)
}

this.UpdateBorderSize();

return taskComplSource.Task;
}

public void CloseDialog()
Expand All @@ -77,6 +89,7 @@ public void CloseDialog()
}
this.Children.Remove(removedChild.ChildBorder);
this.Children.Remove(removedChild.ChildBackground);
removedChild.TaskComplSource.TrySetResult(null);

if (_children.Count == 0)
{
Expand Down Expand Up @@ -156,12 +169,21 @@ public Size InitialSize
get;
}

internal ChildInfo(Control child, Control childBorder, Size initialSize, Grid childBackground)
public TaskCompletionSource<object?> TaskComplSource
{
get;
}

internal ChildInfo(
Control child, Control childBorder,
Size initialSize, Grid childBackground,
TaskCompletionSource<object?> taskComplSource)
{
this.Child = child;
this.ChildBorder = childBorder;
this.InitialSize = initialSize;
this.ChildBackground = childBackground;
this.TaskComplSource = taskComplSource;
}
}
}
Expand Down

0 comments on commit 082fa84

Please sign in to comment.