Skip to content

Commit 5ea2359

Browse files
authored
Chore: Migrate Dialogs (DialogCoordinator) to ChildWindows (#3271)
* Chore: Migrate dialogs... * Chore: Migrate dialogs... * Feature: Migrate more dialogs.... * Feature: More dialogs * Feature: Migrate more dialogs * Feature: More dialogs * Chore: migrate more dialogs * Update PowerShellControl.xaml.cs * Dotnet format * Update TigerVNCSettingsView.xaml.cs * Feature: Migrate more dialogs * Feature: Migrate dialog * Feature: More dialogs * Feature: More dialogs * Chore: More cleanup * Chore: ARP dialog * Chore: Remove dialog coordinator * Feature: SNMP Settings dialog * Feature: SNMP dialog * Fix: NullException in SNMP OID selection * Docs: #3271 * Chore: Add default server * Feature: More dialogs * dotnet format * Feature: More dialogs * Feature: More dialogs * Feature: More dialogs * Feature: Migration done & cleanup * Update AppearanceManager.cs * Docs: #3271 * Fix: ComboBox focus issue
1 parent 95258fd commit 5ea2359

File tree

187 files changed

+1281
-1588
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

187 files changed

+1281
-1588
lines changed

Source/NETworkManager.Controls/MultiSelectDataGrid.cs

Lines changed: 78 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,14 +1,17 @@
11
using System.Collections;
2+
using System.Collections.Specialized;
23
using System.Windows;
34
using System.Windows.Controls;
45

56
namespace NETworkManager.Controls;
67

78
public class MultiSelectDataGrid : DataGrid
89
{
10+
private bool _isUpdatingSelection;
11+
912
public static readonly DependencyProperty SelectedItemsListProperty =
1013
DependencyProperty.Register("SelectedItemsList", typeof(IList), typeof(MultiSelectDataGrid),
11-
new PropertyMetadata(null));
14+
new PropertyMetadata(null, OnSelectedItemsListChanged));
1215

1316
public MultiSelectDataGrid()
1417
{
@@ -21,8 +24,81 @@ public IList SelectedItemsList
2124
set => SetValue(SelectedItemsListProperty, value);
2225
}
2326

27+
private static void OnSelectedItemsListChanged(DependencyObject d, DependencyPropertyChangedEventArgs e)
28+
{
29+
if (d is not MultiSelectDataGrid dataGrid)
30+
return;
31+
32+
dataGrid.UnsubscribeFromCollectionChanged(e.OldValue as IList);
33+
dataGrid.SubscribeToCollectionChanged(e.NewValue as IList);
34+
dataGrid.UpdateSelectedItems();
35+
}
36+
37+
private void SubscribeToCollectionChanged(IList list)
38+
{
39+
if (list is INotifyCollectionChanged observableCollection)
40+
{
41+
observableCollection.CollectionChanged += OnSelectedItemsListCollectionChanged;
42+
}
43+
}
44+
45+
private void UnsubscribeFromCollectionChanged(IList list)
46+
{
47+
if (list is INotifyCollectionChanged observableCollection)
48+
{
49+
observableCollection.CollectionChanged -= OnSelectedItemsListCollectionChanged;
50+
}
51+
}
52+
53+
private void OnSelectedItemsListCollectionChanged(object sender, NotifyCollectionChangedEventArgs e)
54+
{
55+
UpdateSelectedItems();
56+
}
57+
58+
private void UpdateSelectedItems()
59+
{
60+
if (_isUpdatingSelection)
61+
return;
62+
63+
_isUpdatingSelection = true;
64+
65+
try
66+
{
67+
SelectedItems.Clear();
68+
69+
if (SelectedItemsList != null)
70+
{
71+
foreach (var item in SelectedItemsList)
72+
{
73+
SelectedItems.Add(item);
74+
}
75+
}
76+
}
77+
finally
78+
{
79+
_isUpdatingSelection = false;
80+
}
81+
}
82+
2483
private void DataGridMultiItemSelect_SelectionChanged(object sender, SelectionChangedEventArgs e)
2584
{
26-
SelectedItemsList = SelectedItems;
85+
if (_isUpdatingSelection || SelectedItemsList == null)
86+
return;
87+
88+
_isUpdatingSelection = true;
89+
90+
try
91+
{
92+
SelectedItemsList.Clear();
93+
94+
foreach (var item in SelectedItems)
95+
{
96+
SelectedItemsList.Add(item);
97+
}
98+
}
99+
finally
100+
{
101+
_isUpdatingSelection = false;
102+
}
27103
}
28104
}

Source/NETworkManager.Settings/AppearanceManager.cs

Lines changed: 0 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,4 @@
11
using ControlzEx.Theming;
2-
using MahApps.Metro.Controls.Dialogs;
32
using MahApps.Metro.Theming;
43
using NETworkManager.Models.Appearance;
54
using System;
@@ -42,11 +41,6 @@ public static class AppearanceManager
4241
/// </summary>
4342
private const string ThemeFolderName = "Themes";
4443

45-
/// <summary>
46-
/// Contains the default settings for a new <see cref="BaseMetroDialog" />
47-
/// </summary>
48-
public static readonly MetroDialogSettings MetroDialog = new();
49-
5044
/// <summary>
5145
/// List who contains all MahApps.Metro themes.
5246
/// </summary>
@@ -83,15 +77,6 @@ static AppearanceManager()
8377
ThemeManager.Current.ThemeChanged += Current_ThemeChanged;
8478

8579
LoadCustomThemes();
86-
87-
MetroDialog.CustomResourceDictionary = new ResourceDictionary
88-
{
89-
Source = new Uri("NETworkManager;component/Resources/Styles/MetroDialogStyles.xaml",
90-
UriKind.RelativeOrAbsolute)
91-
};
92-
93-
MetroDialog.DialogButtonFontSize = 14;
94-
MetroDialog.DialogMessageFontSize = 14;
9580
}
9681
#endregion
9782

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/App.xaml

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -35,7 +35,6 @@
3535
<ResourceDictionary Source="/Resources/Styles/LoadingIndicatorArcsStyle.xaml" />
3636
<ResourceDictionary Source="/Resources/Styles/LoadingIndicatorPulseStyle.xaml" />
3737
<ResourceDictionary Source="/Resources/Styles/MenuItemStyles.xaml" />
38-
<ResourceDictionary Source="/Resources/Styles/MetroDialogStyles.xaml" />
3938
<ResourceDictionary Source="/Resources/Styles/NumericUpDownStyles.xaml" />
4039
<ResourceDictionary Source="/Resources/Styles/RadioButtonStyles.xaml" />
4140
<ResourceDictionary Source="/Resources/Styles/ScrollBarStyles.xaml" />

Source/NETworkManager/Controls/DragablzTabHostWindow.xaml

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -10,12 +10,10 @@
1010
xmlns:controls="clr-namespace:NETworkManager.Controls"
1111
xmlns:application="clr-namespace:NETworkManager.Models;assembly=NETworkManager.Models"
1212
xmlns:iconPacks="http://metro.mahapps.com/winfx/xaml/iconpacks"
13-
xmlns:wpfHelpers="clr-namespace:NETworkManager.Utilities.WPF;assembly=NETworkManager.Utilities.WPF"
14-
xmlns:dialogs="clr-namespace:MahApps.Metro.Controls.Dialogs;assembly=MahApps.Metro"
13+
xmlns:wpfHelpers="clr-namespace:NETworkManager.Utilities.WPF;assembly=NETworkManager.Utilities.WPF"
1514
mc:Ignorable="d"
1615
Style="{DynamicResource DefaultWindow}" MinWidth="800" Width="1024" Height="768" MinHeight="600"
17-
TitleAlignment="Left" Activated="MetroWindow_Activated"
18-
dialogs:DialogParticipation.Register="{Binding}"
16+
TitleAlignment="Left" Activated="MetroWindow_Activated"
1917
Closing="DragablzTabHostWindow_OnClosing"
2018
d:DataContext="{d:DesignInstance controls:DragablzTabHostWindow}">
2119
<mah:MetroWindow.Resources>

Source/NETworkManager/Controls/DragablzTabHostWindow.xaml.cs

Lines changed: 5 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,4 @@
11
using Dragablz;
2-
using MahApps.Metro.Controls.Dialogs;
32
using NETworkManager.Localization;
43
using NETworkManager.Localization.Resources;
54
using NETworkManager.Models;
@@ -224,13 +223,13 @@ private async void RemoteDesktop_SendCtrlAltDelAction(object view)
224223
}
225224
catch (Exception ex)
226225
{
227-
ConfigurationManager.OnDialogOpen();
226+
//ConfigurationManager.OnDialogOpen();
228227

229-
await this.ShowMessageAsync(Strings.Error,
230-
string.Format("{0}\n\nMessage:\n{1}",
231-
Strings.CouldNotSendKeystroke, ex.Message));
228+
// Use built-in message box because we have visual issues in the dragablz window
229+
System.Windows.MessageBox.Show(string.Format("{0}\n\nMessage:\n{1}",
230+
Strings.CouldNotSendKeystroke, ex.Message), Strings.Error, MessageBoxButton.OK, MessageBoxImage.Error);
232231

233-
ConfigurationManager.OnDialogClose();
232+
//ConfigurationManager.OnDialogClose();
234233
}
235234
}
236235

Source/NETworkManager/Controls/PowerShellControl.xaml

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -8,8 +8,7 @@
88
xmlns:localization="clr-namespace:NETworkManager.Localization.Resources;assembly=NETworkManager.Localization"
99
xmlns:local="clr-namespace:NETworkManager.Controls"
1010
xmlns:mah="http://metro.mahapps.com/winfx/xaml/controls"
11-
xmlns:settings="clr-namespace:NETworkManager.Settings;assembly=NETworkManager.Settings"
12-
mah:DialogParticipation.Register="{Binding}"
11+
xmlns:settings="clr-namespace:NETworkManager.Settings;assembly=NETworkManager.Settings"
1312
mc:Ignorable="d" Loaded="UserControl_Loaded"
1413
d:DataContext="{d:DesignInstance local:PowerShellControl}">
1514
<local:UserControlBase.Resources>

Source/NETworkManager/Controls/PowerShellControl.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.PowerShell;
1110
using NETworkManager.Settings;
@@ -29,8 +28,6 @@ private void WindowGrid_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 PowerShellSessionInfo _sessionInfo;
3633

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

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

8378
_tabId = tabId;
@@ -196,17 +191,8 @@ private async Task Connect()
196191
catch (Exception ex)
197192
{
198193
if (!_closed)
199-
{
200-
var settings = AppearanceManager.MetroDialog;
201-
settings.AffirmativeButtonText = Strings.OK;
202-
203-
ConfigurationManager.OnDialogOpen();
204-
205-
await _dialogCoordinator.ShowMessageAsync(this, Strings.Error,
206-
ex.Message, MessageDialogStyle.Affirmative, settings);
207-
208-
ConfigurationManager.OnDialogClose();
209-
}
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);
210196
}
211197

212198
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;

0 commit comments

Comments
 (0)