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 4 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
42 changes: 35 additions & 7 deletions src/GraphMetadataViewExtension/GraphMetadataViewModel.cs
Original file line number Diff line number Diff line change
@@ -1,13 +1,13 @@
using System;
using System.Collections.ObjectModel;
using System.IO;
using System.Linq;
using System.Windows.Media.Imaging;
using Dynamo.Core;
using Dynamo.Graph.Workspaces;
using Dynamo.GraphMetadata.Controls;
using Dynamo.Linting;
using Dynamo.UI.Commands;
using Dynamo.ViewModels;
using Dynamo.Wpf.Extensions;

namespace Dynamo.GraphMetadata
Expand Down Expand Up @@ -114,10 +114,9 @@ public GraphMetadataViewModel(ViewLoadedParams viewLoadedParams, GraphMetadataVi
this.linterManager = viewLoadedParams.StartupParams.LinterManager;

this.viewLoadedParams.CurrentWorkspaceChanged += OnCurrentWorkspaceChanged;
// using this as CurrentWorkspaceChanged wont trigger if you:
// Close a saved workspace and open a New homeworkspace..
// This means that properties defined in the previous opened workspace will still be showed in the extension.
// CurrentWorkspaceCleared will trigger everytime a graph is closed which allows us to reset the properties.
// Using this as CurrentWorkspaceChanged won't trigger if you close a saved workspace and open a new homeworkspace.
// This means that properties defined in the previous opened workspace will still be shown in the extension.
// CurrentWorkspaceCleared will trigger every time a graph is closed which allows us to reset the properties.
this.viewLoadedParams.CurrentWorkspaceCleared += OnCurrentWorkspaceChanged;
if (linterManager != null)
{
Expand All @@ -128,21 +127,41 @@ public GraphMetadataViewModel(ViewLoadedParams viewLoadedParams, GraphMetadataVi
InitializeCommands();
}

/// <summary>
/// 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.
/// </summary>
private void OnCurrentWorkspaceChanged(Graph.Workspaces.IWorkspaceModel obj)
{
if (!(obj is HomeWorkspaceModel hwm))
//Todo review if the workspace properties should be managed in the Workspace model.
//Due to the fact that Dynamo often leaves the workspace objects 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 properties with the clearing logic.

//Handle the case of a custom workspace model opening
if (obj is not HomeWorkspaceModel hwm)
QilongTang marked this conversation as resolved.
Show resolved Hide resolved
{
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 +171,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,7 +236,15 @@ 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;
do
{
propName = Properties.Resources.CustomPropertyControl_CustomPropertyDefault + " " + increment;
increment++;
}
while (CustomProperties.Any(x => x.PropertyName == propName));

AddCustomProperty(propName, string.Empty);
}

Expand Down
Loading