public void RebuildSections(Blackboard blackboard) { m_Store = blackboard.Store; var currentGraphModel = (VSGraphModel)blackboard.Store.GetState().CurrentGraphModel; blackboard.ClearContents(); if (blackboard.Sections != null && blackboard.Sections.Count > 1) { blackboard.Sections[k_InputPortDeclarationsSection].title = k_InputPortDeclarationsSectionTitle; blackboard.Sections[k_OutputPortDeclarationsSection].title = k_OutputPortDeclarationsSectionTitle; } if (currentGraphModel.NodeModels == null) { return; } foreach (VariableDeclarationModel declaration in currentGraphModel.VariableDeclarations) { var blackboardField = new BlackboardVariableField(blackboard.Store, declaration, blackboard.GraphView); var blackboardRow = new BlackboardRow( blackboardField, new BlackboardVariablePropertyView(blackboard.Store, declaration, blackboard.Rebuild, m_Stencil) .WithTypeSelector() .WithTooltipField()) { Model = declaration, expanded = true, // TODO not pretty }; if (blackboard.Sections != null) { switch (declaration.Modifiers) { case ModifierFlags.ReadOnly: blackboard.Sections[k_InputPortDeclarationsSection].Add(blackboardRow); break; case ModifierFlags.WriteOnly: blackboard.Sections[k_OutputPortDeclarationsSection].Add(blackboardRow); break; } } blackboard.GraphVariables.Add(blackboardField); } }
public void RebuildSections(Blackboard blackboard) { VSGraphModel currentGraphModel = (VSGraphModel)blackboard.Store.GetState().CurrentGraphModel; Dictionary <IVariableDeclarationModel, bool> expandedRows = new Dictionary <IVariableDeclarationModel, bool>(); foreach (BlackboardSection blackBoardSection in blackboard.Sections) { foreach (VisualElement visualElement in blackBoardSection.Children()) { if (visualElement is BlackboardRow row) { if (row.Model is IVariableDeclarationModel model) { expandedRows[model] = row.expanded; } } } } blackboard.ClearContents(); if (CanDisplayThisToken) { var thisNodeModel = currentGraphModel.NodeModels.OfType <ThisNodeModel>().FirstOrDefault(); var thisField = new BlackboardThisField(blackboard.GraphView, thisNodeModel, currentGraphModel); blackboard.Sections[k_MainSection].Add(thisField); blackboard.GraphVariables.Add(thisField); blackboard.RestoreSelectionForElement(thisField); } // Fetch all fields from the GraphModel in the main section foreach (IVariableDeclarationModel variableDeclarationModel in ((IVSGraphModel)currentGraphModel).GraphVariableModels) { var blackboardField = new BlackboardVariableField(blackboard.Store, variableDeclarationModel, blackboard.GraphView); var blackboardRow = new BlackboardRow( blackboardField, CreateExtendedFieldView(blackboard.Store, variableDeclarationModel, blackboard.Rebuild)) { Model = variableDeclarationModel, expanded = expandedRows.TryGetValue(variableDeclarationModel, out var expandedValue) && expandedValue }; blackboard.Sections[k_MainSection].Add(blackboardRow); blackboard.GraphVariables.Add(blackboardField); blackboard.RestoreSelectionForElement(blackboardField); } if (blackboard.selection != null) { // Fill local scope section foreach (Tuple <IVariableDeclarationModel, bool> variableDeclarationModelTuple in blackboard.GraphView.UIController .GetAllVariableDeclarationsFromSelection(blackboard.selection)) { var blackboardField = new BlackboardVariableField(blackboard.Store, variableDeclarationModelTuple.Item1, blackboard.GraphView); if (variableDeclarationModelTuple.Item2) { var blackboardRow = new BlackboardRow( blackboardField, CreateExtendedFieldView(blackboard.Store, variableDeclarationModelTuple.Item1, blackboard.Rebuild)) { userData = variableDeclarationModelTuple, expanded = expandedRows.TryGetValue(variableDeclarationModelTuple.Item1, out var expandedValue) && expandedValue }; blackboard.Sections[k_CurrentScopeVariableDeclarationsSection].Add(blackboardRow); } else { blackboardField.AddToClassList("readonly"); blackboard.Sections[k_CurrentScopeVariableDeclarationsSection].Add(blackboardField); } blackboard.GraphVariables.Add(blackboardField); blackboard.RestoreSelectionForElement(blackboardField); } } }