Skip to content

Commit a554f06

Browse files
committed
Added settings search box to playground app
1 parent abbaf9e commit a554f06

File tree

6 files changed

+364
-170
lines changed

6 files changed

+364
-170
lines changed

Examples/Nodify.Playground/Editor/NodeViewModel.cs

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
using System.Windows;
22
using System.Windows.Controls;
3+
using System.Windows.Input;
34

45
namespace Nodify.Playground
56
{
@@ -20,5 +21,12 @@ public Point Location
2021
}
2122

2223
public Orientation Orientation { get; protected set; }
24+
25+
public ICommand DeleteCommand { get; }
26+
27+
public NodeViewModel()
28+
{
29+
DeleteCommand = new DelegateCommand(() => Graph.Nodes.Remove(this));
30+
}
2331
}
2432
}

Examples/Nodify.Playground/Editor/NodifyEditorView.xaml

Lines changed: 202 additions & 96 deletions
Large diffs are not rendered by default.

Examples/Nodify.Playground/Editor/NodifyEditorViewModel.cs

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -93,6 +93,13 @@ public ConnectionViewModel? SelectedConnection
9393
set => SetProperty(ref _selectedConnection, value);
9494
}
9595

96+
private NodeViewModel? _selectedNode;
97+
public NodeViewModel? SelectedNode
98+
{
99+
get => _selectedNode;
100+
set => SetProperty(ref _selectedNode, value);
101+
}
102+
96103
public GraphSchema Schema { get; }
97104

98105
public ICommand DeleteSelectionCommand { get; }

Examples/Nodify.Playground/EditorSettings.cs

Lines changed: 49 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,4 @@
11
using System.Collections.Generic;
2-
using System.Collections.ObjectModel;
32
using System.Windows;
43

54
namespace Nodify.Playground
@@ -14,18 +13,33 @@ public enum ConnectionStyle
1413

1514
public class EditorSettings : ObservableObject
1615
{
17-
public IReadOnlyCollection<ISettingViewModel> Settings { get; }
18-
public IReadOnlyCollection<ISettingViewModel> AdvancedSettings { get; }
16+
private readonly IReadOnlyCollection<ISettingViewModel> _settings;
17+
public IEnumerable<ISettingViewModel> Settings => PlaygroundSettings.Instance.FilterAndSort(_settings);
18+
19+
private readonly IReadOnlyCollection<ISettingViewModel> _advancedSettings;
20+
public IEnumerable<ISettingViewModel> AdvancedSettings => PlaygroundSettings.Instance.FilterAndSort(_advancedSettings);
1921

2022
private EditorSettings()
2123
{
22-
Settings = new ObservableCollection<ISettingViewModel>()
24+
PlaygroundSettings.Instance.PropertyChanged += OnSearchTextChanged;
25+
26+
_settings = new List<ISettingViewModel>()
2327
{
2428
new ProxySettingViewModel<bool>(
2529
() => Instance.EnableRealtimeSelection,
2630
val => Instance.EnableRealtimeSelection = val,
2731
"Realtime selection: ",
2832
"Selects items when finished if disabled."),
33+
new ProxySettingViewModel<bool>(
34+
() => Instance.SelectableNodes,
35+
val => Instance.SelectableNodes = val,
36+
"Selectable nodes: ",
37+
"Whether nodes can be selected."),
38+
new ProxySettingViewModel<bool>(
39+
() => Instance.DraggableNodes,
40+
val => Instance.DraggableNodes= val,
41+
"Draggable nodes: ",
42+
"Whether nodes can be dragged."),
2943
new ProxySettingViewModel<bool>(
3044
() => Instance.CanSelectMultipleNodes,
3145
val => Instance.CanSelectMultipleNodes = val,
@@ -189,7 +203,7 @@ private EditorSettings()
189203
"Whether the grouping node is sticky or not"),
190204
};
191205

192-
AdvancedSettings = new ObservableCollection<ISettingViewModel>()
206+
_advancedSettings = new List<ISettingViewModel>()
193207
{
194208
new ProxySettingViewModel<double>(
195209
() => Instance.HandleRightClickAfterPanningThreshold,
@@ -276,6 +290,15 @@ private EditorSettings()
276290
EnableCuttingLinePreview = true;
277291
}
278292

293+
private void OnSearchTextChanged(object? sender, System.ComponentModel.PropertyChangedEventArgs e)
294+
{
295+
if (e.PropertyName == nameof(PlaygroundSettings.SearchText))
296+
{
297+
OnPropertyChanged(nameof(Settings));
298+
OnPropertyChanged(nameof(AdvancedSettings));
299+
}
300+
}
301+
279302
public static EditorSettings Instance { get; } = new EditorSettings();
280303

281304
#region Default settings
@@ -378,27 +401,41 @@ public PointEditor Location
378401
set => SetProperty(ref _location, value);
379402
}
380403

404+
private bool _selectableConnections = true;
405+
public bool SelectableConnections
406+
{
407+
get => _selectableConnections;
408+
set => SetProperty(ref _selectableConnections, value);
409+
}
410+
381411
private bool _canSelectMultipleConnections = true;
382412
public bool CanSelectMultipleConnections
383413
{
384414
get => _canSelectMultipleConnections;
385415
set => SetProperty(ref _canSelectMultipleConnections, value);
386416
}
387417

418+
private bool _draggableNodes = true;
419+
public bool DraggableNodes
420+
{
421+
get => _draggableNodes;
422+
set => SetProperty(ref _draggableNodes, value);
423+
}
424+
425+
private bool _selectableNodes = true;
426+
public bool SelectableNodes
427+
{
428+
get => _selectableNodes;
429+
set => SetProperty(ref _selectableNodes, value);
430+
}
431+
388432
private bool _canSelectMultipleNodes = true;
389433
public bool CanSelectMultipleNodes
390434
{
391435
get => _canSelectMultipleNodes;
392436
set => SetProperty(ref _canSelectMultipleNodes, value);
393437
}
394438

395-
private bool _selectableConnections = true;
396-
public bool SelectableConnections
397-
{
398-
get => _selectableConnections;
399-
set => SetProperty(ref _selectableConnections, value);
400-
}
401-
402439
private ConnectionStyle _connectionStyle;
403440
public ConnectionStyle ConnectionStyle
404441
{

Examples/Nodify.Playground/MainWindow.xaml

Lines changed: 71 additions & 59 deletions
Original file line numberDiff line numberDiff line change
@@ -8,8 +8,8 @@
88
xmlns:nodify="https://miroiu.github.io/nodify"
99
mc:Ignorable="d"
1010
Title="MainWindow"
11-
Height="600"
12-
Width="1200">
11+
Height="700"
12+
Width="1300">
1313

1414
<Window.Resources>
1515
<shared:DebugConverter x:Key="DebugConverter" />
@@ -108,65 +108,76 @@
108108
</Style>
109109
</Expander.Style>
110110

111-
<ScrollViewer>
112-
<Grid IsSharedSizeScope="True"
113-
Width="330">
114-
<Grid.RowDefinitions>
115-
<RowDefinition Height="Auto" />
116-
<RowDefinition Height="Auto" />
117-
</Grid.RowDefinitions>
111+
<Grid>
112+
<Grid.RowDefinitions>
113+
<RowDefinition Height="Auto" />
114+
<RowDefinition Height="*" />
115+
</Grid.RowDefinitions>
116+
<StackPanel Margin="0 0 5 10">
117+
<TextBlock Margin="0 0 0 3">Search:</TextBlock>
118+
<TextBox Text="{Binding Source={x:Static local:PlaygroundSettings.Instance}, Path=SearchText, UpdateSourceTrigger=PropertyChanged, Mode=TwoWay}"
119+
Padding="4" />
120+
</StackPanel>
121+
<ScrollViewer Grid.Row="1">
122+
<Grid IsSharedSizeScope="True"
123+
Width="330">
124+
<Grid.RowDefinitions>
125+
<RowDefinition Height="Auto" />
126+
<RowDefinition Height="Auto" />
127+
</Grid.RowDefinitions>
118128

119-
<Expander Header="Playground Settings"
120-
Padding="0 5 0 0"
121-
BorderThickness="0 0 0 1"
122-
IsExpanded="True"
123-
BorderBrush="{DynamicResource BackgroundBrush}">
124-
<Expander.Style>
125-
<Style TargetType="{x:Type Expander}"
126-
BasedOn="{StaticResource {x:Type Expander}}">
127-
<Setter Property="Tag"
128-
Value="{StaticResource ExpandRightIcon}" />
129-
<Style.Triggers>
130-
<Trigger Property="IsExpanded"
131-
Value="True">
132-
<Setter Property="Tag"
133-
Value="{StaticResource ExpandDownIcon}" />
134-
</Trigger>
135-
</Style.Triggers>
136-
</Style>
137-
</Expander.Style>
138-
<Border BorderThickness="1"
139-
Padding="10"
140-
HorizontalAlignment="Stretch">
141-
<local:SettingsView Items="{Binding Source={x:Static local:PlaygroundSettings.Instance}, Path=Settings}" />
142-
</Border>
143-
</Expander>
129+
<Expander Header="Playground Settings"
130+
Padding="0 5 0 0"
131+
BorderThickness="0 0 0 1"
132+
IsExpanded="True"
133+
BorderBrush="{DynamicResource BackgroundBrush}">
134+
<Expander.Style>
135+
<Style TargetType="{x:Type Expander}"
136+
BasedOn="{StaticResource {x:Type Expander}}">
137+
<Setter Property="Tag"
138+
Value="{StaticResource ExpandRightIcon}" />
139+
<Style.Triggers>
140+
<Trigger Property="IsExpanded"
141+
Value="True">
142+
<Setter Property="Tag"
143+
Value="{StaticResource ExpandDownIcon}" />
144+
</Trigger>
145+
</Style.Triggers>
146+
</Style>
147+
</Expander.Style>
148+
<Border BorderThickness="1"
149+
Padding="10"
150+
HorizontalAlignment="Stretch">
151+
<local:SettingsView Items="{Binding Source={x:Static local:PlaygroundSettings.Instance}, Path=Settings}" />
152+
</Border>
153+
</Expander>
144154

145-
<Expander Header="Editor Settings"
146-
Padding="0 5 0 0"
147-
BorderThickness="0 0 0 1"
148-
IsExpanded="True"
149-
BorderBrush="{DynamicResource BackgroundBrush}"
150-
Grid.Row="1">
151-
<Expander.Style>
152-
<Style TargetType="{x:Type Expander}"
153-
BasedOn="{StaticResource {x:Type Expander}}">
154-
<Setter Property="Tag"
155-
Value="{StaticResource ExpandRightIcon}" />
156-
<Style.Triggers>
157-
<Trigger Property="IsExpanded"
158-
Value="True">
159-
<Setter Property="Tag"
160-
Value="{StaticResource ExpandDownIcon}" />
161-
</Trigger>
162-
</Style.Triggers>
163-
</Style>
164-
</Expander.Style>
155+
<Expander Header="Editor Settings"
156+
Padding="0 5 0 0"
157+
BorderThickness="0 0 0 1"
158+
IsExpanded="True"
159+
BorderBrush="{DynamicResource BackgroundBrush}"
160+
Grid.Row="1">
161+
<Expander.Style>
162+
<Style TargetType="{x:Type Expander}"
163+
BasedOn="{StaticResource {x:Type Expander}}">
164+
<Setter Property="Tag"
165+
Value="{StaticResource ExpandRightIcon}" />
166+
<Style.Triggers>
167+
<Trigger Property="IsExpanded"
168+
Value="True">
169+
<Setter Property="Tag"
170+
Value="{StaticResource ExpandDownIcon}" />
171+
</Trigger>
172+
</Style.Triggers>
173+
</Style>
174+
</Expander.Style>
165175

166-
<local:EditorSettingsView />
167-
</Expander>
168-
</Grid>
169-
</ScrollViewer>
176+
<local:EditorSettingsView />
177+
</Expander>
178+
</Grid>
179+
</ScrollViewer>
180+
</Grid>
170181
</Expander>
171182

172183
<!--INFORMATION-->
@@ -236,7 +247,8 @@
236247
<TextBlock ToolTip="The estimated frame rate. (my be buggy)">
237248
<TextBlock.Inlines>
238249
<Run Text="FPS: " />
239-
<Run Foreground="LawnGreen" Name="FPSText" />
250+
<Run Foreground="LawnGreen"
251+
Name="FPSText" />
240252
</TextBlock.Inlines>
241253
</TextBlock>
242254
</StackPanel>

Examples/Nodify.Playground/PlaygroundSettings.cs

Lines changed: 27 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,16 +1,25 @@
11
using System.Collections.Generic;
2-
using System.Collections.ObjectModel;
2+
using System.Linq;
33
using System.Windows;
44

55
namespace Nodify.Playground
66
{
77
public class PlaygroundSettings : ObservableObject
88
{
9-
public IReadOnlyCollection<ISettingViewModel> Settings { get; }
9+
private readonly IReadOnlyCollection<ISettingViewModel> _settings;
10+
public IEnumerable<ISettingViewModel> Settings => FilterAndSort(_settings);
11+
12+
private string? _searchText;
13+
public string? SearchText
14+
{
15+
get => _searchText;
16+
set => SetProperty(ref _searchText, value)
17+
.Then(() => OnPropertyChanged(nameof(Settings)));
18+
}
1019

1120
private PlaygroundSettings()
1221
{
13-
Settings = new ObservableCollection<ISettingViewModel>()
22+
_settings = new List<ISettingViewModel>()
1423
{
1524
new ProxySettingViewModel<EditorGesturesMappings>(
1625
() => Instance.EditorGesturesMappings,
@@ -79,6 +88,21 @@ private PlaygroundSettings()
7988
};
8089
}
8190

91+
public IEnumerable<ISettingViewModel> FilterAndSort(IReadOnlyCollection<ISettingViewModel> settings)
92+
{
93+
if (string.IsNullOrWhiteSpace(SearchText))
94+
{
95+
return settings;
96+
}
97+
98+
string searchText = SearchText!.ToLowerInvariant();
99+
100+
var matchingValues = settings.Where(s => s.Name.ToLowerInvariant().Contains(searchText) || (s.Description?.ToLowerInvariant()?.Contains(searchText) ?? false));
101+
var sortedValues = matchingValues.OrderByDescending(s => s.Name.ToLowerInvariant().Contains(searchText));
102+
103+
return sortedValues;
104+
}
105+
82106
public static PlaygroundSettings Instance { get; } = new PlaygroundSettings();
83107

84108
private EditorGesturesMappings _editorGesturesMappings;

0 commit comments

Comments
 (0)