private void toolbar_AddClicked() { if (m_data.ReadOnly) { return; } var result = PopupEditors.EditString(m_helper.ControlDefinition.GetString("editprompt"), string.Empty); if (result.Cancelled) { return; } if (!ValidateInput(result.Result)) { return; } if (m_list == null) { CurrentList = m_helper.Controller.CreateNewEditableList(m_data.Name, m_helper.ControlDefinition.Attribute, result.Result, true); } else { PrepareForEditing(); m_list.Add(result.Result); } }
private void EditCurrentSelection() { if (listBox.SelectedItem == null) { return; } if (m_data.ReadOnly) { return; } EditableListItem <string> currentSelection = (EditableListItem <string>)listBox.SelectedItem; int index = listBox.SelectedIndex; var result = PopupEditors.EditString(m_helper.ControlDefinition.GetString("editprompt"), currentSelection.Value); if (result.Cancelled) { return; } if (result.Result == currentSelection.Value) { return; } if (!ValidateInput(result.Result)) { return; } PrepareForEditing(); m_list.Update(index, result.Result); }
protected virtual void Add(string attributeName, Func <object> createAttributeValue) { if (attributeName.Length == 0) { PopupEditors.EditStringResult result = PopupEditors.EditString(L.T("EditorEnterNameAttribute"), string.Empty); if (result.Cancelled) { return; } attributeName = result.Result; } bool setSelection = true; if (!lstAttributes.Items.ContainsKey(attributeName)) { m_controller.StartTransaction(string.Format("Add '{0}' attribute", attributeName)); ValidationResult setAttrResult = m_data.SetAttribute(attributeName, createAttributeValue()); if (!setAttrResult.Valid) { PopupEditors.DisplayValidationError(setAttrResult, attributeName, "Unable to add attribute"); setSelection = false; } m_controller.EndTransaction(); } if (setSelection) { lstAttributes.Items[attributeName].Selected = true; lstAttributes.SelectedItems[0].EnsureVisible(); } }
private void AddVerb(string selectedPattern, string selectedAttribute) { bool setSelection = true; if (!lstAttributes.Items.ContainsKey(selectedAttribute)) { if (!CanAddVerb(selectedPattern, selectedAttribute)) { return; } Controller.StartTransaction(string.Format("Add '{0}' verb", selectedPattern)); if (!Controller.IsVerbAttribute(selectedAttribute)) { CreateNewVerb(selectedPattern, selectedAttribute); } ValidationResult setAttrResult = Data.SetAttribute(selectedAttribute, String.Empty); if (!setAttrResult.Valid) { PopupEditors.DisplayValidationError(setAttrResult, selectedAttribute, "Unable to add verb"); setSelection = false; } Controller.EndTransaction(); } if (setSelection) { lstAttributes.Items[selectedAttribute].Selected = true; lstAttributes.SelectedItems[0].EnsureVisible(); } }
private void cmdAddScript_Click(object sender, RoutedEventArgs e) { var script = PopupEditors.AddScript(m_controller); if (script != null) { AddNewScriptCommand(script); } }
private void InsertObject(TextProcessorCommand command) { var objects = m_helper.Controller.GetObjectNames("object", true).OrderBy(n => n); var result = PopupEditors.EditStringWithDropdown( "Please choose an object", string.Empty, null, null, string.Empty, objects); if (!result.Cancelled) { InsertText(command.InsertBefore + result.Result + command.InsertAfter, string.Empty); } }
private void InsertPage(TextProcessorCommand command) { var pages = m_helper.Controller.GetObjectNames("object", true).Where(n => n != "player").OrderBy(n => n); var result = PopupEditors.EditStringWithDropdown("Link text", string.Empty, "Add link to", pages, pages.First(), allowEmptyString: true); if (!result.Cancelled) { InsertText( command.InsertBefore + result.ListResult + (result.Result.Length > 0 ? ":" + result.Result : "") + command.InsertAfter, string.Empty); } }
private void InsertExit(TextProcessorCommand command) { var text = L.T("EditorKeypromptEnterExitName"); var objects = m_helper.Controller.GetObjectNames("exit", true).OrderBy(n => n); var result = PopupEditors.EditStringWithDropdown( text, string.Empty, null, null, string.Empty, objects); if (!result.Cancelled) { InsertText(command.InsertBefore + result.Result + command.InsertAfter, string.Empty); } }
private void AddNewPage() { m_manager.DoAddKeyAction((newKey) => { ValidationResult result = m_controller.CanAdd(newKey); if (!result.Valid) { PopupEditors.DisplayValidationError(result, newKey, "Unable to add page"); return(false); } m_controller.CreateNewObject(newKey, null, null); return(true); }, m_controller.GetUniqueElementName("Page1")); }
private void InsertFromList(string itemName, IEnumerable <string> items) { var result = PopupEditors.EditStringWithDropdown( string.Format("Please enter {0} name", itemName), string.Empty, null, null, "", items); if (result.Cancelled) { txtExpression.Focus(); return; } InsertString(result.Result); }
private bool ValidateInput(string input) { if (m_list == null) { return(true); } ValidationResult result = m_list.CanAdd(input); if (result.Valid) { return(true); } PopupEditors.DisplayValidationError(result, input, "Unable to add item"); return(false); }
public void DoEditKey(string key, int index) { var newKey = PopupEditors.EditString(m_controlData.GetString("keyprompt"), key, GetAutoCompleteList()); if (newKey.Cancelled || newKey.Result == key) { return; } if (!ValidateInput(newKey.Result)) { return; } m_controller.StartTransaction(string.Format("Update key '{0}' to '{1}'", key, newKey.Result)); m_list.ChangeKey(key, newKey.Result); m_controller.EndTransaction(); }
public void DoAddKeyAction(Func <string, bool> keyAction, string suggestedNewKey) { var addKey = PopupEditors.EditString(m_controlData.GetString("keyprompt"), suggestedNewKey, GetAutoCompleteList()); if (addKey.Cancelled) { return; } if (!ValidateInput(addKey.Result)) { return; } if (keyAction(addKey.Result)) { AddNewValue(addKey); } }
protected override void AddNewValue(PopupEditors.EditStringResult addKey) { IEditableScripts script = Controller.CreateNewEditableScripts(null, null, null, true); if (List == null) { Value = Controller.CreateNewEditableScriptDictionary(ElementName, AttributeName, addKey.Result, script, true); // Script will have been cloned, so ensure we use a reference to the script that actually appears in the dictionary script = List[addKey.Result]; } else { List.Add(addKey.Result, script); } PopupEditors.EditScript(Controller, ref script, null, null, false, () => RaiseDirty(new DataModifiedEventArgs(null, List))); }
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); }
public void Save() { bool save = true; if (!m_helper.IsDirty) { return; } m_saving = true; string saveValue = null; if (SimpleMode) { saveValue = ConvertFromSimpleExpression(SimpleValue); } else if (TemplateMode) { saveValue = m_templateEditor.SaveExpression(); } else { saveValue = txtExpression.Text; } ValidationResult result = m_helper.Controller.ValidateExpression(saveValue); save = result.Valid; if (!result.Valid) { PopupEditors.DisplayValidationError(result, saveValue, "Invalid expression"); } if (m_helper.ControlDefinition.GetBool("nullable") && string.IsNullOrEmpty(saveValue)) { saveValue = null; } if (save) { m_helper.Save(saveValue); } m_saving = false; if (!save) { Populate(m_data); } }
protected override void EditValue(string key) { var result = PopupEditors.EditString(ControlData.GetString("valueprompt"), List[key], allowEmptyString: true); if (result.Cancelled) { return; } if (result.Result == List[key]) { return; } PrepareForEditing(); Controller.StartTransaction(string.Format("Update '{0}='{1}'", key, result.Result)); List.Update(key, result.Result); Controller.EndTransaction(); }
private void cmdAddType_Click(object sender, EventArgs e) { if (m_readOnly) { return; } var availableTypes = m_controller.GetElementNames("type") .Where(t => !lstTypes.Items.ContainsKey(t)) .Where(t => !m_controller.IsDefaultTypeName(t)) .OrderBy(t => t); var result = PopupEditors.EditStringWithDropdown(L.T("EditorChooseTypeToAdd"), string.Empty, null, null, string.Empty, availableTypes); if (result.Cancelled) { return; } if (!availableTypes.Contains(result.Result)) { if (lstTypes.Items.ContainsKey(result.Result)) { MessageBox.Show(string.Format("Type '{0}' is already inherited", result.Result), "Invalid type", MessageBoxButtons.OK, MessageBoxIcon.Exclamation); } else { MessageBox.Show(string.Format("Type '{0}' does not exist", result.Result), "Invalid type", MessageBoxButtons.OK, MessageBoxIcon.Exclamation); } return; } var addResult = m_controller.AddInheritedTypeToElement(m_data.Name, result.Result, true); if (!addResult.Valid) { PopupEditors.DisplayValidationError(addResult, null, "Unable to add type"); } }
protected override void AddNewValue(PopupEditors.EditStringResult addKey) { var addValue = PopupEditors.EditString(ControlData.GetString("valueprompt"), string.Empty, allowEmptyString: true); if (addValue.Cancelled) { return; } PrepareForEditing(); if (List == null) { Value = Controller.CreateNewEditableStringDictionary(ElementName, AttributeName, addKey.Result, addValue.Result, true); } else { List.Add(addKey.Result, addValue.Result); } }
protected override void Add() { // TO DO: This fetches all verbs in the game, but verbs can be defined in rooms, so we should // filter out any out-of-scope verbs. IDictionary <string, string> availableVerbs = Controller.GetVerbProperties(); PopupEditors.EditStringResult result = PopupEditors.EditString( "Please enter a name for the new verb", string.Empty, availableVerbs.Values); if (result.Cancelled) { return; } string selectedPattern = result.Result.ToLower(); string selectedAttribute = Controller.GetVerbAttributeForPattern(selectedPattern); AddVerb(selectedPattern, selectedAttribute); }
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(); }
protected override void EditValue(string key) { IEditableScripts script = List[key]; PopupEditors.EditScript(Controller, ref script, null, null, false, () => RaiseDirty(new DataModifiedEventArgs(null, List))); }