static State RenameElement(State previousState, RenameElementAction action) { var graphModel = (VSGraphModel)previousState.CurrentGraphModel; if (string.IsNullOrWhiteSpace(action.Name)) { return(previousState); } Undo.RegisterCompleteObjectUndo((Object)graphModel.AssetModel, "Rename"); action.RenamableModel.Rename(action.Name); EditorUtility.SetDirty((Object)graphModel.AssetModel); IGraphChangeList graphChangeList = previousState.CurrentGraphModel.LastChanges; VSGraphModel vsGraphModel = (VSGraphModel)previousState.CurrentGraphModel; if (action.RenamableModel is VariableDeclarationModel variableDeclarationModel) { graphChangeList.BlackBoardChanged = true; // update usage names graphChangeList.ChangedElements.AddRange(vsGraphModel.FindUsages <VariableNodeModel>(variableDeclarationModel)); } else if (action.RenamableModel is IVariableModel variableModel) { graphChangeList.BlackBoardChanged = true; variableDeclarationModel = variableModel.DeclarationModel as VariableDeclarationModel; graphChangeList.ChangedElements.Add(variableDeclarationModel); graphChangeList.ChangedElements.AddRange(vsGraphModel.FindUsages <VariableNodeModel>(variableDeclarationModel)); } else if (action.RenamableModel is IEdgePortalModel edgePortalModel) { variableDeclarationModel = edgePortalModel.DeclarationModel as VariableDeclarationModel; graphChangeList.ChangedElements.Add(variableDeclarationModel); graphChangeList.ChangedElements.AddRange(vsGraphModel.FindUsages <EdgePortalModel>(variableDeclarationModel)); } else { graphChangeList.ChangedElements.Add(action.RenamableModel as IGraphElementModel); } previousState.MarkForUpdate(UpdateFlags.RequestCompilation | UpdateFlags.RequestRebuild); return(previousState); }
static State UpdateType(State previousState, UpdateTypeAction action) { VSGraphModel graphModel = (VSGraphModel)((GraphModel)previousState.CurrentGraphModel); if (action.Handle.IsValid) { Undo.RegisterCompleteObjectUndo(action.VariableDeclarationModel.SerializableAsset, "Update Type"); if (action.VariableDeclarationModel.DataType != action.Handle) { action.VariableDeclarationModel.CreateInitializationValue(); } action.VariableDeclarationModel.DataType = action.Handle; foreach (var usage in graphModel.FindUsages(action.VariableDeclarationModel)) { usage.UpdateTypeFromDeclaration(); } previousState.MarkForUpdate(UpdateFlags.RequestRebuild); } return(previousState); }
public override bool CanPasteNode(NodeModel originalModel, VSGraphModel graph) { if (originalModel is VariableNodeModel variableNodeModel && variableNodeModel.DeclarationModel?.IsInputOrOutput() == true) { var canPasteNode = !graph.FindUsages((VariableDeclarationModel)variableNodeModel.DeclarationModel).Any(); if (!canPasteNode) { Debug.LogWarning(k_DuplicateInputOutputWarning); } return(canPasteNode); } return(base.CanPasteNode(originalModel, graph)); }
public override bool CanPasteNode(NodeModel originalModel, VSGraphModel graph) { switch (originalModel) { case VariableNodeModel variableNodeModel when variableNodeModel.DeclarationModel?.IsInputOrOutput() == true: { var canPasteNode = !graph.FindUsages((VariableDeclarationModel)variableNodeModel.DeclarationModel).Any(); if (!canPasteNode) { Debug.LogWarning(k_DuplicateInputOutputWarning); } return(canPasteNode); } case EdgePortalModel edgePortalModel: return(graph.PortalDeclarations.Contains(edgePortalModel.DeclarationModel)); default: return(base.CanPasteNode(originalModel, graph)); } }
static State UpdateTypeRank(State previousState, UpdateTypeRankAction action) { VSGraphModel graphModel = (VSGraphModel)((GraphModel)previousState.CurrentGraphModel); TypeHandle newType = action.IsArray ? action.VariableDeclarationModel.DataType.MakeVsArrayType(graphModel.Stencil) : action.VariableDeclarationModel.DataType.GetGenericArguments(graphModel.Stencil).Any() ? action.VariableDeclarationModel.DataType.GetVsArrayElementType(graphModel.Stencil) : action.VariableDeclarationModel.DataType; Undo.RegisterCompleteObjectUndo(action.VariableDeclarationModel, "Update Type Rank"); action.VariableDeclarationModel.DataType = newType; foreach (var usage in graphModel.FindUsages(action.VariableDeclarationModel)) { usage.UpdateTypeFromDeclaration(); } previousState.MarkForUpdate(UpdateFlags.RequestRebuild); return(previousState); }
static State RenameElement(State previousState, RenameElementAction action) { if (string.IsNullOrWhiteSpace(action.Name)) { return(previousState); } Undo.RegisterCompleteObjectUndo((Object)action.RenamableModel.AssetModel, "Renaming graph element"); action.RenamableModel.Rename(action.Name); IGraphChangeList graphChangeList = previousState.CurrentGraphModel.LastChanges; VSGraphModel vsGraphModel = (VSGraphModel)previousState.CurrentGraphModel; if (action.RenamableModel is IFunctionModel functionDefinitionModel) { RenameFunctionUsages((FunctionModel)functionDefinitionModel); } else if (action.RenamableModel is VariableDeclarationModel variableDeclarationModel) { graphChangeList.BlackBoardChanged = true; if (variableDeclarationModel.Owner is IFunctionModel functionModel) { RenameFunctionUsages((FunctionModel)functionModel); } // update usage names graphChangeList.ChangedElements.AddRange(vsGraphModel.FindUsages(variableDeclarationModel)); } else if (action.RenamableModel is IVariableModel variableModel) { graphChangeList.BlackBoardChanged = true; variableDeclarationModel = variableModel.DeclarationModel as VariableDeclarationModel; graphChangeList.ChangedElements.Add(variableDeclarationModel); graphChangeList.ChangedElements.AddRange(vsGraphModel.FindUsages(variableDeclarationModel)); if (variableDeclarationModel.FunctionModel != null) { graphChangeList.ChangedElements.Add(variableDeclarationModel.FunctionModel); } } else { graphChangeList.ChangedElements.Add(action.RenamableModel); } previousState.MarkForUpdate(UpdateFlags.RequestCompilation | UpdateFlags.RequestRebuild); return(previousState); void RenameFunctionUsages(FunctionModel functionModel) { var toUpdate = functionModel.FindFunctionUsages(previousState.CurrentGraphModel); graphChangeList.ChangedElements.AddRange(toUpdate); graphChangeList.ChangedElements.Add(functionModel); } }