Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
88 changes: 88 additions & 0 deletions Source/NETworkManager.Controls/GroupExpander.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,88 @@
using System.ComponentModel;
using System.Windows;
using System.Windows.Controls;

namespace NETworkManager.Controls
{
public class GroupExpander : Expander
{
public static readonly DependencyProperty StateStoreProperty =
DependencyProperty.Register(
"StateStore",
typeof(GroupExpanderStateStore),
typeof(GroupExpander),
new PropertyMetadata(null, OnStateStoreChanged));

public GroupExpanderStateStore StateStore
{
get => (GroupExpanderStateStore)GetValue(StateStoreProperty);
set => SetValue(StateStoreProperty, value);
}

public static readonly DependencyProperty GroupNameProperty =
DependencyProperty.Register(
nameof(GroupName),
typeof(string),
typeof(GroupExpander),
new PropertyMetadata(null, OnGroupNameChanged));

public string GroupName
{
get => (string)GetValue(GroupNameProperty);
set => SetValue(GroupNameProperty, value);
}

static GroupExpander()
{
IsExpandedProperty.OverrideMetadata(
typeof(GroupExpander),
new FrameworkPropertyMetadata(false, FrameworkPropertyMetadataOptions.BindsTwoWayByDefault, OnIsExpandedChanged));
}

private static void OnIsExpandedChanged(DependencyObject d, DependencyPropertyChangedEventArgs e)
{
var expander = (GroupExpander)d;

if (expander.StateStore != null && expander.GroupName != null)
expander.StateStore[expander.GroupName] = (bool)e.NewValue;
}

private static void OnStateStoreChanged(DependencyObject d, DependencyPropertyChangedEventArgs e)
{
var expander = (GroupExpander)d;

if (e.OldValue is GroupExpanderStateStore oldStore)
oldStore.PropertyChanged -= expander.StateStore_PropertyChanged;

if (e.NewValue is GroupExpanderStateStore newStore)
newStore.PropertyChanged += expander.StateStore_PropertyChanged;

expander.UpdateIsExpanded();
}

private void StateStore_PropertyChanged(object sender, PropertyChangedEventArgs e)
{
if (e.PropertyName == $"Item[{GroupName}]")
UpdateIsExpanded();
}

private static void OnGroupNameChanged(DependencyObject d, DependencyPropertyChangedEventArgs e)
{
var expander = (GroupExpander)d;

expander.UpdateIsExpanded();
}

private void UpdateIsExpanded()
{
if (StateStore == null || GroupName == null)
return;

// Prevent recursive updates
if (IsExpanded == StateStore[GroupName])
return;

IsExpanded = StateStore[GroupName];
}
}
}
46 changes: 46 additions & 0 deletions Source/NETworkManager.Controls/GroupExpanderStateStore.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,46 @@
using System.Collections.Generic;
using System.ComponentModel;
using System.Diagnostics;

namespace NETworkManager.Controls
{
public class GroupExpanderStateStore : INotifyPropertyChanged
{
public event PropertyChangedEventHandler PropertyChanged;

protected void OnPropertyChanged(string propertyName) =>
PropertyChanged?.Invoke(this, new PropertyChangedEventArgs(propertyName));

/// <summary>
/// Stores the expansion state of each group by its name.
/// </summary>
private readonly Dictionary<string, bool> _states = [];

/// <summary>
/// The indexer to get or set the expansion state of a group by its name.
/// </summary>
/// <param name="groupName">Name of the group.</param>
/// <returns>True if expanded, false if collapsed.</returns>
public bool this[string groupName]
{
get
{
// Default to expanded if not set
if (!_states.TryGetValue(groupName, out var val))
_states[groupName] = val = true;

return val;
}
set
{
if (_states.TryGetValue(groupName, out var existing) && existing == value)
return;

Debug.WriteLine("GroupExpanderStateStore: Setting state of '{0}' to {1}", groupName, value);

_states[groupName] = value;
OnPropertyChanged($"Item[{groupName}]");
}
}
}
}
18 changes: 18 additions & 0 deletions Source/NETworkManager.Localization/Resources/Strings.Designer.cs

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

6 changes: 6 additions & 0 deletions Source/NETworkManager.Localization/Resources/Strings.resx
Original file line number Diff line number Diff line change
Expand Up @@ -3987,4 +3987,10 @@ Right-click for more options.</value>
<data name="AddGroupDots" xml:space="preserve">
<value>Add group...</value>
</data>
<data name="ExpandAll" xml:space="preserve">
<value>Expand all</value>
</data>
<data name="CollapseAll" xml:space="preserve">
<value>Collapse all</value>
</data>
</root>
23 changes: 23 additions & 0 deletions Source/NETworkManager/ViewModels/AWSSessionManagerHostViewModel.cs
Original file line number Diff line number Diff line change
Expand Up @@ -308,6 +308,9 @@ public bool IsProfileFilterSet
OnPropertyChanged();
}
}

private readonly GroupExpanderStateStore _groupExpanderStateStore = new();
public GroupExpanderStateStore GroupExpanderStateStore => _groupExpanderStateStore;

private bool _canProfileWidthChange = true;
private double _tempProfileWidth;
Expand Down Expand Up @@ -625,6 +628,20 @@ private void ClearProfileFilterAction()
ProfileFilterIsOpen = false;
}

public ICommand ExpandAllProfileGroupsCommand => new RelayCommand(_ => ExpandAllProfileGroupsAction());

private void ExpandAllProfileGroupsAction()
{
SetIsExpandedForAllProfileGroups(true);
}

public ICommand CollapseAllProfileGroupsCommand => new RelayCommand(_ => CollapseAllProfileGroupsAction());

private void CollapseAllProfileGroupsAction()
{
SetIsExpandedForAllProfileGroups(false);
}

public ICommand OpenDocumentationCommand
{
get { return new RelayCommand(_ => OpenDocumentationAction()); }
Expand Down Expand Up @@ -1011,6 +1028,12 @@ private static void AddRegionToHistory(string region)
SettingsManager.Current.General_HistoryListEntries));
}

private void SetIsExpandedForAllProfileGroups(bool isExpanded)
{
foreach (var group in Profiles.Groups.Cast<CollectionViewGroup>())
GroupExpanderStateStore[group.Name.ToString()] = isExpanded;
}

private void ResizeProfile(bool dueToChangedSize)
{
_canProfileWidthChange = false;
Expand Down
23 changes: 23 additions & 0 deletions Source/NETworkManager/ViewModels/DNSLookupHostViewModel.cs
Original file line number Diff line number Diff line change
Expand Up @@ -196,6 +196,9 @@ public bool IsProfileFilterSet
}
}

private readonly GroupExpanderStateStore _groupExpanderStateStore = new();
public GroupExpanderStateStore GroupExpanderStateStore => _groupExpanderStateStore;

private bool _canProfileWidthChange = true;
private double _tempProfileWidth;

Expand Down Expand Up @@ -399,6 +402,20 @@ private void ClearProfileFilterAction()
ProfileFilterIsOpen = false;
}

public ICommand ExpandAllProfileGroupsCommand => new RelayCommand(_ => ExpandAllProfileGroupsAction());

private void ExpandAllProfileGroupsAction()
{
SetIsExpandedForAllProfileGroups(true);
}

public ICommand CollapseAllProfileGroupsCommand => new RelayCommand(_ => CollapseAllProfileGroupsAction());

private void CollapseAllProfileGroupsAction()
{
SetIsExpandedForAllProfileGroups(false);
}

public ItemActionCallback CloseItemCommand => CloseItemAction;

private static void CloseItemAction(ItemActionCallbackArgs<TabablzControl> args)
Expand All @@ -410,6 +427,12 @@ private static void CloseItemAction(ItemActionCallbackArgs<TabablzControl> args)

#region Methods

private void SetIsExpandedForAllProfileGroups(bool isExpanded)
{
foreach (var group in Profiles.Groups.Cast<CollectionViewGroup>())
GroupExpanderStateStore[group.Name.ToString()] = isExpanded;
}

private void ResizeProfile(bool dueToChangedSize)
{
_canProfileWidthChange = false;
Expand Down
23 changes: 23 additions & 0 deletions Source/NETworkManager/ViewModels/IPGeolocationHostViewModel.cs
Original file line number Diff line number Diff line change
Expand Up @@ -197,6 +197,9 @@ public bool IsProfileFilterSet
}
}

private readonly GroupExpanderStateStore _groupExpanderStateStore = new();
public GroupExpanderStateStore GroupExpanderStateStore => _groupExpanderStateStore;

private bool _canProfileWidthChange = true;
private double _tempProfileWidth;

Expand Down Expand Up @@ -399,6 +402,20 @@ private void ClearProfileFilterAction()
ProfileFilterIsOpen = false;
}

public ICommand ExpandAllProfileGroupsCommand => new RelayCommand(_ => ExpandAllProfileGroupsAction());

private void ExpandAllProfileGroupsAction()
{
SetIsExpandedForAllProfileGroups(true);
}

public ICommand CollapseAllProfileGroupsCommand => new RelayCommand(_ => CollapseAllProfileGroupsAction());

private void CollapseAllProfileGroupsAction()
{
SetIsExpandedForAllProfileGroups(false);
}

public ItemActionCallback CloseItemCommand => CloseItemAction;

private static void CloseItemAction(ItemActionCallbackArgs<TabablzControl> args)
Expand All @@ -410,6 +427,12 @@ private static void CloseItemAction(ItemActionCallbackArgs<TabablzControl> args)

#region Methods

private void SetIsExpandedForAllProfileGroups(bool isExpanded)
{
foreach (var group in Profiles.Groups.Cast<CollectionViewGroup>())
GroupExpanderStateStore[group.Name.ToString()] = isExpanded;
}

private void ResizeProfile(bool dueToChangedSize)
{
_canProfileWidthChange = false;
Expand Down
23 changes: 23 additions & 0 deletions Source/NETworkManager/ViewModels/IPScannerHostViewModel.cs
Original file line number Diff line number Diff line change
Expand Up @@ -196,6 +196,9 @@ public bool IsProfileFilterSet
OnPropertyChanged();
}
}

private readonly GroupExpanderStateStore _groupExpanderStateStore = new();
public GroupExpanderStateStore GroupExpanderStateStore => _groupExpanderStateStore;

private bool _canProfileWidthChange = true;
private double _tempProfileWidth;
Expand Down Expand Up @@ -398,6 +401,20 @@ private void ClearProfileFilterAction()
IsProfileFilterSet = false;
ProfileFilterIsOpen = false;
}

public ICommand ExpandAllProfileGroupsCommand => new RelayCommand(_ => ExpandAllProfileGroupsAction());

private void ExpandAllProfileGroupsAction()
{
SetIsExpandedForAllProfileGroups(true);
}

public ICommand CollapseAllProfileGroupsCommand => new RelayCommand(_ => CollapseAllProfileGroupsAction());

private void CollapseAllProfileGroupsAction()
{
SetIsExpandedForAllProfileGroups(false);
}

public ItemActionCallback CloseItemCommand => CloseItemAction;

Expand All @@ -410,6 +427,12 @@ private static void CloseItemAction(ItemActionCallbackArgs<TabablzControl> args)

#region Methods

private void SetIsExpandedForAllProfileGroups(bool isExpanded)
{
foreach (var group in Profiles.Groups.Cast<CollectionViewGroup>())
GroupExpanderStateStore[group.Name.ToString()] = isExpanded;
}

private void ResizeProfile(bool dueToChangedSize)
{
_canProfileWidthChange = false;
Expand Down
Loading