예제 #1
0
파일: Chirp.cs 프로젝트: cbilson/chirpy
        /// <summary>Implements the Exec method of the IDTCommandTarget interface. This is called when the command is invoked.</summary>
        /// <param name='commandName'>The name of the command to execute.</param>
        /// <param name='executeOption'>Describes how the command should be run.</param>
        /// <param name='varIn'>Parameters passed from the caller to the command handler.</param>
        /// <param name='varOut'>Parameters passed from the command handler to the caller.</param>
        /// <param name='handled'>Informs the caller if the command was handled or not.</param>
        public void Exec(string commandName, vsCommandExecOption executeOption, ref object varIn, ref object varOut, ref bool handled)
        {
            handled = false;

            if (executeOption == vsCommandExecOption.vsCommandExecOptionDoDefault) {
                if (this.App != null) {
                    string fileToTry = string.Empty;

                    try {
                        if (commandName == COMMANDNAMESPACE + "." + POPUP_MENU_NAME_MINIFIER) {
                            try {
                                ProjectItem projectItem = this.App.SelectedItems.Item(1).ProjectItem;
                                if (EngineManager.IsHandledWithoutHint(projectItem.FileName()))
                                {
                                    this.ProjectItemsEvents_ItemAdded(projectItem);
                                }
                                else
                                {
                                    string path = projectItem.FileName();
                                    string code = System.IO.File.ReadAllText(path);
                                    var settings = Settings.Instance(path);
                                    string outputExtension = settings.OutputExtensionJS;
                                    if (this.IsLessFile(path))
                                    {
                                        code = LessEngine.TransformToCss(path, code, projectItem);
                                        outputExtension = settings.OutputExtensionCSS;
                                    }
                                    else if (this.IsCoffeeScriptFile(path))
                                    {
                                        code = CoffeeScriptEngine.TransformToJs(path, code, projectItem);
                                        outputExtension = settings.OutputExtensionJS;
                                    }
                                    else if (this.IsSassFile(path))
                                    {
                                        code = SassEngine.TransformToCss(path, code, projectItem);
                                        outputExtension = settings.OutputExtensionCSS;
                                    }
                                    else if (this.IsCssFile(path))
                                    {
                                        code = CssEngine.Minify(path, code, projectItem, Xml.MinifyType.Unspecified);
                                        outputExtension = settings.OutputExtensionCSS;
                                    }
                                    else if (this.IsJsFile(path))
                                    {
                                        code = JsEngine.Minify(path, code, projectItem, Xml.MinifyType.Unspecified, string.Empty);
                                        outputExtension = settings.OutputExtensionJS;
                                    }
                                    using (var manager = new Manager.VSProjectItemManager(this.App, projectItem))
                                    {
                                        manager.AddFileByFileName(Utilities.GetBaseFileName(path) + outputExtension, code);
                                    }
                                }
                            } catch (Exception e) {
                                this.OutputWindowWriteText(e.ToString());
                            }
                        } else if (commandName == COMMANDNAMESPACE + "." + POPUP_MENU_NAME_JSHINT) {
                            try {
                                ProjectItem projectItem = this.App.SelectedItems.Item(1).ProjectItem;
                                string path = projectItem.FileName();
                                JSHintEngine.Run(path, projectItem);
                            } catch (Exception e) {
                                this.OutputWindowWriteText(e.ToString());
                            }
                        } else if (commandName == COMMANDNAMESPACE + "." + POPUP_MENU_NAME_CSSLINT) {
                            try {
                                ProjectItem projectItem = this.App.SelectedItems.Item(1).ProjectItem;
                                string path = projectItem.FileName();
                                CSSLintEngine.Run(path, projectItem);
                            } catch (Exception e) {
                                this.OutputWindowWriteText(e.ToString());
                            }
                        }
                    } catch (Exception ex) {
                        this.OutputWindowWriteText(string.Format("Error occured.\r\nFileName:\r\n{0}\r\nException details:\r\n{1}", fileToTry, ex));
                    } // try

                    handled = true;

                    return;
                }
            }
        }
예제 #2
0
        /// <summary>Implements the Exec method of the IDTCommandTarget interface. This is called when the command is invoked.</summary>
        /// <param name='commandName'>The name of the command to execute.</param>
        /// <param name='executeOption'>Describes how the command should be run.</param>
        /// <param name='varIn'>Parameters passed from the caller to the command handler.</param>
        /// <param name='varOut'>Parameters passed from the command handler to the caller.</param>
        /// <param name='handled'>Informs the caller if the command was handled or not.</param>
        public void Exec(string commandName, vsCommandExecOption executeOption, ref object varIn, ref object varOut, ref bool handled)
        {
            handled = false;

            if (executeOption == vsCommandExecOption.vsCommandExecOptionDoDefault)
            {
                if (this.App != null)
                {
                    string fileToTry = string.Empty;

                    try {
                        if (commandName == COMMANDNAMESPACE + "." + POPUP_MENU_NAME_MINIFIER)
                        {
                            try {
                                ProjectItem projectItem = this.App.SelectedItems.Item(1).ProjectItem;
                                if (EngineManager.IsHandledWithoutHint(projectItem.FileName()))
                                {
                                    this.ProjectItemsEvents_ItemAdded(projectItem);
                                }
                                else
                                {
                                    string path            = projectItem.FileName();
                                    string code            = System.IO.File.ReadAllText(path);
                                    var    settings        = Settings.Instance(path);
                                    string outputExtension = settings.OutputExtensionJS;
                                    if (this.IsLessFile(path))
                                    {
                                        code            = LessEngine.TransformToCss(path, code, projectItem);
                                        outputExtension = settings.OutputExtensionCSS;
                                    }
                                    else if (this.IsCoffeeScriptFile(path))
                                    {
                                        code            = CoffeeScriptEngine.TransformToJs(path, code, projectItem);
                                        outputExtension = settings.OutputExtensionJS;
                                    }
                                    else if (this.IsSassFile(path))
                                    {
                                        code            = SassEngine.TransformToCss(path, code, projectItem);
                                        outputExtension = settings.OutputExtensionCSS;
                                    }
                                    else if (this.IsCssFile(path))
                                    {
                                        code            = CssEngine.Minify(path, code, projectItem, Xml.MinifyType.Unspecified);
                                        outputExtension = settings.OutputExtensionCSS;
                                    }
                                    else if (this.IsJsFile(path))
                                    {
                                        code            = JsEngine.Minify(path, code, projectItem, Xml.MinifyType.Unspecified, string.Empty);
                                        outputExtension = settings.OutputExtensionJS;
                                    }
                                    using (var manager = new Manager.VSProjectItemManager(this.App, projectItem))
                                    {
                                        manager.AddFileByFileName(Utilities.GetBaseFileName(path) + outputExtension, code);
                                    }
                                }
                            } catch (Exception e) {
                                this.OutputWindowWriteText(e.ToString());
                            }
                        }
                        else if (commandName == COMMANDNAMESPACE + "." + POPUP_MENU_NAME_JSHINT)
                        {
                            try {
                                ProjectItem projectItem = this.App.SelectedItems.Item(1).ProjectItem;
                                string      path        = projectItem.FileName();
                                JSHintEngine.Run(path, projectItem);
                            } catch (Exception e) {
                                this.OutputWindowWriteText(e.ToString());
                            }
                        }
                        else if (commandName == COMMANDNAMESPACE + "." + POPUP_MENU_NAME_CSSLINT)
                        {
                            try {
                                ProjectItem projectItem = this.App.SelectedItems.Item(1).ProjectItem;
                                string      path        = projectItem.FileName();
                                CSSLintEngine.Run(path, projectItem);
                            } catch (Exception e) {
                                this.OutputWindowWriteText(e.ToString());
                            }
                        }
                        else if (commandName == COMMANDNAMESPACE + "." + POPUP_MENU_NAME_TYPESCRIPT)
                        {
                            try
                            {
                                ProjectItem projectItem = this.App.SelectedItems.Item(1).ProjectItem;
                                string      path        = projectItem.FileName();
                                TypeScriptEngine.Run(path, projectItem);
                            }
                            catch (Exception e)
                            {
                                this.OutputWindowWriteText(e.ToString());
                            }
                        }
                    } catch (Exception ex) {
                        this.OutputWindowWriteText(string.Format("Error occured.\r\nFileName:\r\n{0}\r\nException details:\r\n{1}", fileToTry, ex));
                    } // try

                    handled = true;

                    return;
                }
            }
        } // Exec