Skip to content

Commit 01d0a0e

Browse files
committed
Removed the messagebox dependency and a lot of warnings with it
1 parent 9d45e87 commit 01d0a0e

File tree

4 files changed

+192
-36
lines changed

4 files changed

+192
-36
lines changed

.gitignore

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
.claude/settings.local.json

Source/VisualPairCoding/VisualPairCoding.AvaloniaUI/EnterNamesWindow.axaml.cs

Lines changed: 35 additions & 35 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
using Avalonia;
22
using Avalonia.Controls;
33
using Avalonia.Interactivity;
4+
using Avalonia.Platform.Storage;
45
using System;
56
using System.Collections.Generic;
67
using System.Threading.Tasks;
@@ -136,8 +137,7 @@ public async void StartForm(object? sender, RoutedEventArgs args)
136137

137138
if (!string.IsNullOrWhiteSpace(validationMessage))
138139
{
139-
var messageBoxStandardWindow = MessageBox.Avalonia.MessageBoxManager.GetMessageBoxStandardWindow("Error", validationMessage, MessageBox.Avalonia.Enums.ButtonEnum.Ok, MessageBox.Avalonia.Enums.Icon.Error, WindowStartupLocation.CenterScreen);
140-
messageBoxStandardWindow?.Show();
140+
await MessageBoxHelper.ShowError(this, "Error", validationMessage);
141141
return;
142142
}
143143

@@ -166,7 +166,7 @@ public async void StartForm(object? sender, RoutedEventArgs args)
166166
Show();
167167
}
168168

169-
private void LoadSessionIntoGui(string fileName)
169+
private async void LoadSessionIntoGui(string fileName)
170170
{
171171
try
172172
{
@@ -176,8 +176,7 @@ private void LoadSessionIntoGui(string fileName)
176176
}
177177
catch (Exception ex)
178178
{
179-
var messageBoxStandardWindow = MessageBox.Avalonia.MessageBoxManager.GetMessageBoxStandardWindow("Loading Error", "Error Loading configuration File: " + ex.Message, MessageBox.Avalonia.Enums.ButtonEnum.Ok, MessageBox.Avalonia.Enums.Icon.Error, WindowStartupLocation.CenterScreen);
180-
messageBoxStandardWindow.Show();
179+
await MessageBoxHelper.ShowError(this, "Loading Error", "Error Loading configuration File: " + ex.Message);
181180
}
182181
}
183182

@@ -275,61 +274,62 @@ private string[] GetParticipants()
275274

276275
public async void LoadSessionConfiguration(object? sender, RoutedEventArgs args)
277276
{
278-
OpenFileDialog openFileDialog = new()
277+
var fileTypes = new List<FilePickerFileType>
279278
{
280-
Title = "Open VPC Session",
281-
Filters = new List<FileDialogFilter>
279+
new("VPC Session")
282280
{
283-
new()
284-
{
285-
Name = "VPC Session",
286-
Extensions = new List<string> { "vpcsession" }
287-
},
288-
new()
289-
{
290-
Name = "All Files",
291-
Extensions = new List<string> { "*" }
292-
}
293-
281+
Patterns = new[] { "*.vpcsession" }
294282
},
295-
AllowMultiple = false
283+
FilePickerFileTypes.All
296284
};
297285

298-
var result = await openFileDialog.ShowAsync(this);
286+
var files = await StorageProvider.OpenFilePickerAsync(new FilePickerOpenOptions
287+
{
288+
Title = "Open VPC Session",
289+
FileTypeFilter = fileTypes,
290+
AllowMultiple = false
291+
});
299292

300-
if (result?.Length > 0)
293+
if (files.Count > 0)
301294
{
302-
LoadSessionIntoGui(result[0]);
295+
LoadSessionIntoGui(files[0].Path.LocalPath);
303296
}
304297
}
305298
public async void SaveSessionConfiguration(object? sender, RoutedEventArgs args)
306299
{
307300
var participants = GetParticipants();
308301

309-
SaveFileDialog saveFileDialog = new();
310-
saveFileDialog.Filters?.Add(new FileDialogFilter { Name = "VPC Session", Extensions = { "vpcsession" } });
311-
saveFileDialog.InitialFileName = string.Join("_", participants);
302+
var fileTypes = new List<FilePickerFileType>
303+
{
304+
new("VPC Session")
305+
{
306+
Patterns = new[] { "*.vpcsession" }
307+
}
308+
};
312309

313-
var result = await saveFileDialog.ShowAsync(this);
310+
var file = await StorageProvider.SaveFilePickerAsync(new FilePickerSaveOptions
311+
{
312+
Title = "Save VPC Session",
313+
FileTypeChoices = fileTypes,
314+
SuggestedFileName = string.Join("_", participants),
315+
DefaultExtension = "vpcsession"
316+
});
314317

315-
if (!string.IsNullOrWhiteSpace(result))
318+
if (file != null)
316319
{
317320
try
318321
{
319-
SessionConfigurationFileHandler.Save(result, new SessionConfiguration(participants, (int)minutesPerTurn.Value));
320-
var messageBoxStandardWindow = MessageBox.Avalonia.MessageBoxManager.GetMessageBoxStandardWindow("Config Saved", "Session Configuration saved successfully!", MessageBox.Avalonia.Enums.ButtonEnum.Ok, MessageBox.Avalonia.Enums.Icon.Success, WindowStartupLocation.CenterScreen);
321-
messageBoxStandardWindow?.Show();
322+
SessionConfigurationFileHandler.Save(file.Path.LocalPath, new SessionConfiguration(participants, (int)minutesPerTurn.Value));
323+
await MessageBoxHelper.ShowInfo(this, "Config Saved", "Session Configuration saved successfully!");
322324
}
323325
catch (Exception ex)
324326
{
325-
var messageBoxStandardWindow = MessageBox.Avalonia.MessageBoxManager.GetMessageBoxStandardWindow("Error Saving Config", "Error saving configuration File: " + ex.Message, MessageBox.Avalonia.Enums.ButtonEnum.Ok, MessageBox.Avalonia.Enums.Icon.Error, WindowStartupLocation.CenterScreen);
326-
messageBoxStandardWindow?.Show();
327+
await MessageBoxHelper.ShowError(this, "Error Saving Config", "Error saving configuration File: " + ex.Message);
327328
}
328329
}
329330
else
330331
{
331-
var messageBoxStandardWindow = MessageBox.Avalonia.MessageBoxManager.GetMessageBoxStandardWindow("Error Saving Config", "Could not save Configuration File ", MessageBox.Avalonia.Enums.ButtonEnum.Ok, MessageBox.Avalonia.Enums.Icon.Error, WindowStartupLocation.CenterScreen);
332-
messageBoxStandardWindow?.Show();
332+
await MessageBoxHelper.ShowError(this, "Error Saving Config", "Could not save Configuration File");
333333

334334
}
335335
}
Lines changed: 156 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,156 @@
1+
using Avalonia.Controls;
2+
using Avalonia.Media;
3+
using Avalonia.Layout;
4+
using System.Threading.Tasks;
5+
6+
namespace VisualPairCoding.AvaloniaUI
7+
{
8+
public static class MessageBoxHelper
9+
{
10+
private static async Task<bool> ShowDialog(Window owner, string title, string message, bool isError)
11+
{
12+
var dialog = new Window
13+
{
14+
Title = title,
15+
Width = 420,
16+
Height = 220,
17+
WindowStartupLocation = WindowStartupLocation.CenterOwner,
18+
CanResize = false,
19+
ShowInTaskbar = false,
20+
SystemDecorations = SystemDecorations.BorderOnly,
21+
ExtendClientAreaToDecorationsHint = true,
22+
ExtendClientAreaTitleBarHeightHint = -1,
23+
Background = new SolidColorBrush(Color.FromRgb(245, 245, 245))
24+
};
25+
26+
// Main container with border
27+
var border = new Border
28+
{
29+
BorderBrush = new SolidColorBrush(isError ? Color.FromRgb(220, 53, 69) : Color.FromRgb(40, 167, 69)),
30+
BorderThickness = new Avalonia.Thickness(0, 3, 0, 0),
31+
Background = Brushes.White,
32+
CornerRadius = new Avalonia.CornerRadius(0)
33+
};
34+
35+
var mainPanel = new DockPanel
36+
{
37+
LastChildFill = true
38+
};
39+
40+
// Title bar
41+
var titlePanel = new Border
42+
{
43+
Background = new SolidColorBrush(Color.FromRgb(240, 240, 240)),
44+
Height = 40,
45+
[DockPanel.DockProperty] = Dock.Top
46+
};
47+
48+
var titleText = new TextBlock
49+
{
50+
Text = title,
51+
FontSize = 14,
52+
FontWeight = FontWeight.SemiBold,
53+
VerticalAlignment = VerticalAlignment.Center,
54+
Margin = new Avalonia.Thickness(15, 0, 0, 0)
55+
};
56+
57+
titlePanel.Child = titleText;
58+
mainPanel.Children.Add(titlePanel);
59+
60+
// Content area
61+
var contentPanel = new Grid
62+
{
63+
Margin = new Avalonia.Thickness(25, 20, 25, 20),
64+
RowDefinitions = new RowDefinitions("*, Auto")
65+
};
66+
67+
// Icon and message panel
68+
var messagePanel = new DockPanel
69+
{
70+
[Grid.RowProperty] = 0,
71+
Margin = new Avalonia.Thickness(0, 0, 0, 20)
72+
};
73+
74+
// Icon
75+
var iconBorder = new Border
76+
{
77+
Width = 48,
78+
Height = 48,
79+
CornerRadius = new Avalonia.CornerRadius(24),
80+
Background = new SolidColorBrush(isError ? Color.FromRgb(255, 235, 238) : Color.FromRgb(232, 246, 234)),
81+
[DockPanel.DockProperty] = Dock.Left,
82+
Margin = new Avalonia.Thickness(0, 0, 15, 0)
83+
};
84+
85+
var iconText = new TextBlock
86+
{
87+
Text = isError ? "!" : "✓",
88+
FontSize = 24,
89+
FontWeight = FontWeight.Bold,
90+
Foreground = new SolidColorBrush(isError ? Color.FromRgb(220, 53, 69) : Color.FromRgb(40, 167, 69)),
91+
HorizontalAlignment = HorizontalAlignment.Center,
92+
VerticalAlignment = VerticalAlignment.Center
93+
};
94+
95+
iconBorder.Child = iconText;
96+
messagePanel.Children.Add(iconBorder);
97+
98+
// Message text
99+
var messageText = new TextBlock
100+
{
101+
Text = message,
102+
TextWrapping = TextWrapping.Wrap,
103+
FontSize = 13,
104+
VerticalAlignment = VerticalAlignment.Center,
105+
LineHeight = 20
106+
};
107+
108+
messagePanel.Children.Add(messageText);
109+
contentPanel.Children.Add(messagePanel);
110+
111+
// Button panel
112+
var buttonPanel = new StackPanel
113+
{
114+
Orientation = Orientation.Horizontal,
115+
HorizontalAlignment = HorizontalAlignment.Right,
116+
[Grid.RowProperty] = 1
117+
};
118+
119+
var button = new Button
120+
{
121+
Content = "OK",
122+
Width = 90,
123+
Height = 32,
124+
HorizontalContentAlignment = HorizontalAlignment.Center,
125+
VerticalContentAlignment = VerticalAlignment.Center,
126+
Background = new SolidColorBrush(isError ? Color.FromRgb(220, 53, 69) : Color.FromRgb(40, 167, 69)),
127+
Foreground = Brushes.White,
128+
FontWeight = FontWeight.Medium,
129+
CornerRadius = new Avalonia.CornerRadius(4)
130+
};
131+
132+
button.Classes.Add("primary");
133+
button.Click += (s, e) => dialog.Close();
134+
135+
buttonPanel.Children.Add(button);
136+
contentPanel.Children.Add(buttonPanel);
137+
138+
mainPanel.Children.Add(contentPanel);
139+
border.Child = mainPanel;
140+
dialog.Content = border;
141+
142+
await dialog.ShowDialog(owner);
143+
return true;
144+
}
145+
146+
public static async Task<bool> ShowError(Window owner, string title, string message)
147+
{
148+
return await ShowDialog(owner, title, message, true);
149+
}
150+
151+
public static async Task<bool> ShowInfo(Window owner, string title, string message)
152+
{
153+
return await ShowDialog(owner, title, message, false);
154+
}
155+
}
156+
}

Source/VisualPairCoding/VisualPairCoding.AvaloniaUI/VisualPairCoding.AvaloniaUI.csproj

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,6 @@
2828
<!--Condition below is needed to remove Avalonia.Diagnostics package from build output in Release configuration.-->
2929
<PackageReference Condition="'$(Configuration)' == 'Debug'" Include="Avalonia.Diagnostics" Version="11.3.0" />
3030
<PackageReference Include="Avalonia.Themes.Fluent" Version="11.3.0" />
31-
<PackageReference Include="MessageBox.Avalonia-mainthread" Version="2.0.1" />
3231
</ItemGroup>
3332
<ItemGroup>
3433
<!--<ProjectReference Include="..\VisualPairCoding.BL.Tests\VisualPairCoding.BL.Tests.csproj" />-->

0 commit comments

Comments
 (0)