protected override ContextMenuStrip CreateMenu() { var menu = new ContextMenuStrip(); var container = new ToolStripMenuItem(Env.AppName); var fileItems = CommandFileParser.ParseDirectoryCommand(CommandFilePath, FolderPath); if (fileItems.Count > 0) { container.DropDownItems.AddRange(fileItems.ToArray()); container.DropDownItems.Add(new ToolStripSeparator()); } var globalSettingPath = Path.Combine(Util.Reg.GetAppFolderPath(), Env.GlobalSettingFileName); if (File.Exists(globalSettingPath)) { var globalItems = CommandFileParser.ParseGlobalCommand(globalSettingPath, FolderPath); if (globalItems.Count > 0) { container.DropDownItems.AddRange(globalItems.ToArray()); container.DropDownItems.Add(new ToolStripSeparator()); } } if (!File.Exists(CommandFilePath)) { container.DropDownItems.Add(BuildinMenuItems.InitDirectoryFile(CommandFilePath)); } container.DropDownItems.Add(BuildinMenuItems.OpenApp()); menu.Items.Add(container); return(menu); }
public static List <ToolStripMenuItem> ParseGlobalCommand(string path, string workingDir) { var result = new List <ToolStripMenuItem>(); try { var config = Util.Yaml.LoadYaml <GlobalConfig>(path); foreach (var entry in config.GlobalCommands) { var item = entry.ToMenuItem(workingDir); if (item.Enabled) { result.Add(item); } } if (config.Functions.CopyPath) { result.Add(BuildinMenuItems.GetCopyPathMenuItem(workingDir)); } } catch { } return(result); }