public override IEnumerable<FileProvider> GetFiles(IProgressMonitor monitor, FilterOptions filterOptions) { 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); } }
public bool ValidatePattern (FilterOptions filter, string pattern) { if (filter.RegexSearch) { try { new Regex (pattern, RegexOptions.Compiled); return true; } catch (Exception) { return false; } } return true; }
public IEnumerable<SearchResult> FindAll(Scope scope, IProgressMonitor monitor, string pattern, string replacePattern, FilterOptions filter) { if (filter.RegexSearch) { RegexOptions regexOptions = RegexOptions.Compiled; if (!filter.CaseSensitive) regexOptions |= RegexOptions.IgnoreCase; regex = new Regex (pattern, regexOptions); } IsRunning = true; FoundMatchesCount = SearchedFilesCount = 0; monitor.BeginTask (scope.GetDescription (filter, pattern, replacePattern), 50); try { int totalWork = scope.GetTotalWork (filter); int step = Math.Max (1, totalWork / 50); string content; foreach (FileProvider provider in scope.GetFiles (monitor, filter)) { if (monitor.IsCancelRequested) yield break; SearchedFilesCount++; try { content = provider.ReadString (); if (replacePattern != null) provider.BeginReplace (content); } catch (System.IO.FileNotFoundException) { Application.Invoke (delegate { MessageService.ShowError (string.Format (GettextCatalog.GetString ("File {0} not found.")), provider.FileName); }); continue; } foreach (SearchResult result in FindAll (monitor, provider, content, pattern, replacePattern, filter)) { if (monitor.IsCancelRequested) yield break; FoundMatchesCount++; yield return result; } if (replacePattern != null) provider.EndReplace (); if (SearchedFilesCount % step == 0) monitor.Step (1); } } finally { monitor.EndTask (); IsRunning = false; } }
public IEnumerable<SearchResult> FindAll (Scope scope, IProgressMonitor monitor, string pattern, string replacePattern, FilterOptions filter) { if (filter.RegexSearch) { RegexOptions regexOptions = RegexOptions.Compiled; if (!filter.CaseSensitive) regexOptions |= RegexOptions.IgnoreCase; regex = new Regex (pattern, regexOptions); } else { CompilePattern (pattern, filter); } IsRunning = true; FoundMatchesCount = SearchedFilesCount = 0; monitor.BeginTask (scope.GetDescription (filter, pattern, replacePattern), 100); try { int totalWork = scope.GetTotalWork (filter); int step = Math.Max (1, totalWork / 100); foreach (FileProvider provider in scope.GetFiles (monitor, filter)) { if (monitor.IsCancelRequested) break; SearchedFilesCount++; if (!string.IsNullOrEmpty (replacePattern)) provider.BeginReplace (); foreach (SearchResult result in FindAll (monitor, provider, pattern, replacePattern, filter)) { if (monitor.IsCancelRequested) break; FoundMatchesCount++; yield return result; } if (!string.IsNullOrEmpty (replacePattern)) provider.EndReplace (); if (SearchedFilesCount % step == 0) monitor.Step (1); DispatchService.RunPendingEvents (); } } finally { monitor.EndTask (); IsRunning = false; } }
public override IEnumerable <FileProvider> GetFiles(ProgressMonitor monitor, FilterOptions filterOptions) { monitor.Log.WriteLine(GettextCatalog.GetString("Looking in '{0}'", path)); return(fileNames); }
public override int GetTotalWork (FilterOptions filterOptions) { return 1; }
public abstract int GetTotalWork (FilterOptions filterOptions);
public override int GetTotalWork (FilterOptions filterOptions) { return IdeApp.Workbench.Documents.Count; }
public override string GetDescription(FilterOptions filterOptions, string pattern, string replacePattern) { if (replacePattern == null) return GettextCatalog.GetString("Looking for '{0}' in current document", pattern); return GettextCatalog.GetString("Replacing '{0}' in current document", pattern); }
internal static void SearchReplace (string findPattern, string replacePattern, Scope scope, FilterOptions options, System.Action UpdateStopButton) { if (find != null && find.IsRunning) { if (!MessageService.Confirm (GettextCatalog.GetString ("There is a search already in progress. Do you want to stop it?"), AlertButton.Stop)) return; lock (searchesInProgress) { foreach (var mon in searchesInProgress) mon.AsyncOperation.Cancel (); searchesInProgress.Clear (); } } if (scope == null) return; find = new FindReplace (); string pattern = findPattern; if (!find.ValidatePattern (options, pattern)) { MessageService.ShowError (GettextCatalog.GetString ("Search pattern is invalid")); return; } if (replacePattern != null && !find.ValidatePattern (options, replacePattern)) { MessageService.ShowError (GettextCatalog.GetString ("Replace pattern is invalid")); return; } ThreadPool.QueueUserWorkItem (delegate { using (ISearchProgressMonitor searchMonitor = IdeApp.Workbench.ProgressMonitors.GetSearchProgressMonitor (true)) { searchMonitor.ReportStatus (scope.GetDescription (options, pattern, null)); lock (searchesInProgress) searchesInProgress.Add (searchMonitor); if (UpdateStopButton != null) { Application.Invoke (delegate { UpdateStopButton (); }); } DateTime timer = DateTime.Now; string errorMessage = null; try { var results = new List<SearchResult> (); foreach (SearchResult result in find.FindAll (scope, searchMonitor, pattern, replacePattern, options)) { if (searchMonitor.IsCancelRequested) return; results.Add (result); } searchMonitor.ReportResults (results); } catch (Exception ex) { errorMessage = ex.Message; LoggingService.LogError ("Error while search", ex); } string message; if (errorMessage != null) { message = GettextCatalog.GetString ("The search could not be finished: {0}", errorMessage); searchMonitor.ReportError (message, null); } else if (searchMonitor.IsCancelRequested) { message = GettextCatalog.GetString ("Search cancelled."); searchMonitor.ReportWarning (message); } else { string matches = string.Format (GettextCatalog.GetPluralString ("{0} match found", "{0} matches found", find.FoundMatchesCount), find.FoundMatchesCount); string files = string.Format (GettextCatalog.GetPluralString ("in {0} file.", "in {0} files.", find.SearchedFilesCount), find.SearchedFilesCount); message = GettextCatalog.GetString ("Search completed.") + Environment.NewLine + matches + " " + files; searchMonitor.ReportSuccess (message); } searchMonitor.ReportStatus (message); searchMonitor.Log.WriteLine (GettextCatalog.GetString ("Search time: {0} seconds."), (DateTime.Now - timer).TotalSeconds); searchesInProgress.Remove (searchMonitor); } if (UpdateStopButton != null) { Application.Invoke (delegate { UpdateStopButton (); }); } }); }
public IEnumerable <SearchResult> Search(FileProvider provider, string content, string pattern, FilterOptions filter) { if (string.IsNullOrEmpty(content)) { yield break; } int idx = provider.SelectionStartPosition < 0 ? 0 : Math.Max(0, provider.SelectionStartPosition); var comparison = filter.CaseSensitive ? StringComparison.Ordinal : StringComparison.OrdinalIgnoreCase; int end = provider.SelectionEndPosition < 0 ? content.Length : Math.Min(content.Length, provider.SelectionEndPosition); while ((idx = content.IndexOf(pattern, idx, end - idx, comparison)) >= 0) { if (!filter.WholeWordsOnly || FilterOptions.IsWholeWordAt(content, idx, pattern.Length)) { yield return(new SearchResult(provider, idx, pattern.Length)); } idx += pattern.Length; } }
public override IEnumerable <FileProvider> GetFiles(IProgressMonitor monitor, FilterOptions filterOptions) { if (IdeApp.Workspace.IsOpen) { 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.GetMimeTypeIsText(DesktopService.GetMimeTypeForUri(file.Name))) { continue; } yield return(new FileProvider(file.Name, project)); } } }
public override IEnumerable <FileProvider> GetFiles(ProgressMonitor monitor, FilterOptions filterOptions) { if (!IdeApp.Workspace.IsOpen) { return(null); } var alreadyVisited = new HashSet <string> (); var results = new List <FileProvider> (); var options = new ParallelOptions(); options.MaxDegreeOfParallelism = 4; Parallel.ForEach(IdeApp.Workspace.GetAllSolutionItems().OfType <SolutionFolder> (), options, () => new List <FileProvider> (), (folder, loop, providers) => { foreach (var file in folder.Files.Where(f => filterOptions.NameMatches(f.FileName) && File.Exists(f.FullPath))) { if (!IncludeBinaryFiles && !DesktopService.GetFileIsText(file.FullPath)) { continue; } lock (alreadyVisited) { if (alreadyVisited.Contains(file.FullPath)) { continue; } alreadyVisited.Add(file.FullPath); } providers.Add(new FileProvider(file.FullPath)); } return(providers); }, (providers) => { lock (results) { results.AddRange(providers); } }); Parallel.ForEach(IdeApp.Workspace.GetAllProjects(), options, () => new List <FileProvider> (), (project, loop, providers) => { var conf = project.DefaultConfiguration?.Selector; foreach (ProjectFile file in project.GetSourceFilesAsync(conf).Result.Where(f => filterOptions.NameMatches(f.Name) && File.Exists(f.Name))) { if ((file.Flags & ProjectItemFlags.Hidden) == ProjectItemFlags.Hidden) { continue; } if (!IncludeBinaryFiles && !DesktopService.GetFileIsText(file.FilePath)) { continue; } lock (alreadyVisited) { if (alreadyVisited.Contains(file.FilePath.FullPath)) { continue; } alreadyVisited.Add(file.FilePath.FullPath); } providers.Add(new FileProvider(file.Name, project)); } return(providers); }, (providers) => { lock (results) { results.AddRange(providers); } }); return(results); }
public override IEnumerable <FileProvider> GetFiles(IProgressMonitor monitor, FilterOptions filterOptions) { if (IdeApp.Workspace.IsOpen) { monitor.Log.WriteLine(GettextCatalog.GetString("Looking in project '{0}'", project.Name)); return(project.Files.Where(f => filterOptions.NameMatches(f.Name) && File.Exists(f.Name)).Select(f => new FileProvider(f.Name, project))); } return(Enumerable.Empty <FileProvider> ()); }
public override IEnumerable <FileProvider> GetFiles(IProgressMonitor monitor, FilterOptions filterOptions) { if (IdeApp.Workspace.IsOpen) { 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))) { yield return(new FileProvider(file.Name, project)); } } } }
void ISearchDataSource.Activate (int item) { var options = new FilterOptions (); if (PropertyService.Get ("AutoSetPatternCasing", true)) options.CaseSensitive = searchPattern.Pattern.Any (c => char.IsUpper (c)); FindInFilesDialog.SearchReplace (searchPattern.Pattern, null, new WholeSolutionScope (), options, null); }
public IEnumerable <SearchResult> FindAll(Scope scope, ProgressMonitor monitor, string pattern, string replacePattern, FilterOptions filter) { if (filter.RegexSearch) { RegexOptions regexOptions = RegexOptions.Compiled; if (!filter.CaseSensitive) { regexOptions |= RegexOptions.IgnoreCase; } regex = new Regex(pattern, regexOptions); } IsRunning = true; FoundMatchesCount = SearchedFilesCount = 0; monitor.BeginTask(scope.GetDescription(filter, pattern, replacePattern), 150); try { int totalWork = scope.GetTotalWork(filter); int step = Math.Max(1, totalWork / 50); var contents = new List <Tuple <FileProvider, string, List <SearchResult> > >(); foreach (var provider in scope.GetFiles(monitor, filter)) { try { searchedFilesCount++; contents.Add(Tuple.Create(provider, provider.ReadString(), new List <SearchResult> ())); if (searchedFilesCount % step == 0) { monitor.Step(2); } } catch (FileNotFoundException) { MessageService.ShowError(string.Format(GettextCatalog.GetString("File {0} not found.")), provider.FileName); } } var results = new List <SearchResult>(); if (filter.RegexSearch && replacePattern != null) { foreach (var content in contents) { results.AddRange(RegexSearch(monitor, content.Item1, content.Item2, replacePattern, filter)); } } else { Parallel.ForEach(contents, content => { if (monitor.CancellationToken.IsCancellationRequested) { return; } try { Interlocked.Increment(ref searchedFilesCount); content.Item3.AddRange(FindAll(monitor, content.Item1, content.Item2, pattern, replacePattern, filter)); lock (results) { results.AddRange(content.Item3); } FoundMatchesCount += content.Item3.Count; if (searchedFilesCount % step == 0) { monitor.Step(1); } } catch (Exception e) { LoggingService.LogError("Exception during search.", e); } }); if (replacePattern != null) { foreach (var content in contents) { if (content.Item3.Count == 0) { continue; } try { content.Item1.BeginReplace(content.Item2); Replace(content.Item1, content.Item3, replacePattern); content.Item1.EndReplace(); } catch (Exception e) { LoggingService.LogError("Exception during replace.", e); } } } } return(results); } finally { monitor.EndTask(); IsRunning = false; } }
IEnumerable<string> GetFileNames(IProgressMonitor monitor, FilterOptions filterOptions) { if (monitor != null) monitor.Log.WriteLine (GettextCatalog.GetString ("Looking in '{0}'", path)); var directoryStack = new Stack<string> (); directoryStack.Push (path); while (directoryStack.Count > 0) { var curPath = directoryStack.Pop (); try { var readPermission = new FileIOPermission(FileIOPermissionAccess.Read, curPath); readPermission.Demand (); } catch (Exception e) { LoggingService.LogError ("Can't access path " + curPath, e); yield break; } foreach (string fileName in Directory.EnumerateFiles (curPath, "*")) { if (!IncludeHiddenFiles) { if (Platform.IsWindows) { var attr = File.GetAttributes (fileName); if (attr.HasFlag (FileAttributes.Hidden)) continue; } if (Path.GetFileName (fileName).StartsWith (".", StringComparison.Ordinal)) continue; } if (!filterOptions.NameMatches (fileName)) continue; if (!IncludeBinaryFiles && !DesktopService.GetFileIsText (fileName)) continue; yield return fileName; } if (recurse) { foreach (string directoryName in Directory.EnumerateDirectories (curPath)) { if (!IncludeHiddenFiles) { if (Platform.IsWindows) { var attr = File.GetAttributes (directoryName); if (attr.HasFlag (FileAttributes.Hidden)) continue; } if (Path.GetFileName (directoryName).StartsWith (".", StringComparison.Ordinal)) continue; } directoryStack.Push (directoryName); } } } }
internal static void SearchReplace(string findPattern, string replacePattern, Scope scope, FilterOptions options, System.Action UpdateStopButton) { if (find != null && find.IsRunning) { if (!MessageService.Confirm(GettextCatalog.GetString("There is a search already in progress. Do you want to stop it?"), AlertButton.Stop)) { return; } lock (searchesInProgress) { foreach (var mon in searchesInProgress) { mon.AsyncOperation.Cancel(); } searchesInProgress.Clear(); } } if (scope == null) { return; } find = new FindReplace(); string pattern = findPattern; if (String.IsNullOrEmpty(pattern)) { return; } if (!find.ValidatePattern(options, pattern)) { MessageService.ShowError(GettextCatalog.GetString("Search pattern is invalid")); return; } if (replacePattern != null && !find.ValidatePattern(options, replacePattern)) { MessageService.ShowError(GettextCatalog.GetString("Replace pattern is invalid")); return; } ThreadPool.QueueUserWorkItem(delegate { using (ISearchProgressMonitor searchMonitor = IdeApp.Workbench.ProgressMonitors.GetSearchProgressMonitor(true)) { searchMonitor.PathMode = scope.PathMode; searchMonitor.ReportStatus(scope.GetDescription(options, pattern, null)); lock (searchesInProgress) searchesInProgress.Add(searchMonitor); if (UpdateStopButton != null) { Application.Invoke(delegate { UpdateStopButton(); }); } DateTime timer = DateTime.Now; string errorMessage = null; try { var results = new List <SearchResult> (); foreach (SearchResult result in find.FindAll(scope, searchMonitor, pattern, replacePattern, options)) { if (searchMonitor.IsCancelRequested) { return; } results.Add(result); } searchMonitor.ReportResults(results); } catch (Exception ex) { errorMessage = ex.Message; LoggingService.LogError("Error while search", ex); } string message; if (errorMessage != null) { message = GettextCatalog.GetString("The search could not be finished: {0}", errorMessage); searchMonitor.ReportError(message, null); } else if (searchMonitor.IsCancelRequested) { message = GettextCatalog.GetString("Search cancelled."); searchMonitor.ReportWarning(message); } else { string matches = string.Format(GettextCatalog.GetPluralString("{0} match found", "{0} matches found", find.FoundMatchesCount), find.FoundMatchesCount); string files = string.Format(GettextCatalog.GetPluralString("in {0} file.", "in {0} files.", find.SearchedFilesCount), find.SearchedFilesCount); message = GettextCatalog.GetString("Search completed.") + Environment.NewLine + matches + " " + files; searchMonitor.ReportSuccess(message); } searchMonitor.ReportStatus(message); searchMonitor.Log.WriteLine(GettextCatalog.GetString("Search time: {0} seconds."), (DateTime.Now - timer).TotalSeconds); searchesInProgress.Remove(searchMonitor); } if (UpdateStopButton != null) { Application.Invoke(delegate { UpdateStopButton(); }); } }); }
public override IEnumerable<FileProvider> GetFiles (IProgressMonitor monitor, FilterOptions filterOptions) { return GetFileNames (monitor, filterOptions).Select (file => new FileProvider (file)); }
public IEnumerable <SearchResult> FindAll(Scope scope, ProgressMonitor monitor, string pattern, string replacePattern, FilterOptions filter, CancellationToken token) { if (filter.RegexSearch) { RegexOptions regexOptions = RegexOptions.Compiled | RegexOptions.Multiline; if (!filter.CaseSensitive) { regexOptions |= RegexOptions.IgnoreCase; } regex = new Regex(pattern, regexOptions); } IsRunning = true; FoundMatchesCount = SearchedFilesCount = 0; monitor.BeginTask(scope.GetDescription(filter, pattern, replacePattern), 150); try { int totalWork = scope.GetTotalWork(filter); int step = Math.Max(1, totalWork / 50); var contents = new List <FileSearchResult>(); var filenames = new List <string> (); foreach (var provider in scope.GetFiles(monitor, filter)) { if (token.IsCancellationRequested) { return(Enumerable.Empty <SearchResult> ()); } try { searchedFilesCount++; contents.Add(new FileSearchResult(provider, null, new List <SearchResult> ())); filenames.Add(Path.GetFullPath(provider.FileName)); if (searchedFilesCount % step == 0) { monitor.Step(2); } } catch (FileNotFoundException) { MessageService.ShowError(string.Format(GettextCatalog.GetString("File {0} not found.")), provider.FileName); } } var readers = IdeApp.Workbench.GetDocumentReaders(filenames); int idx = 0; if (readers != null) { foreach (var r in readers) { contents [idx].Reader = r; idx++; } } idx = 0; int c = 0; int t = 0; foreach (var result in contents) { if (readers == null || readers [idx] == null) { result.Reader = result.Provider.GetReaderForFileName(); } else { result.Reader = readers [idx]; c++; } t++; idx++; } var results = new List <SearchResult>(); if (filter.RegexSearch && replacePattern != null) { foreach (var content in contents) { if (token.IsCancellationRequested) { return(Enumerable.Empty <SearchResult> ()); } results.AddRange(RegexSearch(monitor, content.Provider, content.Reader, replacePattern, filter)); } } else { var options = new ParallelOptions(); options.MaxDegreeOfParallelism = 4; options.CancellationToken = token; Parallel.ForEach(contents, options, content => { if (token.IsCancellationRequested) { return; } try { Interlocked.Increment(ref searchedFilesCount); if (replacePattern != null) { content.Text = content.Reader.ReadToEnd(); content.Encoding = content.Provider.CurrentEncoding; content.Reader = new StringReader(content.Text); } content.Results.AddRange(FindAll(monitor, content.Provider, content.Reader, pattern, replacePattern, filter)); lock (results) { results.AddRange(content.Results); } FoundMatchesCount += content.Results.Count; if (searchedFilesCount % step == 0) { monitor.Step(1); } } catch (Exception e) { LoggingService.LogError("Exception during search.", e); } }); if (replacePattern != null) { foreach (var content in contents) { if (token.IsCancellationRequested) { return(Enumerable.Empty <SearchResult> ()); } if (content.Results.Count == 0) { continue; } try { content.Provider.BeginReplace(content.Text, content.Encoding); Replace(content.Provider, content.Results, replacePattern); content.Provider.EndReplace(); } catch (Exception e) { LoggingService.LogError("Exception during replace.", e); } } } } return(results); } finally { monitor.EndTask(); IsRunning = false; } }
public override IEnumerable<FileProvider> GetFiles (IProgressMonitor monitor, FilterOptions filterOptions) { if (IdeApp.Workspace.IsOpen) { monitor.Log.WriteLine (GettextCatalog.GetString ("Looking in project '{0}'", project.Name)); foreach (ProjectFile file in project.Files) { if (filterOptions.NameMatches (file.Name)) yield return new FileProvider (file.Name, project); } } }
public IEnumerable <SearchResult> Search(FileProvider provider, TextReader reader, string pattern, FilterOptions filter) { if (reader == null) { yield break; } int i = provider.SelectionStartPosition < 0 ? 0 : Math.Max(0, provider.SelectionStartPosition); var buffer = new RingBufferReader(reader, pattern.Length + 2); bool wasSeparator = true; if (!filter.CaseSensitive) { pattern = pattern.ToUpperInvariant(); } while (true) { int next = buffer.Next(); if (next < 0) { yield break; } char ch = (char)next; if ((filter.CaseSensitive ? ch : char.ToUpperInvariant(ch)) == pattern [0] && (!filter.WholeWordsOnly || wasSeparator)) { bool isMatch = true; for (int j = 1; j < pattern.Length; j++) { next = buffer.Next(); if (next < 0) { yield break; } if ((filter.CaseSensitive ? next : char.ToUpperInvariant((char)next)) != pattern [j]) { buffer.TakeBack(j); isMatch = false; break; } } if (isMatch) { if (filter.WholeWordsOnly) { next = buffer.Next(); if (next >= 0 && !FilterOptions.IsWordSeparator((char)next)) { buffer.TakeBack(pattern.Length); i++; continue; } buffer.TakeBack(1); } yield return(new SearchResult(provider, i, pattern.Length)); i += pattern.Length - 1; } } i++; if (filter.WholeWordsOnly) { wasSeparator = FilterOptions.IsWordSeparator((char)ch); } } }
IEnumerable<string> GetFileNames (IProgressMonitor monitor, string path, bool recurse, FilterOptions filterOptions) { if (monitor != null) monitor.Log.WriteLine (GettextCatalog.GetString ("Looking in '{0}'", path)); foreach (string fileMask in filterOptions.FileMask.Split (',', ';')) { string[] files; try { files = Directory.GetFiles (path, fileMask, SearchOption.TopDirectoryOnly); } catch (Exception e) { LoggingService.LogError ("Can't access path " + path, e); continue; } foreach (string fileName in files) { if (fileName.StartsWith (".") && !IncludeHiddenFiles) continue; if (!IncludeBinaryFiles && MimeTypeIsBinary (DesktopService.GetMimeTypeForUri (fileName))) continue; yield return fileName; } if (recurse) { foreach (string directoryName in Directory.GetDirectories (path)) { if (directoryName.StartsWith (".") && !IncludeHiddenFiles) continue; foreach (string fileName in GetFileNames (monitor, Path.Combine (path, directoryName), recurse, filterOptions)) { yield return fileName; } } } } }
public override int GetTotalWork(FilterOptions filterOptions) { return(project.Files.Count); }
public abstract string GetDescription (FilterOptions filterOptions, string pattern, string replacePattern);
public override IEnumerable <FileProvider> GetFiles(IProgressMonitor monitor, FilterOptions filterOptions) { 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 ((file.Flags & ProjectItemFlags.Hidden) == ProjectItemFlags.Hidden) { continue; } if (!IncludeBinaryFiles && !DesktopService.GetFileIsText(file.Name)) { continue; } if (alreadyVisited.Contains(file.FilePath.FullPath)) { continue; } alreadyVisited.Add(file.FilePath.FullPath); yield return(new FileProvider(file.Name, project)); } } }
public override string GetDescription(FilterOptions filterOptions, string pattern, string replacePattern) { if (string.IsNullOrEmpty(replacePattern)) return GettextCatalog.GetString("Looking for '{0}' in current selection", pattern); return GettextCatalog.GetString("Replacing '{0}' in current selection", pattern); }
public override int GetTotalWork(FilterOptions filterOptions) { return(IdeApp.Workbench.Documents.Count); }
public override IEnumerable <FileProvider> GetFiles(IProgressMonitor monitor, FilterOptions filterOptions) { 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)); } } }
public override int GetTotalWork(FilterOptions filterOptions) { return(GetFileNames(null, filterOptions).Count()); }
public override IEnumerable<FileProvider> GetFiles (ProgressMonitor monitor, FilterOptions filterOptions) { if (IdeApp.Workspace.IsOpen) { monitor.Log.WriteLine (GettextCatalog.GetString ("Looking in project '{0}'", project.Name)); var alreadyVisited = new HashSet<string> (); var conf = project.DefaultConfiguration?.Selector; foreach (ProjectFile file in project.GetSourceFilesAsync (conf).Result.Where (f => filterOptions.NameMatches (f.Name) && File.Exists (f.Name))) { if ((file.Flags & ProjectItemFlags.Hidden) == ProjectItemFlags.Hidden) continue; if (!IncludeBinaryFiles && !DesktopService.GetFileIsText (file.Name)) continue; if (alreadyVisited.Contains (file.FilePath.FullPath)) continue; alreadyVisited.Add (file.FilePath.FullPath); yield return new FileProvider (file.Name, project); } } }
IEnumerable <string> GetFileNames(IProgressMonitor monitor, FilterOptions filterOptions) { if (monitor != null) { monitor.Log.WriteLine(GettextCatalog.GetString("Looking in '{0}'", path)); } var directoryStack = new Stack <string> (); directoryStack.Push(path); while (directoryStack.Count > 0) { var curPath = directoryStack.Pop(); try { var readPermission = new FileIOPermission(FileIOPermissionAccess.Read, curPath); readPermission.Demand(); } catch (Exception e) { LoggingService.LogError("Can't access path " + curPath, e); yield break; } foreach (string fileName in Directory.EnumerateFiles(curPath, "*")) { if (!IncludeHiddenFiles) { if (Platform.IsWindows) { var attr = File.GetAttributes(fileName); if (attr.HasFlag(FileAttributes.Hidden)) { continue; } } if (Path.GetFileName(fileName).StartsWith(".", StringComparison.Ordinal)) { continue; } } if (!filterOptions.NameMatches(fileName)) { continue; } if (!IncludeBinaryFiles && !DesktopService.GetFileIsText(fileName)) { continue; } yield return(fileName); } if (recurse) { foreach (string directoryName in Directory.EnumerateDirectories(curPath)) { if (!IncludeHiddenFiles) { if (Platform.IsWindows) { var attr = File.GetAttributes(directoryName); if (attr.HasFlag(FileAttributes.Hidden)) { continue; } } if (Path.GetFileName(directoryName).StartsWith(".", StringComparison.Ordinal)) { continue; } } directoryStack.Push(directoryName); } } } }
public override void Activate () { var options = new FilterOptions (); if (PropertyService.Get ("AutoSetPatternCasing", true)) options.CaseSensitive = pattern.Pattern.Any (char.IsUpper); FindInFilesDialog.SearchReplace (pattern.Pattern, null, new WholeSolutionScope (), options, null, null); }
public override IEnumerable <FileProvider> GetFiles(IProgressMonitor monitor, FilterOptions filterOptions) { return(GetFileNames(monitor, filterOptions).Select(file => new FileProvider(file))); }
public override IEnumerable<FileProvider> GetFiles (IProgressMonitor monitor, FilterOptions filterOptions) { if (IdeApp.Workspace.IsOpen) { monitor.Log.WriteLine (GettextCatalog.GetString ("Looking in project '{0}'", project.Name)); return project.Files.Where (f => filterOptions.NameMatches (f.Name) && File.Exists (f.Name)).Select (f => new FileProvider (f.Name, project)); } return Enumerable.Empty<FileProvider> (); }
public abstract int GetTotalWork(FilterOptions filterOptions);
public override IEnumerable<FileProvider> GetFiles(IProgressMonitor monitor, FilterOptions filterOptions) { 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))) { if (!IncludeBinaryFiles && !DesktopService.GetFileIsText (file.FullPath)) continue; if (alreadyVisited.Contains (file.FullPath)) continue; alreadyVisited.Add (file.FileName); yield return 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)) continue; if (alreadyVisited.Contains (file.Name)) continue; alreadyVisited.Add (file.Name); yield return new FileProvider (file.Name, project); } } } }
public abstract IEnumerable <FileProvider> GetFiles(IProgressMonitor monitor, FilterOptions filterOptions);
public override IEnumerable<FileProvider> GetFiles (IProgressMonitor monitor, FilterOptions filterOptions) { if (IdeApp.Workspace.IsOpen) { 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.GetMimeTypeIsText (DesktopService.GetMimeTypeForUri (file.Name))) continue; yield return new FileProvider (file.Name, project); } } }
public abstract string GetDescription(FilterOptions filterOptions, string pattern, string replacePattern);
public override string GetDescription (FilterOptions filterOptions, string pattern, string replacePattern) { if (replacePattern == null) return GettextCatalog.GetString ("Looking for '{0}' in directory '{1}'", pattern, path); return GettextCatalog.GetString ("Replacing '{0}' in directory '{1}'", pattern, path); }
public override IEnumerable <FileProvider> GetFiles(IProgressMonitor monitor, FilterOptions filterOptions) { monitor.Log.WriteLine(GettextCatalog.GetString("Looking in '{0}'", IdeApp.Workbench.ActiveDocument.FileName)); yield return(new FileProvider(IdeApp.Workbench.ActiveDocument.FileName)); }
public override int GetTotalWork (FilterOptions filterOptions) { return project.Files.Count; }
public override int GetTotalWork(FilterOptions filterOptions) { return(1); }
public override string GetDescription (FilterOptions filterOptions, string pattern, string replacePattern) { if (string.IsNullOrEmpty (replacePattern)) return GettextCatalog.GetString ("Looking for '{0}' in project '{1}'", pattern, project.Name); return GettextCatalog.GetString ("Replacing '{0}' in project '{1}'", pattern, project.Name); }
public override IEnumerable <FileProvider> GetFiles(IProgressMonitor monitor, FilterOptions filterOptions) { var selection = IdeApp.Workbench.ActiveDocument.Editor.SelectionRange; yield return(new FileProvider(IdeApp.Workbench.ActiveDocument.FileName, null, selection.Offset, selection.EndOffset)); }
public override int GetTotalWork (FilterOptions filterOptions) { return GetFileNames (null, path, recurse, filterOptions).Count (); }
IEnumerable <SearchResult> FindAll(IProgressMonitor monitor, FileProvider provider, string content, string pattern, string replacePattern, FilterOptions filter) { if (string.IsNullOrEmpty(pattern)) { return(Enumerable.Empty <SearchResult> ()); } if (filter.RegexSearch) { return(RegexSearch(monitor, provider, content, replacePattern, filter)); } return(Search(provider, content, pattern, replacePattern, filter)); }
public override IEnumerable<FileProvider> GetFiles (IProgressMonitor monitor, FilterOptions filterOptions) { foreach (string file in GetFileNames (monitor, path, recurse, filterOptions)) { yield return new FileProvider (file); } }
IEnumerable <SearchResult> FindAll(IProgressMonitor monitor, FileProvider provider, string pattern, string replacePattern, FilterOptions filter) { if (string.IsNullOrEmpty(pattern)) { return(Enumerable.Empty <SearchResult> ()); } string content; try { content = provider.ReadString(); if (content == null) { return(Enumerable.Empty <SearchResult> ()); } } catch (Exception e) { LoggingService.LogError("Error while reading file", e); return(Enumerable.Empty <SearchResult> ()); } if (filter.RegexSearch) { return(RegexSearch(monitor, provider, content, replacePattern, filter)); } return(Search(provider, content, pattern, replacePattern, filter)); }
public abstract IEnumerable<FileProvider> GetFiles (IProgressMonitor monitor, FilterOptions filterOptions);
IEnumerable <SearchResult> RegexSearch(IProgressMonitor monitor, FileProvider provider, string content, string replacePattern, FilterOptions filter) { var results = new List <SearchResult> (); if (replacePattern == null) { foreach (Match match in regex.Matches(content)) { if (monitor.IsCancelRequested) { break; } if (provider.SelectionStartPosition > -1 && match.Index < provider.SelectionStartPosition) { continue; } if (provider.SelectionEndPosition > -1 && match.Index + match.Length > provider.SelectionEndPosition) { continue; } if (!filter.WholeWordsOnly || FilterOptions.IsWholeWordAt(content, match.Index, match.Length)) { results.Add(new SearchResult(provider, match.Index, match.Length)); } } } else { var matches = new List <Match> (); foreach (Match match in regex.Matches(content)) { if (provider.SelectionStartPosition > -1 && match.Index < provider.SelectionStartPosition) { continue; } if (provider.SelectionEndPosition > -1 && match.Index + match.Length > provider.SelectionEndPosition) { continue; } matches.Add(match); } provider.BeginReplace(); int delta = 0; for (int i = 0; !monitor.IsCancelRequested && i < matches.Count; i++) { Match match = matches[i]; if (!filter.WholeWordsOnly || FilterOptions.IsWholeWordAt(content, match.Index, match.Length)) { string replacement = match.Result(replacePattern); results.Add(new SearchResult(provider, match.Index + delta, replacement.Length)); provider.Replace(match.Index + delta, match.Length, replacement); delta += replacement.Length - match.Length; } } provider.EndReplace(); } return(results); }
public override IEnumerable<FileProvider> GetFiles (IProgressMonitor monitor, FilterOptions filterOptions) { monitor.Log.WriteLine (GettextCatalog.GetString ("Looking in '{0}'", IdeApp.Workbench.ActiveDocument.FileName)); yield return new FileProvider(IdeApp.Workbench.ActiveDocument.FileName); }
public IEnumerable <SearchResult> Search(FileProvider provider, string content, string pattern, string replacePattern, FilterOptions filter) { if (string.IsNullOrEmpty(content)) { yield break; } int idx = provider.SelectionStartPosition < 0 ? 0 : Math.Max(0, provider.SelectionStartPosition); int delta = 0; var comparison = filter.CaseSensitive ? StringComparison.Ordinal : StringComparison.OrdinalIgnoreCase; while ((idx = content.IndexOf(pattern, idx, content.Length - idx, comparison)) >= 0) { if (!filter.WholeWordsOnly || FilterOptions.IsWholeWordAt(content, idx, pattern.Length)) { if (replacePattern != null) { provider.Replace(idx + delta, pattern.Length, replacePattern); yield return(new SearchResult(provider, idx + delta, replacePattern.Length)); delta += replacePattern.Length - pattern.Length; } else { yield return(new SearchResult(provider, idx, pattern.Length)); } } idx += pattern.Length; } }
public override IEnumerable<FileProvider> GetFiles (IProgressMonitor monitor, FilterOptions filterOptions) { yield return new FileProvider(IdeApp.Workbench.ActiveDocument.FileName, null, IdeApp.Workbench.ActiveDocument.Editor.SelectionRange.Offset, IdeApp.Workbench.ActiveDocument.Editor.SelectionRange.EndOffset); }
public IEnumerable <SearchResult> FindAll(Scope scope, IProgressMonitor monitor, string pattern, string replacePattern, FilterOptions filter) { if (filter.RegexSearch) { RegexOptions regexOptions = RegexOptions.Compiled; if (!filter.CaseSensitive) { regexOptions |= RegexOptions.IgnoreCase; } regex = new Regex(pattern, regexOptions); } IsRunning = true; FoundMatchesCount = SearchedFilesCount = 0; monitor.BeginTask(scope.GetDescription(filter, pattern, replacePattern), 50); try { int totalWork = scope.GetTotalWork(filter); int step = Math.Max(1, totalWork / 50); foreach (FileProvider provider in scope.GetFiles(monitor, filter)) { if (monitor.IsCancelRequested) { yield break; } SearchedFilesCount++; try { if (replacePattern != null) { provider.BeginReplace(); } } catch (System.IO.FileNotFoundException) { MessageService.ShowError(string.Format(GettextCatalog.GetString("File {0} not found.")), provider.FileName); continue; } foreach (SearchResult result in FindAll(monitor, provider, pattern, replacePattern, filter)) { if (monitor.IsCancelRequested) { yield break; } FoundMatchesCount++; yield return(result); } if (replacePattern != null) { provider.EndReplace(); } if (SearchedFilesCount % step == 0) { monitor.Step(1); } } } finally { monitor.EndTask(); IsRunning = false; } }
public override int GetTotalWork (FilterOptions filterOptions) { int result = 0; if (IdeApp.Workspace.IsOpen) result = IdeApp.Workspace.GetAllProjects ().Sum (p => p.Files.Count); return result; }
public override int GetTotalWork(FilterOptions filterOptions) { fileNames = GetFileNames(filterOptions).Select(file => new FileProvider(file)).ToArray(); return(fileNames.Length); }