Пример #1
0
        private static void LoadNodes(XmlNode pnode, ShortcutCollection nodes)
        {
            foreach (XmlNode node in pnode.ChildNodes)
            {
                if (node.Name != "node")
                {
                    continue;
                }

                //string name = node.Attributes["name"].Value;
                var typeName = node.Attributes["type"].Value;

                if (node.HasChildNodes)
                {
                    var customShortcut = FindNodeType(typeName, nodes);

                    if (customShortcut == null)
                    {
                        continue;
                    }

                    foreach (XmlNode entry in node.ChildNodes)
                    {
                        var key   = entry.Attributes["key"].Value;
                        var value = entry.Attributes["value"].Value;
                        var sc    = (Shortcut)Enum
                                    .Parse(typeof(Shortcut), key);

                        customShortcut.HashTable[sc] = value;
                    }
                }
            }
        }
 private void TreeToHashtable(ShortcutCollection node)
 {
     foreach (CustomShortcut cs in node)
     {
         _shortcutMap.Add(cs.OwnerType, cs);
         TreeToHashtable(cs.Nodes);
     }
 }
        public object Clone()
        {
            var scl = new ShortcutCollection(_owner);

            foreach (CustomShortcut cs in List)
            {
                scl.Add((CustomShortcut)cs.Clone());
            }

            return(scl);
        }
        public bool Contains(ShortcutCollection values)
        {
            foreach (CustomShortcut sc in values)
            {
                if (Contains(sc))
                {
                    return(true);
                }
            }

            return(false);
        }
Пример #5
0
        private static void BuildTree(TreeNodeCollection treeNodes,
                                      ShortcutCollection shortcutNodes)
        {
            foreach (CustomShortcut shortcut in shortcutNodes)
            {
                var node = new TreeNode(shortcut.Name, 0, 1)
                {
                    Tag = shortcut
                };

                treeNodes.Add(node);

                BuildTree(node.Nodes, shortcut.Nodes);
            }
        }
Пример #6
0
        private static void SerializeNodes(XmlWriter writer, ShortcutCollection nodes)
        {
            foreach (CustomShortcut cs in nodes)
            {
                writer.WriteStartElement("node");
                writer.WriteAttributeString("name", cs.Name);
                writer.WriteAttributeString("type", cs.OwnerType.ToString());

                HashtableToString(writer, cs.HashTable);

                writer.WriteEndElement();

                SerializeNodes(writer, cs.Nodes);
            }
        }
Пример #7
0
        private static CustomShortcut FindNodeType(
            string typeName, ShortcutCollection nodes)
        {
            foreach (CustomShortcut cs in nodes)
            {
                if (cs.OwnerType.ToString() == typeName)
                {
                    return(cs);
                }

                return(FindNodeType(typeName, cs.Nodes));
            }

            return(null);
        }
Пример #8
0
        private static void BuildTree(TreeNode currentNode, ShortcutCollection node)
        {
            if (node == null)
            {
                return;
            }

            foreach (CustomShortcut cs in node)
            {
                var treeNode = new TreeNode(cs.Name)
                {
                    Tag = cs.OwnerType.ToString()
                };

                currentNode.Nodes.Add(treeNode);

                BuildTree(treeNode, cs.Nodes);
            }
        }
Пример #9
0
        private bool SaveCore(Stream stream,
                              ShortcutCollection nodes, bool forPreset)
        {
            var writer = new XmlTextWriter(stream, Encoding.UTF8)
            {
                Formatting = Formatting.Indented
            };

            writer.WriteStartElement("SerializeShortcuts");
            writer.WriteAttributeString("version", _version);

            SerializeNodes(writer, nodes);

            if (!forPreset)
            {
                SerializePresets(writer);
            }

            writer.WriteEndElement();
            writer.Flush();

            return(true);
        }