Skip to content

Commit 082fa84

Browse files
committed
Preparations for AboutDialog
1 parent 478e1bd commit 082fa84

10 files changed

Lines changed: 128 additions & 12 deletions

MessageCommunicator.TestGui/MainWindow.xaml

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -63,6 +63,10 @@
6363
<MenuItem Header="Light" PointerPressed="OnMnuThemeLight_PointerPressed" />
6464
<MenuItem Header="Dark" PointerPressed="OnMnuThemeDark_PointerPressed" />
6565
</MenuItem>
66+
<MenuItem Header="Info"
67+
Classes="MainMenu">
68+
<MenuItem Header="About" Command="{Binding Path=Command_ShowAboutDialog}" />
69+
</MenuItem>
6670
</Menu>
6771

6872
<GridSplitter Grid.Column="1" Grid.Row="1"

MessageCommunicator.TestGui/MainWindow.xaml.cs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -30,6 +30,7 @@ public MainWindow()
3030
this.ViewServices.Add(new ImportViewService(ctrlDialogHost));
3131
this.ViewServices.Add(new SaveFileDialogService(this));
3232
this.ViewServices.Add(new OpenFileDialogService(this));
33+
this.ViewServices.Add(new AboutDialogService(ctrlDialogHost));
3334

3435
// Load initial main view model
3536
this.ViewModel = new MainWindowViewModel();

MessageCommunicator.TestGui/MainWindowViewModel.cs

Lines changed: 19 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -51,13 +51,16 @@ public ConnectionProfileViewModel? SelectedProfile
5151

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

54+
public ReactiveCommand<object?, Unit> Command_ShowAboutDialog { get; }
55+
5456
public MainWindowViewModel()
5557
{
56-
this.Command_ImportProfiles = ReactiveCommand.CreateFromTask<object?>(this.ImportProfilesAsync);
57-
this.Command_ExportProfiles = ReactiveCommand.CreateFromTask<object?>(this.ExportProfilesAsync);
58-
this.Command_CreateProfile = ReactiveCommand.CreateFromTask<object?>(this.CreateProfileAsync);
59-
this.Command_EditProfile = ReactiveCommand.CreateFromTask<object?>(this.EditProfileAsync);
60-
this.Command_DeleteProfile = ReactiveCommand.CreateFromTask<object?>(this.DeleteSelectedProfile);
58+
this.Command_ImportProfiles = ReactiveCommand.CreateFromTask<object?>(this.OnCommand_ImportProfiles_ExecuteAsync);
59+
this.Command_ExportProfiles = ReactiveCommand.CreateFromTask<object?>(this.OnCommand_ExportProfiles_ExecuteAsync);
60+
this.Command_CreateProfile = ReactiveCommand.CreateFromTask<object?>(this.OnCommand_CreateProfile_ExecuteAsync);
61+
this.Command_EditProfile = ReactiveCommand.CreateFromTask<object?>(this.OnCommand_EditProfile_ExecuteAsync);
62+
this.Command_DeleteProfile = ReactiveCommand.CreateFromTask<object?>(this.OnCommand_DeleteProfile_ExecuteAsync);
63+
this.Command_ShowAboutDialog = ReactiveCommand.CreateFromTask<object?>(this.OnCommand_ShowAboutDialog_ExecuteAsync);
6164

6265
this.SendMessageVM = new SendMessageViewModel();
6366

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

100-
private async Task ImportProfilesAsync(object? arg, CancellationToken cancelToken)
103+
private async Task OnCommand_ImportProfiles_ExecuteAsync(object? arg, CancellationToken cancelToken)
101104
{
102105
var connectionProfiles = this.Profiles
103106
.Select(actProfile => actProfile.Model.Parameters)
@@ -135,7 +138,7 @@ private async Task ImportProfilesAsync(object? arg, CancellationToken cancelToke
135138
}
136139
}
137140

138-
private async Task ExportProfilesAsync(object? arg, CancellationToken cancelToken)
141+
private async Task OnCommand_ExportProfiles_ExecuteAsync(object? arg, CancellationToken cancelToken)
139142
{
140143
if (this.Profiles.Count == 0)
141144
{
@@ -154,7 +157,7 @@ await srvExportDlg.ExportAsync(
154157
Constants.DATA_TYPE_CONNECTION_PROFILES);
155158
}
156159

157-
private async Task CreateProfileAsync(object? arg, CancellationToken cancelToken)
160+
private async Task OnCommand_CreateProfile_ExecuteAsync(object? arg, CancellationToken cancelToken)
158161
{
159162
var srvConnectionConfig = this.GetViewService<IConnectionConfigViewService>();
160163
var connParams = await srvConnectionConfig.ConfigureConnectionAsync(null);
@@ -171,7 +174,7 @@ private async Task CreateProfileAsync(object? arg, CancellationToken cancelToken
171174
}
172175
}
173176

174-
private async Task EditProfileAsync(object? arg, CancellationToken cancelToken)
177+
private async Task OnCommand_EditProfile_ExecuteAsync(object? arg, CancellationToken cancelToken)
175178
{
176179
var selectedProfileVM = this.SelectedProfile;
177180
if (selectedProfileVM == null) { return; }
@@ -200,7 +203,7 @@ private async Task EditProfileAsync(object? arg, CancellationToken cancelToken)
200203
}
201204
}
202205

203-
private async Task DeleteSelectedProfile(object? arg, CancellationToken cancelToken)
206+
private async Task OnCommand_DeleteProfile_ExecuteAsync(object? arg, CancellationToken cancelToken)
204207
{
205208
var selectedProfile = this.SelectedProfile;
206209
if (selectedProfile == null) { return; }
@@ -222,5 +225,11 @@ private async Task DeleteSelectedProfile(object? arg, CancellationToken cancelTo
222225
ConnectionProfileStore.Current.StoreConnectionProfiles(
223226
this.Profiles.Select(actProfileVM => actProfileVM.Model));
224227
}
228+
229+
private Task OnCommand_ShowAboutDialog_ExecuteAsync(object? arg, CancellationToken cancelToken)
230+
{
231+
var srvAboutDlg = this.GetViewService<IAboutDialogService>();
232+
return srvAboutDlg.ShowAboutDialogAsync();
233+
}
225234
}
226235
}

MessageCommunicator.TestGui/MessageCommunicator.TestGui.csproj

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -43,6 +43,7 @@
4343
<None Remove="Assets\MessageCommunicator.ico" />
4444
<None Remove="Assets\Styles\Common.xaml" />
4545
<None Remove="MessageCommunicator.TestGui.csproj.DotSettings" />
46+
<None Remove="ViewServices\_AboutDialog\AboutDialogControl.xaml" />
4647
<None Remove="ViewServices\_ExportDialog\ExportDialogControl.xaml" />
4748
<None Remove="ViewServices\_ImportDialog\ImportDialogControl.xaml" />
4849
<None Remove="Views\_SendMessage\SendMessageView.xaml" />
@@ -60,6 +61,9 @@
6061
<AvaloniaResource Update="Assets\Icons.xaml">
6162
<Generator>MSBuild:Compile</Generator>
6263
</AvaloniaResource>
64+
<AvaloniaResource Update="ViewServices\_AboutDialog\AboutDialogControl.xaml">
65+
<Generator>MSBuild:Compile</Generator>
66+
</AvaloniaResource>
6367
<AvaloniaResource Update="ViewServices\_ExportDialog\ExportDialogControl.xaml">
6468
<Generator>MSBuild:Compile</Generator>
6569
</AvaloniaResource>
@@ -71,6 +75,9 @@
7175
</AvaloniaResource>
7276
</ItemGroup>
7377
<ItemGroup>
78+
<Compile Update="ViewServices\_AboutDialog\AboutDialogControl.xaml.cs">
79+
<DependentUpon>%(Filename)</DependentUpon>
80+
</Compile>
7481
<Compile Update="ViewServices\_ExportDialog\ExportDialogControl.xaml.cs">
7582
<DependentUpon>%(Filename)</DependentUpon>
7683
</Compile>

MessageCommunicator.TestGui/MessageCommunicator.TestGui.xml

Lines changed: 3 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.
Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
using System;
2+
using System.Collections.Generic;
3+
using System.Text;
4+
using System.Threading.Tasks;
5+
6+
namespace MessageCommunicator.TestGui.ViewServices
7+
{
8+
public interface IAboutDialogService : IViewService
9+
{
10+
Task ShowAboutDialogAsync();
11+
}
12+
}
Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
<UserControl xmlns="https://github.com/avaloniaui"
2+
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
3+
xmlns:d="http://schemas.microsoft.com/expression/blend/2008"
4+
xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
5+
xmlns:local="clr-namespace:MessageCommunicator.TestGui.ViewServices;assembly=MessageCommunicator.TestGui"
6+
xmlns:localRoot="clr-namespace:MessageCommunicator.TestGui;assembly=MessageCommunicator.TestGui"
7+
mc:Ignorable="d"
8+
Width="610" Height="400"
9+
x:Class="MessageCommunicator.TestGui.ViewServices.AboutDialogControl">
10+
11+
<Grid>
12+
<TextBox>About ;)</TextBox>
13+
</Grid>
14+
</UserControl>
Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
using System;
2+
using System.ComponentModel;
3+
using System.Reactive.Disposables;
4+
using System.Runtime.InteropServices.ComTypes;
5+
using System.Threading.Tasks;
6+
using Avalonia;
7+
using Avalonia.Controls;
8+
using Avalonia.Markup.Xaml;
9+
using Avalonia.Threading;
10+
11+
namespace MessageCommunicator.TestGui.ViewServices
12+
{
13+
public class AboutDialogControl : OwnUserControlDialog<OwnViewModelBase>
14+
{
15+
public AboutDialogControl()
16+
{
17+
AvaloniaXamlLoader.Load(this);
18+
}
19+
}
20+
}
Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,24 @@
1+
using System;
2+
using System.Collections.Generic;
3+
using System.Text;
4+
using System.Threading.Tasks;
5+
6+
namespace MessageCommunicator.TestGui.ViewServices
7+
{
8+
public class AboutDialogService : ViewServiceBase, IAboutDialogService
9+
{
10+
private DialogHostControl _host;
11+
12+
public AboutDialogService(DialogHostControl host)
13+
{
14+
_host = host;
15+
}
16+
17+
/// <inheritdoc />
18+
public Task ShowAboutDialogAsync()
19+
{
20+
var aboutDialogControl = new AboutDialogControl();
21+
return _host.ShowDialogAsync(aboutDialogControl, "About");
22+
}
23+
}
24+
}

MessageCommunicator.TestGui/_Util/_View/DialogHostControl.cs

Lines changed: 24 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
using System;
22
using System.Collections.Generic;
33
using System.Text;
4+
using System.Threading.Tasks;
45
using Avalonia;
56
using Avalonia.Controls;
67
using Avalonia.Controls.Primitives;
@@ -37,6 +38,11 @@ public DialogHostControl()
3738
}
3839

3940
public void ShowDialog(Control controlToShow, string headerText)
41+
{
42+
this.ShowDialogAsync(controlToShow, headerText);
43+
}
44+
45+
public Task ShowDialogAsync(Control controlToShow, string headerText)
4046
{
4147
var currentChild = controlToShow;
4248
var currentChildInitialSize = new Size(currentChild.Width, currentChild.Height);
@@ -55,7 +61,11 @@ public void ShowDialog(Control controlToShow, string headerText)
5561
var currentBackground = new Grid();
5662
currentBackground.Background = _backgroundDialog;
5763

58-
_children.Push(new ChildInfo(currentChild, currentChildBorder, currentChildInitialSize, currentBackground));
64+
var taskComplSource = new TaskCompletionSource<object?>();
65+
_children.Push(new ChildInfo(
66+
currentChild, currentChildBorder,
67+
currentChildInitialSize, currentBackground,
68+
taskComplSource));
5969

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

6979
this.UpdateBorderSize();
80+
81+
return taskComplSource.Task;
7082
}
7183

7284
public void CloseDialog()
@@ -77,6 +89,7 @@ public void CloseDialog()
7789
}
7890
this.Children.Remove(removedChild.ChildBorder);
7991
this.Children.Remove(removedChild.ChildBackground);
92+
removedChild.TaskComplSource.TrySetResult(null);
8093

8194
if (_children.Count == 0)
8295
{
@@ -156,12 +169,21 @@ public Size InitialSize
156169
get;
157170
}
158171

159-
internal ChildInfo(Control child, Control childBorder, Size initialSize, Grid childBackground)
172+
public TaskCompletionSource<object?> TaskComplSource
173+
{
174+
get;
175+
}
176+
177+
internal ChildInfo(
178+
Control child, Control childBorder,
179+
Size initialSize, Grid childBackground,
180+
TaskCompletionSource<object?> taskComplSource)
160181
{
161182
this.Child = child;
162183
this.ChildBorder = childBorder;
163184
this.InitialSize = initialSize;
164185
this.ChildBackground = childBackground;
186+
this.TaskComplSource = taskComplSource;
165187
}
166188
}
167189
}

0 commit comments

Comments
 (0)