public NamedObjectSave ShowAddNewObjectDialog(AddObjectViewModel addObjectViewModel = null) { NamedObjectSave newNamedObject = null; // add named object, add object, addnamedobject, add new object, addnewobject, createobject, addobject addObjectViewModel = CreateAndShowAddNamedObjectWindow(addObjectViewModel); if (addObjectViewModel.DialogResult == DialogResult.OK) { string whyItIsntValid = null; bool isValid = NameVerifier.IsNamedObjectNameValid(addObjectViewModel.ObjectName, out whyItIsntValid); if (isValid) { if (addObjectViewModel.SourceType == SourceType.Entity && !RecursionManager.Self.CanContainInstanceOf(GlueState.Self.CurrentElement, addObjectViewModel.SourceClassType)) { isValid = false; whyItIsntValid = "This type would result in infinite recursion"; } } if (isValid) { newNamedObject = GlueCommands.Self.GluxCommands.AddNewNamedObjectToSelectedElement(addObjectViewModel); GlueState.Self.CurrentNamedObjectSave = newNamedObject; } else { GlueGui.ShowMessageBox(whyItIsntValid); } } return(newNamedObject); }
public NamedObjectSave AddNewNamedObjectToSelectedElement(AddObjectViewModel addObjectViewModel) { MembershipInfo membershipInfo = NamedObjectSaveExtensionMethodsGlue.GetMemberMembershipInfo(addObjectViewModel.ObjectName); var newNos = NamedObjectSaveExtensionMethodsGlue.AddNewNamedObjectToSelectedElement(addObjectViewModel.ObjectName, membershipInfo, false); if (addObjectViewModel.SourceClassType != NoType && !string.IsNullOrEmpty(addObjectViewModel.SourceClassType)) { newNos.SourceType = addObjectViewModel.SourceType; newNos.SourceClassType = addObjectViewModel.SourceClassType; newNos.SourceFile = addObjectViewModel.SourceFile; newNos.SourceName = addObjectViewModel.SourceNameInFile; newNos.UpdateCustomProperties(); EditorLogic.CurrentElementTreeNode.UpdateReferencedTreeNodes(); } else if (!string.IsNullOrEmpty(addObjectViewModel.SourceFile)) { newNos.SourceType = addObjectViewModel.SourceType; newNos.SourceFile = addObjectViewModel.SourceFile; newNos.SourceName = addObjectViewModel.SourceNameInFile; newNos.UpdateCustomProperties(); EditorLogic.CurrentElementTreeNode.UpdateReferencedTreeNodes(); } newNos.SourceClassGenericType = addObjectViewModel.SourceClassGenericType; var ati = newNos.GetAssetTypeInfo(); if (ati != null && ati.DefaultPublic) { newNos.HasPublicProperty = true; } var currentEntity = GlueState.Self.CurrentElement as EntitySave; if (currentEntity != null && currentEntity.CreatedByOtherEntities && currentEntity.PooledByFactory) { bool wasAnythingAdded = FlatRedBall.Glue.Factories.FactoryManager.AddResetVariablesFor(newNos); if (wasAnythingAdded) { PluginManager.ReceiveOutput("Added reset variables for " + newNos); } } PluginManager.ReactToNewObject(newNos); MainGlueWindow.Self.PropertyGrid.Refresh(); PropertyGridHelper.UpdateNamedObjectDisplay(); ElementViewWindow.GenerateSelectedElementCode(); // it may already be selected, so force select it MainGlueWindow.Self.ElementTreeView.SelectedNode = null; MainGlueWindow.Self.ElementTreeView.SelectedNode = GlueState.Self.Find.NamedObjectTreeNode(newNos); GluxCommands.Self.SaveGlux(); return(newNos); }
private void TryAddSolidCollisions() { // Only add it if it's not already there - if the user already has made another level then we don't need to do it again var currentScreen = GlueState.Self.CurrentScreenSave; var alreadyHasSolidCollisions = currentScreen.NamedObjects.Any(item => item.InstanceName == "SolidCollisions" && item.SourceClassType == "TileShapeCollection"); if (!alreadyHasSolidCollisions) { AddObjectViewModel viewModel = new AddObjectViewModel { SourceType = SourceType.FlatRedBallType, SourceClassType = "TileShapeCollection", ObjectName = "SolidCollisions" }; // SourceType sourceType, // string sourceClassType, // string sourceFile, // string objectName, string sourceNameInFile, string sourceClassGenericType // var namedObjectSave = GlueCommands.Self.GluxCommands.AddNewNamedObjectToSelectedElement( //FlatRedBall.Glue.SaveClasses.SourceType.FlatRedBallType, //"TileShapeCollection", //null, //"SolidCollisions", //null, //null); viewModel); } }
private static NamedObjectSave HandleAddShape(string message, string sourceClassType) { NamedObjectSave toReturn = null; var tiw = new TextInputWindow(); tiw.Message = message; var dialogResult = tiw.ShowDialog(); if (dialogResult == DialogResult.OK) { string whyItIsntValid; NameVerifier.IsNamedObjectNameValid(tiw.Result, out whyItIsntValid); if (!string.IsNullOrEmpty(whyItIsntValid)) { GlueCommands.Self.DialogCommands.ShowMessageBox(whyItIsntValid); } else { var viewModel = new AddObjectViewModel(); viewModel.ObjectName = tiw.Result; viewModel.SourceType = SaveClasses.SourceType.FlatRedBallType; viewModel.SourceClassType = sourceClassType; toReturn = GlueCommands.Self.GluxCommands.AddNewNamedObjectToSelectedElement(viewModel); GlueState.Self.CurrentNamedObjectSave = toReturn; } } return(toReturn); }
public NewObjectTypeSelectionControl(AddObjectViewModel viewModel) { ViewModel = viewModel; InitializeComponent(); PopulateAllTreeViews(); RefreshComboBoxVisibility(); this.FlatRedBallTypeRadioButton.Checked = true; SearchBarHelper.Initialize(SearchTextBox, "Type here to filter options..."); }
internal static void ReactToNewEntityCreated(EntitySave newEntity, AddEntityWindow window) { var control = window.UserControlChildren.FirstOrDefault(item => item is AdditionalEntitiesControls); var viewModel = control?.DataContext as AdditionalEntitiesControlViewModel; if (viewModel?.InstantiateInTileMap == true) { // make it have a factory newEntity.CreatedByOtherEntities = true; GlueCommands.Self.PrintOutput($"Tiled Plugin marked entity {newEntity} as CreatedByOtherEntities=true"); if (viewModel.IncludeListsInScreens) { // loop through all screens that have a TMX object and add them. // be smart - if the base screen does, don't do it in the derived var allScreens = GlueState.Self.CurrentGlueProject.Screens; foreach (var screen in allScreens) { var needsList = GetIfScreenNeedsList(screen); if (needsList) { AddObjectViewModel addObjectViewModel = new AddObjectViewModel(); addObjectViewModel.ObjectName = $"{newEntity.GetStrippedName()}List"; addObjectViewModel.SourceType = SourceType.FlatRedBallType; addObjectViewModel.SourceClassType = "PositionedObjectList<T>"; addObjectViewModel.SourceClassGenericType = newEntity.Name; GlueCommands.Self.GluxCommands.AddNewNamedObjectTo( addObjectViewModel, screen, namedObject: null); GlueCommands.Self.PrintOutput( $"Tiled Plugin added {addObjectViewModel.ObjectName} to {screen}"); GlueCommands.Self.GenerateCodeCommands.GenerateElementCode(screen); } } } GlueCommands.Self.GenerateCodeCommands.GenerateElementCode(newEntity); GlueCommands.Self.ProjectCommands.SaveProjects(); GlueState.Self.CurrentEntitySave = newEntity; } }
private static void HandleAddCollisionRelationshipAddClicked(NamedObjectPairRelationshipViewModel pairViewModel) { var addObjectModel = new AddObjectViewModel(); addObjectModel.SourceType = FlatRedBall.Glue.SaveClasses.SourceType.FlatRedBallType; addObjectModel.SourceClassType = "FlatRedBall.Math.Collision.CollisionRelationship"; addObjectModel.ObjectName = "ToBeRenamed"; IElement selectedElement = GlueState.Self.CurrentElement; var selectedNamedObject = GlueState.Self.CurrentNamedObjectSave; var newNos = GlueCommands.Self.GluxCommands.AddNewNamedObjectTo(addObjectModel, selectedElement, namedObject: null); newNos.Properties.SetValue(nameof(CollisionRelationshipViewModel.IsAutoNameEnabled), true); bool needToInvert = selectedNamedObject.SourceType != SourceType.Entity && selectedNamedObject.IsList == false; if (needToInvert) { newNos.Properties.SetValue(nameof(CollisionRelationshipViewModel.FirstCollisionName), pairViewModel.OtherObjectName); newNos.Properties.SetValue(nameof(CollisionRelationshipViewModel.SecondCollisionName), pairViewModel.SelectedNamedObjectName); } else { newNos.Properties.SetValue(nameof(CollisionRelationshipViewModel.FirstCollisionName), pairViewModel.SelectedNamedObjectName); newNos.Properties.SetValue(nameof(CollisionRelationshipViewModel.SecondCollisionName), pairViewModel.OtherObjectName); } CollisionRelationshipViewModelController.TryFixSourceClassType(newNos); // this will regenerate and save everything too: CollisionRelationshipViewModelController.TryApplyAutoName( selectedElement, newNos); RefreshViewModelTo(selectedElement, selectedNamedObject, ViewModel); CollisionRelationshipViewModelController.TryFixMassesForTileShapeCollisionRelationship(selectedElement, newNos); }
public NamedObjectSave AddNewNamedObjectTo(AddObjectViewModel addObjectViewModel, IElement element, NamedObjectSave namedObject) { if (element == null) { throw new ArgumentNullException(nameof(element)); } MembershipInfo membershipInfo = NamedObjectSaveExtensionMethodsGlue.GetMemberMembershipInfo(addObjectViewModel.ObjectName); var newNos = NamedObjectSaveExtensionMethodsGlue.AddNewNamedObjectTo(addObjectViewModel.ObjectName, membershipInfo, element, namedObject, false); if (addObjectViewModel.SourceClassType != NoType && !string.IsNullOrEmpty(addObjectViewModel.SourceClassType)) { newNos.SourceType = addObjectViewModel.SourceType; newNos.SourceClassType = addObjectViewModel.SourceClassType; newNos.SourceFile = addObjectViewModel.SourceFile; newNos.SourceName = addObjectViewModel.SourceNameInFile; newNos.UpdateCustomProperties(); GlueCommands.Self.RefreshCommands.RefreshUi(element); } else if (!string.IsNullOrEmpty(addObjectViewModel.SourceFile)) { newNos.SourceType = addObjectViewModel.SourceType; newNos.SourceFile = addObjectViewModel.SourceFile; newNos.SourceName = addObjectViewModel.SourceNameInFile; newNos.UpdateCustomProperties(); GlueCommands.Self.RefreshCommands.RefreshUi(element); } newNos.SourceClassGenericType = addObjectViewModel.SourceClassGenericType; var ati = newNos.GetAssetTypeInfo(); if (ati != null && ati.DefaultPublic) { newNos.HasPublicProperty = true; } var entity = element as EntitySave; if (entity != null && entity.CreatedByOtherEntities && entity.PooledByFactory) { bool wasAnythingAdded = FlatRedBall.Glue.Factories.FactoryManager.AddResetVariablesFor(newNos); if (wasAnythingAdded) { PluginManager.ReceiveOutput("Added reset variables for " + newNos); } } PluginManager.ReactToNewObject(newNos); MainGlueWindow.Self.PropertyGrid.Refresh(); PropertyGridHelper.UpdateNamedObjectDisplay(); GlueCommands.Self.GenerateCodeCommands.GenerateElementCode(element); GluxCommands.Self.SaveGlux(); return(newNos); }
public NamedObjectSave AddNewNamedObjectToSelectedElement(AddObjectViewModel addObjectViewModel) { return(AddNewNamedObjectTo(addObjectViewModel, GlueState.Self.CurrentElement, GlueState.Self.CurrentNamedObjectSave)); }
private static AddObjectViewModel CreateAndShowAddNamedObjectWindow(AddObjectViewModel addObjectViewModel = null) { TextInputWindow tiw = new TextInputWindow(); tiw.Message = "Enter the new object's name"; tiw.Text = "New Object"; // If windows is zoomed, the text may not wrap properly, so increase it: tiw.Width = 450; var currentObject = GlueState.Self.CurrentNamedObjectSave; bool isTypePredetermined = currentObject != null && currentObject.IsList; NewObjectTypeSelectionControl typeSelectControl = null; if (!isTypePredetermined) { tiw.Width = 400; typeSelectControl = new NewObjectTypeSelectionControl(); typeSelectControl.Width = tiw.Width - 22; typeSelectControl.AfterStrongSelect += delegate { tiw.ClickOk(); }; typeSelectControl.AfterSelect += delegate(object sender, EventArgs args) { string result = tiw.Result; bool isDefault = string.IsNullOrEmpty(result); // Victor Chelaru November 3, 2012 // I don't know if we want to only re-assign when default. // The downside is that the user may have already entered a // name, an then changed the type. This would result in the // user-entered name being overwritten. However, if we don't // change the name, then an old name that the user entered which // is specific to the type may not get reset. I'm leaning towards // always changing the name to help prevent misnaming, and it's also // less programatically complex. //if (isDefault) { string newName; if (!string.IsNullOrEmpty(typeSelectControl.SourceFile) && !string.IsNullOrEmpty(typeSelectControl.SourceName)) { newName = HandleObjectInFileSelected(typeSelectControl); } else if (string.IsNullOrEmpty(typeSelectControl.SourceClassType)) { newName = "ObjectInstance"; } else { var classType = typeSelectControl.SourceClassType; if (classType?.Contains(".") == true) { // un-qualify if it's something like "FlatRedBall.Sprite" var lastIndex = classType.LastIndexOf("."); classType = classType.Substring(lastIndex + 1); } string textToAssign = classType + "Instance"; if (textToAssign.Contains("/") || textToAssign.Contains("\\")) { textToAssign = FileManager.RemovePath(textToAssign); } newName = textToAssign.Replace("<T>", ""); } // We need to make sure this is a unique name. newName = StringFunctions.MakeStringUnique(newName, EditorLogic.CurrentElement.AllNamedObjects); tiw.Result = newName; } }; if (addObjectViewModel != null) { typeSelectControl.SourceType = addObjectViewModel.SourceType; typeSelectControl.SourceFile = addObjectViewModel.SourceFile; } tiw.AddControl(typeSelectControl, AboveOrBelow.Above); } if (addObjectViewModel == null) { addObjectViewModel = new AddObjectViewModel(); } addObjectViewModel.DialogResult = tiw.ShowDialog(); addObjectViewModel.SourceType = SourceType.FlatRedBallType; addObjectViewModel.SourceClassType = null; addObjectViewModel.SourceFile = null; addObjectViewModel.SourceNameInFile = null; addObjectViewModel.SourceClassGenericType = null; addObjectViewModel.ObjectName = tiw.Result; if (isTypePredetermined) { var parentList = GlueState.Self.CurrentNamedObjectSave; var genericType = parentList.SourceClassGenericType; if (!string.IsNullOrEmpty(genericType)) { addObjectViewModel.SourceClassType = genericType; // the generic type will be fully qualified (like FlatRedBall.Sprite) // but object types for FRB primitives are not qualified, so we need to remove // any dots if (addObjectViewModel.SourceClassType.Contains(".")) { int lastDot = addObjectViewModel.SourceClassType.LastIndexOf('.'); addObjectViewModel.SourceClassType = addObjectViewModel.SourceClassType.Substring(lastDot + 1); } if (ObjectFinder.Self.GetEntitySave(genericType) != null) { addObjectViewModel.SourceType = SourceType.Entity; } else { addObjectViewModel.SourceType = SourceType.FlatRedBallType; } } } if (typeSelectControl != null) { if (!string.IsNullOrEmpty(typeSelectControl.SourceClassType) || typeSelectControl.SourceType == SourceType.File) { addObjectViewModel.SourceType = typeSelectControl.SourceType; } addObjectViewModel.SourceFile = typeSelectControl.SourceFile; addObjectViewModel.SourceNameInFile = typeSelectControl.SourceName; addObjectViewModel.SourceClassType = typeSelectControl.SourceClassType; addObjectViewModel.SourceClassGenericType = typeSelectControl.SourceClassGenericType; } return(addObjectViewModel); }
private static EntitySave CreateEntityAndObjects(AddEntityWindow window, string entityName, string directory) { var gluxCommands = GlueCommands.Self.GluxCommands; var newElement = gluxCommands.EntityCommands.AddEntity( directory + entityName, is2D: true); GlueState.Self.CurrentElement = newElement; if (window.SpriteChecked) { AddObjectViewModel addObjectViewModel = new AddObjectViewModel(); addObjectViewModel.ObjectName = "SpriteInstance"; addObjectViewModel.SourceClassType = "Sprite"; addObjectViewModel.SourceType = SourceType.FlatRedBallType; gluxCommands.AddNewNamedObjectToSelectedElement(addObjectViewModel); GlueState.Self.CurrentElement = newElement; } if (window.TextChecked) { AddObjectViewModel addObjectViewModel = new AddObjectViewModel(); addObjectViewModel.ObjectName = "TextInstance"; addObjectViewModel.SourceClassType = "Text"; addObjectViewModel.SourceType = SourceType.FlatRedBallType; gluxCommands.AddNewNamedObjectToSelectedElement(addObjectViewModel); GlueState.Self.CurrentElement = newElement; } if (window.CircleChecked) { AddObjectViewModel addObjectViewModel = new AddObjectViewModel(); addObjectViewModel.ObjectName = "CircleInstance"; addObjectViewModel.SourceClassType = "Circle"; addObjectViewModel.SourceType = SourceType.FlatRedBallType; gluxCommands.AddNewNamedObjectToSelectedElement(addObjectViewModel); GlueState.Self.CurrentElement = newElement; } if (window.AxisAlignedRectangleChecked) { AddObjectViewModel addObjectViewModel = new AddObjectViewModel(); addObjectViewModel.ObjectName = "AxisAlignedRectangleInstance"; addObjectViewModel.SourceClassType = "AxisAlignedRectangle"; addObjectViewModel.SourceType = SourceType.FlatRedBallType; gluxCommands.AddNewNamedObjectToSelectedElement(addObjectViewModel); GlueState.Self.CurrentElement = newElement; } // There are a few important things to note about this function: // 1. Whenever gluxCommands.AddNewNamedObjectToSelectedElement is called, Glue performs a full // refresh and save. The reason for this is that gluxCommands.AddNewNamedObjectToSelectedElement // is the standard way to add a new named object to an element, and it may be called by other parts // of the code (and plugins) that expect the add to be a complete set of logic (add, refresh, save, etc). // This is less efficient than adding all of them and saving only once, but that would require a second add // method, which would add complexity. For now, we deal with the slower calls because it's not really noticeable. // 2. Some actions, like adding Points to a polygon, are done after the polygon is created and added, and that requires // an additional save. Therefore, we do one last save/refresh at the end of this method in certain situations. // Again, this is less efficient than if we performed just a single call, but a single call would be more complicated. // because we'd have to suppress all the other calls. bool needsRefreshAndSave = false; if (window.PolygonChecked) { AddObjectViewModel addObjectViewModel = new AddObjectViewModel(); addObjectViewModel.ObjectName = "PolygonInstance"; addObjectViewModel.SourceClassType = "Polygon"; addObjectViewModel.SourceType = SourceType.FlatRedBallType; var nos = gluxCommands.AddNewNamedObjectToSelectedElement(addObjectViewModel); CustomVariableInNamedObject instructions = null; instructions = nos.GetCustomVariable("Points"); if (instructions == null) { instructions = new CustomVariableInNamedObject(); instructions.Member = "Points"; nos.InstructionSaves.Add(instructions); } var points = new List <Vector2>(); points.Add(new Vector2(-16, 16)); points.Add(new Vector2(16, 16)); points.Add(new Vector2(16, -16)); points.Add(new Vector2(-16, -16)); points.Add(new Vector2(-16, 16)); instructions.Value = points; needsRefreshAndSave = true; GlueState.Self.CurrentElement = newElement; } if (window.IVisibleChecked) { newElement.ImplementsIVisible = true; needsRefreshAndSave = true; } if (window.IClickableChecked) { newElement.ImplementsIClickable = true; needsRefreshAndSave = true; } if (window.IWindowChecked) { newElement.ImplementsIWindow = true; needsRefreshAndSave = true; } if (window.ICollidableChecked) { newElement.ImplementsICollidable = true; needsRefreshAndSave = true; } if (needsRefreshAndSave) { MainGlueWindow.Self.PropertyGrid.Refresh(); ElementViewWindow.GenerateSelectedElementCode(); GluxCommands.Self.SaveGlux(); } return(newElement); }
public NamedObjectSave CreateNewNamedObjectInElement(IElement elementToCreateIn, EntitySave blueprintEntity, bool createList = false) { if (blueprintEntity == null) { throw new ArgumentNullException($"{nameof(blueprintEntity)} cannot be null"); } if (elementToCreateIn is EntitySave && ((EntitySave)elementToCreateIn).ImplementsIVisible && !blueprintEntity.ImplementsIVisible) { var mbmb = new MultiButtonMessageBoxWpf(); mbmb.MessageText = "The Entity\n\n" + blueprintEntity + "\n\nDoes not Implement IVisible, but the Entity it is being dropped in does. " + "What would you like to do?"; mbmb.AddButton("Make " + blueprintEntity.Name + " implement IVisible", DialogResult.OK); mbmb.AddButton("Nothing (your code will not compile until this problem is resolved manually)", DialogResult.Cancel); var dialogResult = mbmb.ShowDialog(); DialogResult result = DialogResult.Cancel; if (mbmb.ClickedResult != null && dialogResult == true) { result = (DialogResult)mbmb.ClickedResult; } if (result == DialogResult.OK) { blueprintEntity.ImplementsIVisible = true; GlueCommands.Self.GenerateCodeCommands .GenerateElementAndReferencedObjectCodeTask(blueprintEntity); } } var addObjectViewModel = new AddObjectViewModel(); // We'll add "List" or "Instance" below //string newName = FileManager.RemovePath(blueprintEntity.Name); addObjectViewModel.ObjectName = FileManager.RemovePath(blueprintEntity.Name); #region Set the source type properties for the new NamedObject if (createList) { addObjectViewModel.ObjectName += "List"; addObjectViewModel.SourceType = SourceType.FlatRedBallType; addObjectViewModel.SourceClassType = "PositionedObjectList<T>"; addObjectViewModel.SourceClassGenericType = blueprintEntity.Name; } else { addObjectViewModel.ObjectName += "Instance"; addObjectViewModel.SourceType = SourceType.Entity; addObjectViewModel.SourceClassType = blueprintEntity.Name; } #endregion #region Set the name for the new NamedObject // get an acceptable name for the new object if (elementToCreateIn.GetNamedObjectRecursively(addObjectViewModel.ObjectName) != null) { addObjectViewModel.ObjectName += "2"; } while (elementToCreateIn.GetNamedObjectRecursively(addObjectViewModel.ObjectName) != null) { addObjectViewModel.ObjectName = StringFunctions.IncrementNumberAtEnd(addObjectViewModel.ObjectName); } #endregion return(GlueCommands.Self.GluxCommands.AddNewNamedObjectTo(addObjectViewModel, elementToCreateIn, null)); }
private static void MoveReferencedFile(TreeNode treeNodeMoving, TreeNode targetNode) { var response = GeneralResponse.SuccessfulResponse; while (targetNode != null && targetNode.IsReferencedFile()) { targetNode = targetNode.Parent; } // If the user drops a file on a Screen or Entity, let's allow them to // complete the operation on the Files node if (targetNode is BaseElementTreeNode) { targetNode = ((BaseElementTreeNode)targetNode).FilesTreeNode; } ReferencedFileSave referencedFileSave = treeNodeMoving.Tag as ReferencedFileSave; if (!targetNode.IsFilesContainerNode() && !targetNode.IsFolderInFilesContainerNode() && !targetNode.IsFolderForGlobalContentFiles() && !targetNode.IsNamedObjectNode() && !targetNode.IsRootNamedObjectNode()) { response.Fail(@"Can't drop this file here"); } else if (!string.IsNullOrEmpty(referencedFileSave.SourceFile) || referencedFileSave.SourceFileCache.Count != 0) { response.Fail("Can't move the file\n\n" + referencedFileSave.Name + "\n\nbecause it has source-referencing files. These sources will be broken " + "if the file is moved. You will need to manually move the file, modify the source references, remove this file, then add the newly-created file."); } if (response.Succeeded) { if (targetNode.IsGlobalContentContainerNode()) { if (targetNode.GetContainingElementTreeNode() == null) { string targetDirectory = ProjectManager.MakeAbsolute(targetNode.GetRelativePath(), true); MoveReferencedFileToDirectory(referencedFileSave, targetDirectory); } else { DragAddFileToGlobalContent(treeNodeMoving, referencedFileSave); // This means the user wants to add the file // to global content. } } else if (targetNode.IsFolderForGlobalContentFiles()) { string targetDirectory = ProjectManager.MakeAbsolute(targetNode.GetRelativePath(), true); MoveReferencedFileToDirectory(referencedFileSave, targetDirectory); } else if (targetNode.IsRootNamedObjectNode()) { AddObjectViewModel viewModel = new AddObjectViewModel(); viewModel.SourceType = SourceType.File; viewModel.SourceFile = (treeNodeMoving.Tag as ReferencedFileSave).Name; GlueCommands.Self.DialogCommands.ShowAddNewObjectDialog(viewModel); } else if (targetNode.IsNamedObjectNode() && // dropping on an object in the same element targetNode.GetContainingElementTreeNode() == treeNodeMoving.GetContainingElementTreeNode()) { response = HandleDroppingFileOnObjectInSameElement(targetNode, referencedFileSave); } //if (targetNode.IsFolderInFilesContainerNode() || targetNode.IsFilesContainerNode()) else { // See if we're moving the RFS from one Element to another IElement container = ObjectFinder.Self.GetElementContaining(referencedFileSave); TreeNode elementTreeNodeDroppingIn = targetNode.GetContainingElementTreeNode(); IElement elementDroppingIn = null; if (elementTreeNodeDroppingIn != null) { // User didn't drop on an entity, but instead on a node within the entity. // Let's check if it's a subfolder. If so, we need to tell the user that we // can't add the file in a subfolder. if (targetNode.IsFolderInFilesContainerNode()) { response.Message = "Shared files cannot be added to subfolders, so it will be added directly to \"Files\""; } elementDroppingIn = elementTreeNodeDroppingIn.Tag as IElement; } if (container != elementDroppingIn) { // Make sure the target element is not named the same as the file itself. // For example, dropping a file called Level1.tmx in a screen called Level1. // This will not compile so we shouldn't allow it. var areNamedTheSame = elementDroppingIn.GetStrippedName() == referencedFileSave.GetInstanceName(); if (areNamedTheSame) { response.Fail($"The file {referencedFileSave.GetInstanceName()} has the same name as the target screen. it will not be added since this is not allowed."); } if (response.Succeeded) { ElementViewWindow.SelectedNode = targetNode; string absoluteFileName = ProjectManager.MakeAbsolute(referencedFileSave.Name, true); string creationReport; string errorMessage; var newlyCreatedFile = ElementCommands.Self.CreateReferencedFileSaveForExistingFile(elementDroppingIn, null, absoluteFileName, PromptHandleEnum.Prompt, referencedFileSave.GetAssetTypeInfo(), out creationReport, out errorMessage); ElementViewWindow.UpdateChangedElements(); if (!String.IsNullOrEmpty(errorMessage)) { MessageBox.Show(errorMessage); } else if (newlyCreatedFile != null) { GlueCommands.Self.TreeNodeCommands.SelectTreeNode(newlyCreatedFile); } } } else { // Not moving into or out of an element string targetDirectory = ProjectManager.MakeAbsolute(targetNode.GetRelativePath(), true); MoveReferencedFileToDirectory(referencedFileSave, targetDirectory); } } } if (!string.IsNullOrEmpty(response.Message)) { MessageBox.Show(response.Message); } }