Exemplo n.º 1
0
        /// <summary>
        /// Sets the visibility of the command and creates the dynamic list of commands
        /// </summary>
        /// <param name="sender">Sender of the event</param>
        /// <param name="e">Event arguments</param>
        private void SetVisibility(object sender, EventArgs e)
        {
            // gets the full path of the clicked file
            var path = SolutionHelpers.GetSourceFilePath();

            var myCommand = sender as OleMenuCommand;

            // if the currently selected file is a Gruntfile set the command to visible
            myCommand.Visible = this.IsGruntFile();


            if (!this.IsGruntFile() && !this.IsGulpFile())
            {
                this.lastFile = path;
            }

            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 = GruntParser.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.cmdidGruntLauncher + j);
                    j++;
                    OleMenuCommand command = new OleMenuCommand(this.MenuItemCallback, menuCommandID);
                    command.Text = "Grunt: " + ele;
                    command.BeforeQueryStatus += (x, y) => { (x as OleMenuCommand).Visible = true; };
                    commands.Add(command);
                    mcs.AddCommand(command);
                }
            }
        }
Exemplo n.º 2
0
        /// <summary>
        /// Parses task names with help of grunt process execution.
        /// </summary>
        private static bool ParseFromProcess(string path)
        {
            _valid = false;
            try
            {
                System.Diagnostics.ProcessStartInfo procStartInfo = new ProcessStartInfo()
                {
                    RedirectStandardOutput = true,
                    StandardOutputEncoding = System.Text.Encoding.UTF8,
                    UseShellExecute        = false,
                    CreateNoWindow         = true,
                    WorkingDirectory       = Path.GetDirectoryName(path),
                    FileName  = "cmd",
                    Arguments = " /c \"grunt --help 2>&1\"",
                };

                System.Diagnostics.Process proc = new System.Diagnostics.Process()
                {
                    StartInfo           = procStartInfo,
                    EnableRaisingEvents = true
                };

                proc.OutputDataReceived += (object sendingProcess, DataReceivedEventArgs outLine) => GruntParser.OutputHandler(outLine.Data);
                proc.Start();
                proc.BeginOutputReadLine();
                proc.WaitForExit();
                proc.Close();
            }
            catch (Exception)
            {
                return(false);
            }
            return(true);
        }
        /// <summary>
        /// Sets the visibility of the command and creates the dynamic list of commands
        /// </summary>
        /// <param name="sender">Sender of the event</param>
        /// <param name="e">Event arguments</param>
        private void GruntBeforeQueryStatus(object sender, EventArgs e)
        {
            // gets the full path of the clicked file
            var path = SolutionHelpers.GetSourceFilePath();

            var myCommand = sender as OleMenuCommand;

            // if the currently selected file is a Gruntfile set the command to visible
            myCommand.Visible = this.IsGruntFile();


            if (!this.IsGruntFile() && !this.IsGulpFile())
            {
                this.lastFile = path;
            }

            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 = GruntParser.ReadAllTasks(path);

                myCommand.Text    = "Grunt";
                myCommand.Enabled = true;

                if (list.Count == 0)
                {
                    myCommand.Enabled = false;
                    myCommand.Text    = "Gruntfile.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.cmdidGruntLauncher + j);
                    j++;
                    OleMenuCommand command = new OleMenuCommand(this.GruntCallback, menuCommandID);
                    command.Text = "Grunt: " + ele;
                    command.BeforeQueryStatus += (x, y) => { (x as OleMenuCommand).Visible = true; };
                    commands.Add(command);
                    mcs.AddCommand(command);
                }
            }
        }