Exemple #1
0
 public void SetKeydata(string category, HotkeyCommand command)
 {
     this.category = category;
     this.command  = command;
     keyData       = command.KeyData;
     UpdateText();
 }
        public static void ResetToDefault(string category, HotkeyCommand command)
        {
            Dictionary <string, HotkeyCommand[]> defaultHotkeys = CreateDefaultSettings();

            if (!defaultHotkeys.ContainsKey(category))
            {
                return;
            }

            foreach (HotkeyCommand c in defaultHotkeys[category])
            {
                if (c.CommandCode == command.CommandCode)
                {
                    command.KeyData = c.KeyData;
                    break;
                }
            }
        }
        public static void Update(string category, HotkeyCommand command)
        {
            // By convention only one hotkey is supported for each command.
            if (!hotkeys.ContainsKey(category))
            {
                return;
            }

            foreach (HotkeyCommand c in hotkeys[category])
            {
                // We test by the command name because the command code is subject to change
                // when we add commands between existing ones.
                if (c.Name == command.Name)
                {
                    c.KeyData = command.KeyData;
                    break;
                }
            }
        }
        /// <summary>
        /// Returns false if there is a conflict on the hotkey for this category.
        /// </summary>
        public static bool IsUnique(string category, HotkeyCommand command)
        {
            if (!hotkeys.ContainsKey(category) || command.KeyData == Keys.None)
            {
                return(true);
            }

            foreach (HotkeyCommand c in hotkeys[category])
            {
                if (c.CommandCode == command.CommandCode || c.KeyData != command.KeyData)
                {
                    continue;
                }

                return(false);
            }

            return(true);
        }
        private void ParseCategory(XmlReader reader, Dictionary <string, HotkeyCommand[]> hotkeys)
        {
            string name = reader.GetAttribute("name");

            bool empty = reader.IsEmptyElement;

            reader.ReadStartElement();
            if (empty)
            {
                return;
            }

            if (hotkeys.ContainsKey(name))
            {
                return;
            }

            List <HotkeyCommand> hotkeysCommands = new List <HotkeyCommand>();

            while (reader.NodeType == XmlNodeType.Element)
            {
                if (reader.Name == "Hotkey")
                {
                    HotkeyCommand hotkey = ParseHotkey(reader);
                    if (hotkey != null)
                    {
                        hotkeysCommands.Add(hotkey);
                    }
                }
                else
                {
                    reader.ReadOuterXml();
                }
            }

            hotkeys.Add(name, hotkeysCommands.ToArray());
            reader.ReadEndElement();
        }