Example #1
0
        public object Create(object parent, object context, XmlNode section)
        {
            var result = new HotkeyCollection();

            foreach (var node in section.ChildNodes
                     .Cast <XmlNode>()
                     .Where(child => child.Name == "hotkey"))
            {
                void throwFormatException() => throw new FormatException(node.OuterXml);

                var name = node !.Attributes !["name"]?.Value;
Example #2
0
 public void AddHotkey(Section section, Chord chord, Action <Combo> action, string description)
 {
     if (section is Mode mode)
     {
         if (!mode.IsComposeMode && chord.Length > 1)
         {
             throw new ParseException($"Cannot use a chord with multiple keys inside a normal mode section. " +
                                      $"Use a '{Constants.ComposeModeSectionIdentifier}' section instead.");
         }
         if (!mode.IsComposeMode && chord.Length == 1 && chord.First().Modifiers != Modifiers.None)
         {
             throw new ParseException($"Cannot use modifiers inside a normal mode section. " +
                                      $"Use a '{Constants.ComposeModeSectionIdentifier}' section instead.");
         }
         mode.AddHotkey(new ModeHotkey(chord, action, description));
     }
     else
     {
         HotkeyCollection.AddHotkey(chord, action, (StandardSection)section);
     }
 }
        public object Create(object parent, object context, XmlNode section)
        {
            var result = new HotkeyCollection();

            foreach (var node in section.ChildNodes
                     .Cast <XmlNode>()
                     .Where(child => child.Name == "hotkey"))
            {
                void throwFormatException() => throw new FormatException(node.OuterXml);

                var name = node.Attributes["name"]?.Value;
                if (String.IsNullOrWhiteSpace(name))
                {
                    throwFormatException();
                }

                var menuItem = node.Attributes["menuItem"]?.Value;

                uint?mods     = null;
                var  modsText = node.Attributes["mods"]?.Value;
                if (!String.IsNullOrWhiteSpace(modsText))
                {
                    if (!ParsingHelpers.TryParseHexOrDec(modsText, out var modsValue))
                    {
                        throwFormatException();
                    }
                    mods = (uint)modsValue;
                }

                uint?vkey     = null;
                var  vkeyText = node.Attributes["vkey"]?.Value;
                if (!String.IsNullOrWhiteSpace(vkeyText))
                {
                    if (!ParsingHelpers.TryParseHexOrDecOrChar(vkeyText, out var vkeyValue))
                    {
                        throwFormatException();
                    }
                    vkey = (uint)vkeyValue;
                }

                var isScript     = false;
                var isScriptText = node.Attributes["isScript"]?.Value;
                if (isScriptText != null && !ParsingHelpers.TryParseBool(isScriptText, out isScript))
                {
                    throwFormatException();
                }

                var addSeparator     = false;
                var addSeparatorText = node.Attributes["hasSeparator"]?.Value;
                if (addSeparatorText != null && !ParsingHelpers.TryParseBool(addSeparatorText, out addSeparator))
                {
                    throwFormatException();
                }

                result.Add(new Hotkey
                {
                    Name         = name !,
                    MenuItem     = menuItem,
                    Mods         = mods,
                    Vkey         = vkey,
                    IsScript     = isScript,
                    AddSeparator = addSeparator,
                    Data         = node.InnerText
                });
Example #4
0
 public void Clear()
 {
     Modes.Clear();
     HotkeyCollection.Clear();
     DynamicHotkeyCollection.Clear();
 }