Beispiel #1
0
 private void Settings_FormClosing(object sender, FormClosingEventArgs e)
 {
     ConfigPersistence.SaveDefinitions(SnoToDefinitionGroups);
     ConfigPersistence.SaveKeybinds(Keybinds);
     ConfigPersistence.SaveHotkeys(Hotkeys);
     ConfigPersistence.SaveAutoActions(AutoActions);
     e.Cancel = true;
 }
Beispiel #2
0
        private void InitializeAutoActions()
        {
            dgv_AutoActions.RowHeadersVisible                   = false;
            dgv_AutoActions.AllowUserToAddRows                  = false;
            dgv_AutoActions.AllowUserToResizeColumns            = false;
            dgv_AutoActions.AllowUserToResizeRows               = false;
            dgv_AutoActions.DefaultCellStyle.SelectionBackColor = dgv_AutoActions.DefaultCellStyle.BackColor;
            dgv_AutoActions.DefaultCellStyle.SelectionForeColor = dgv_AutoActions.DefaultCellStyle.ForeColor;

            var columns = DgvFormUtil.GetAutoActionsColumns();

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

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

            dgv_AutoActions.CellContentClick += (sender, args) =>
            {
                if (args.RowIndex < 0 || args.ColumnIndex != dgv_AutoActions.Columns["active"]?.Index)
                {
                    return;
                }

                var val       = (DataGridViewCheckBoxCell)dgv_AutoActions.Rows[args.RowIndex].Cells["active"];
                var isChecked = Convert.ToBoolean(val.Value);

                var autoAction = (AbstractAutoAction)dgv_AutoActions.Rows[args.RowIndex].DataBoundItem;
                autoAction.active = isChecked;

                ConfigPersistence.SaveAutoActions(AutoActions);
            };

            dgv_AutoActions.CellClick += (sender, args) =>
            {
                if (args.RowIndex < 0 || args.ColumnIndex != dgv_Hotkeys.Columns["edit"]?.Index)
                {
                    return;
                }

                var autoAction = (AbstractAutoAction)dgv_AutoActions.Rows[args.RowIndex].DataBoundItem;
                if (string.IsNullOrWhiteSpace(autoAction?.attributes))
                {
                    return;
                }
                if (AutoActionEditor.EditAutoAction(autoAction))
                {
                    ConfigPersistence.SaveAutoActions(AutoActions);
                }

                dgv_AutoActions.Refresh();
            };

            dgv_AutoActions.CellMouseEnter += (sender, args) =>
            {
                if (args.RowIndex < 0)
                {
                    return;
                }

                var row = dgv_AutoActions.Rows[args.RowIndex];
                row.Cells[args.ColumnIndex].ToolTipText = ((AbstractAutoAction)row.DataBoundItem).tooltip;
            };

            autoActionBinding          = new BindingSource(AutoActions.autoActions, null);
            dgv_AutoActions.DataSource = autoActionBinding;

            DgvFormUtil.AdjustDataGridViewColumns(dgv_AutoActions);
        }