private void GulpBeforeQueryStatus(object sender, EventArgs e) { // gets the full path of the clicked file var path = SolutionHelpers.GetSourceFilePath(); var myCommand = sender as OleMenuCommand; myCommand.Visible = this.IsGulpFile(); if (!this.IsNewFile()) { return; } OleMenuCommandService mcs = GetService(typeof(IMenuCommandService)) as OleMenuCommandService; // delete the old command list if (commands == null) { commands = new List <OleMenuCommand>(); } foreach (var cmd in commands) { mcs.RemoveCommand(cmd); } if (myCommand.Visible) { this.lastFile = path; var list = GulpParser.ReadAllTasks(path); if (list.Contains("default")) { list.Remove("default"); } // creates the list of commands int j = 1; foreach (var ele in list) { CommandID menuCommandID = new CommandID(GuidList.guidGruntLauncherCmdSet, (int)PkgCmdIDList.cmdidGulpLauncher + j); j++; OleMenuCommand command = new OleMenuCommand(this.GulpCallback, menuCommandID); command.Text = "Gulp: " + ele; command.BeforeQueryStatus += (x, y) => { (x as OleMenuCommand).Visible = true; }; commands.Add(command); mcs.AddCommand(command); } } }
private void GulpBeforeQueryStatus(object sender, EventArgs e) { // gets the full path of the clicked file var path = SolutionHelpers.GetSourceFilePath(); var myCommand = sender as OleMenuCommand; myCommand.Visible = this.IsGulpFile(); if (!this.IsNewFile()) { return; } OleMenuCommandService mcs = GetService(typeof(IMenuCommandService)) as OleMenuCommandService; // delete the old command list if (commands == null) { commands = new List <OleMenuCommand>(); } foreach (var cmd in commands) { mcs.RemoveCommand(cmd); } if (myCommand.Visible) { this.lastFile = path; var list = GulpParser.ReadAllTasks(path); myCommand.Text = "Gulp"; myCommand.Enabled = true; if (list.Count == 0) { myCommand.Enabled = false; myCommand.Text = "Gulpfile.js not found"; } if (list.Contains("default")) { list.Remove("default"); } string n = exclusionRegex; Regex a = null; if (!string.IsNullOrEmpty(n)) { try { a = new Regex(n); } catch (Exception) { // invalid regex -> ignore } } // creates the list of commands int j = 1; foreach (var ele in list) { if (a != null) { if (a.Match(ele).Success) { continue; } } CommandID menuCommandID = new CommandID(GuidList.guidGruntLauncherCmdSet, (int)PkgCmdIDList.cmdidGulpLauncher + j); j++; OleMenuCommand command = new OleMenuCommand(this.GulpCallback, menuCommandID); command.Text = "Gulp: " + ele; command.BeforeQueryStatus += (x, y) => { (x as OleMenuCommand).Visible = true; }; commands.Add(command); mcs.AddCommand(command); } } }