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- 6893 input and output nodes should not show in home workspace. #15257

Merged
merged 5 commits into from
May 29, 2024
Merged
Show file tree
Hide file tree
Changes from all 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
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,10 @@ class LoadedTypeItem
public string itemType { get; set; }
public string description { get; set; }
public string keywords { get; set; }
/// <summary>
/// controls if a type is shown in the library in the homeworkspace context.
/// </summary>
public bool hiddenInWorkspaceContext { get; set; }
}

class LoadedTypeData<T> where T : LoadedTypeItem
Expand All @@ -41,6 +45,9 @@ class NodeItemDataProvider : ResourceProviderBase
{
protected NodeSearchModel model;
private IconResourceProvider iconProvider;
readonly string[] typesToHideInHomeWorkspaces = {
typeof(Graph.Nodes.CustomNodes.Symbol).ToString(),
typeof(Graph.Nodes.CustomNodes.Output).ToString() };
/// <summary>
/// Constructor
/// </summary>
Expand Down Expand Up @@ -169,8 +176,12 @@ public static string GetFullyQualifiedName(NodeSearchElement element)
description = element.Description,
keywords = element.SearchKeywords.Any()
? element.SearchKeywords.Where(s => !string.IsNullOrEmpty(s)).Aggregate((x, y) => string.Format("{0}, {1}", x, y))
: string.Empty
: string.Empty,
};
if (typesToHideInHomeWorkspaces.Contains(element.CreationName))
{
item.hiddenInWorkspaceContext = true;
}

//If this element is not a custom node then we are done. The icon url for custom node is different
if (!element.ElementType.HasFlag(ElementTypes.CustomNode)) return item;
Expand Down
9 changes: 9 additions & 0 deletions src/LibraryViewExtensionWebView2/LibraryViewController.cs
Original file line number Diff line number Diff line change
Expand Up @@ -753,5 +753,14 @@ public static async Task<string> ExecuteScriptFunctionAsync(WebView2 webView2, s
script += ");";
return await webView2.ExecuteScriptAsync(script);
}
/// <summary>
/// Gives the library UI information on Dynamo's current context.
/// </summary>
/// <param name="type"></param>
internal void UpdateContext(string type)
{
ExecuteScriptFunctionAsync(browser,"libController.setHostContext", type);
ExecuteScriptFunctionAsync(browser, "replaceImages");
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -183,6 +183,7 @@
}, replaceImageDelayTime);
}


function refreshLibraryView(libraryController) {
window.chrome.webview.postMessage("RefreshLibrary");
}
Expand All @@ -194,6 +195,9 @@

refreshLibraryView(libController);

//initial state
libController.setHostContext("home")

var searchCallback = null;
function completeSearch(searchLoadedTypes){
searchCallback(JSON.parse(searchLoadedTypes));
Expand Down
24 changes: 22 additions & 2 deletions src/LibraryViewExtensionWebView2/ViewExtension.cs
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
using System.Windows;
using Dynamo.Graph.Workspaces;
using Dynamo.Models;
using Dynamo.ViewModels;
using Dynamo.Wpf.Extensions;
Expand All @@ -8,6 +9,12 @@ namespace Dynamo.LibraryViewExtensionWebView2
{
public class LibraryViewExtensionWebView2 : IViewExtension
{
/// <summary>
/// Possible hosting contexts for the library. These represent
/// Dynamo home and custom workspaces.
/// </summary>
private enum HostingContextType { home,custom, none};

private ViewLoadedParams viewParams;
private LibraryViewCustomization customization = new LibraryViewCustomization();
private LibraryViewController controller;
Expand Down Expand Up @@ -37,7 +44,17 @@ public void Loaded(ViewLoadedParams viewLoadedParams)
controller = new LibraryViewController(viewLoadedParams.DynamoWindow, viewLoadedParams.CommandExecutive, customization);
(viewLoadedParams.DynamoWindow.DataContext as DynamoViewModel).PropertyChanged += handleDynamoViewPropertyChanges;
}

viewParams.CurrentWorkspaceChanged += ViewParams_CurrentWorkspaceChanged;
}

private void ViewParams_CurrentWorkspaceChanged(IWorkspaceModel workspace)
{
var type = workspace switch
{
HomeWorkspaceModel _ => HostingContextType.home.ToString(),
CustomNodeWorkspaceModel _ => HostingContextType.custom.ToString()
};
controller.UpdateContext(type);
}

//hide browser directly when startpage is shown to deal with air space problem.
Expand Down Expand Up @@ -78,7 +95,10 @@ protected void Dispose(bool disposing)
{
(viewParams.DynamoWindow.DataContext as DynamoViewModel).PropertyChanged -= handleDynamoViewPropertyChanges;
}

if (viewParams != null)
{
viewParams.CurrentWorkspaceChanged -= ViewParams_CurrentWorkspaceChanged;
}

customization = null;
controller = null;
Expand Down
Loading