예제 #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;
 }
예제 #2
0
        private void updateHotkey(HotkeyPopup.MyKeyEvent keyEvent, AbstractHotkeyAction hotkey)
        {
            if (keyEvent is null)
            {
                return;
            }

            var iKeyEvent = keyEvent.toIKeyEvent(Hud.Input);

            hotkey.SetKeyEvent(keyEvent, iKeyEvent);
            ConfigPersistence.SaveHotkeys(Hotkeys);
        }
예제 #3
0
        private void InitializeHotkeys()
        {
            dgv_Hotkeys.RowHeadersVisible                   = false;
            dgv_Hotkeys.AllowUserToAddRows                  = false;
            dgv_Hotkeys.AllowUserToResizeColumns            = false;
            dgv_Hotkeys.AllowUserToResizeRows               = false;
            dgv_Hotkeys.DefaultCellStyle.SelectionBackColor = dgv_Hotkeys.DefaultCellStyle.BackColor;
            dgv_Hotkeys.DefaultCellStyle.SelectionForeColor = dgv_Hotkeys.DefaultCellStyle.ForeColor;

            var columns = DgvFormUtil.GetHotkeysColumns();

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

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

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

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

                var hotkey = (AbstractHotkeyAction)dgv_Hotkeys.Rows[args.RowIndex].DataBoundItem;
                hotkey.active = isChecked;

                ConfigPersistence.SaveHotkeys(Hotkeys);
            };

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

                if (args.ColumnIndex == dgv_Hotkeys.Columns["hotkey"]?.Index)
                {
                    var keyEvent = HotkeyPopup.getHotkey();
                    var hotkey   = (AbstractHotkeyAction)dgv_Hotkeys.Rows[args.RowIndex].DataBoundItem;
                    updateHotkey(keyEvent, hotkey);
                }
                else if (args.ColumnIndex == dgv_Hotkeys.Columns["remove"]?.Index)
                {
                    var hotkey = (AbstractHotkeyAction)dgv_Hotkeys.Rows[args.RowIndex].DataBoundItem;
                    hotkey.RemoveKeybind();
                    ConfigPersistence.SaveHotkeys(Hotkeys);
                }
                else if (args.ColumnIndex == dgv_Hotkeys.Columns["edit"]?.Index)
                {
                    var hotkey = (AbstractHotkeyAction)dgv_Hotkeys.Rows[args.RowIndex].DataBoundItem;
                    if (string.IsNullOrWhiteSpace(hotkey.attributes))
                    {
                        return;
                    }

                    if (HotkeyEditor.EditHotkeyAction(hotkey))
                    {
                        ConfigPersistence.SaveHotkeys(Hotkeys);
                    }
                }
                else
                {
                    return;
                }

                dgv_Hotkeys.Refresh();
            };

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

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

            hotkeyBinding          = new BindingSource(Hotkeys.hotkeyActions, null);
            dgv_Hotkeys.DataSource = hotkeyBinding;

            DgvFormUtil.AdjustDataGridViewColumns(dgv_Hotkeys);
        }