Exemplo n.º 1
0
        private void AddFactoryClick(object sender, EventArgs e)
        {
            if (_factoryDialog.ShowDialog(this) == DialogResult.OK)
            {
                var type = _factoryDialog.FactoryType;
                var name = _factoryDialog.FactoryName;

                try
                {
                    // Create a new instance of this factory type.
                    var instance = Activator.CreateInstance(type) as IFactory;
                    if (instance == null)
                    {
                        // This should not happen. Ever.
                        throw new ArgumentException("Resulting object was not a factory.");
                    }
                    instance.Name = name;

                    // Register it.
                    FactoryManager.Add(instance);

                    // And select it.
                    SelectFactory(instance);

                    // Add undo command.
                    PushUndo("add factory", () =>
                    {
                        if (MessageBox.Show(this,
                                            "Are you sure you wish to delete the factory '" + instance.Name + "'?",
                                            "Confirmation", MessageBoxButtons.YesNo,
                                            MessageBoxIcon.Question) == DialogResult.Yes)
                        {
                            FactoryManager.Remove(instance);
                            return(true);
                        }
                        return(false);
                    });
                }
                catch (Exception ex)
                {
                    MessageBox.Show(this, "Failed creating new factory:\n" + ex, "Error",
                                    MessageBoxButtons.OK, MessageBoxIcon.Error);
                }
            }
        }
Exemplo n.º 2
0
        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);
                        });
                    }
                }
            }
        }