void IAddChildViewModel.AddChildren(IReadOnlyCollection <object> children, AddChildModifiers modifiers) { var worldPosition = Controller.GetMousePositionInUI(); var target = GetDropTarget(ref worldPosition, children, modifiers, out string _); ((IAddChildViewModel)target)?.AddChildren(children, modifiers); }
public override void AddChildren(IReadOnlyCollection <object> children, AddChildModifiers modifiers) { var symbol = (Symbol)children.Select(x => (NodeViewModel)x).First().NodeValue; var command = TargetNode.GetCommand(SetSymbolReferenceCommand.CommandName); command.Execute(symbol); }
public override bool CanAddChildren(IReadOnlyCollection <object> children, AddChildModifiers modifiers, out string message) { UPath path = null; var singleChild = true; foreach (var child in children) { if (!singleChild) { message = "Multiple files selected"; return(false); } path = child as UPath; if (path == null) { message = "The selection is not a file nor a directory"; return(false); } singleChild = false; } if (path == null) { message = "The selection is not a file nor a directory"; return(false); } message = $"Use {path}"; return(true); }
public override void AddChildren(IReadOnlyCollection <object> children, AddChildModifiers modifiers) { var subEntity = (EntityViewModel)children.First(); var command = TargetNode.GetCommand(SetEntityReferenceCommand.CommandName); command.Execute(subEntity); }
public override bool CanAddChildren(IReadOnlyCollection <object> children, AddChildModifiers modifiers, out string message) { Symbol symbol = null; bool singleChild = true; foreach (var child in children.Select(x => (NodeViewModel)x)) { if (!singleChild) { message = "Multiple symbols selected"; return(false); } symbol = child.NodeValue as Symbol; if (symbol == null) { message = "The selection is not a symbol"; return(false); } singleChild = false; } if (symbol == null) { message = "The selection is not a symbol"; return(false); } message = $"Reference {symbol.Name}"; return(true); }
public override bool CanAddChildren(IReadOnlyCollection <object> children, AddChildModifiers modifiers, out string message) { EntityViewModel entity = null; bool singleChild = true; foreach (var child in children) { if (!singleChild) { message = "Multiple entities selected"; return(false); } entity = child as EntityViewModel; if (entity == null) { message = "The selection is not an entity"; return(false); } singleChild = false; } if (entity == null) { message = "The selection is not an entity"; return(false); } message = $"Reference {entity.Name}"; return(true); }
public bool CanAddChildren(IReadOnlyCollection <object> children, AddChildModifiers modifiers, out string message) { if (children.Count != 1) { message = "Multiple elements selected."; return(false); } var child = children.Single(); var droppedObject = GetDroppedUnderlyingObject(child); if (droppedObject == null) { message = "Can't drop an object of this type here."; return(false); } var selectedMember = FindDropProperty(droppedObject); if (selectedMember == null) { message = "Couldn't find any property to set on this block."; return(false); } message = $"Replace property {selectedMember.Name} with [{droppedObject}]"; return(true); }
public void AddChildren(IReadOnlyCollection <object> children, AddChildModifiers modifiers) { // This shouldn't fail if CanAddChildren succeeded var child = children.Single(); var droppedObject = GetDroppedUnderlyingObject(child); var selectedMember = FindDropProperty(droppedObject); selectedMember.Update(droppedObject); }
public override bool CanAddChildren(IReadOnlyCollection <object> children, AddChildModifiers modifiers, out string message) { AssetViewModel asset = null; var singleChild = true; foreach (var child in children) { if (!singleChild) { message = "Multiple assets selected"; return(false); } asset = child as AssetViewModel; if (asset == null) { message = "The selection is not an asset"; return(false); } if (AssetRegistry.IsContentType(TargetNode.Type) || typeof(AssetReference).IsAssignableFrom(TargetNode.Type)) { var isCompatible = false; var resolvedAssetTypes = AssetRegistry.GetAssetTypes(TargetNode.Type); foreach (var resolvedAssetType in resolvedAssetTypes) { if (resolvedAssetType.IsAssignableFrom(asset.AssetType)) { isCompatible = true; break; } } if (!isCompatible) { message = "Incompatible asset"; return(false); } } var command = TargetNode.GetCommand("SetContentReference"); var param = new SetContentReferenceCommand.Parameter { Asset = asset, Type = TargetNode.Type }; if (!command.CanExecute(param)) { message = "The selection is not valid in this context"; return(false); } singleChild = false; } if (asset == null) { message = "The selection is not an asset"; return(false); } message = $"Reference {asset.Url}"; return(true); }
public override void AddChildren(IReadOnlyCollection <object> children, AddChildModifiers modifiers) { var asset = (AssetViewModel)children.First(); var param = new SetContentReferenceCommand.Parameter { Asset = asset, Type = TargetNode.Type }; var command = TargetNode.GetCommand("SetContentReference"); command.Execute(param); }
void IAddChildViewModel.AddChildren(IReadOnlyCollection <object> children, AddChildModifiers modifiers) { int directoriesMoved = 0; int assetsMoved = 0; DirectoryViewModel singleDirectoryMoved = null; AssetViewModel singleAssetMoved = null; using (var transaction = UndoRedoService.CreateTransaction()) { foreach (var child in children) { var directory = child as DirectoryViewModel; var asset = child as AssetViewModel; if (directory != null) { ++directoriesMoved; singleDirectoryMoved = directoriesMoved == 1 ? directory : null; var hierarchy = new List <DirectoryBaseViewModel>(); directory.GetDirectoryHierarchy(hierarchy); assetsMoved += hierarchy.Select(x => x.Assets.Count).Sum(); singleAssetMoved = assetsMoved == 1 ? hierarchy.SelectMany(x => x.Assets).FirstOrDefault() : null; directory.Parent = this; } if (asset != null) { ++assetsMoved; singleAssetMoved = assetsMoved == 1 ? asset : null; Package.MoveAsset(asset, this); } } string message = ""; if (singleDirectoryMoved != null) { message = $"Move directory '{singleDirectoryMoved.Name}'"; } else if (directoriesMoved > 1) { message = $"Move {directoriesMoved} directories"; } if (assetsMoved > 0) { message += message.Length > 0 ? " and " : "Move "; if (singleAssetMoved != null) { message += $"asset '{singleAssetMoved.Url}'"; } else { message += $"{assetsMoved} assets"; } } UndoRedoService.SetName(transaction, message); } }
public override void AddChildren(IReadOnlyCollection <object> children, AddChildModifiers modifiers) { var subEntity = (EntityViewModel)children.First(); var index = subEntity.Components.IndexOf(x => TargetNode.Type.IsInstanceOfType(x)); if (index >= 0) { var command = TargetNode.GetCommand(SetComponentReferenceCommand.CommandName); command.Execute(new SetComponentReferenceCommand.Parameter { Entity = subEntity, Index = index }); } }
public override void AddChildren(IReadOnlyCollection <object> children, AddChildModifiers modifiers) { var path = (UFile)children.First(); var dirPath = new UDirectory(path); if (TargetNode.Type == typeof(UFile) && File.Exists(path)) { TargetNode.NodeValue = path; } if (TargetNode.Type == typeof(UDirectory) && Directory.Exists(dirPath)) { TargetNode.NodeValue = dirPath; } }
/// <inheritdoc/> public void AddChildren(IReadOnlyCollection <object> children, AddChildModifiers modifiers) { var actionService = serviceProvider.Get <IUndoRedoService>(); using (var transaction = actionService.CreateTransaction()) { foreach (var propertyProvider in propertyProviders) { propertyProvider.AddChildren(children, modifiers); } // TODO: If there is only a single transaction, take its name instead actionService.SetName(transaction, "Add new component(s)"); } }
/// <inheritdoc/> public bool CanAddChildren(IReadOnlyCollection <object> children, AddChildModifiers modifiers, out string message) { var messageBuilder = new StringBuilder(); foreach (var propertyProvider in propertyProviders) { if (!propertyProvider.CanAddChildren(children, modifiers, out message)) { return(false); } messageBuilder.AppendLine(message); } // Combined message message = messageBuilder.ToString(); return(true); }
public override bool CanAddChildren(IReadOnlyCollection <object> children, AddChildModifiers modifiers, out string message) { EntityViewModel entity = null; bool singleChild = true; foreach (var child in children) { if (!singleChild) { message = "Multiple entities selected"; return(false); } entity = child as EntityViewModel; if (entity == null) { message = "The selection is not an entity"; return(false); } bool isCompatible = entity.AssetSideEntity.Components.Any(x => TargetNode.Type.IsInstanceOfType(x)); if (!isCompatible) { message = "The selected entity does not have the required component"; return(false); } singleChild = false; } if (entity == null) { message = "The selection is not an entity"; return(false); } message = $"Reference {entity.Name}"; return(true); }
void IAddChildViewModel.AddChildren(IReadOnlyCollection <object> children, AddChildModifiers modifiers) { ((IAddChildViewModel)AssetMountPoint).AddChildren(children, modifiers); }
public void InsertChildren(IReadOnlyCollection <object> children, InsertPosition position, AddChildModifiers modifiers) { // FIXME: This feature is disabled for now. //var sourceNode = (NodeViewModel)children.First(); //var sourceIndex = sourceNode.Index.Int; //var targetIndex = targetNode.Index.Int; //if (position == InsertPosition.After) // ++targetIndex; //if (sourceNode.Parent.NodeValue == targetNode.Parent.NodeValue && sourceIndex < targetIndex) // --targetIndex; //var moveCommand = (NodeCommandWrapperBase)sourceNode.Parent.GetCommand(MoveItemCommand.CommandName); //if (moveCommand == null) // return; //var actionService = sourceNode.ServiceProvider.Get<IUndoRedoService>(); //using (var transaction = actionService.CreateTransaction()) //{ // moveCommand.Invoke(Tuple.Create(sourceIndex, targetIndex)); // actionService.SetName(transaction, $"Move item {sourceIndex}"); //} }
bool IAddChildViewModel.CanAddChildren(IReadOnlyCollection <object> children, AddChildModifiers modifiers, out string message) { return(((IAddChildViewModel)AssetMountPoint).CanAddChildren(children, modifiers, out message)); }
/// <summary> /// Similar to <see cref="CanAddOrInsert(EntityHierarchyItemViewModel,AssetViewModel,AddChildModifiers,int,out string,object[])"/> but with the proper type for <paramref name="asset"/>. /// </summary> /// <param name="parent">The parent item where the asset will be added or inserted.</param> /// <param name="asset">The asset.</param> /// <param name="modifier">The modifier keys currently active.</param> /// <param name="index">The index at which the insertion occurs.</param> /// <param name="message">A message explaining the reason the operation is accepted or refused.</param> /// <param name="messageArgs">Optional arguments for the message.</param> /// <returns><c>true</c> if the provided <paramref name="asset"/> can be added or inserted; otherwise, <c>false</c>.</returns> /// <seealso cref="CanAddOrInsert(EntityHierarchyItemViewModel,AssetViewModel,AddChildModifiers,int,out string,object[])"/> protected abstract bool CanAddOrInsert([NotNull] EntityHierarchyItemViewModel parent, [NotNull] TAssetViewModel asset, AddChildModifiers modifier, int index, [NotNull] out string message, [NotNull] params object[] messageArgs);
public bool CanInsertChildren(IReadOnlyCollection <object> children, InsertPosition position, AddChildModifiers modifiers, out string message) { // FIXME: This feature is disabled for now. message = ""; return(false); //if (children.Count != 1) //{ // message = "Only a single item can be moved at a time"; // return false; //} //var node = children.First() as NodeViewModel; //if (node?.Parent == null || !(TypeDescriptorFactory.Default.Find(node.Parent.Type) is CollectionDescriptor)) //{ // message = "This item cannot be moved because it is not in a collection"; // return false; //} //if (node.Parent.Type != targetNode.Parent.Type) //{ // message = "Invalid target location"; // return false; //} //object data; //if (!node.AssociatedData.TryGetValue("ReorderCollectionItem", out data)) // return false; //var sourceNode = (NodeViewModel)children.First(); //var sourceIndex = sourceNode.Index.Int; //var targetIndex = targetNode.Index.Int; //if (sourceIndex == targetIndex) //{ // message = "The target position is the same that the current position"; // return false; //} //message = string.Format(position == InsertPosition.Before ? "Insert before {0}" : "Insert after {0}", targetNode.DisplayName); //return node.Index.IsInt && data is IReorderItemViewModel; }
/// <inheritdoc /> protected override bool CanAddOrInsert(EntityHierarchyItemViewModel parent, TAssetViewModel asset, AddChildModifiers modifier, int index, out string message, params object[] messageArgs) { message = string.Format("Add the selection into {0}", messageArgs); return(true); }
bool IAddChildViewModel.CanAddChildren(IReadOnlyCollection <object> children, AddChildModifiers modifiers, out string message) { if (children.Any(x => (x is IIsEditableViewModel) && !((IIsEditableViewModel)x).IsEditable)) { message = "Some source items are read-only"; return(false); } if (!Package.IsEditable) { message = "Read-only package"; return(false); } message = $"Add to {Path}"; foreach (var child in children) { var mountPoint = child as MountPointViewModel; var directory = child as DirectoryViewModel; var asset = child as AssetViewModel; if (mountPoint != null) { message = DragDropBehavior.InvalidDropAreaMessage; return(false); } if (directory != null) { if (directory == this) { message = "Can't drop a folder on itself or its children"; return(false); } if (directory.Root.GetType() != Root.GetType()) { message = "Incompatible folder"; return(false); } if (directory.Root is ProjectViewModel && Root != directory.Root) { message = "Can't move source files between projects"; return(false); } if (SubDirectories.Any(x => x.Name == directory.Name)) { message = $"Directory {((this is DirectoryViewModel) ? Path : Name)} already contains a subfolder named {directory.Name}"; return(false); } if (children.OfType <DirectoryViewModel>().Any(x => x != child && string.Compare(x.Name, directory.Name, StringComparison.OrdinalIgnoreCase) == 0)) { message = "Can't move directories with duplicate names"; return(false); } var currentParent = Parent; while (currentParent != null) { if (currentParent == directory) { message = "Can't drop a directory on itself or its children"; return(false); } currentParent = currentParent.Parent; } } else if (asset != null) { if (asset.IsLocked) { message = $"Asset {asset.Url} can't be moved"; return(false); } if (Assets.Any(x => string.Compare(x.Name, asset.Name, StringComparison.OrdinalIgnoreCase) == 0)) { message = $"{(!string.IsNullOrEmpty(Path) ? $"Directory {Path}" : "This directory")} already contains an asset named {asset.Name}"; return(false); } if (children.OfType <AssetViewModel>().Any(x => x != child && string.Compare(x.Name, asset.Name, StringComparison.OrdinalIgnoreCase) == 0)) { message = "Can't move assets with duplicate names"; return(false); } if (asset.Directory.Root.GetType() != Root.GetType()) { message = "Incompatible folder"; return(false); } if (asset.Directory.Root is ProjectViewModel && Root != asset.Directory.Root) { message = "Can't move source files between projects"; return(false); } } else { message = "Only folders can be dropped"; return(false); } } return(true); }
/// <inheritdoc /> protected override bool CanAddOrInsert(EntityHierarchyItemViewModel parent, ScriptSourceFileAssetViewModel asset, AddChildModifiers modifiers, int index, out string message, params object[] messageArgs) { var scriptType = FindScriptType(asset.ServiceProvider, asset.AssetItem)?.FirstOrDefault(); if (scriptType == null) { message = $"No scripts inheriting from {nameof(ScriptComponent)} found in asset {asset.Url}"; return(false); } // TODO: Check how many scripts there is inside this file? message = string.Format($"Add script {scriptType.Name} into {{0}}", messageArgs); return(true); }
bool IAddChildViewModel.CanAddChildren(IReadOnlyCollection <object> children, AddChildModifiers modifiers, out string message) { var worldPosition = Controller.GetMousePositionInUI(); var element = GetDropTarget(ref worldPosition, children, modifiers, out message); if (element != null) { Controller.AdornerService.HighlightAdorner(element.Id.ObjectId).Forget(); return(true); } Controller.AdornerService.UnlitAllAdorners().Forget(); return(false); }
/// <inheritdoc /> protected override bool CanAddOrInsert(EntityHierarchyItemViewModel parent, PrefabViewModel asset, AddChildModifiers modifiers, int index, out string message, params object[] messageArgs) { var prefab = asset; if (prefab == parent.Asset || prefab.GatherAllBasePartAssets().Contains(parent.Asset)) { message = "This prefab depends on this asset and can't be added."; return(false); } if (prefab.Asset.Hierarchy.Parts.Count == 0) { message = "This prefab is empty and can't be added."; return(false); } message = (modifiers & AddChildModifiers.Alt) != AddChildModifiers.Alt ? string.Format("Add the prefab to {0}\r\n(Hold Alt to add without a container entity)", messageArgs) : string.Format("Add the prefab to {0}\r\n(Release Alt to add with a container entity)", messageArgs); return(true); }
void IInsertChildViewModel.InsertChildren(IReadOnlyCollection <object> children, InsertPosition position, AddChildModifiers modifiers) { string message; if (((IAddChildViewModel)this).CanAddChildren(children, modifiers, out message) && children.All(x => x is UFile)) { Editor.ImportFiles(children.OfType <UFile>(), index); return; } using (var transaction = Editor.UndoRedoService.CreateTransaction()) { foreach (var image in children.OfType <SpriteInfoViewModel>()) { image.Editor.RemoveImage(image.GetSpriteInfo(), image.index); } var insertIndex = position == InsertPosition.After ? index + 1 : index; insertIndex = MathUtil.Clamp(insertIndex, 0, Editor.Sprites.Count); foreach (var image in children.OfType <SpriteInfoViewModel>()) { Editor.InsertImage(image.GetSpriteInfo(), insertIndex++); } Editor.UndoRedoService.SetName(transaction, "Move images"); } }
bool IInsertChildViewModel.CanInsertChildren(IReadOnlyCollection <object> children, InsertPosition position, AddChildModifiers modifiers, out string message) { if (((IAddChildViewModel)this).CanAddChildren(children, modifiers, out message)) { return(true); } message = "Invalid object"; foreach (var child in children) { var image = child as SpriteInfoViewModel; if (image == null) { return(false); } } message = string.Format(position == InsertPosition.Before ? "Insert before {0}" : "Insert after {0}", Name); return(true); }
void IAddChildViewModel.AddChildren(IReadOnlyCollection <object> children, AddChildModifiers modifiers) { ((IAddChildViewModel)Editor).AddChildren(children, modifiers); }
private UIElementViewModel GetDropTarget(ref Vector3 worldPosition, IReadOnlyCollection <object> children, AddChildModifiers modifiers, out string message) { message = DragDropBehavior.InvalidDropAreaMessage; var elements = GetElementsAtPosition(ref worldPosition); if (elements == null) { return(null); } foreach (var target in elements) { if (((IAddChildViewModel)target).CanAddChildren(children, modifiers, out message)) { return(target); } } return(null); }