コード例 #1
0
        private static void ClearNode(IUndoRedoService actionService, AssetViewModel asset, ItemToReload itemToReload)
        {
            // Get the node we want to change
            var index    = itemToReload.GraphPathIndex;
            var node     = itemToReload.GraphPath.GetNode();
            var oldValue = node.Retrieve(index);

            // Apply the change
            // TODO: Share this code with ContentValueChangeOperation?
            // TODO: How to better detect CollectionAdd vs ValueChange?
            ContentChangeType operationType;

            if (index != NodeIndex.Empty)
            {
                if (CollectionItemIdHelper.TryGetCollectionItemIds(node.Retrieve(), out CollectionItemIdentifiers ids))
                {
                    itemToReload.ItemId = ids[index.Value];
                }
                operationType = ContentChangeType.CollectionRemove;
                ((IObjectNode)node).Remove(oldValue, index);
            }
            else
            {
                operationType = ContentChangeType.ValueChange;
                ((IMemberNode)node).Update(null);
            }

            // Save the change on the stack
            var operation = new ContentValueChangeOperation(node, operationType, index, oldValue, null, Enumerable.Empty <IDirtiable>());

            actionService.PushOperation(operation);
            string operationName = $"Unload object {oldValue.GetType().Name} in asset {asset.Url}";

            actionService.SetName(operation, operationName);
        }
コード例 #2
0
        private static void ReplaceNode(IUndoRedoService actionService, AssetViewModel asset, ItemToReload itemToReload)
        {
            // Get the node we want to change
            var graphPath = itemToReload.GraphPath;
            var index     = itemToReload.GraphPathIndex;
            var node      = graphPath.GetNode();

            // Apply the change
            // TODO: Share this code with ContentValueChangeOperation?
            // TODO: How to better detect CollectionAdd vs ValueChange?
            ContentChangeType operationType;

            if (index != NodeIndex.Empty)
            {
                operationType = ContentChangeType.CollectionAdd;
                ((IAssetObjectNode)node).Restore(itemToReload.UpdatedObject, index, itemToReload.ItemId);
            }
            else
            {
                operationType = ContentChangeType.ValueChange;
                ((IMemberNode)node).Update(itemToReload.UpdatedObject);
            }

            // Save the change on the stack
            var operation = new ContentValueChangeOperation(node, operationType, index, null, itemToReload.UpdatedObject, asset.Dirtiables);

            actionService.PushOperation(operation);
            string operationName = $"Reload object {itemToReload.UpdatedObject.GetType().Name} in asset {asset.Url}";

            actionService.SetName(operation, operationName);
        }
コード例 #3
0
 /// <summary>
 /// Sets the current value of the graph node.
 /// </summary>
 /// <param name="value">The value to set for the graph node content.</param>
 /// <remarks>This method can be invoked from a property setter.</remarks>
 /// <remarks>This method will invoke the delegates passed to the constructor of this instance if the new value is different from the previous one.</remarks>
 public void SetNodeValue(TTargetType value)
 {
     using (var transaction = actionService?.CreateTransaction())
     {
         node.Update(converter(value));
         actionService?.SetName(transaction, $"Update property {propertyName}");
     }
 }