private void b_AddDefinition_Click(object sender, EventArgs e)
        {
            var definition = DefinitionEditor.GetNewDefinition(hud, parentDefinitionGroup);

            if (definition is null)
            {
                return;
            }

            definition.SetParentDefinitionGroup(parentDefinitionGroup);
            parentDefinitionGroup.definitions.Add(definition);
            modified = true;

            ReloadDefinitions();
        }
예제 #2
0
        private static DefinitionEditor GetNewDefinitionEditor(IController hud, AbstractDefinition definition = null)
        {
            var definitionEditor = new DefinitionEditor(hud)
            {
                Enabled = true
            };

            if (definition is null)
            {
                return(definitionEditor);
            }

            definitionEditor.LoadExistingDefinition(definition);
            definitionEditor.cb_Group.Enabled          = false;
            definitionEditor.cb_DefinitionType.Enabled = false;

            return(definitionEditor);
        }
        private void  InitializeDataGridView()
        {
            dgv_Definitions.RowHeadersVisible                   = false;
            dgv_Definitions.AllowUserToAddRows                  = false;
            dgv_Definitions.AllowUserToResizeColumns            = false;
            dgv_Definitions.AllowUserToResizeRows               = false;
            dgv_Definitions.DefaultCellStyle.SelectionBackColor = dgv_Definitions.DefaultCellStyle.BackColor;
            dgv_Definitions.DefaultCellStyle.SelectionForeColor = dgv_Definitions.DefaultCellStyle.ForeColor;

            var columns = DgvFormUtil.GetDefinitionGroupEditorColumns();

            columns.ForEach(column => dgv_Definitions.Columns.Add(column));

            dgv_Definitions.CurrentCellDirtyStateChanged += (sender, args) =>
            {
                if (dgv_Definitions.IsCurrentCellDirty &&
                    (dgv_Definitions.CurrentCell.OwningColumn == dgv_Definitions.Columns["active"] ||
                     dgv_Definitions.CurrentCell.OwningColumn == dgv_Definitions.Columns["inverted"])
                    )
                {
                    dgv_Definitions.CommitEdit(DataGridViewDataErrorContexts.Commit);
                }
            };

            dgv_Definitions.CellContentClick += (sender, args) =>
            {
                if (args.ColumnIndex == dgv_Definitions.Columns["active"]?.Index)
                {
                    var val       = (DataGridViewCheckBoxCell)dgv_Definitions.Rows[args.RowIndex].Cells["active"];
                    var isChecked = Convert.ToBoolean(val.Value);
                    parentDefinitionGroup.definitions[args.RowIndex].active = isChecked;
                    modified = true;
                }

                else if (args.ColumnIndex == dgv_Definitions.Columns["inverted"]?.Index)
                {
                    var val       = (DataGridViewCheckBoxCell)dgv_Definitions.Rows[args.RowIndex].Cells["inverted"];
                    var isChecked = Convert.ToBoolean(val.Value);
                    parentDefinitionGroup.definitions[args.RowIndex].inverted = isChecked;
                    modified = true;
                }
            };

            dgv_Definitions.CellClick += (sender, args) =>
            {
                if (args.ColumnIndex == dgv_Definitions.Columns["edit"]?.Index)
                {
                    modified |= DefinitionEditor.EditExistingDefinition(hud, parentDefinitionGroup.definitions[args.RowIndex]);
                }

                else if (args.ColumnIndex == dgv_Definitions.Columns["delete"]?.Index)
                {
                    parentDefinitionGroup.definitions.RemoveAt(args.RowIndex);
                    modified = true;
                }

                if (modified)
                {
                    ReloadDefinitions();
                }
            };
        }