Skip to content

Commit

Permalink
[DYN-7466] Navigate-to-corresponding-node/group-by-clicking-it-in-the…
Browse files Browse the repository at this point in the history
…-TuneUp-list (#61)

* centers on groups

* mid progress record

* works - option 1

* draft for PR

* comments removed

* Update ProfiledNodeViewModel.cs
  • Loading branch information
ivaylo-matov authored Sep 24, 2024
1 parent e5547c9 commit 98793bd
Show file tree
Hide file tree
Showing 3 changed files with 51 additions and 54 deletions.
61 changes: 25 additions & 36 deletions TuneUp/ProfiledNodeViewModel.cs
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ namespace TuneUp
public class ProfiledNodeViewModel : NotificationObject
{
#region Properties

/// <summary>
/// Checks if the Node has been Renamed after its creation
/// </summary>
Expand Down Expand Up @@ -46,9 +46,7 @@ public string OriginalName
{
get
{
//string originalName = NodeModel.GetOriginalName();
string originalName = GetOriginalName(NodeModel);
return originalName;
return GetOriginalName(NodeModel);
}
internal set
{
Expand All @@ -62,23 +60,16 @@ internal set
/// <summary>
/// Indicates whether this node represents the total execution time for its group
/// </summary>
public bool IsGroupExecutionTime
{
get => isGroupExecutionTime;
set
{
isGroupExecutionTime = value;
RaisePropertyChanged(nameof(IsGroupExecutionTime));
}
}
private bool isGroupExecutionTime = false;
public bool IsGroupExecutionTime => NodeModel == null && GroupModel == null;

/// <summary>
/// Prefix string of execution time.
/// </summary>
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 <Double click here to edit group title>";
private const string DefaultDisplayGroupName = "Title";

private string name = String.Empty;
/// <summary>
Expand All @@ -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; }
Expand Down Expand Up @@ -233,16 +232,7 @@ public string GroupName
/// <summary>
/// Indicates if this node is a group
/// </summary>
public bool IsGroup
{
get => isGroup;
set
{
isGroup = value;
RaisePropertyChanged(nameof(IsGroup));
}
}
private bool isGroup;
public bool IsGroup => NodeModel == null && GroupModel != null;

public bool ShowGroupIndicator
{
Expand Down Expand Up @@ -297,6 +287,8 @@ public string StateDescription

internal NodeModel NodeModel { get; set; }

internal AnnotationModel GroupModel { get; set; }

#endregion

/// <summary>
Expand Down Expand Up @@ -371,7 +363,6 @@ public ProfiledNodeViewModel(NodeModel node)
/// <param name="state">state which determine grouping</param>
public ProfiledNodeViewModel(string name, TimeSpan exTimeSum, ProfiledNodeState state)
{
NodeModel = null;
this.Name = name;
this.ExecutionTime = exTimeSum;
State = state;
Expand All @@ -383,12 +374,10 @@ public ProfiledNodeViewModel(string name, TimeSpan exTimeSum, ProfiledNodeState
/// <param name="group">the annotation model</param>
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;
}
Expand Down
43 changes: 26 additions & 17 deletions TuneUp/TuneUpWindow.xaml.cs
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Globalization;
using System.Linq;
Expand All @@ -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;
Expand Down Expand Up @@ -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<NodeModel>();
foreach (var item in e.AddedItems)
var selectedItem = e.AddedItems.OfType<ProfiledNodeViewModel>().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());
}
}

Expand Down
1 change: 0 additions & 1 deletion TuneUp/TuneUpWindowViewModel.cs
Original file line number Diff line number Diff line change
Expand Up @@ -898,7 +898,6 @@ private ProfiledNodeViewModel CreateGroupTotalTimeNode(ProfiledNodeViewModel pro
GroupGUID = profiledGroup.GroupGUID,
GroupName = profiledGroup.GroupName,
BackgroundBrush = profiledGroup.BackgroundBrush,
IsGroupExecutionTime = true,
ShowGroupIndicator = true
};

Expand Down

0 comments on commit 98793bd

Please sign in to comment.