コード例 #1
0
        static State RenameElement(State previousState, RenameElementAction action)
        {
            if (!string.IsNullOrWhiteSpace(action.Name))
            {
                action.RenamableModel.Rename(action.Name);
            }

            if (action.RenamableModel is IVariableDeclarationModel variableDeclarationModel)
            {
                if (variableDeclarationModel.Owner is IFunctionModel functionModel)
                {
                    var toUpdate = previousState.CurrentGraphModel.NodeModels
                                   .OfType <FunctionRefCallNodeModel>()
                                   .Where(f => functionModel == (IFunctionModel)f.Function);
                    previousState.CurrentGraphModel.LastChanges.ChangedElements.AddRange(toUpdate);
                }
            }

            if (action.RenamableModel is IVariableModel)
            {
                previousState.CurrentGraphModel.LastChanges.BlackBoardChanged = true;
            }

            previousState.MarkForUpdate(UpdateFlags.RequestCompilation | UpdateFlags.RequestRebuild);

            return(previousState);
        }
コード例 #2
0
        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);
            }
        }