private bool ResolveDuplicateProjectEntry(bool wasChanged, ProjectItem buildItem) { #if GLUE var mbmb = new MultiButtonMessageBoxWpf(); mbmb.MessageText = "The item " + buildItem.UnevaluatedInclude + " is part of " + "the project twice. Glue does not support double-entries in a project. What would you like to do?"; mbmb.AddButton("Remove the duplicate entry and continue", System.Windows.Forms.DialogResult.OK); mbmb.AddButton("Remove the duplicate, but show me a list of all contained objects before removal", System.Windows.Forms.DialogResult.No); mbmb.AddButton("Cancel loading the project - this will throw an exception", System.Windows.Forms.DialogResult.Cancel); DialogResult result = DialogResult.Cancel; if (mbmb.ShowDialog() == true) { result = (DialogResult)mbmb.ClickedResult; switch (result) { case DialogResult.OK: mProject.RemoveItem(buildItem); mProject.ReevaluateIfNecessary(); break; case DialogResult.No: StringBuilder stringBuilder = new StringBuilder(); foreach (var item in mProject.AllEvaluatedItems) { stringBuilder.AppendLine(item.ItemType + " " + item.UnevaluatedInclude); } string whereToSave = FileManager.UserApplicationDataForThisApplication + "ProjectFileOutput.txt"; FileManager.SaveText(stringBuilder.ToString(), whereToSave); Process.Start(whereToSave); mProject.RemoveItem(buildItem); mProject.ReevaluateIfNecessary(); break; case DialogResult.Cancel: throw new Exception("Duplicate entries found: " + buildItem.ItemType + " " + buildItem.UnevaluatedInclude); } } else #endif { //mProject.EvaluatedItems.RemoveItemAt(i); mProject.RemoveItem(buildItem); mProject.ReevaluateIfNecessary(); } wasChanged = true; return(wasChanged); }
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)); }
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; CodeGeneratorIElement.GenerateElementDerivedAndReferenced(blueprintEntity); } } NamedObjectSave newNamedObject = new NamedObjectSave(); // We'll add "List" or "Instance" below string newName = FileManager.RemovePath(blueprintEntity.Name); #region Set the source type properties for the new NamedObject if (createList) { newName += "List"; newNamedObject.SourceType = SourceType.FlatRedBallType; newNamedObject.SourceClassType = "PositionedObjectList<T>"; newNamedObject.SourceClassGenericType = blueprintEntity.Name; newNamedObject.UpdateCustomProperties(); } else { newName += "Instance"; newNamedObject.SourceType = SourceType.Entity; newNamedObject.SourceClassType = blueprintEntity.Name; newNamedObject.UpdateCustomProperties(); } #endregion #region Set the name for the new NamedObject // get an acceptable name for the new object if (elementToCreateIn.GetNamedObjectRecursively(newName) != null) { newName += "2"; } while (elementToCreateIn.GetNamedObjectRecursively(newName) != null) { newName = StringFunctions.IncrementNumberAtEnd(newName); } newNamedObject.InstanceName = newName; #endregion // We need to add to managers here. Why? Because normally when the type of a NamedObject is changed, // the PropertyGrid handles setting whether it should be added or not. But in this case, we're not changing // the type of the new NamedObject through the PropertyGrid - instead it's being set programatically to be an // Entity. So, we should add to managers programatically since the PropertyGrid won't do it for us. // Update December 11, 2011 // AddToManagers defaults to // true on new NamedObjectSaves // so there's no need to explicitly // set it to true here. //newNamedObject.AddToManagers = true; NamedObjectSaveExtensionMethodsGlue.AddExistingNamedObjectToElement(elementToCreateIn, newNamedObject, true); Plugins.PluginManager.ReceiveOutput($"Created {newNamedObject}"); return(newNamedObject); }