private void _mainForm_FormLoad(object sender, EventArgs e) { foreach (string file in Directory.GetFiles(_mainForm.ScriptsFolder, "*.cs")) { AddScript(file, true); } foreach (string directory in Directory.GetDirectories(_mainForm.ScriptsFolder)) { AddScript(directory, true); } //load script status from json if (_mainForm.LeSettings.ScriptStatus != null) { foreach(string key in _mainForm.LeSettings.ScriptStatus.Keys) { var tempScript = _sm.Scripts.FirstOrDefault(z => z.ScriptName == key); tempScript.Enabled = _mainForm.LeSettings.ScriptStatus[key]; } } else { _mainForm.LeSettings.ScriptStatus = new System.Collections.Generic.Dictionary<string, bool>(); foreach (ExecutableScript scriptName in _sm.Scripts) { _mainForm.LeSettings.ScriptStatus.Add(scriptName.ScriptName, true); } } foreach (var item in _sm.Scripts) { var a = new MenuItem[] { }; var box = new MyCheckBox(); var button = new MyButton(); button.Script = item; box.Tag = item.ScriptName; box.Text = item.ScriptName; box.Script = item; box.Checked = item.Enabled; _mainForm.AddScriptControlsToPanel(box, button); var menuItem = new MenuItem(item.ScriptName); var myMenuEnable = new MyMenuItem(); myMenuEnable.Text = item.Enabled ? "Disable" : "Enable"; myMenuEnable.Click += _mainForm_TrayScriptEnableClick; myMenuEnable.Script = item; var myMenuAction = new MyMenuItem(); myMenuAction.Text = "Action"; myMenuAction.Click += _mainForm_TrayScriptActionClick; myMenuAction.Script = item; menuItem.MenuItems.Add(myMenuEnable); menuItem.MenuItems.Add(myMenuAction); _mainForm.TrayIcon.ContextMenu.MenuItems.Add(menuItem); } RepopulatePanel(); StartLoop(); }
/// <summary> /// Repopulates the ScriptPanel with scripts from the current ScriptManager instance. /// </summary> private void RepopulatePanel() { _mainForm.ScriptPanel.Controls.Clear(); _mainForm.CheckBoxList.Clear(); _mainForm.ActionButtonList.Clear(); foreach (var item in _sm.Scripts) { var box = new MyCheckBox(); var button = new MyButton(); button.Script = item; box.Tag = item.ScriptName; box.Text = item.ScriptName; box.Script = item; box.Checked = item.Enabled; _mainForm.AddScriptControlsToPanel(box,button); } }