Skip to content

Commit 61f9636

Browse files
committed
Feature: Migrate more dialogs
1 parent 627cc0b commit 61f9636

File tree

7 files changed

+24
-37
lines changed

7 files changed

+24
-37
lines changed

Source/NETworkManager.Utilities/VisualTreeHelper.cs

Lines changed: 18 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,8 +3,25 @@
33

44
namespace NETworkManager.Utilities;
55

6+
/// <summary>
7+
/// Provides helper methods for traversing and querying the visual tree of WPF elements.
8+
/// </summary>
9+
/// <remarks>The VisualTreeHelper class contains static methods that facilitate searching for and enumerating
10+
/// visual child elements within a WPF application's visual tree. These methods are useful for scenarios where you need
11+
/// to locate elements of a specific type or perform operations on all descendants of a visual element.</remarks>
612
public class VisualTreeHelper
713
{
14+
/// <summary>
15+
/// Enumerates all descendant visual children of a specified type from the visual tree starting at the given
16+
/// dependency object.
17+
/// </summary>
18+
/// <remarks>This method performs a recursive depth-first traversal of the visual tree. It yields each
19+
/// descendant of the specified type, including those nested at any depth. The enumeration is deferred and elements
20+
/// are returned as they are discovered.</remarks>
21+
/// <typeparam name="T">The type of visual child to search for. Must derive from DependencyObject.</typeparam>
22+
/// <param name="depObj">The root of the visual tree to search. Cannot be null.</param>
23+
/// <returns>An enumerable collection of all descendant elements of type T found in the visual tree. The collection is empty
24+
/// if no matching elements are found.</returns>
825
public static IEnumerable<T> FindVisualChildren<T>(DependencyObject depObj) where T : DependencyObject
926
{
1027
if (depObj == null)
@@ -19,4 +36,4 @@ public static IEnumerable<T> FindVisualChildren<T>(DependencyObject depObj) wher
1936
foreach (var childOfChild in FindVisualChildren<T>(child)) yield return childOfChild;
2037
}
2138
}
22-
}
39+
}

Source/NETworkManager/Controls/PowerShellControl.xaml.cs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -191,8 +191,8 @@ private async Task Connect()
191191
catch (Exception ex)
192192
{
193193
if (!_closed)
194-
// ToDo: target the correct window
195-
await DialogHelper.ShowMessageAsync(Application.Current.MainWindow, Strings.Error, ex.Message, ChildWindowIcon.Error);
194+
// Use built-in message box because we have visual issues in the dragablz window
195+
MessageBox.Show(ex.Message, Strings.Error, MessageBoxButton.OK, MessageBoxImage.Error);
196196
}
197197

198198
IsConnecting = false;

Source/NETworkManager/Controls/PuTTYControl.xaml

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,6 @@
99
xmlns:local="clr-namespace:NETworkManager.Controls"
1010
xmlns:mah="http://metro.mahapps.com/winfx/xaml/controls"
1111
xmlns:settings="clr-namespace:NETworkManager.Settings;assembly=NETworkManager.Settings"
12-
mah:DialogParticipation.Register="{Binding}"
1312
mc:Ignorable="d" Loaded="UserControl_Loaded"
1413
d:DataContext="{d:DesignInstance local:PuTTYControl}">
1514
<local:UserControlBase.Resources>

Source/NETworkManager/Controls/PuTTYControl.xaml.cs

Lines changed: 2 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,6 @@
55
using System.Threading.Tasks;
66
using System.Windows;
77
using System.Windows.Input;
8-
using MahApps.Metro.Controls.Dialogs;
98
using NETworkManager.Localization.Resources;
109
using NETworkManager.Models.PuTTY;
1110
using NETworkManager.Settings;
@@ -30,8 +29,6 @@ private void WindowGrid_SizeChanged(object sender, SizeChangedEventArgs e)
3029
private bool _initialized;
3130
private bool _closed;
3231

33-
private readonly IDialogCoordinator _dialogCoordinator;
34-
3532
private readonly Guid _tabId;
3633
private readonly PuTTYSessionInfo _sessionInfo;
3734

@@ -77,8 +74,6 @@ public PuTTYControl(Guid tabId, PuTTYSessionInfo sessionInfo)
7774
InitializeComponent();
7875
DataContext = this;
7976

80-
_dialogCoordinator = DialogCoordinator.Instance;
81-
8277
ConfigurationManager.Current.PuTTYTabCount++;
8378

8479
_tabId = tabId;
@@ -213,17 +208,8 @@ private async Task Connect()
213208
catch (Exception ex)
214209
{
215210
if (!_closed)
216-
{
217-
var settings = AppearanceManager.MetroDialog;
218-
settings.AffirmativeButtonText = Strings.OK;
219-
220-
ConfigurationManager.OnDialogOpen();
221-
222-
await _dialogCoordinator.ShowMessageAsync(this, Strings.Error,
223-
ex.Message, MessageDialogStyle.Affirmative, settings);
224-
225-
ConfigurationManager.OnDialogClose();
226-
}
211+
// Use built-in message box because we have visual issues in the dragablz window
212+
MessageBox.Show(ex.Message, Strings.Error, MessageBoxButton.OK, MessageBoxImage.Error);
227213
}
228214

229215
IsConnecting = false;

Source/NETworkManager/Controls/TigerVNCControl.xaml

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,6 @@
99
xmlns:local="clr-namespace:NETworkManager.Controls"
1010
xmlns:mah="http://metro.mahapps.com/winfx/xaml/controls"
1111
xmlns:settings="clr-namespace:NETworkManager.Settings;assembly=NETworkManager.Settings"
12-
mah:DialogParticipation.Register="{Binding}"
1312
mc:Ignorable="d" Loaded="UserControl_Loaded"
1413
d:DataContext="{d:DesignInstance local:TigerVNCControl}">
1514
<local:UserControlBase.Resources>

Source/NETworkManager/Controls/TigerVNCControl.xaml.cs

Lines changed: 2 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,6 @@
55
using System.Threading.Tasks;
66
using System.Windows;
77
using System.Windows.Input;
8-
using MahApps.Metro.Controls.Dialogs;
98
using NETworkManager.Localization.Resources;
109
using NETworkManager.Models.TigerVNC;
1110
using NETworkManager.Settings;
@@ -29,8 +28,6 @@ private void TigerVNCGrid_SizeChanged(object sender, SizeChangedEventArgs e)
2928
private bool _initialized;
3029
private bool _closed;
3130

32-
private readonly IDialogCoordinator _dialogCoordinator;
33-
3431
private readonly Guid _tabId;
3532
private readonly TigerVNCSessionInfo _sessionInfo;
3633

@@ -76,8 +73,6 @@ public TigerVNCControl(Guid tabId, TigerVNCSessionInfo sessionInfo)
7673
InitializeComponent();
7774
DataContext = this;
7875

79-
_dialogCoordinator = DialogCoordinator.Instance;
80-
8176
ConfigurationManager.Current.TigerVNCTabCount++;
8277

8378
_tabId = tabId;
@@ -209,16 +204,8 @@ private async Task Connect()
209204
catch (Exception ex)
210205
{
211206
if (!_closed)
212-
{
213-
var settings = AppearanceManager.MetroDialog;
214-
settings.AffirmativeButtonText = Strings.OK;
215-
ConfigurationManager.OnDialogOpen();
216-
217-
await _dialogCoordinator.ShowMessageAsync(this, Strings.Error,
218-
ex.Message, MessageDialogStyle.Affirmative, settings);
219-
220-
ConfigurationManager.OnDialogClose();
221-
}
207+
// Use built-in message box because we have visual issues in the dragablz window
208+
MessageBox.Show(ex.Message, Strings.Error, MessageBoxButton.OK, MessageBoxImage.Error);
222209
}
223210

224211
IsConnecting = false;

Source/NETworkManager/Controls/WebConsoleControl.xaml

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,6 @@
1010
xmlns:iconPacks="http://metro.mahapps.com/winfx/xaml/iconpacks"
1111
xmlns:settings="clr-namespace:NETworkManager.Settings;assembly=NETworkManager.Settings"
1212
xmlns:webview="clr-namespace:Microsoft.Web.WebView2.Wpf;assembly=Microsoft.Web.WebView2.Wpf"
13-
mah:DialogParticipation.Register="{Binding}"
1413
mc:Ignorable="d" Loaded="UserControl_Loaded"
1514
d:DataContext="{d:DesignInstance local:WebConsoleControl}">
1615
<local:UserControlBase.Resources>

0 commit comments

Comments
 (0)