private void lstTypes_SelectionChanged(object sender, SelectionChangedEventArgs e) { // only respond to user changes if (m_settingType) { return; } TypesListItem selectedType = m_types.First(s => s.TypeIndex == lstTypes.SelectedIndex); UserSelectedNewType(selectedType); }
private void UserSelectedNewType(TypesListItem type) { m_controller.StartTransaction(string.Format("Change type of '{0}' {1} to '{2}'", m_data.Name, m_definition.Attribute, type.TypeDescription)); object newValue; // If the user has previously selected this type, use the previous value, otherwise create a new // default value for that type. This allows the user to switch back and forth between different // types without the value being cleared out if they change their mind. if (m_storedValues.ContainsKey(type.TypeName)) { newValue = m_storedValues[type.TypeName]; } else { switch (type.TypeName) { case "boolean": newValue = false; break; case "string": newValue = ""; break; case "int": newValue = 0; break; case "script": newValue = m_controller.CreateNewEditableScripts(m_data.Name, m_definition.Attribute, null, false); break; case "stringlist": newValue = m_controller.CreateNewEditableList(m_data.Name, m_definition.Attribute, null, false); break; case "object": newValue = m_controller.CreateNewEditableObjectReference(m_data.Name, m_definition.Attribute, false); break; case "simplepattern": newValue = m_controller.CreateNewEditableCommandPattern(m_data.Name, m_definition.Attribute, "", false); break; case "stringdictionary": newValue = m_controller.CreateNewEditableStringDictionary(m_data.Name, m_definition.Attribute, null, null, false); break; case "scriptdictionary": newValue = m_controller.CreateNewEditableScriptDictionary(m_data.Name, m_definition.Attribute, null, null, false); break; case "null": newValue = null; break; default: throw new InvalidOperationException(); } } var result = m_data.SetAttribute(m_definition.Attribute, newValue); if (!result.Valid) { PopupEditors.DisplayValidationError(result, newValue as string, "Unable to set attribute value"); } m_controller.EndTransaction(); }
private void UserSelectedNewType(TypesListItem type) { m_controller.StartTransaction(string.Format("Change type of '{0}' {1} to '{2}'", m_data.Name, m_definition.Attribute, type.TypeDescription)); object newValue; // If the user has previously selected this type, use the previous value, otherwise create a new // default value for that type. This allows the user to switch back and forth between different // types without the value being cleared out if they change their mind. if (m_storedValues.ContainsKey(type.TypeName)) { newValue = m_storedValues[type.TypeName]; } else { switch (type.TypeName) { case "boolean": newValue = false; break; case "string": newValue = ""; break; case "int": newValue = 0; break; case "double": newValue = 0.0; break; case "script": newValue = m_controller.CreateNewEditableScripts(m_data.Name, m_definition.Attribute, null, false); break; case "stringlist": newValue = m_controller.CreateNewEditableList(m_data.Name, m_definition.Attribute, null, false); break; case "object": newValue = m_controller.CreateNewEditableObjectReference(m_data.Name, m_definition.Attribute, false); break; case "simplepattern": newValue = m_controller.CreateNewEditableCommandPattern(m_data.Name, m_definition.Attribute, "", false); break; case "stringdictionary": newValue = m_controller.CreateNewEditableStringDictionary(m_data.Name, m_definition.Attribute, null, null, false); break; case "scriptdictionary": newValue = m_controller.CreateNewEditableScriptDictionary(m_data.Name, m_definition.Attribute, null, null, false); break; case "null": newValue = null; break; default: throw new InvalidOperationException(); } } var result = m_data.SetAttribute(m_definition.Attribute, newValue); if (!result.Valid) { PopupEditors.DisplayValidationError(result, newValue as string, "Unable to set attribute value"); } m_controller.EndTransaction(); }