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.

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>
Original file line number Diff line number Diff line change
Expand Up @@ -3987,4 +3987,10 @@ Rechtsklick für weitere Optionen.</value>
<data name="AddGroupDots" xml:space="preserve">
<value>Gruppe hinzufügen...</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>
Original file line number Diff line number Diff line change
Expand Up @@ -3984,4 +3984,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>
Original file line number Diff line number Diff line change
Expand Up @@ -3987,4 +3987,10 @@ Clic droit pour plus d'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>
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>
Original file line number Diff line number Diff line change
Expand Up @@ -4090,4 +4090,10 @@ Per maggiori dettagli consulta il file registro.</value>
<data name="AddGroupDots" xml:space="preserve">
<value>Aggiungi gruppo...</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>
Original file line number Diff line number Diff line change
Expand Up @@ -3987,4 +3987,10 @@ Open Windows Settings &gt; Privacy &amp; security &gt; Location, enable access f
<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>
Original file line number Diff line number Diff line change
Expand Up @@ -3984,4 +3984,10 @@ Open Windows Settings &gt; Privacy &amp; security &gt; Location, enable access f
<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>
Original file line number Diff line number Diff line change
Expand Up @@ -3984,4 +3984,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>
Original file line number Diff line number Diff line change
Expand Up @@ -3984,4 +3984,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>
Original file line number Diff line number Diff line change
Expand Up @@ -3987,4 +3987,10 @@ Clique direito para mais opções.</value>
<data name="AddGroupDots" xml:space="preserve">
<value>Adicionar grupo...</value>
</data>
<data name="ExpandAll" xml:space="preserve">
<value>Exportar tudo</value>
</data>
<data name="CollapseAll" xml:space="preserve">
<value>Fechar todos</value>
</data>
</root>
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>
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>
Original file line number Diff line number Diff line change
Expand Up @@ -3969,4 +3969,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>
Original file line number Diff line number Diff line change
Expand Up @@ -3984,4 +3984,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>
Original file line number Diff line number Diff line change
Expand Up @@ -3988,4 +3988,10 @@ Open Windows Settings &gt; Privacy &amp; security &gt; Location, enable access f
<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>
24 changes: 15 additions & 9 deletions Source/NETworkManager.Localization/Resources/Strings.zh-TW.resx
Original file line number Diff line number Diff line change
Expand Up @@ -3960,30 +3960,36 @@ $$hostname$$ --&gt; 主機名稱</value>
<value>刪除瀏覽資料時發生錯誤。歡迎在 GitHub 上回報此問題。</value>
</data>
<data name="ExampleTag" xml:space="preserve">
<value>production</value>
<value>生產</value>
</data>
<data name="AddTag" xml:space="preserve">
<value>Add tag</value>
<value>新增標籤</value>
</data>
<data name="ApplyFilter" xml:space="preserve">
<value>Apply filter</value>
<value>套用篩選</value>
</data>
<data name="FilterProfilesDots" xml:space="preserve">
<value>Filter profiles...</value>
<value>篩選設定檔...</value>
</data>
<data name="FilterByTags" xml:space="preserve">
<value>Filter by tags</value>
<value>依標籤篩選</value>
</data>
<data name="NoTagsFound" xml:space="preserve">
<value>No tags found!</value>
<value>找不到標籤!</value>
</data>
<data name="Match" xml:space="preserve">
<value>Match</value>
<value>匹配</value>
</data>
<data name="Any" xml:space="preserve">
<value>Any</value>
<value>任何</value>
</data>
<data name="AddGroupDots" xml:space="preserve">
<value>Add group...</value>
<value>新增群組...</value>
</data>
<data name="ExpandAll" xml:space="preserve">
<value>擴展全部</value>
</data>
<data name="CollapseAll" xml:space="preserve">
<value>全部摺疊</value>
</data>
</root>
Loading