コード例 #1
0
ファイル: EditMacro.cs プロジェクト: nagyist/IR-Server-Suite
        private void PopulateCommandList(string[] categories)
        {
            treeViewCommandList.Nodes.Clear();
            Dictionary <string, TreeNode> categoryNodes = new Dictionary <string, TreeNode>(categories.Length);

            // Create requested categories ...
            foreach (string category in categories)
            {
                TreeNode categoryNode = new TreeNode(category);
                //categoryNode.NodeFont = new Font(treeViewCommandList.Font, FontStyle.Underline);
                categoryNodes.Add(category, categoryNode);
            }

            List <Type> allCommands = new List <Type>();

            Type[] specialCommands = Processor.GetBuiltInCommands();
            allCommands.AddRange(specialCommands);

            Type[] libCommands = Processor.GetLibraryCommands();
            if (libCommands != null)
            {
                allCommands.AddRange(libCommands);
            }

            foreach (Type type in allCommands)
            {
                Command command = (Command)Activator.CreateInstance(type);

                string commandCategory = command.GetCategory();

                if (categoryNodes.ContainsKey(commandCategory))
                {
                    TreeNode newNode = new TreeNode(command.GetUserInterfaceText());
                    newNode.Tag = type;

                    categoryNodes[commandCategory].Nodes.Add(newNode);
                }
            }

            // Add list of existing IR Commands ...
            if (categoryNodes.ContainsKey(Processor.CategoryIRCommands))
            {
                string[] irFiles = Processor.GetListIR();
                if (irFiles != null)
                {
                    foreach (string irFile in irFiles)
                    {
                        TreeNode newNode = new TreeNode(Path.GetFileNameWithoutExtension(irFile));
                        newNode.Tag = irFile;

                        categoryNodes[Processor.CategoryIRCommands].Nodes.Add(newNode);
                    }
                }
            }

            // Add list of existing Macros ...
            if (categoryNodes.ContainsKey(Processor.CategoryMacros))
            {
                string macroFolder = _macroFolder;
                if (String.IsNullOrEmpty(_macroFolder))
                {
                    macroFolder = Path.GetDirectoryName(_fileName);
                }
                string[] macros = Processor.GetListMacro(macroFolder);
                if (macros != null)
                {
                    foreach (string macro in macros)
                    {
                        TreeNode newNode = new TreeNode(Path.GetFileNameWithoutExtension(macro));
                        newNode.Tag = macro;

                        categoryNodes[Processor.CategoryMacros].Nodes.Add(newNode);
                    }
                }
            }

            // Put all commands into tree view ...
            foreach (TreeNode treeNode in categoryNodes.Values)
            {
                if (treeNode.Nodes.Count > 0)
                {
                    treeViewCommandList.Nodes.Add(treeNode);
                }
            }

            treeViewCommandList.SelectedNode = treeViewCommandList.Nodes[0];
            treeViewCommandList.SelectedNode.Expand();
        }