private void PrepareNewComponentSave(ComponentSave componentSave, string componentName) { componentSave.Name = componentName; componentSave.BaseType = "Container"; componentSave.InitializeDefaultAndComponentVariables(); // components shouldn't set their positions to 0 by default, so if the // default state sets those values, we should null them out: var xVariable = componentSave.DefaultState.GetVariableSave("X"); var yVariable = componentSave.DefaultState.GetVariableSave("Y"); if (xVariable != null) { xVariable.Value = null; xVariable.SetsValue = false; } if (yVariable != null) { yVariable.Value = null; yVariable.SetsValue = false; } var hasEventsVariable = componentSave.DefaultState.GetVariableSave("HasEvents"); if (hasEventsVariable != null) { hasEventsVariable.Value = true; } }
public ComponentSave AddComponent(string componentName) { ComponentSave componentSave = new ComponentSave(); componentSave.BaseType = "Container"; componentSave.Name = componentName; ProjectManager.Self.GumProjectSave.ComponentReferences.Add(new ElementReference { Name = componentName, ElementType = ElementType.Component }); ProjectManager.Self.GumProjectSave.ComponentReferences.Sort((first, second) => first.Name.CompareTo(second.Name)); ProjectManager.Self.GumProjectSave.Components.Add(componentSave); componentSave.InitializeDefaultAndComponentVariables(); // components shouldn't set their positions to 0 by default, so if the // default state sets those values, we should null them out: var xVariable = componentSave.DefaultState.GetVariableSave("X"); var yVariable = componentSave.DefaultState.GetVariableSave("Y"); if (xVariable != null) { xVariable.Value = null; xVariable.SetsValue = false; } if (yVariable != null) { yVariable.Value = null; yVariable.SetsValue = false; } return(componentSave); }