/// <summary>Implements the QueryStatus method of the IDTCommandTarget interface. This is called when the command's availability is updated</summary> /// <param name='commandName'>The name of the command to determine state for.</param> /// <param name='neededText'>Text that is needed for the command.</param> /// <param name='status'>The state of the command in the user interface.</param> /// <param name='commandText'>Text requested by the neededText parameter.</param> public void QueryStatus(string commandName, vsCommandStatusTextWanted neededText, ref vsCommandStatus status, ref object commandText) { if (neededText == vsCommandStatusTextWanted.vsCommandStatusTextWantedNone) { if (commandName == COMMANDNAMESPACE + "." + POPUP_MENU_NAME_MINIFIER) { status = vsCommandStatus.vsCommandStatusInvisible; ProjectItem projectItem = this.App.SelectedItems.Item(1).ProjectItem; if (EngineManager.IsHandledWithoutHint(projectItem.FileName())) { status = vsCommandStatus.vsCommandStatusSupported | vsCommandStatus.vsCommandStatusEnabled; } else { string path = projectItem.FileName(); if (this.IsLessFile(path) || this.IsCoffeeScriptFile(path) || this.IsCssFile(path) || this.IsJsFile(path)) { status = vsCommandStatus.vsCommandStatusSupported | vsCommandStatus.vsCommandStatusEnabled; } } } } if (commandName == COMMANDNAMESPACE + "." + POPUP_MENU_NAME_JSHINT) { status = vsCommandStatus.vsCommandStatusInvisible; ProjectItem projectItem = this.App.SelectedItems.Item(1).ProjectItem; string path = projectItem.FileName(); if (this.IsJsFile(path)) { status = vsCommandStatus.vsCommandStatusSupported | vsCommandStatus.vsCommandStatusEnabled; } } if (commandName == COMMANDNAMESPACE + "." + POPUP_MENU_NAME_CSSLINT) { status = vsCommandStatus.vsCommandStatusInvisible; ProjectItem projectItem = this.App.SelectedItems.Item(1).ProjectItem; string path = projectItem.FileName(); if (this.IsCssFile(path)) { status = vsCommandStatus.vsCommandStatusSupported | vsCommandStatus.vsCommandStatusEnabled; } } if (commandName == COMMANDNAMESPACE + "." + POPUP_MENU_NAME_TYPESCRIPT) { status = vsCommandStatus.vsCommandStatusInvisible; ProjectItem projectItem = this.App.SelectedItems.Item(1).ProjectItem; string path = projectItem.FileName(); if (this.IsTypeScriptFile(path)) { status = vsCommandStatus.vsCommandStatusSupported | vsCommandStatus.vsCommandStatusEnabled; } } }
public void RemoveDependencies(ProjectItem projectItem) { var filename = projectItem.FileName(); if (Dependencies.ContainsKey(filename)) Dependencies.Remove(filename); RemoveDependenciesForFile(projectItem); }
private void ProjectItemsEvents_ItemRemoved(ProjectItem projectItem) { string fileName = projectItem.FileName(); this.tasks.Remove(fileName); if (T4Engine.Handles(fileName) > 0) { this.T4Engine.Run(fileName, projectItem); } }
public void RemoveDependencies(ProjectItem projectItem) { var filename = projectItem.FileName(); if (Dependencies.ContainsKey(filename)) { Dependencies.Remove(filename); } RemoveDependenciesForFile(projectItem); }
public bool CheckDependencies(ProjectItem projectItem) { var filename = projectItem.FileName(); var engine = EngineResolver.GetEngineByFilename(filename); if (engine == null) return false; var contents = FileHandler.GetContents(filename); SaveDependencies(projectItem, filename, contents, engine); return true; }
private void ProjectItemsEvents_ItemRenamed(ProjectItem projectItem, string oldFileName) { if (EngineManager.IsTransformed(projectItem.FileName())) { // Now a chirp file this.ProjectItemsEvents_ItemAdded(projectItem); } else if (EngineManager.IsTransformed(oldFileName)) { try { VSProjectItemManager.DeleteAllItems(projectItem.ProjectItems); this.tasks.Remove(oldFileName); } catch (Exception e) { this.OutputWindowWriteText("Exception was thrown when trying to rename file.\n" + e.ToString()); } } }
public bool CheckDependencies(ProjectItem projectItem) { var filename = projectItem.FileName(); var engine = EngineResolver.GetEngineByFilename(filename); if (engine == null) { return(false); } var contents = FileHandler.GetContents(filename); SaveDependencies(projectItem, filename, contents, engine); return(true); }
public IEnumerable<FileAssociation> Run(ProjectItem projectItem) { var filename = projectItem.FileName(); var engine = EngineResolver.GetEngineByFilename(filename); var result = new List<FileAssociation>(); TaskList.Remove(filename); if (engine != null) result.AddRange(ProcessEngine(projectItem, filename, engine)); var associations = RunDependencies(filename); if (associations != null) result.AddRange(associations); return result; }
/// <summary> /// build a dictionary that has the files that could change as the key. /// for the value it is a LIST of config files that need updated if it does change. /// so, when a .less.css file changes, we look in the list and rebuild any of the configs associated with it. /// if a config file changes...this rebuild all of this.... /// </summary> /// <param name="projectItem">project Item</param> internal void ReloadFileDependencies(ProjectItem projectItem) { string configFileName = projectItem.FileName(); // remove all current dependencies for this config file... foreach (string key in this.dependentFiles.Keys.ToArray()) { List <string> files = this.dependentFiles[key]; if (files.Remove(configFileName) && files.Count == 0) { this.dependentFiles.Remove(key); } } IEnumerable <string> dependents; if (IsLessFile(configFileName)) { var root = System.IO.Path.GetDirectoryName(projectItem.ContainingProject.FullName); var text = System.IO.File.ReadAllText(configFileName); var imports = LessEngine.FindDependencies(configFileName, text, root); dependents = imports.Where(x => x.IsFile).Select(x => x.LocalPath); } else { var fileGroups = this.LoadConfigFileGroups(configFileName); dependents = fileGroups.SelectMany(x => x.Files).Select(x => x.Path); } foreach (var file in dependents) { if (!this.dependentFiles.ContainsKey(file)) { this.dependentFiles.Add(file, new List <string> { configFileName }); } else { this.dependentFiles[file].Add(configFileName); } } }
public void CheckForConfigRefresh(ProjectItem projectItem) { string fullFileName = projectItem.FileName(); if (this.dependentFiles.ContainsKey(fullFileName)) { foreach (string configFile in this.dependentFiles[fullFileName] .Distinct(StringComparer.InvariantCultureIgnoreCase) // prevent the same config file from being fired multiple times .ToArray()) { // ToArray to prevent "Collection Modified" exceptions this.Refresh(configFile); } } if (projectItem.ProjectItems != null) { foreach (ProjectItem projectItemInner in projectItem.ProjectItems.Cast<ProjectItem>().ToArray()) { // ToArray to prevent "Collection Modified" exceptions this.CheckForConfigRefresh(projectItemInner); } } }
public IEnumerable <FileAssociation> Run(ProjectItem projectItem) { var filename = projectItem.FileName(); var engine = EngineResolver.GetEngineByFilename(filename); var result = new List <FileAssociation>(); TaskList.Remove(filename); if (engine != null) { result.AddRange(ProcessEngine(projectItem, filename, engine)); } var associations = RunDependencies(filename); if (associations != null) { result.AddRange(associations); } return(result); }
public void CheckForConfigRefresh(ProjectItem projectItem) { string fullFileName = projectItem.FileName(); if (this.dependentFiles.ContainsKey(fullFileName)) { foreach (string configFile in this.dependentFiles[fullFileName] .Distinct(StringComparer.InvariantCultureIgnoreCase) // prevent the same config file from being fired multiple times .ToArray()) { // ToArray to prevent "Collection Modified" exceptions this.Refresh(configFile); } } if (projectItem.ProjectItems != null) { foreach (ProjectItem projectItemInner in projectItem.ProjectItems.Cast <ProjectItem>().ToArray()) { // ToArray to prevent "Collection Modified" exceptions this.CheckForConfigRefresh(projectItemInner); } } }
public void ItemClosed(ProjectItem projectItem) { Chirp.TaskList.Remove(projectItem.FileName()); }
/// <summary> /// build a dictionary that has the files that could change as the key. /// for the value it is a LIST of config files that need updated if it does change. /// so, when a .less.css file changes, we look in the list and rebuild any of the configs associated with it. /// if a config file changes...this rebuild all of this.... /// </summary> /// <param name="projectItem">project Item</param> internal void ReloadFileDependencies(ProjectItem projectItem) { string configFileName = projectItem.FileName(); // remove all current dependencies for this config file... foreach (string key in this.dependentFiles.Keys.ToArray()) { List<string> files = this.dependentFiles[key]; if (files.Remove(configFileName) && files.Count == 0) { this.dependentFiles.Remove(key); } } IEnumerable<string> dependents; if (IsLessFile(configFileName)) { var root = System.IO.Path.GetDirectoryName(projectItem.ContainingProject.FullName); var text = System.IO.File.ReadAllText(configFileName); var imports = LessEngine.FindDependencies(configFileName, text, root); dependents = imports.Where(x => x.IsFile).Select(x => x.LocalPath); } else { var fileGroups = this.LoadConfigFileGroups(configFileName); dependents = fileGroups.SelectMany(x => x.Files).Select(x => x.Path); } foreach (var file in dependents) { if (!this.dependentFiles.ContainsKey(file)) { this.dependentFiles.Add(file, new List<string> { configFileName }); } else { this.dependentFiles[file].Add(configFileName); } } }
/// <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