Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Position node autocomplete UI against respective input port #11190

Merged
merged 11 commits into from
Oct 20, 2020
2 changes: 1 addition & 1 deletion src/DynamoCore/Core/DynamoSelection.cs
Original file line number Diff line number Diff line change
Expand Up @@ -160,7 +160,7 @@ public void AddRange(IEnumerable<T> range)
{
foreach (var item in range)
{
Items.Add(item);
Add(item);
}

this.OnPropertyChanged(new PropertyChangedEventArgs("Count"));
Expand Down
8 changes: 5 additions & 3 deletions src/DynamoCore/Graph/Nodes/NodeModel.cs
Original file line number Diff line number Diff line change
Expand Up @@ -64,12 +64,14 @@ public abstract class NodeModel : ModelBase, IRenderPackageSource<NodeModel>, ID
private ObservableCollection<PortModel> inPorts = new ObservableCollection<PortModel>();
private ObservableCollection<PortModel> outPorts = new ObservableCollection<PortModel>();

private readonly Dictionary<int, Tuple<int, NodeModel>> inputNodes;
private readonly Dictionary<int, HashSet<Tuple<int, NodeModel>>> outputNodes;

#endregion

#region public members
internal const double NodeHeaderHeight = 25;
aparajit-pratap marked this conversation as resolved.
Show resolved Hide resolved

private readonly Dictionary<int, Tuple<int, NodeModel>> inputNodes;
private readonly Dictionary<int, HashSet<Tuple<int, NodeModel>>> outputNodes;
#region public members

/// <summary>
/// The unique name that was created the node by
Expand Down
3 changes: 1 addition & 2 deletions src/DynamoCore/Graph/Nodes/PortModel.cs
Original file line number Diff line number Diff line change
Expand Up @@ -163,10 +163,9 @@ public Point2D Center
get
{
double halfHeight = Height * 0.5;
const double headerHeight = 25;

double offset = Owner.GetPortVerticalOffset(this);
double y = Owner.Y + headerHeight + 5 + halfHeight + offset;
double y = Owner.Y + NodeModel.NodeHeaderHeight + 5 + halfHeight + offset;
aparajit-pratap marked this conversation as resolved.
Show resolved Hide resolved

switch (PortType)
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -36,8 +36,16 @@ public NodeAutoCompleteSearchControl()
{
Application.Current.Deactivated += currentApplicationDeactivated;
}
Loaded += NodeAutoCompleteSearchControl_Loaded;
Unloaded += NodeAutoCompleteSearchControl_Unloaded;
}

private void NodeAutoCompleteSearchControl_Loaded(object sender, RoutedEventArgs e)
{
if(ViewModel != null && ViewModel.PortViewModel != null)
{
ViewModel.PortViewModel.PlaceNodeAutocompleteWindow(this, null);
}
}

private void NodeAutoCompleteSearchControl_Unloaded(object sender, RoutedEventArgs e)
Expand Down
32 changes: 28 additions & 4 deletions src/DynamoCoreWpf/ViewModels/Core/PortViewModel.cs
Original file line number Diff line number Diff line change
@@ -1,8 +1,10 @@
using System;
using System.Windows;
using System.Windows.Controls.Primitives;
using Dynamo.Graph.Nodes;
using Dynamo.Models;
using Dynamo.UI.Commands;
using Dynamo.UI.Controls;
using Dynamo.Utilities;

namespace Dynamo.ViewModels
Expand Down Expand Up @@ -226,6 +228,27 @@ public override void Dispose()
_node.WorkspaceViewModel.PropertyChanged -= Workspace_PropertyChanged;
}

internal void PlaceNodeAutocompleteWindow(object sender, EventArgs e)
aparajit-pratap marked this conversation as resolved.
Show resolved Hide resolved
{
var popup = sender as NodeAutoCompleteSearchControl;

double x;
if (PortModel.PortType == PortType.Input)
{
// Position node autocomplete UI offset left from X position of node by its width.
x = _node.X - popup.ActualWidth;
}
else
{
// Position node autocomplete UI offset right from X position of node by node width.
x = _node.X + _node.NodeModel.Width;
}
// Position UI down from the top of the node but offset by the node header and against the respective port.
var y = _node.Y + NodeModel.NodeHeaderHeight + PortModel.Index * PortModel.Height;
aparajit-pratap marked this conversation as resolved.
Show resolved Hide resolved

(popup.Parent as Popup).PlacementRectangle = new Rect(x, y, 0, 0);
}

private void Workspace_PropertyChanged(object sender, System.ComponentModel.PropertyChangedEventArgs e)
{
switch (e.PropertyName)
Expand Down Expand Up @@ -367,10 +390,11 @@ private bool CanConnect(object parameter)
// Handler to invoke node Auto Complete
private void AutoComplete(object parameter)
{
DynamoViewModel dynamoViewModel = _node.DynamoViewModel;
var svm = dynamoViewModel.CurrentSpaceViewModel.NodeAutoCompleteSearchViewModel as NodeAutoCompleteSearchViewModel;
svm.PortViewModel = parameter as PortViewModel;
dynamoViewModel.CurrentSpaceViewModel.OnRequestNodeAutoCompleteSearch(ShowHideFlags.Show);
var wsViewModel = _node.WorkspaceViewModel;
var svm = wsViewModel.NodeAutoCompleteSearchViewModel as NodeAutoCompleteSearchViewModel;
svm.PortViewModel = this;

wsViewModel.OnRequestNodeAutoCompleteSearch(ShowHideFlags.Show);
}

private bool CanAutoComplete(object parameter)
Expand Down
5 changes: 3 additions & 2 deletions src/DynamoCoreWpf/ViewModels/Core/WorkspaceViewModel.cs
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@
using System.IO;
using System.Linq;
using System.Windows;
using System.Windows.Controls.Primitives;
using System.Windows.Data;
using System.Windows.Input;
using Dynamo.Configuration;
Expand Down Expand Up @@ -163,9 +164,8 @@ private void OnRequestShowInCanvasSearch(object param)

internal event Action<ShowHideFlags> RequestNodeAutoCompleteSearch;

internal void OnRequestNodeAutoCompleteSearch(object param)
internal void OnRequestNodeAutoCompleteSearch(ShowHideFlags flag)
{
var flag = (ShowHideFlags)param;
RequestNodeAutoCompleteSearch?.Invoke(flag);
}

Expand Down Expand Up @@ -1401,6 +1401,7 @@ private void RefreshViewOnSelectionChange(object sender, NotifyCollectionChanged
RaisePropertyChanged("AnyNodeVisible");
RaisePropertyChanged("SelectionArgumentLacing");
}

}

public class ViewModelEventArgs : EventArgs
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
using System.Collections.Generic;
using System.Linq;
using Dynamo.Controls;
using Dynamo.Search.SearchElements;
using Dynamo.Wpf.ViewModels;

Expand All @@ -13,6 +12,7 @@ public class NodeAutoCompleteSearchViewModel : SearchViewModel
{
internal PortViewModel PortViewModel { get; set; }


aparajit-pratap marked this conversation as resolved.
Show resolved Hide resolved
internal NodeAutoCompleteSearchViewModel(DynamoViewModel dynamoViewModel) : base(dynamoViewModel)
{
// Do nothing for now, but we may off load some time consuming operation here later
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -290,10 +290,7 @@ protected virtual void CreateAndConnectToPort(object parameter)
DynamoSelection.Instance.ClearSelection();
var inputNodes = initialNode.InputNodes.Values.Where(x => x != null).Select(y => y.Item2);

foreach (var inputNode in inputNodes)
{
DynamoSelection.Instance.Selection.AddUnique(inputNode);
}
DynamoSelection.Instance.Selection.AddRange(inputNodes);
aparajit-pratap marked this conversation as resolved.
Show resolved Hide resolved
}

protected virtual bool CanCreateAndConnectToPort(object parameter)
Expand Down
2 changes: 0 additions & 2 deletions src/DynamoCoreWpf/Views/Core/WorkspaceView.xaml
Original file line number Diff line number Diff line change
Expand Up @@ -349,8 +349,6 @@
StaysOpen="True"
AllowsTransparency="True"
IsOpen="False"
Placement="MousePoint"
HorizontalOffset="-290"
aparajit-pratap marked this conversation as resolved.
Show resolved Hide resolved
DataContext="{Binding NodeAutoCompleteSearchViewModel}">
<ui:NodeAutoCompleteSearchControl RequestShowNodeAutoCompleteSearch="ShowHideNodeAutoCompleteControl" />
</Popup>
Expand Down
2 changes: 2 additions & 0 deletions src/DynamoCoreWpf/Views/Core/WorkspaceView.xaml.cs
Original file line number Diff line number Diff line change
Expand Up @@ -155,6 +155,7 @@ void OnWorkspaceViewUnloaded(object sender, RoutedEventArgs e)
if (ViewModel != null)
{
removeViewModelsubscriptions(ViewModel);
ViewModel.RequestNodeAutoCompleteSearch -= ShowHideNodeAutoCompleteControl;
aparajit-pratap marked this conversation as resolved.
Show resolved Hide resolved
}

infiniteGridView.DetachFromZoomBorder(zoomBorder);
Expand Down Expand Up @@ -186,6 +187,7 @@ private void ShowHidePopup(ShowHideFlags flag, Popup popup)
case ShowHideFlags.Show:
// Show InCanvas search just in case, when mouse is over workspace.
popup.IsOpen = DynamoModel.IsTestMode || IsMouseOver;

aparajit-pratap marked this conversation as resolved.
Show resolved Hide resolved
ViewModel.InCanvasSearchViewModel.SearchText = string.Empty;
ViewModel.InCanvasSearchViewModel.InCanvasSearchPosition = inCanvasSearchPosition;
break;
Expand Down