void RunTravers(MacroContainer container, bool supressMessage = false)
        {
            if (IsValidDirectory(out string message))
            {
                var menu = GetMacroMenu(container.Form);

                if (menu != null)
                {
                    var button = menu.InsertCommandbarButton(1, Key_Button_OpenInExplorer, MacroManagerResources.OpenInExplorerCommand);
                    container.Tools.Add(button.Tool, "OpenInExplorerCommand");
                }

                var macrosDirectory = Path2.GetFullPathFromPathWithVariables(Settings[Key_MacrosDirectory]);


                int folderCounter = 1;
                int fileCounter   = 1;

                if (Directory.Exists(macrosDirectory))
                {
                    DirectoryConverter.Travers(menu, 3, ref folderCounter, ref fileCounter, macrosDirectory, container, true);
                }
            }
            else
            {
                if (!supressMessage)
                {
                    MessageBox.Show(container.Form, message, container.Form.ProductName, MessageBoxButtons.OK, MessageBoxIcon.Error);
                }
            }
        }
        void UpdateTools(MacroContainer container, bool supressMessage = false)
        {
            foreach (var tool in container.Tools)
            {
                tool.Key.ToolbarsManager.Tools.Remove(tool.Key);
            }

            container.Tools.Clear();
            container.Macros.Clear();
            RunTravers(container, supressMessage);
        }
        protected override void OnHostingFormLoaded(Form form)
        {
            if (form is MainForm mainForm)
            {
                var container = new MacroContainer(form);
                form.FormClosed += Form_FormClosed;
                _containers.Add(container);

                var oldMacroEditorTool = mainForm.GetMainCommandbarManager().GetReferenceEditorCommandbar(MainFormReferenceEditorCommandbarId.Menu).GetCommandbarMenu(MainFormReferenceEditorCommandbarMenuId.Tools).GetCommandbarButton("ShowMacroEditorForm");

                if (oldMacroEditorTool != null)
                {
                    oldMacroEditorTool.Tool.ToolbarsManager.Tools.Remove(oldMacroEditorTool.Tool);
                }

                var menu = mainForm.GetMainCommandbarManager()
                           .GetReferenceEditorCommandbar(MainFormReferenceEditorCommandbarId.Menu)
                           .InsertCommandbarMenu(17, Key_Menu_MacroManager, MacroManagerResources.MacroCommand);

                if (menu != null)
                {
                    menu.AddCommandbarButton(Key_Button_Config, MacroManagerResources.ConfigurateCommand);

                    UpdateTools(container, true);

                    if (menu != null)
                    {
                        var button = menu.InsertCommandbarButton(2, Key_Button_ShowMacroEditor, MacroManagerResources.MacroEditorCommand);
                        button.Shortcut     = (Shortcut)(Keys.Alt | Keys.F11);
                        button.HasSeparator = true;


                        button = menu.AddCommandbarButton(Key_Button_Refresh, MacroManagerResources.RefreshCommand, image: MacroManagerResources.Refresh);
                        button.Tool.InstanceProps.IsFirstInGroup = true;
                    }
                }
            }

            base.OnHostingFormLoaded(form);
        }
        public static void Travers(CommandbarMenu commandbarMenu, int index, ref int folderCounter, ref int fileCounter, string path, MacroContainer container, bool isFirst)
        {
            try
            {
                foreach (var directory in Directory.GetDirectories(path))
                {
                    var directoryInfo = new DirectoryInfo(directory);

                    if (directoryInfo.GetFiles("*.cs", SearchOption.AllDirectories).Length == 0)
                    {
                        continue;
                    }

                    folderCounter++;
                    var menu = commandbarMenu.InsertCommandbarMenu(index, Addon.Key_Menu_Directory.FormatString(folderCounter), directoryInfo.Name);

                    index = index + 1;

                    if (isFirst)
                    {
                        menu.Tool.InstanceProps.IsFirstInGroup = true;
                        isFirst = false;
                    }

                    container.Tools.Add(menu.Tool, null);
                    Travers(menu, 0, ref folderCounter, ref fileCounter, directory, container, isFirst);
                }

                foreach (var strFile in Directory.GetFiles(path, "*.cs"))
                {
                    fileCounter++;

                    var key  = Addon.Key_Menu_Directory.FormatString(folderCounter) + "." + fileCounter;
                    var menu = commandbarMenu.InsertCommandbarMenu(index, key, Path.GetFileName(strFile), image: MacroManagerResources.Macro);
                    index = index + 1;
                    if (isFirst)
                    {
                        menu.Tool.InstanceProps.IsFirstInGroup = true;
                        isFirst = false;
                    }

                    container.Tools.Add(menu.Tool, null);
                    key = Addon.Key_Button_Directory + "." + fileCounter + ".1";
                    var button = menu.AddCommandbarButton(key, MacroManagerResources.EditCommand);
                    container.Macros.Add(button.Tool.Key, new MacroCommand(strFile, MacroAction.Edit));
                    container.Tools.Add(button.Tool, "EditCommand");
                    key    = Addon.Key_Button_Directory + "." + fileCounter + ".2";
                    button = menu.AddCommandbarButton(Addon.Key_Button_Directory + "." + fileCounter + ".2", MacroManagerResources.RunCommand);
                    container.Macros.Add(button.Tool.Key, new MacroCommand(strFile, MacroAction.Run));
                    container.Tools.Add(button.Tool, "RunCommand");
                }
            }
            catch (Exception)
            {
            }
        }