using System.Collections.Generic; using JetBrains.ActionManagement; using JetBrains.ProjectModel; using JetBrains.ReSharper; using JetBrains.ReSharper.CodeView.Occurences; using JetBrains.ReSharper.CodeView.Util; using JetBrains.Util; using JetBrains.Util.DataStructures.TreeModel; namespace ExploreJoshResults { [ActionHandler("PowerToys.ExploreJoshAction")] public class ExploreJoshAction : IActionHandler { public bool Update(IDataContext context, ActionPresentation presentation, DelegateUpdate nextUpdate) { return context.CheckAllNotNull(DataConstants.SOLUTION); } public void Execute(IDataContext context, DelegateExecute nextExecute) { ISolution solution = context.GetData(DataConstants.SOLUTION); if (solution == null) return; List occs = new List(); JoshProjectVisitor visitor = new JoshProjectVisitor(occs); foreach (IProject project in new List(solution.GetAllProjects())) { project.Accept(visitor); } JoshResultsDescriptor descriptor = new JoshResultsDescriptor(solution, occs); // Show the results in the gui. CodeViewUtil.ShowResults(descriptor); } } public class JoshResultsDescriptor : OccurenceBrowserDescriptor { public JoshResultsDescriptor(ISolution solution, IList occs) : base(solution) { MergeOccurences = false; base.SetResults(occs); } public override string Title { get { return "Josh Results"; } } private readonly TreeModel myModel = new TreeSimpleModel(); public override TreeModel Model { get { return myModel; } } } public class JoshProjectVisitor : RecursiveProjectVisitor { private readonly IList occurences; public JoshProjectVisitor(IList occurences) { this.occurences = occurences; } public override void VisitProjectFile(IProjectFile projectFile) { base.VisitProjectFile(projectFile); if(projectFile.Kind == ProjectItemKind.PHYSICAL_FILE) { if(projectFile.LanguageType == ProjectFileType.CSHARP) { TextualOccurence o = new TextualOccurence(projectFile, new TextRange(1, 3)); occurences.Add(o); } } } } }