private void AddItemPoolClick(object sender, EventArgs e) { if (_itemPoolDialog.ShowDialog(this) == DialogResult.OK) { var name = _itemPoolDialog.ItemPoolName; try { // Create a new instance. var instance = new ItemPool { Name = name }; // Register it. ItemPoolManager.Add(instance); // And select it. SelectItemPool(instance); // Add undo command. PushUndo("add item pool", () => { if (MessageBox.Show(this, "Are you sure you wish to delete the item pool '" + instance.Name + "'?", "Confirmation", MessageBoxButtons.YesNo, MessageBoxIcon.Question) == DialogResult.Yes) { ItemPoolManager.Remove(instance); return(true); } return(false); }); } catch (Exception ex) { MessageBox.Show(this, "Failed creating new item pool:\n" + ex, "Error", MessageBoxButtons.OK, MessageBoxIcon.Error); } } }
private void RemoveClick(object sender, EventArgs e) { if (pgProperties.SelectedObject == null) { return; } if (tvData.Focused || (sender == miDelete && miDelete.Visible)) { if (pgProperties.SelectedObject is IFactory) { var factory = (IFactory)pgProperties.SelectedObject; if ((ModifierKeys & Keys.Shift) != 0 || MessageBox.Show(this, "Are you sure you wish to delete the factory '" + factory.Name + "'?", "Confirmation", MessageBoxButtons.YesNo, MessageBoxIcon.Question) == DialogResult.Yes) { FactoryManager.Remove(factory); // Add undo command. PushUndo("remove factory", () => { FactoryManager.Add(factory); return(true); }); } } else if (pgProperties.SelectedObject is ItemPool) { var itemPool = (ItemPool)pgProperties.SelectedObject; if ((ModifierKeys & Keys.Shift) != 0 || MessageBox.Show(this, "Are you sure you wish to delete the item pool '" + itemPool.Name + "'?", "Confirmation", MessageBoxButtons.YesNo, MessageBoxIcon.Question) == DialogResult.Yes) { ItemPoolManager.Remove(itemPool); // Add undo command. PushUndo("remove item pool", () => { ItemPoolManager.Add(itemPool); return(true); }); } } else if (pgProperties.SelectedObject is AttributePool) { var attributePool = (AttributePool)pgProperties.SelectedObject; if ((ModifierKeys & Keys.Shift) != 0 || MessageBox.Show(this, "Are you sure you wish to delete the attribute pool '" + attributePool.Name + "'?", "Confirmation", MessageBoxButtons.YesNo, MessageBoxIcon.Question) == DialogResult.Yes) { AttributePoolManager.Remove(attributePool); // Add undo command. PushUndo("remove attribute pool", () => { AttributePoolManager.Add(attributePool); return(true); }); } } } }