public override void AddItem(object value) { if (!RootNode.IsEnumerable) { throw new NodePresenterException($"{nameof(RootNodePresenter)}.{nameof(AddItem)} cannot be invoked on objects that are not collection."); } try { RootNode.Add(value); } catch (Exception e) { throw new NodePresenterException("An error occurred while adding an item to the node, see the inner exception for more information.", e); } }
private void AddNewCameraSlot() { using (var transaction = UndoRedoService.CreateTransaction()) { var cameraSlot = new SceneCameraSlot(); cameraSlotsNode.Add(cameraSlot); UndoRedoService.SetName(transaction, "Create new camera slot"); } }
private void AddNewRenderStage() { using (var transaction = UndoRedoService.CreateTransaction()) { var renderStage = new RenderStage(); renderStagesNode.Add(renderStage); UndoRedoService.SetName(transaction, "Create new render stage"); } }
private void AddNewRenderFeature(AbstractNodeType abstractNodeType) { using (var transaction = UndoRedoService.CreateTransaction()) { var renderFeature = abstractNodeType.GenerateValue(null); renderFeaturesNode.Add(renderFeature); UndoRedoService.SetName(transaction, "Create new render feature"); } }
private static void SetMaterial(IObjectNode materialNode, Index index, Material value) { if (materialNode.Indices.Contains(index)) { materialNode.Update(value, index); } else { materialNode.Add(value, index); } }
private void Create() { // Create renderer var renderer = (ISharedRenderer)Activator.CreateInstance(Type); // Add renderer using (var transaction = ServiceProvider.Get <IUndoRedoService>().CreateTransaction()) { sharedRenderersNode.Add(renderer); ServiceProvider.Get <IUndoRedoService>().SetName(transaction, "Create renderer"); } }
private void ChildrenCollectionChanged(object sender, [NotNull] NotifyCollectionChangedEventArgs e) { if (updatingChildren || UndoRedoService.UndoRedoInProgress) { return; } try { updatingChildren = true; switch (e.Action) { case NotifyCollectionChangedAction.Replace: case NotifyCollectionChangedAction.Add: case NotifyCollectionChangedAction.Remove: if (e.OldItems?.Count > 0) { foreach (var scene in e.OldItems.Cast <SceneViewModel>()) { scene.Parent = null; childrenNode.Remove(scene.Id, new NodeIndex(e.OldStartingIndex)); } } if (e.NewItems?.Count > 0) { var index = e.NewStartingIndex; foreach (var scene in e.NewItems.Cast <SceneViewModel>()) { // Note: this can happen after a cut/paste when the parent/child relationship is fixed-up. if (scene.Parent != this) { scene.Parent?.Children.Remove(scene); scene.Parent = this; } childrenNode.Add(scene.Id, new NodeIndex(index++)); } } break; case NotifyCollectionChangedAction.Move: case NotifyCollectionChangedAction.Reset: throw new NotSupportedException(); default: throw new ArgumentOutOfRangeException(); } } finally { updatingChildren = false; } }
private void SetMaterialEnabled(IObjectNode materialNode, Index index, bool value) { if (value) { var material = GetMaterial(materialNode, index); materialNode.Add(material, index); } else { var material = materialNode.Retrieve(index); materialNode.Remove(material, index); } }
protected static bool UpdateCollection([NotNull] IObjectNode node, object value, Index index) { if (IsIndexExisting(node, index)) { node.Update(value, index); return(true); } if (IsIndexValid(node, index)) { node.Add(value, index); return(true); } return(false); }
/// <summary> /// Setter for the virtual node's value. /// </summary> /// <param name="undoRedoService"></param> /// <param name="propertyContainerNode">The node containing the property.</param> /// <param name="propertyIndex">The index of the property in the node.</param> /// <param name="value">The value to set.</param> private static void Setter(IUndoRedoService undoRedoService, [NotNull] IObjectNode propertyContainerNode, NodeIndex propertyIndex, object value) { using (undoRedoService?.CreateTransaction()) { if (!propertyContainerNode.Indices.Contains(propertyIndex)) { // Note: update would probably work, but we want to remove the property when Undo propertyContainerNode.Add(value, propertyIndex); } else { propertyContainerNode.Update(value, propertyIndex); } } }
public void AddMethod(Method method) { methodsContent.Add(method); }
public void AddParameter(Parameter parameter) { parametersContent.Add(parameter); }
public void AddLink(Link link) { linksContent.Add(link); }
public void AddBlock(Block block) { blocksContent.Add(block); }
protected virtual void InsertItem(IObjectNode collection, NodeIndex index, object newItem) { collection.Add(newItem, index); }
public void ChangeChildElementLayoutProperties([NotNull] UIElement child, PanelCommandMode mode) { if (child == null) { throw new ArgumentNullException(nameof(child)); } using (var transaction = Editor.UndoRedoService.CreateTransaction()) { var canvas = AssetSidePanel as Canvas; if (canvas != null) { var pinOrigin = GetDependencyPropertyValue(child, Canvas.PinOriginPropertyKey); switch (mode) { case PanelCommandMode.PinTopLeft: pinOrigin.X = 0.0f; pinOrigin.Y = 0.0f; break; case PanelCommandMode.PinTop: pinOrigin.X = 0.5f; pinOrigin.Y = 0.0f; break; case PanelCommandMode.PinTopRight: pinOrigin.X = 1.0f; pinOrigin.Y = 0.0f; break; case PanelCommandMode.PinLeft: pinOrigin.X = 0.0f; pinOrigin.Y = 0.5f; break; case PanelCommandMode.PinCenter: pinOrigin.X = 0.5f; pinOrigin.Y = 0.5f; break; case PanelCommandMode.PinRight: pinOrigin.X = 1.0f; pinOrigin.Y = 0.5f; break; case PanelCommandMode.PinBottomLeft: pinOrigin.X = 0.0f; pinOrigin.Y = 1.0f; break; case PanelCommandMode.PinBottom: pinOrigin.X = 0.5f; pinOrigin.Y = 1.0f; break; case PanelCommandMode.PinBottomRight: pinOrigin.X = 1.0f; pinOrigin.Y = 1.0f; break; case PanelCommandMode.PinFront: pinOrigin.Z = 1.0f; break; case PanelCommandMode.PinMiddle: pinOrigin.Z = 0.5f; break; case PanelCommandMode.PinBack: pinOrigin.Z = 0.0f; break; default: throw new ArgumentException($"{mode} is not a supported mode.", nameof(mode)); } SetDependencyPropertyValue(child, Canvas.PinOriginPropertyKey, pinOrigin); Editor.UndoRedoService.SetName(transaction, $"Change Pin Origin of {UIEditorBaseViewModel.GetDisplayName(child)}"); return; } var grid = AssetSidePanel as GridBase; if (grid != null) { PropertyKey <int> propertyKey; int offset; switch (mode) { case PanelCommandMode.MoveUp: propertyKey = GridBase.RowPropertyKey; offset = -1; break; case PanelCommandMode.MoveDown: propertyKey = GridBase.RowPropertyKey; offset = 1; break; case PanelCommandMode.MoveLeft: propertyKey = GridBase.ColumnPropertyKey; offset = -1; break; case PanelCommandMode.MoveRight: propertyKey = GridBase.ColumnPropertyKey; offset = 1; break; case PanelCommandMode.MoveBack: propertyKey = GridBase.LayerPropertyKey; offset = -1; break; case PanelCommandMode.MoveFront: propertyKey = GridBase.LayerPropertyKey; offset = 1; break; default: throw new ArgumentException($"{mode} is not a supported mode.", nameof(mode)); } var currentValue = GetDependencyPropertyValue(child, propertyKey); var newValue = Math.Max(0, currentValue + offset); SetDependencyPropertyValue(child, propertyKey, newValue); Editor.UndoRedoService.SetName(transaction, $"Move {UIEditorBaseViewModel.GetDisplayName(child)}"); return; } var stackPanel = AssetSidePanel as StackPanel; if (stackPanel != null) { var collection = AssetSidePanel.Children; var index = collection.IndexOf(child); if (index == -1) { throw new InvalidOperationException("The given element is not a child of this panel."); } int newIndex; switch (mode) { case PanelCommandMode.MoveDown: newIndex = index + 1; if (newIndex >= collection.Count) { return; } break; case PanelCommandMode.MoveUp: newIndex = index - 1; if (newIndex < 0) { return; } break; default: throw new ArgumentException($"{mode} is not a supported mode.", nameof(mode)); } // FIXME: review if this is fine doing it that way or if we need to do it the same way as when moving elements around childrenNode.Remove(child, new NodeIndex(index)); childrenNode.Add(child, new NodeIndex(newIndex)); Editor.UndoRedoService.SetName(transaction, $"Move {UIEditorBaseViewModel.GetDisplayName(child)}"); } } }
public void AddProperty(Property property) { propertiesContent.Add(property); }