private void CreateNewVerb(string selectedPattern, string selectedAttribute) { string newVerbId = Controller.CreateNewVerb(null, false); IEditorData verbData = Controller.GetEditorData(newVerbId); verbData.SetAttribute("property", selectedAttribute); EditableCommandPattern pattern = (EditableCommandPattern)verbData.GetAttribute("pattern"); pattern.Pattern = selectedPattern; verbData.SetAttribute("defaultexpression", m_defaultExpression.Replace("#verb#", selectedPattern)); }
private void FilenameUpdated(string filename) { if (m_data != null) { m_helper.Controller.StartTransaction(String.Format("Set filename to '{0}'", filename)); m_data.SetAttribute(m_helper.ControlDefinition.Attribute, filename); m_helper.Controller.EndTransaction(); Populate(m_data); } }
internal void Save(T newValue) { if (m_populating) { return; } if (!m_dirty) { return; } if (m_saving) { return; } m_saving = true; // When we call m_data.SetAttribute below, that can trigger off a whole chain of events which may // cause us to be Unpopulated before we finish the function. We'll still need to finish the transaction, // so we make copies first. bool directlySaveable = m_data.IsDirectlySaveable; EditorController controller = Controller; string caption = ControlDefinition.Caption; if (directlySaveable) { controller.StartTransaction(string.Format("Set {0} to '{1}'", ControlDefinition.Caption, newValue == null ? "null" : newValue.ToString())); } ValidationResult result = m_data.SetAttribute(ControlDefinition.Attribute, newValue); if (!result.Valid) { string errorValue = newValue as string; PopupEditors.DisplayValidationError(result, errorValue, string.Format("Unable to set '{0}'", caption)); } if (directlySaveable) { controller.EndTransaction(); } m_saving = false; // Repopulating ensures we see the currently set value, and that dirty=false m_parent.Populate(m_data); }
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(); }
public void Save(IEditorData data) { if (IsDirty) { string description = string.Format("Set {0} to '{1}'", m_attributeName, Value); m_controller.StartTransaction(description); data.SetAttribute(AttributeName, Value); m_controller.EndTransaction(); // reset the dirty flag Value = Value; System.Diagnostics.Debug.Assert(!IsDirty); } }
private object GetScriptParameterValue(ElementSaveData.ScriptSaveData scriptLine, EditorController controller, IValueProvider provider, string attributePrefix, string controlType, string simpleEditor, string templatesFilter, string oldValue, string ignoreExpression) { if (attributePrefix == ignoreExpression) { return(new IgnoredValue()); } if (controlType == "expression") { if (templatesFilter == null) { string dropdownKey = string.Format("{0}-expressioneditordropdown", attributePrefix); ValueProviderResult dropdownKeyValueResult = provider.GetValue(dropdownKey); string dropdownKeyValue = (dropdownKeyValueResult != null) ? dropdownKeyValueResult.ConvertTo(typeof(string)) as string : null; if (dropdownKeyValue == "expression" || dropdownKeyValue == null) { string key = string.Format("{0}-expressioneditor", attributePrefix); return(GetAndValidateValueProviderString(provider, key, oldValue, scriptLine, controller)); } else { if (simpleEditor == "boolean") { return(dropdownKeyValue == "yes" ? "true" : "false"); } else { string key = string.Format("{0}-simpleeditor", attributePrefix); string simpleValue = GetValueProviderString(provider, key); if (simpleValue == null) { return(string.Empty); } switch (simpleEditor) { case "objects": case "number": case "numberdouble": return(simpleValue); default: return(EditorUtility.ConvertFromSimpleStringExpression(simpleValue)); } } } } else { string dropdownKey = string.Format("{0}-templatedropdown", attributePrefix); string dropdownKeyValue = provider.GetValue(dropdownKey).ConvertTo(typeof(string)) as string; if (dropdownKeyValue == "expression") { string key = attributePrefix; return(GetAndValidateValueProviderString(provider, key, oldValue, scriptLine, controller)); } else { IEditorDefinition editorDefinition = controller.GetExpressionEditorDefinition(oldValue, templatesFilter); IEditorData data = controller.GetExpressionEditorData(oldValue, templatesFilter, null); foreach (IEditorControl ctl in editorDefinition.Controls.Where(c => c.Attribute != null)) { string key = attributePrefix + "-" + ctl.Attribute; object value = GetScriptParameterValue(scriptLine, controller, provider, key, ctl.ControlType, ctl.GetString("simpleeditor") ?? "textbox", null, null, ignoreExpression); data.SetAttribute(ctl.Attribute, value); } return(controller.GetExpression(data, null, null)); } } } else { string key = attributePrefix; return(GetValueProviderString(provider, key)); } }