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

DYN-6427 & DYN-6828 Graph Properties UI Fixes #15200

Merged
merged 8 commits into from
May 20, 2024
Merged
Changes from 2 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
34 changes: 33 additions & 1 deletion src/GraphMetadataViewExtension/GraphMetadataViewModel.cs
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
using System;
using System.Collections.ObjectModel;
using System.IO;
using System.Linq;
using System.Windows.Media.Imaging;
using Dynamo.Core;
using Dynamo.Graph.Workspaces;
Expand Down Expand Up @@ -130,19 +131,38 @@ public GraphMetadataViewModel(ViewLoadedParams viewLoadedParams, GraphMetadataVi

private void OnCurrentWorkspaceChanged(Graph.Workspaces.IWorkspaceModel obj)
{
//This event is triggered when a new workspace is opened or when the current workspace is cleared.
//This event manages state of the workspace properties (ie GraphDescription, GraphAuthor, HelpLink, Thumbnail)
//as well as the custom properties in the extension which do not live in the workspace model.

//Todo review if the workspace properties should be managed in the Workspace model.
//Do to the fact that Dynamo oftens leaves the workspace objs in memory and resets their properties when you open a new workspace
//the management of state is not straightforward. However it may make more sense to update those properteis with the clearing logic.

//Handle the case of a custom workspace model opening
if (!(obj is HomeWorkspaceModel hwm))
{
extension.Closed();
return;
}

//Handle workspace change cases in UI. First is a new workspace or template opening
//In this case the properties should be cleared
if (!hwm.IsTemplate && string.IsNullOrEmpty(hwm.FileName) )
{
GraphDescription = string.Empty;
GraphAuthor = string.Empty;
HelpLink = null;
Thumbnail = null;
}
//Second is switching between an open workspace and open custom node and no state changes are required.
//This case can also be true if you close an open workspace while focused on a custom node.
//However in that scenario the first case will be triggered first due to empty filename.
else if(hwm == currentWorkspace)
{
return;
}
//Third is a new workspace opening from a saved file
else
{
currentWorkspace = hwm;
Expand All @@ -152,6 +172,7 @@ private void OnCurrentWorkspaceChanged(Graph.Workspaces.IWorkspaceModel obj)
RaisePropertyChanged(nameof(Thumbnail));
}

//Clear custom properties for cases one and two.
CustomProperties.Clear();
}

Expand Down Expand Up @@ -216,8 +237,19 @@ private void OpenGraphStatusExecute(object obj)

private void AddCustomPropertyExecute(object obj)
{
var propName = Properties.Resources.CustomPropertyControl_CustomPropertyDefault + " " + (CustomProperties.Count + 1);
int increment = CustomProperties.Count + 1;
string propName = DefaultPropertyName(increment);

//Ensure the property name is unique
while (CustomProperties.Any(x => x.PropertyName == propName))
{
increment++;
propName = DefaultPropertyName(increment);
}

AddCustomProperty(propName, string.Empty);

string DefaultPropertyName(int number) => Properties.Resources.CustomPropertyControl_CustomPropertyDefault + " " + number;
}

internal void AddCustomProperty(string propertyName, string propertyValue, bool markChange = true)
Expand Down
Loading