Skip to content

Commit 66ba90a

Browse files
committed
Expand/collapse rows recursively when shift is held.
1 parent 233333f commit 66ba90a

File tree

6 files changed

+46
-21
lines changed

6 files changed

+46
-21
lines changed

DsmSuite.DsmViewer.Model/Core/DsmElement.cs

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -95,6 +95,16 @@ public string GetRelativeName(IDsmElement element)
9595

9696
public bool IsExpanded { get; set; }
9797

98+
public void ExpandRecursively(bool expanded)
99+
{
100+
if (!HasChildren)
101+
return;
102+
103+
IsExpanded = expanded;
104+
foreach (DsmElement child in Children)
105+
child.ExpandRecursively(expanded);
106+
}
107+
98108
public bool IsMatch { get; set; }
99109

100110
public bool IsIncludedInTree { get; set; }

DsmSuite.DsmViewer.Model/Interfaces/IDsmElement.cs

Lines changed: 16 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -43,12 +43,12 @@ public interface IDsmElement : IComparable
4343
bool IsRoot { get; }
4444

4545
/// <summary>
46-
/// Has the element any children that are in the tree.
46+
/// Has the element any children that are in the tree (see <see cref="IsIncludedInTree"/>).
4747
/// </summary>
4848
bool HasChildren { get; }
4949

5050
/// <summary>
51-
/// Tree children of the element.
51+
/// Tree children of the element (see <see cref="IsIncludedInTree"/>).
5252
/// </summary>
5353
IList<IDsmElement> Children { get; }
5454

@@ -69,17 +69,29 @@ public interface IDsmElement : IComparable
6969
bool IsRecursiveChildOf(IDsmElement element);
7070

7171
/// <summary>
72-
/// Is the element expanded in the viewer.
72+
/// Is the element expanded in the viewer. This is only meaningful for elements with children.<br/>
73+
/// If an element is expanded, each of its children has a line in the matrix and the element
74+
/// itself hasn't, but is used to vertically group the children.<br/>
75+
/// If an element is not expanded, its children are not displayed and the element itself has
76+
/// a row in the matrix.<br/>
77+
/// This property is only relevant and should only be changed for elements that are in the
78+
/// tree (see <see cref="IsIncludedInTree"/>).
7379
/// </summary>
7480
bool IsExpanded { get; set; }
7581

82+
/// <summary>
83+
/// Set or clear the IsExpanded property recursively for elements in the tree.
84+
/// </summary>
85+
void ExpandRecursively(bool expanded);
86+
7687
/// <summary>
7788
/// Is the element match in search.
7889
/// </summary>
7990
bool IsMatch{ get; set; }
8091

8192
/// <summary>
82-
/// Is the element included in the tree
93+
/// Is the element included in the tree. The tree is the set of elements that are in scope
94+
/// for the viewer, i.e. that are not filtered out.
8395
/// </summary>
8496
bool IsIncludedInTree { get; set; }
8597
}

DsmSuite.DsmViewer.View/Matrix/MatrixRowHeaderView.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -59,7 +59,7 @@ private void OnMouseDown(object sender, MouseButtonEventArgs e)
5959

6060
if (e.ChangedButton == MouseButton.Left && pt.X < 20 && pt.Y < 24)
6161
{
62-
_matrixViewModel.ToggleElementExpandedCommand.Execute(null);
62+
_matrixViewModel.ToggleElementExpandedCommand.Execute(Keyboard.Modifiers == ModifierKeys.Shift);
6363
InvalidateVisual();
6464
}
6565
}

DsmSuite.DsmViewer.ViewModel/Main/MainViewModel.cs

Lines changed: 14 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -426,13 +426,22 @@ private bool ZoomOutCanExecute(object parameter)
426426
return ActiveMatrix?.ZoomLevel > _minZoom;
427427
}
428428

429-
private void ToggleElementExpandedExecute(object parameter)
429+
/// <summary>
430+
/// Toggle the IsExpanded state of the current row. If <paramref name="recursive"/> is
431+
/// <c>bool true</c>, the IsExpanded state of the entire subtree under the current element
432+
/// is set to the same new value as element.
433+
/// If <paramref name="recursive"/> is false, only the current element is toggled.
434+
/// </summary>
435+
private void ToggleElementExpandedExecute(object recursive)
430436
{
431437
ElementTreeItemViewModel vm = ActiveMatrix.FindElementViewModel(ActiveMatrix.HoveredRow?.Element);
432-
if (vm != null && vm.IsExpandable)
433-
{
434-
vm.IsExpanded = !vm.IsExpanded;
435-
}
438+
if (vm == null || !vm.IsExpandable)
439+
return;
440+
441+
if ((bool)recursive)
442+
vm.Element.ExpandRecursively(!vm.IsExpanded);
443+
else
444+
vm.Element.IsExpanded = !vm.IsExpanded;
436445

437446
ActiveMatrix.Reload();
438447
}

DsmSuite.DsmViewer.ViewModel/Matrix/ElementTreeItemViewModel.cs

Lines changed: 2 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -72,17 +72,8 @@ public MatrixColor Color
7272

7373
public bool IsExpandable => Element.HasChildren;
7474

75-
public bool IsExpanded
76-
{
77-
get
78-
{
79-
return Element.IsExpanded;
80-
}
81-
set
82-
{
83-
Element.IsExpanded = value;
84-
}
85-
}
75+
public bool IsExpanded => Element.IsExpanded;
76+
8677

8778
public IReadOnlyList<ElementTreeItemViewModel> Children => _children;
8879

README.md

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,8 @@ Settings are read and saved from %APPDATA%, usually `%HOME%/AppData/{Local,Roami
2020
Several smallish changes to the functionality were made; see Changes below.
2121
Larger changes are described in the remainder of this section.
2222

23+
* Expanding or collapsing a row header with shift pressed will expand or collapse recursively.
24+
2325

2426
### Snapshots
2527
Snapshots are saved as part of the action list with the model. You can return to a snapshot by selecting it from the dropdown list (narrow down-triangle) next to the action button.
@@ -37,6 +39,7 @@ A snapshot is a marker in the undo/redo list. This has some important consequenc
3739
* 24-08-28 Show current selection in legend.
3840
* 25-02-15 Filtering is an action and can be undone and saved.
3941
* 25-03-09 A dropdown list next to the 'Make snapshot' button allows jumping back to a snapshot.
42+
* 25-03-23 Expand/collapse recursively with shift.
4043

4144
## Implementation notes
4245

0 commit comments

Comments
 (0)