private void button1_Click(object sender, EventArgs e)
        {
            if (_configContent == null)
            {
                return;
            }

            //MessageBox.Show("Not implemented yet!","Not Implemented",MessageBoxButtons.OK,MessageBoxIcon.Warning);

            DialogResult dlgRes = MessageBox.Show("Do you want to restore default short cuts for all actions?", "Confirmation", MessageBoxButtons.YesNo, MessageBoxIcon.Question);

            if (dlgRes == DialogResult.No)
            {
                return;
            }

            _newShortcuts.Clear();
            string[] actionNames = Enum.GetNames(typeof(ScriptEditorActions));
            foreach (string actionName in actionNames)
            {
                ScriptEditorActions action = (ScriptEditorActions)Enum.Parse(typeof(ScriptEditorActions), actionName);
                Keys defShortcut           = ScriptEditorShortcutKeysProvider.GetDefaultShortCut(action);
                if (_newShortcuts.ContainsKey(action))
                {
                    _newShortcuts[action] = defShortcut;
                }
                else
                {
                    _newShortcuts.Add(action, defShortcut);
                }
            }
            LoadFrom(_newShortcuts);
            panEdit.Enabled = false;
            _isModified     = true;
        }
        private void btnSet_Click(object sender, EventArgs e)
        {
            if (lv.SelectedItems.Count == 0)
            {
                MessageBox.Show("No shortcut is currently selected!", "Error", MessageBoxButtons.OK, MessageBoxIcon.Error);
            }

            ListViewItem        item   = lv.SelectedItems[0];
            ScriptEditorActions action = (ScriptEditorActions)Enum.Parse(typeof(ScriptEditorActions), item.Text);

            Keys result = CreateKeysFromUserInput();

            item.Tag = result;
            item.SubItems[1].Text = ScriptEditorShortcutKeysProvider.ShortcutKeysAsStringFromKeys(result);
            _isModified           = true;

            if (_newShortcuts.ContainsKey(action))
            {
                _newShortcuts[action] = result;
            }
            else
            {
                _newShortcuts.Add(action, result);
            }
        }
Exemple #3
0
        public static void SetShortCut(ScriptEditorActions action, Keys keys)
        {
            FieldInfo fi = typeof(ScriptEditorShortcutKeysProvider).GetField(Enum.GetName(action.GetType(), action));

            if (fi == null)
            {
                throw new InvalidOperationException(String.Format("Field \"{0}\" is not defined in ScriptEditorShortcutKeysProvider class", Enum.GetName(action.GetType(), action)));
            }
            fi.SetValue(null, keys);
        }
Exemple #4
0
        public static Keys GetDefaultShortCut(ScriptEditorActions action)
        {
            PropertyInfo pi = typeof(ScriptEditorShortcutKeysProvider).GetProperty("Def" + Enum.GetName(action.GetType(), action));

            if (pi == null)
            {
                throw new InvalidOperationException(String.Format("Property \"{0}\" is not defined in ScriptEditorShortcutKeysProvider class", "Def" + Enum.GetName(action.GetType(), action)));
            }
            return((Keys)pi.GetValue(null, null));
        }
Exemple #5
0
        public static string ShortcutKeysAsStringFromAction(ScriptEditorActions action)
        {
            string result = String.Empty;

            Keys keys    = ScriptEditorShortcutKeysProvider.GetShortCut(action);
            Keys modKeys = Keys.Modifiers & keys;

            //Ctrl+Alt+Shift+M


            if ((Keys.Control & modKeys) == Keys.Control)
            {
                result += "Ctrl";
            }

            if ((Keys.Alt & modKeys) == Keys.Alt)
            {
                if (!String.IsNullOrEmpty(result))
                {
                    result += "+Alt";
                }
                else
                {
                    result += "Alt";
                }
            }

            if ((Keys.Shift & modKeys) == Keys.Shift)
            {
                if (!String.IsNullOrEmpty(result))
                {
                    result += "+Shift";
                }
                else
                {
                    result += "Shift";
                }
            }

            Keys key = Keys.KeyCode & keys;

            if (String.IsNullOrEmpty(result))
            {
                result += Enum.GetName(typeof(Keys), key);
            }
            else
            {
                result += "+" + Enum.GetName(typeof(Keys), key);
            }

            return(result);
        }