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
17 changes: 8 additions & 9 deletions src/DynamoCoreWpf/UI/Themes/Modern/DynamoModern.xaml
Original file line number Diff line number Diff line change
Expand Up @@ -486,15 +486,14 @@
Background="#535353"
BorderBrush="{DynamicResource MidLightBlueBrush}"
BorderThickness="0,6,0,0" />
<ScrollViewer Margin="0,6,0,6" SnapsToDevicePixels="True">
<StackPanel KeyboardNavigation.DirectionalNavigation="Contained">
<ContentControl x:Name="SearchSlot"
Content="{TemplateBinding Tag}"
Visibility="{Binding Content, RelativeSource={RelativeSource Self}, Converter={StaticResource NullToVisibiltyConverter}}"
/>

<StackPanel IsItemsHost="True" />
</StackPanel>
<ContentControl x:Name="SearchSlot"
Content="{TemplateBinding Tag}"
Visibility="{Binding Content, RelativeSource={RelativeSource Self}, Converter={StaticResource NullToVisibiltyConverter}}"
Margin="0,6,0,0"
VerticalAlignment="Top"/>
<ScrollViewer Margin="0,36,0,0" SnapsToDevicePixels="True">
<StackPanel KeyboardNavigation.DirectionalNavigation="Contained"
IsItemsHost="True" />
</ScrollViewer>
</Grid>
</Popup>
Expand Down
Original file line number Diff line number Diff line change
@@ -1,39 +1,39 @@
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Diagnostics;
using System.IO;
using System.Linq;
using System.Reflection;
using System.Text.RegularExpressions;
using System.Threading.Tasks;
using System.Windows.Data;
using System.Windows.Media;
using Dynamo.Configuration;
using Dynamo.Engine;
using Dynamo.Graph;
using Dynamo.Graph.Connectors;
using Dynamo.Graph.Nodes;
using Dynamo.Graph.Nodes.CustomNodes;
using Dynamo.Graph.Nodes.ZeroTouch;
using Dynamo.Graph.Workspaces;
using Dynamo.Logging;
using Dynamo.Models;
using Dynamo.NodeAutoComplete.Services;
using Dynamo.PackageManager;
using Dynamo.Properties;
using Dynamo.Search;
using Dynamo.Search.SearchElements;
using Dynamo.Utilities;
using Dynamo.ViewModels;
using Dynamo.Wpf.Utilities;
using Dynamo.Wpf.ViewModels;
using Greg;
using Newtonsoft.Json;
using ProtoCore.AST.AssociativeAST;
using ProtoCore.Mirror;
using ProtoCore.Utils;
using RestSharp;
using Dynamo.Wpf.Utilities;
using Dynamo.ViewModels;
using System.Reflection;
using Dynamo.Graph.Workspaces;
using Dynamo.Graph;
using System.Windows.Media;
using System.ComponentModel;
using System.Windows.Data;
using Dynamo.NodeAutoComplete.Services;

namespace Dynamo.NodeAutoComplete.ViewModels
{
Expand All @@ -51,6 +51,7 @@ public class NodeAutoCompleteBarViewModel : SearchViewModel
private const string nodeClusterAutocompleteMLEndpoint = "MLNodeClusterAutocomplete";
private const double minClusterConfidenceScore = 0.001;
private static Assembly dynamoCoreWpfAssembly;
private string lastSerializedAddedCluster = null;

private bool _isSingleAutocomplete;
public bool IsInput => PortViewModel.PortType == PortType.Input;
Expand Down Expand Up @@ -157,7 +158,7 @@ internal IEnumerable<DNADropdownViewModel> DropdownResults
/// Return the filter associated currently with dropdown results.
/// </summary>
public ICollectionView FilteredView { get; set; }

/// <summary>
/// Return the qualified results from the ML service above preferred confidence threshold
/// </summary>
Expand Down Expand Up @@ -228,9 +229,14 @@ public string SearchInput
_searchInput = value;

if (FilteredView != null)
{
{
FilteredView.Refresh();
}
if (FilteredView.Cast<DNADropdownViewModel>().Any())
{
SelectedIndex = 0;
RefocusSearchBox?.Invoke();
}

RaisePropertyChanged(nameof(SearchInput));
}
Expand Down Expand Up @@ -262,6 +268,26 @@ public int SelectedIndex
}
}
}
bool isDropDownOpen = false;
public bool IsDropDownOpen
{
get
{
return isDropDownOpen;
}
set
{
if (isDropDownOpen != value)
{
isDropDownOpen = value;
if (value)
{
RefocusSearchBox?.Invoke();
}
RaisePropertyChanged(nameof(IsDropDownOpen));
}
}
}

internal void ConsolidateTransientNodes()
{
Expand Down Expand Up @@ -380,6 +406,7 @@ public bool IsDNAClusterPlacementEnabled
}

internal event Action<NodeModel> ParentNodeRemoved;
internal event Action RefocusSearchBox;

internal MLNodeClusterAutoCompletionResponse FullResults { private set; get; }
private Guid LastRequestGuid;
Expand Down Expand Up @@ -413,7 +440,8 @@ internal void ResetAutoCompleteSearchViewState()
FilteredResults = new List<NodeSearchElementViewModel>();
FilteredHighConfidenceResults = new List<NodeSearchElementViewModel>();
FilteredLowConfidenceResults = new List<NodeSearchElementViewModel>();
SearchInput = string.Empty;
SearchInput = string.Empty;
lastSerializedAddedCluster = null;
}

internal MLNodeAutoCompletionRequest GenerateRequestForMLAutocomplete()
Expand Down Expand Up @@ -500,7 +528,7 @@ internal MLNodeAutoCompletionRequest GenerateRequestForMLAutocomplete()

if (startNode.Equals(nodeInfo) || endNode.Equals(nodeInfo) || upstreamAndDownstreamNodes.Contains(startNode) || upstreamAndDownstreamNodes.Contains(endNode))
{
var startPortName = (startNode is VariableInputNode || startNode is DSVarArgFunction) ? ParseVariableInputPortName(connector.Start.Name): connector.Start.Name;
var startPortName = (startNode is VariableInputNode || startNode is DSVarArgFunction) ? ParseVariableInputPortName(connector.Start.Name) : connector.Start.Name;
var endPortName = (endNode is VariableInputNode || endNode is DSVarArgFunction) ? ParseVariableInputPortName(connector.End.Name) : connector.End.Name;

var connectorRequest = new ConnectionItem
Expand Down Expand Up @@ -570,7 +598,7 @@ private IEnumerable<SingleResultItem> GetNodeAutocompleMLResults()

// Set PortToConnect for each element based on port-index and port-name
nodeSearchElement.AutoCompletionNodeElementInfo = new AutoCompletionNodeElementInfo
{
{
PortToConnect = portIndex
};

Expand Down Expand Up @@ -621,7 +649,7 @@ private IEnumerable<SingleResultItem> GetNodeAutocompleMLResults()


private T GetGenericAutocompleteResult<T>(string endpoint)
{
{
var requestDTO = GenerateRequestForMLAutocomplete();
var jsonRequest = JsonConvert.SerializeObject(requestDTO);

Expand Down Expand Up @@ -795,14 +823,23 @@ internal void AddCluster(int filterredIndex)
var currentFilter = FilteredView.Cast<DNADropdownViewModel>().ToList();
var currentItem = filterredIndex >= 0 && filterredIndex < currentFilter.Count ? currentFilter[filterredIndex] : null;

AddCluster(currentItem.ClusterResultItem);
if (currentItem?.ClusterResultItem != null)
{
AddCluster(currentItem.ClusterResultItem);
}
}

// Add Cluster from server result into the workspace
internal void AddCluster(ClusterResultItem clusterResultItem)
{
if (clusterResultItem == null || clusterResultItem.Topology == null)
return;
var nextCluster = JsonConvert.SerializeObject(clusterResultItem);
if (lastSerializedAddedCluster == nextCluster)
{
return; // Avoid adding the same cluster multiple times when filtered items dont change
}
lastSerializedAddedCluster = nextCluster;

List<ModelBase> createdClusterItems = new List<ModelBase>();

Expand Down Expand Up @@ -833,7 +870,7 @@ internal void AddCluster(ClusterResultItem clusterResultItem)
var typeInfo = new NodeModelTypeId(nodeItem.Type.Id);

NodeModel newNode = dynamoModel.CreateNodeFromNameOrType(Guid.NewGuid(), typeInfo.FullName, true);

if (newNode != null)
{
newNode.X = offset; // Adjust X position
Expand All @@ -856,7 +893,7 @@ internal void AddCluster(ClusterResultItem clusterResultItem)
if (PortViewModel.PortType == PortType.Output)
{
var portIndex = clusterResultItem.EntryNodeInPort;
if (entryNode.InPorts.Count > portIndex &&!entryNode.InPorts[portIndex].Connectors.Any())
if (entryNode.InPorts.Count > portIndex && !entryNode.InPorts[portIndex].Connectors.Any())
{
entryConnector = ConnectorModel.Make(PortViewModel.NodeViewModel.NodeModel, entryNode, PortViewModel.PortModel.Index, portIndex);
}
Expand Down Expand Up @@ -946,7 +983,7 @@ internal void PopulateAutoComplete()
ResetAutoCompleteSearchViewState();

FullResults = null;
if(DropdownResults != null)
if (DropdownResults != null)
{
DropdownResults = null;
}
Expand Down Expand Up @@ -979,7 +1016,7 @@ internal void PopulateAutoComplete()

dynamoViewModel.UIDispatcher.BeginInvoke(() =>
{
if(LastRequestGuid != myRequest)
if (LastRequestGuid != myRequest)
{
//a newer request came, we're no longer interested in the results of this one
//only latest request has the right to be committed to the UI and internal data structures
Expand Down Expand Up @@ -1029,11 +1066,11 @@ internal void PopulateAutoComplete()
}
// this runs synchronously on the UI thread, so the UI can't disappear during execution
DropdownResults = comboboxResults;
if (comboboxResults.Any())
IsDropDownOpen = true;
if (FilteredView.Cast<DNADropdownViewModel>().Any())
{
SelectedIndex = 0;
}

});
});
//Tracking Analytics when raising Node Autocomplete with the Recommended Nodes option selected (Machine Learning)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -162,6 +162,7 @@
FontFamily="{StaticResource ArtifaktElementRegular}"
Foreground="{StaticResource DefaultSearchTextBlockText}"
ItemsSource="{Binding FilteredView, NotifyOnTargetUpdated=True}"
IsDropDownOpen="{Binding IsDropDownOpen, Mode=TwoWay}"
Visibility="{Binding ResultsLoaded, UpdateSourceTrigger=PropertyChanged, Converter={StaticResource BooleanToVisibilityConverter}}"
TabIndex="0"
>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,14 @@ internal void ReloadDataContext(NodeAutoCompleteBarViewModel dataContext)
LoadAndPopulate();
}

private void OnRefocusSearchbox()
{
Dispatcher.BeginInvoke(new Action(() =>
{
AutoCompleteSearchBox.Focus();
Comment thread
chubakueno marked this conversation as resolved.
}), DispatcherPriority.ApplicationIdle);
}

private void SubscribeEvents()
{
if (string.IsNullOrEmpty(DynamoModel.HostAnalyticsInfo.HostName) && Application.Current != null)
Expand All @@ -46,6 +54,7 @@ private void SubscribeEvents()
}
HomeWorkspaceModel.WorkspaceClosed += CloseAutoComplete;
ViewModel.ParentNodeRemoved += OnParentNodeRemoved;
ViewModel.RefocusSearchBox += OnRefocusSearchbox;
}

private void UnsubscribeEvents(object sender, System.ComponentModel.CancelEventArgs e)
Expand All @@ -59,6 +68,7 @@ private void UnsubscribeEvents(object sender, System.ComponentModel.CancelEventA
}
HomeWorkspaceModel.WorkspaceClosed -= CloseAutoComplete;
ViewModel.ParentNodeRemoved -= OnParentNodeRemoved;
ViewModel.RefocusSearchBox -= OnRefocusSearchbox;
}

private void LoadAndPopulate()
Expand Down
Loading