From 98793bd27eea265556f7a9cb11553186b3c87adb Mon Sep 17 00:00:00 2001 From: Ivo Petrov <48355182+ivaylo-matov@users.noreply.github.com> Date: Tue, 24 Sep 2024 15:55:21 +0100 Subject: [PATCH] [DYN-7466] Navigate-to-corresponding-node/group-by-clicking-it-in-the-TuneUp-list (#61) * centers on groups * mid progress record * works - option 1 * draft for PR * comments removed * Update ProfiledNodeViewModel.cs --- TuneUp/ProfiledNodeViewModel.cs | 61 ++++++++++++++------------------- TuneUp/TuneUpWindow.xaml.cs | 43 ++++++++++++++--------- TuneUp/TuneUpWindowViewModel.cs | 1 - 3 files changed, 51 insertions(+), 54 deletions(-) diff --git a/TuneUp/ProfiledNodeViewModel.cs b/TuneUp/ProfiledNodeViewModel.cs index d6848e7..e6f06d2 100644 --- a/TuneUp/ProfiledNodeViewModel.cs +++ b/TuneUp/ProfiledNodeViewModel.cs @@ -15,7 +15,7 @@ namespace TuneUp public class ProfiledNodeViewModel : NotificationObject { #region Properties - + /// /// Checks if the Node has been Renamed after its creation /// @@ -46,9 +46,7 @@ public string OriginalName { get { - //string originalName = NodeModel.GetOriginalName(); - string originalName = GetOriginalName(NodeModel); - return originalName; + return GetOriginalName(NodeModel); } internal set { @@ -62,23 +60,16 @@ internal set /// /// Indicates whether this node represents the total execution time for its group /// - public bool IsGroupExecutionTime - { - get => isGroupExecutionTime; - set - { - isGroupExecutionTime = value; - RaisePropertyChanged(nameof(IsGroupExecutionTime)); - } - } - private bool isGroupExecutionTime = false; + public bool IsGroupExecutionTime => NodeModel == null && GroupModel == null; /// /// Prefix string of execution time. /// - public static readonly string ExecutionTimelString = "Execution Time"; - public static readonly string GroupNodePrefix = "Group: "; - public static readonly string GroupExecutionTimeString = "Group total"; + internal const string ExecutionTimelString = "Execution Time"; + internal const string GroupNodePrefix = "Group: "; + internal const string GroupExecutionTimeString = "Group total"; + private const string DefaultGroupName = "Title "; + private const string DefaultDisplayGroupName = "Title"; private string name = String.Empty; /// @@ -90,11 +81,19 @@ public string Name { get { - // For virtual row, do not attempt to grab node name - if (!name.Contains(ExecutionTimelString) && - !name.StartsWith(GroupNodePrefix) && - !name.Equals(GroupExecutionTimeString)) - name = NodeModel?.Name; + // For virtual row, do not attempt to grab node or group name if it's already handled + if (!this.IsGroupExecutionTime) + { + if (NodeModel != null) + { + return NodeModel.Name; + } + else if (GroupModel != null) + { + return GroupModel.AnnotationText == DefaultGroupName ? + $"{GroupNodePrefix}{DefaultDisplayGroupName}" : GroupModel.AnnotationText; + } + } return name; } internal set { name = value; } @@ -233,16 +232,7 @@ public string GroupName /// /// Indicates if this node is a group /// - public bool IsGroup - { - get => isGroup; - set - { - isGroup = value; - RaisePropertyChanged(nameof(IsGroup)); - } - } - private bool isGroup; + public bool IsGroup => NodeModel == null && GroupModel != null; public bool ShowGroupIndicator { @@ -297,6 +287,8 @@ public string StateDescription internal NodeModel NodeModel { get; set; } + internal AnnotationModel GroupModel { get; set; } + #endregion /// @@ -371,7 +363,6 @@ public ProfiledNodeViewModel(NodeModel node) /// state which determine grouping public ProfiledNodeViewModel(string name, TimeSpan exTimeSum, ProfiledNodeState state) { - NodeModel = null; this.Name = name; this.ExecutionTime = exTimeSum; State = state; @@ -383,12 +374,10 @@ public ProfiledNodeViewModel(string name, TimeSpan exTimeSum, ProfiledNodeState /// the annotation model public ProfiledNodeViewModel(AnnotationModel group) { - NodeModel = null; - Name = $"{GroupNodePrefix}{group.AnnotationText}"; + GroupModel = group; GroupName = group.AnnotationText; GroupGUID = group.GUID; BackgroundBrush = new SolidColorBrush((Color)ColorConverter.ConvertFromString(group.Background)); - IsGroup = true; State = ProfiledNodeState.NotExecuted; ShowGroupIndicator = true; } diff --git a/TuneUp/TuneUpWindow.xaml.cs b/TuneUp/TuneUpWindow.xaml.cs index 23b8a12..2b11968 100644 --- a/TuneUp/TuneUpWindow.xaml.cs +++ b/TuneUp/TuneUpWindow.xaml.cs @@ -1,5 +1,4 @@ using System; -using System.Collections.Generic; using System.ComponentModel; using System.Globalization; using System.Linq; @@ -8,7 +7,7 @@ using System.Windows.Data; using System.Windows.Media; using Dynamo.Extensions; -using Dynamo.Graph.Nodes; +using Dynamo.Graph; using Dynamo.Models; using Dynamo.UI; using Dynamo.Utilities; @@ -53,29 +52,39 @@ public TuneUpWindow(ViewLoadedParams vlp, string id) } private void NodeAnalysisTable_SelectionChanged(object sender, SelectionChangedEventArgs e) - { + { if (!isUserInitiatedSelection) return; - // Get NodeModel(s) that correspond to selected row(s) - var selectedNodes = new List(); - foreach (var item in e.AddedItems) + var selectedItem = e.AddedItems.OfType().FirstOrDefault(); + + if (selectedItem == null) return; + + // Extract the GUID and type (NodeModel or GroupModel) + var modelBase = selectedItem.NodeModel ?? (ModelBase)selectedItem.GroupModel; + + if (modelBase != null) { - // Check NodeModel valid before actual selection - var nodeModel = (item as ProfiledNodeViewModel).NodeModel; - if (nodeModel != null) + // Clear the selection in other DataGrids based on the sender + if (sender == LatestRunTable) { - selectedNodes.Add(nodeModel); + NotExecutedTable.SelectedItem = null; + PreviousRunTable.SelectedItem = null; + } + else if (sender == NotExecutedTable) + { + LatestRunTable.SelectedItem = null; + PreviousRunTable.SelectedItem = null; + } + else if (sender == PreviousRunTable) + { + LatestRunTable.SelectedItem = null; + NotExecutedTable.SelectedItem = null; } - } - if (selectedNodes.Count() > 0) - { - // Select - var command = new DynamoModel.SelectModelCommand(selectedNodes.Select(nm => nm.GUID), ModifierKeys.None); + var command = new DynamoModel.SelectModelCommand(new[] { modelBase.GUID }, ModifierKeys.None); commandExecutive.ExecuteCommand(command, uniqueId, "TuneUp"); - // Focus on selected - viewModelCommandExecutive.FindByIdCommand(selectedNodes.First().GUID.ToString()); + viewModelCommandExecutive.FindByIdCommand(modelBase.GUID.ToString()); } } diff --git a/TuneUp/TuneUpWindowViewModel.cs b/TuneUp/TuneUpWindowViewModel.cs index b2b3194..81c7716 100644 --- a/TuneUp/TuneUpWindowViewModel.cs +++ b/TuneUp/TuneUpWindowViewModel.cs @@ -898,7 +898,6 @@ private ProfiledNodeViewModel CreateGroupTotalTimeNode(ProfiledNodeViewModel pro GroupGUID = profiledGroup.GroupGUID, GroupName = profiledGroup.GroupName, BackgroundBrush = profiledGroup.BackgroundBrush, - IsGroupExecutionTime = true, ShowGroupIndicator = true };