Skip to content

Commit 71846e9

Browse files
BogdanZavuzavub
andauthored
DYN-9999 : dna filtering improvements (#16281)
Co-authored-by: Bogdan Zavu <bogdan.zavu@autodesk.com>
1 parent b4977e4 commit 71846e9

6 files changed

Lines changed: 94 additions & 41 deletions

File tree

src/DynamoCoreWpf/PublicAPI.Unshipped.txt

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -373,6 +373,10 @@ Dynamo.Controls.LeftThicknessConverter
373373
Dynamo.Controls.LeftThicknessConverter.Convert(object value, System.Type targetType, object parameter, System.Globalization.CultureInfo culture) -> object
374374
Dynamo.Controls.LeftThicknessConverter.ConvertBack(object value, System.Type targetType, object parameter, System.Globalization.CultureInfo culture) -> object
375375
Dynamo.Controls.LeftThicknessConverter.LeftThicknessConverter() -> void
376+
Dynamo.Controls.LengthToVisibilityConverter
377+
Dynamo.Controls.LengthToVisibilityConverter.Convert(object value, System.Type targetType, object parameter, System.Globalization.CultureInfo culture) -> object
378+
Dynamo.Controls.LengthToVisibilityConverter.ConvertBack(object value, System.Type targetType, object parameter, System.Globalization.CultureInfo culture) -> object
379+
Dynamo.Controls.LengthToVisibilityConverter.LengthToVisibilityConverter() -> void
376380
Dynamo.Controls.LibraryTreeItemsHostVisibilityConverter
377381
Dynamo.Controls.LibraryTreeItemsHostVisibilityConverter.Convert(object value, System.Type targetType, object parameter, System.Globalization.CultureInfo culture) -> object
378382
Dynamo.Controls.LibraryTreeItemsHostVisibilityConverter.ConvertBack(object value, System.Type targetType, object parameter, System.Globalization.CultureInfo culture) -> object

src/DynamoCoreWpf/UI/Converters.cs

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4310,4 +4310,20 @@ public object ConvertBack(object value, Type targetType, object parameter, Cultu
43104310
return Binding.DoNothing;
43114311
}
43124312
}
4313+
4314+
public class LengthToVisibilityConverter : IValueConverter
4315+
{
4316+
public object Convert(object value, Type targetType, object parameter, CultureInfo culture)
4317+
{
4318+
if (value is int length)
4319+
return length > 0 ? Visibility.Collapsed : Visibility.Visible;
4320+
4321+
return Visibility.Visible;
4322+
}
4323+
4324+
public object ConvertBack(object value, Type targetType, object parameter, CultureInfo culture)
4325+
{
4326+
throw new NotImplementedException();
4327+
}
4328+
}
43134329
}

src/DynamoCoreWpf/UI/Themes/Modern/DynamoConverters.xaml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -176,4 +176,5 @@
176176
<controls:PortTypeToStringConverter x:Key="PortTypeToStringConverter" />
177177
<controls:BooleanNegationConverter x:Key="BooleanNegationConverter" />
178178
<controls:LeftMarginConverter x:Key="LeftMarginConverter" />
179+
<controls:LengthToVisibilityConverter x:Key="LengthToVisibilityConverter" />
179180
</ResourceDictionary>

src/NodeAutoCompleteViewExtension/ViewModels/NodeAutoCompleteBarViewModel.cs

Lines changed: 28 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -191,7 +191,7 @@ public bool IsOpen
191191
}
192192
}
193193

194-
private int ClusterResultsCount => DropdownResults == null ? 0 : DropdownResults.Count();
194+
private int ClusterResultsCount => FilteredView == null ? 0 : FilteredView.Cast<object>().ToList().Count;
195195

196196
private int selectedIndex = 0;
197197

@@ -231,6 +231,8 @@ public string SearchInput
231231
{
232232
FilteredView.Refresh();
233233
}
234+
235+
RaisePropertyChanged(nameof(SearchInput));
234236
}
235237
}
236238

@@ -245,30 +247,19 @@ public int SelectedIndex
245247
}
246248
set
247249
{
248-
/*don't try to add a node if the index is out of range or a selection is not made yet (-1)
249-
an index of -1 occurs when using the switch to change between modes.*/
250-
if (selectedIndex != value && value >= 0 && selectedIndex != -1)
250+
if (selectedIndex != value && value >= -1)
251251
{
252-
ReAddNode(value);
253-
}
254-
selectedIndex = value;
255-
RaisePropertyChanged(nameof(SelectedIndex));
256-
RaisePropertyChanged(nameof(NthofTotal));
257-
RaisePropertyChanged(nameof(PreviousSource));
258-
RaisePropertyChanged(nameof(NextSource));
259-
}
260-
}
252+
selectedIndex = value;
253+
if (selectedIndex != -1)
254+
{
255+
AddCluster(selectedIndex);
256+
}
261257

262-
private void ReAddNode(int index)
263-
{
264-
if(FullResults == null)
265-
{
266-
return;
267-
}
268-
var results = QualifiedResults.ToList();
269-
if(index >= 0 && index < results.Count)
270-
{
271-
AddCluster(results[index]);
258+
RaisePropertyChanged(nameof(SelectedIndex));
259+
RaisePropertyChanged(nameof(NthofTotal));
260+
RaisePropertyChanged(nameof(PreviousSource));
261+
RaisePropertyChanged(nameof(NextSource));
262+
}
272263
}
273264
}
274265

@@ -426,6 +417,7 @@ internal void ResetAutoCompleteSearchViewState()
426417
FilteredResults = new List<NodeSearchElementViewModel>();
427418
FilteredHighConfidenceResults = new List<NodeSearchElementViewModel>();
428419
FilteredLowConfidenceResults = new List<NodeSearchElementViewModel>();
420+
SearchInput = string.Empty;
429421
}
430422

431423
internal MLNodeAutoCompletionRequest GenerateRequestForMLAutocomplete()
@@ -796,6 +788,19 @@ internal void DeleteTransientNodes()
796788
}
797789
}
798790

791+
792+
internal void AddCluster(int filterredIndex)
793+
{
794+
var currentFilter = FilteredView.Cast<DNADropdownViewModel>().ToList();
795+
var currentItem = filterredIndex >= 0 && filterredIndex < currentFilter.Count ? currentFilter[filterredIndex] : null;
796+
797+
var realCluster = QualifiedResults.FirstOrDefault(x => x.Description.Equals(currentItem.Description));
798+
if (realCluster != null)
799+
{
800+
AddCluster(realCluster);
801+
}
802+
}
803+
799804
// Add Cluster from server result into the workspace
800805
internal void AddCluster(ClusterResultItem clusterResultItem)
801806
{
@@ -1040,8 +1045,6 @@ internal void PopulateAutoComplete()
10401045
if (comboboxResults.Any())
10411046
{
10421047
SelectedIndex = 0;
1043-
var ClusterResultItem = QualifiedResults.First();
1044-
AddCluster(ClusterResultItem);
10451048
}
10461049

10471050
});

src/NodeAutoCompleteViewExtension/Views/NodeAutoCompleteBarView.xaml

Lines changed: 44 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@
66
xmlns:ui="clr-namespace:Dynamo.UI;assembly=DynamoCoreWpf"
77
xmlns:local="clr-namespace:Dynamo.PackageManager.UI;assembly=DynamoCoreWpf"
88
xmlns:dynconverters="clr-namespace:Dynamo.Controls;assembly=DynamoCoreWpf"
9+
xmlns:resxother="clr-namespace:Dynamo.Wpf.Properties;assembly=DynamoCoreWpf"
910
mc:Ignorable="d"
1011
WindowStyle="None"
1112
AllowsTransparency="True"
@@ -40,6 +41,7 @@
4041
</Style>
4142
<dynconverters:BoolToVisibilityConverter x:Key="BooleanToVisibilityConverter"/>
4243
<dynconverters:InverseBoolToVisibilityConverter x:Key="InverseBooleanToVisibilityConverter"/>
44+
<dynconverters:LengthToVisibilityConverter x:Key="LengthToVisibilityConverter"/>
4345
</ResourceDictionary>
4446
</Window.Resources>
4547

@@ -160,21 +162,48 @@
160162
</Style>
161163
</ComboBox.Style>
162164
<ComboBox.Tag>
163-
<TextBox x:Name="AutoCompleteSearchBox"
164-
HorizontalAlignment="Stretch"
165-
Height="24"
166-
Margin="16,5,16,5"
167-
Padding="2"
168-
Width="Auto"
169-
Foreground="{Binding Foreground, RelativeSource={RelativeSource AncestorType=ComboBox}}"
170-
Background="{Binding Background, RelativeSource={RelativeSource AncestorType=ComboBox}}"
171-
FontFamily="{Binding FontFamily, RelativeSource={RelativeSource AncestorType=ComboBox}}"
172-
CaretBrush="{Binding Foreground, RelativeSource={RelativeSource AncestorType=ComboBox}}"
173-
FontSize="14">
174-
<TextBox.Text>
175-
<Binding Path="SearchInput" Mode="OneWayToSource" UpdateSourceTrigger="PropertyChanged" />
176-
</TextBox.Text>
177-
</TextBox>
165+
<Grid>
166+
<TextBox x:Name="AutoCompleteSearchBox"
167+
HorizontalAlignment="Stretch"
168+
Height="28"
169+
Margin="7,3,7,3"
170+
Padding="2"
171+
Width="Auto"
172+
BorderThickness="0,0,0,1"
173+
Foreground="{Binding Foreground, RelativeSource={RelativeSource AncestorType=ComboBox}}"
174+
Background="{Binding Background, RelativeSource={RelativeSource AncestorType=ComboBox}}"
175+
FontFamily="{Binding FontFamily, RelativeSource={RelativeSource AncestorType=ComboBox}}"
176+
CaretBrush="{Binding Foreground, RelativeSource={RelativeSource AncestorType=ComboBox}}"
177+
FontSize="14">
178+
<TextBox.Text>
179+
<Binding Path="SearchInput" Mode="TwoWay" UpdateSourceTrigger="PropertyChanged" />
180+
</TextBox.Text>
181+
</TextBox>
182+
183+
<StackPanel x:Name="PlaceholderPanel"
184+
Orientation="Horizontal"
185+
VerticalAlignment="Center"
186+
IsHitTestVisible="False"
187+
HorizontalAlignment="Stretch"
188+
Height="28"
189+
Margin="12,3,7,3"
190+
Width="Auto"
191+
Visibility="{Binding Text.Length, ElementName=AutoCompleteSearchBox, Converter={StaticResource LengthToVisibilityConverter}}">
192+
<Image x:Name="SearchIcon"
193+
Width="20px"
194+
Height="20px"
195+
HorizontalAlignment="Left"
196+
VerticalAlignment="Center"
197+
DockPanel.Dock="Left">
198+
<Image.Style>
199+
<Style TargetType="{x:Type Image}">
200+
<Setter Property="Source" Value="/DynamoCoreWpf;component/UI/Images/searchmagnifier.png" />
201+
</Style>
202+
</Image.Style>
203+
</Image>
204+
<TextBlock Padding="2" FontSize="14" Text="{x:Static resxother:Resources.LibraryViewSearchText}" Foreground="{Binding Foreground, RelativeSource={RelativeSource AncestorType=ComboBox}}" VerticalAlignment="Center"/>
205+
</StackPanel>
206+
</Grid>
178207
</ComboBox.Tag>
179208
<ComboBox.ItemTemplate>
180209
<DataTemplate>

src/NodeAutoCompleteViewExtension/Views/NodeAutoCompleteBarView.xaml.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -75,7 +75,7 @@ private void GripHandle_MouseLeftButtonDown(object sender, MouseButtonEventArgs
7575

7676
private void MoveIndex(int step)
7777
{
78-
ViewModel.SelectedIndex = Math.Min(ViewModel.DropdownResults.Count() - 1, Math.Max(0, ViewModel.SelectedIndex + step));
78+
ViewModel.SelectedIndex = Math.Min(ViewModel.FilteredView.Cast<object>().Count() - 1, Math.Max(0, ViewModel.SelectedIndex + step));
7979
}
8080

8181
private void PrevButton_OnClick(object sender, RoutedEventArgs e)

0 commit comments

Comments
 (0)