public static RazorScript AddScript(string file) { RazorScript script = new RazorScript { Lines = File.ReadAllLines(file), Name = Path.GetFileNameWithoutExtension(file), Path = file }; if (Path.GetDirectoryName(script.Path).Equals(Config.GetUserDirectory("Scripts"))) { script.Category = string.Empty; } else { string cat = file.Replace(Config.GetUserDirectory("Scripts"), "").Substring(1); script.Category = Path.GetDirectoryName(cat).Replace("/", "\\"); } AddHotkey(script); _scriptList.Add(script); return(script); }
private static void Recurse(TreeNodeCollection nodes, string path) { try { var razorFiles = Directory.GetFiles(path, "*.razor"); razorFiles = razorFiles.OrderBy(fileName => fileName).ToArray(); foreach (var file in razorFiles) { RazorScript script = AddScript(file); if (nodes != null) { TreeNode node = new TreeNode(script.Name) { Tag = script }; nodes.Add(node); } } } catch { // ignored } try { foreach (string directory in Directory.GetDirectories(path)) { if (!string.IsNullOrEmpty(directory) && !directory.Equals(".") && !directory.Equals("..")) { if (nodes != null) { TreeNode node = new TreeNode($"[{Path.GetFileName(directory)}]") { Tag = directory }; nodes.Add(node); Recurse(node.Nodes, directory); } else { Recurse(null, directory); } } } } catch { // ignored } }
public static void RemoveScript(RazorScript script) { RemoveHotkey(script); _scriptList.Remove(script); }
public static void OnHotKey(ref object state) { RazorScript script = (RazorScript)state; PlayScript(script.Lines); }
private static void RemoveHotkey(RazorScript script) { HotKey.Remove(Language.Format(LocString.PlayScript, script.ToString())); }
private static void AddHotkey(RazorScript script) { HotKey.Add(HKCategory.Scripts, HKSubCat.None, Language.Format(LocString.PlayScript, script), OnHotKey, script); }
public static void AddHotkey(RazorScript script) { HotKey.Add(HKCategory.Scripts, HKSubCat.None, Language.Format(LocString.PlayScript, script), HotkeyCallback, script); }