diff options
author | Lluis Sanchez <lluis@xamarin.com> | 2014-01-20 19:32:53 +0400 |
---|---|---|
committer | Lluis Sanchez Gual <lluis@xamarin.com> | 2014-10-21 18:39:14 +0400 |
commit | f73b2a9990495587d514aa1856919c21170a3940 (patch) | |
tree | 9842411ee8644ead5915a715ee7e53984a601df4 /main/src/core/MonoDevelop.Ide/MonoDevelop.Ide.FindInFiles/Scope.cs | |
parent | a2046b6331a271e8203df7d3d0f14500d33d60fa (diff) |
Initial drop of the new project model
Diffstat (limited to 'main/src/core/MonoDevelop.Ide/MonoDevelop.Ide.FindInFiles/Scope.cs')
-rw-r--r-- | main/src/core/MonoDevelop.Ide/MonoDevelop.Ide.FindInFiles/Scope.cs | 116 |
1 files changed, 69 insertions, 47 deletions
diff --git a/main/src/core/MonoDevelop.Ide/MonoDevelop.Ide.FindInFiles/Scope.cs b/main/src/core/MonoDevelop.Ide/MonoDevelop.Ide.FindInFiles/Scope.cs index fff1d1202b..ca62a49cd9 100644 --- a/main/src/core/MonoDevelop.Ide/MonoDevelop.Ide.FindInFiles/Scope.cs +++ b/main/src/core/MonoDevelop.Ide/MonoDevelop.Ide.FindInFiles/Scope.cs @@ -33,6 +33,7 @@ using MonoDevelop.Ide.Gui; using MonoDevelop.Core; using System.Security.Permissions; using System.Security; +using System.Threading.Tasks; namespace MonoDevelop.Ide.FindInFiles @@ -44,22 +45,24 @@ namespace MonoDevelop.Ide.FindInFiles set; } - public abstract int GetTotalWork (FilterOptions filterOptions); - public abstract IEnumerable<FileProvider> GetFiles (IProgressMonitor monitor, FilterOptions filterOptions); + public abstract Task<int> GetTotalWork (FilterOptions filterOptions); + public abstract Task GetFiles (ProgressMonitor monitor, FilterOptions filterOptions, ResultQueue<FileProvider> results); public abstract string GetDescription (FilterOptions filterOptions, string pattern, string replacePattern); } public class DocumentScope : Scope { - public override int GetTotalWork (FilterOptions filterOptions) + public override Task<int> GetTotalWork (FilterOptions filterOptions) { - return 1; + return Task.FromResult (1); }
- public override IEnumerable<FileProvider> GetFiles (IProgressMonitor monitor, FilterOptions filterOptions) + public override Task GetFiles (ProgressMonitor monitor, FilterOptions filterOptions, ResultQueue<FileProvider> results) { monitor.Log.WriteLine (GettextCatalog.GetString ("Looking in '{0}'", IdeApp.Workbench.ActiveDocument.FileName)); - yield return new FileProvider(IdeApp.Workbench.ActiveDocument.FileName); + results.Enqueue (new FileProvider(IdeApp.Workbench.ActiveDocument.FileName)); + results.SetComplete (); + return Task.FromResult (0); } public override string GetDescription(FilterOptions filterOptions, string pattern, string replacePattern) @@ -73,15 +76,17 @@ namespace MonoDevelop.Ide.FindInFiles public class SelectionScope : Scope { - public override int GetTotalWork (FilterOptions filterOptions) + public override Task<int> GetTotalWork (FilterOptions filterOptions) { - return 1; + return Task.FromResult (1); }
- public override IEnumerable<FileProvider> GetFiles (IProgressMonitor monitor, FilterOptions filterOptions) + public override Task GetFiles (ProgressMonitor monitor, FilterOptions filterOptions, ResultQueue<FileProvider> results) { var selection = IdeApp.Workbench.ActiveDocument.Editor.SelectionRange; - yield return new FileProvider(IdeApp.Workbench.ActiveDocument.FileName, null, selection.Offset, selection.EndOffset); + results.Enqueue (new FileProvider (IdeApp.Workbench.ActiveDocument.FileName, null, selection.Offset, selection.EndOffset)); + results.SetComplete (); + return Task.FromResult (0); } public override string GetDescription(FilterOptions filterOptions, string pattern, string replacePattern) @@ -95,40 +100,44 @@ namespace MonoDevelop.Ide.FindInFiles public class WholeSolutionScope : Scope { - public override int GetTotalWork (FilterOptions filterOptions) + public override Task<int> GetTotalWork (FilterOptions filterOptions) { int result = 0; if (IdeApp.Workspace.IsOpen) result = IdeApp.Workspace.GetAllProjects ().Sum (p => p.Files.Count); - return result; + return Task.FromResult (result); } - public override IEnumerable<FileProvider> GetFiles (IProgressMonitor monitor, FilterOptions filterOptions) + public async override Task GetFiles (ProgressMonitor monitor, FilterOptions filterOptions, ResultQueue<FileProvider> results) { if (IdeApp.Workspace.IsOpen) { var alreadyVisited = new HashSet<string> (); - foreach (var solutionFolder in IdeApp.Workspace.GetAllSolutionItems().OfType<SolutionFolder>()) { - monitor.Log.WriteLine (GettextCatalog.GetString ("Looking in solution folder '{0}'", solutionFolder.Name)); - foreach (var file in solutionFolder.Files.Where (f => filterOptions.NameMatches (f.FileName) && File.Exists (f.FullPath))) { + var allFiles = IdeApp.Workspace.GetAllSolutionItems ().OfType<SolutionFolder> ().SelectMany (sf => sf.Files).Where (f => filterOptions.NameMatches (f.FileName)).Select (f => f.FullPath).ToArray (); + await Task.Factory.StartNew (delegate { + foreach (var file in allFiles.Where (f => File.Exists (f.FullPath))) { if (!IncludeBinaryFiles && !DesktopService.GetFileIsText (file.FullPath)) continue; if (alreadyVisited.Contains (file.FullPath)) continue; alreadyVisited.Add (file.FileName); - yield return new FileProvider (file.FullPath); + results.Enqueue (new FileProvider (file.FullPath)); } - } - foreach (Project project in IdeApp.Workspace.GetAllProjects ()) { - monitor.Log.WriteLine (GettextCatalog.GetString ("Looking in project '{0}'", project.Name)); - foreach (ProjectFile file in project.Files.Where (f => filterOptions.NameMatches (f.Name) && File.Exists (f.Name))) { - if (!IncludeBinaryFiles && !DesktopService.GetFileIsText (file.FilePath)) + results.SetComplete (); + }); + + var allProjectFiles = IdeApp.Workspace.GetAllProjects ().SelectMany (project => project.Files).Where (f => filterOptions.NameMatches (f.Name)).Select (f => new Tuple<Project,string>(f.Project,f.Name)).ToArray (); + await Task.Factory.StartNew (delegate { + foreach (var ft in allProjectFiles.Where (f => File.Exists (f.Item2))) { + var file = ft.Item2; + if (!IncludeBinaryFiles && !DesktopService.GetFileIsText (file)) continue; - if (alreadyVisited.Contains (file.Name)) + if (alreadyVisited.Contains (file)) continue; - alreadyVisited.Add (file.Name); - yield return new FileProvider (file.Name, project); + alreadyVisited.Add (file); + results.Enqueue (new FileProvider (file, ft.Item1)); } - } + results.SetComplete (); + }); } } @@ -144,9 +153,9 @@ namespace MonoDevelop.Ide.FindInFiles {
readonly Project project; - public override int GetTotalWork (FilterOptions filterOptions) + public override Task<int> GetTotalWork (FilterOptions filterOptions) { - return project.Files.Count; + return Task.FromResult (project.Files.Count); } public WholeProjectScope (Project project) @@ -157,21 +166,26 @@ namespace MonoDevelop.Ide.FindInFiles this.project = project; } - public override IEnumerable<FileProvider> GetFiles (IProgressMonitor monitor, FilterOptions filterOptions) + public override Task GetFiles (ProgressMonitor monitor, FilterOptions filterOptions, ResultQueue<FileProvider> results) { if (IdeApp.Workspace.IsOpen) { monitor.Log.WriteLine (GettextCatalog.GetString ("Looking in project '{0}'", project.Name)); var alreadyVisited = new HashSet<string> (); - foreach (ProjectFile file in project.Files.Where (f => filterOptions.NameMatches (f.Name) && File.Exists (f.Name))) { - if (!IncludeBinaryFiles && !DesktopService.GetFileIsText (file.Name)) - continue; + var allFiles = project.Files.Where (f => filterOptions.NameMatches (f.Name) && File.Exists (f.Name)).Select (f => f.Name).ToArray (); + return Task.Factory.StartNew (delegate { + foreach (string file in allFiles) { + if (!IncludeBinaryFiles && !DesktopService.GetFileIsText (file)) + continue; - if (alreadyVisited.Contains (file.Name)) - continue; - alreadyVisited.Add (file.Name); - yield return new FileProvider (file.Name, project); - } + if (alreadyVisited.Contains (file)) + continue; + alreadyVisited.Add (file); + results.Enqueue (new FileProvider (file, project)); + } + results.SetComplete (); + }); } + return Task.FromResult (0); } public override string GetDescription (FilterOptions filterOptions, string pattern, string replacePattern) @@ -185,18 +199,20 @@ namespace MonoDevelop.Ide.FindInFiles public class AllOpenFilesScope : Scope { - public override int GetTotalWork (FilterOptions filterOptions) + public override Task<int> GetTotalWork (FilterOptions filterOptions) { - return IdeApp.Workbench.Documents.Count; + return Task.FromResult (IdeApp.Workbench.Documents.Count); }
- public override IEnumerable<FileProvider> GetFiles (IProgressMonitor monitor, FilterOptions filterOptions) + public override Task GetFiles (ProgressMonitor monitor, FilterOptions filterOptions, ResultQueue<FileProvider> results) { foreach (Document document in IdeApp.Workbench.Documents) { monitor.Log.WriteLine (GettextCatalog.GetString ("Looking in '{0}'", document.FileName)); if (!string.IsNullOrEmpty (document.FileName) && filterOptions.NameMatches (document.FileName)) - yield return new FileProvider (document.FileName); + results.Enqueue (new FileProvider (document.FileName)); } + results.SetComplete (); + return Task.FromResult (0); } public override string GetDescription (FilterOptions filterOptions, string pattern, string replacePattern) @@ -218,9 +234,11 @@ namespace MonoDevelop.Ide.FindInFiles set; } - public override int GetTotalWork (FilterOptions filterOptions) + public override Task<int> GetTotalWork (FilterOptions filterOptions) { - return GetFileNames (null, filterOptions).Count (); + return Task<int>.Factory.StartNew (delegate { + return GetFileNames (null, filterOptions).Count (); + }); } public DirectoryScope (string path, bool recurse) @@ -229,7 +247,7 @@ namespace MonoDevelop.Ide.FindInFiles this.recurse = recurse; } - IEnumerable<string> GetFileNames (IProgressMonitor monitor, FilterOptions filterOptions) + IEnumerable<string> GetFileNames (ProgressMonitor monitor, FilterOptions filterOptions) { if (monitor != null) monitor.Log.WriteLine (GettextCatalog.GetString ("Looking in '{0}'", path)); @@ -282,9 +300,13 @@ namespace MonoDevelop.Ide.FindInFiles } } - public override IEnumerable<FileProvider> GetFiles (IProgressMonitor monitor, FilterOptions filterOptions)
- {
- return GetFileNames (monitor, filterOptions).Select (file => new FileProvider (file));
+ public override Task GetFiles (ProgressMonitor monitor, FilterOptions filterOptions, ResultQueue<FileProvider> results)
+ { + return Task.Factory.StartNew (delegate {
+ foreach (var r in GetFileNames (monitor, filterOptions).Select (file => new FileProvider (file))) + results.Enqueue (r); + results.SetComplete (); + });
}
public override string GetDescription (FilterOptions filterOptions, string pattern, string replacePattern) |