コード例 #1
0
        public IEnumerable <FindResult> Find(string searchString, bool caseSensitive, bool wholeWords, bool regex, string[] fileMasks)
        {
            var shell = IoC.Get <IShell>();

            var searchStrategy = SearchStrategyFactory.Create(searchString, !caseSensitive, wholeWords, regex ? SearchMode.RegEx : SearchMode.Normal);

            if (shell.CurrentSolution == null)
            {
                return(Enumerable.Empty <FindResult>());
            }

            var files = shell.CurrentSolution.Projects.SelectMany(p => p.SourceFiles);

            if (fileMasks != null && fileMasks.Count() > 0)
            {
                // Construct corresponding regular expression. Note Regex.Escape!
                var options = RegexOptions.Singleline | RegexOptions.Compiled | RegexOptions.IgnoreCase;

                var patterns = fileMasks
                               .Select(f => new Regex("^" + Regex.Escape(f).Replace("\\*", ".*") + "$", options))
                               .ToArray();

                files = files.Where(f => patterns.Any(p => p.IsMatch(f.FilePath)));
            }

            return(files.SelectMany(f => GetResults(searchStrategy, f)));
        }
コード例 #2
0
        public Dictionary <int, string> GetManualResult(string text, bool regexMode, bool ignoreCaseMode)
        {
            Dictionary <int, string> returnValue = new Dictionary <int, string>();
            ISearchStrategy          strategy    = SearchStrategyFactory.Create(text, ignoreCaseMode, false, regexMode ? SearchMode.RegEx : SearchMode.Normal);

            GetSearchResult(ref returnValue, strategy);
            return(returnValue);
        }
コード例 #3
0
 public void UpdateSearch()
 {
     // only reset as long as there are results
     // if no results are found, the "no matches found" message should not flicker.
     // if results are found by the next run, the message will be hidden inside DoSearch ...
     strategy = SearchStrategyFactory.Create(SearchPattern ?? "", true, false, SearchMode.Normal);
     OnSearchOptionsChanged(new SearchOptionsChangedEventArgs(SearchPattern, true, false, false));
     DoSearch(true);
 }
コード例 #4
0
 void UpdateSearch()
 {
     // only reset as long as there are results
     // if no results are found, the "no matches found" message should not flicker.
     // if results are found by the next run, the message will be hidden inside DoSearch ...
     if (_renderer.CurrentResults.Any())
     {
         _messageView.IsOpen = false;
     }
     _strategy = SearchStrategyFactory.Create(SearchPattern ?? "", !MatchCase, WholeWords, UseRegex ? SearchMode.RegEx : SearchMode.Normal);
     OnSearchOptionsChanged(new SearchOptionsChangedEventArgs(SearchPattern, MatchCase, UseRegex, WholeWords));
     DoSearch(true);
 }
コード例 #5
0
 void FindNextButtonClicked(object sender, EventArgs e)
 {
     try {
         WritebackOptions();
         var location = new SearchLocation(SearchOptions.SearchTarget, SearchOptions.LookIn, SearchOptions.LookInFiletypes, SearchOptions.IncludeSubdirectories, SearchOptions.SearchTarget == SearchTarget.CurrentSelection ? SearchManager.GetActiveSelection(true) : null);
         var strategy = SearchStrategyFactory.Create(SearchOptions.FindPattern, !SearchOptions.MatchCase, SearchOptions.MatchWholeWord, SearchOptions.SearchMode);
         lastMatch = SearchManager.FindNext(strategy, location);
         SearchManager.SelectResult(lastMatch);
         Focus();
     } catch (SearchPatternException ex) {
         MessageService.ShowError(ex.Message);
     }
 }
コード例 #6
0
 public override void Run()
 {
     if (SearchOptions.CurrentFindPattern.Length > 0)
     {
         var location = new SearchLocation(SearchOptions.SearchTarget, SearchOptions.LookIn, SearchOptions.LookInFiletypes, SearchOptions.IncludeSubdirectories, SearchOptions.SearchTarget == SearchTarget.CurrentSelection ? SearchManager.GetActiveSelection(true) : null);
         var strategy = SearchStrategyFactory.Create(SearchOptions.FindPattern, !SearchOptions.MatchCase, SearchOptions.MatchWholeWord, SearchOptions.SearchMode);
         var result   = SearchManager.FindNext(strategy, location);
         SearchManager.SelectResult(result);
     }
     else
     {
         Find find = new Find();
         find.Run();
     }
 }
コード例 #7
0
 void BookmarkAllButtonClicked(object sender, EventArgs e)
 {
     WritebackOptions();
     using (var monitor = WorkbenchSingleton.StatusBar.CreateProgressMonitor()) {
         monitor.TaskName = StringParser.Parse("${res:AddIns.SearchReplace.SearchProgressTitle}");
         try {
             var location = new SearchLocation(SearchOptions.SearchTarget, SearchOptions.LookIn, SearchOptions.LookInFiletypes, SearchOptions.IncludeSubdirectories, SearchOptions.SearchTarget == SearchTarget.CurrentSelection ? SearchManager.GetActiveSelection(false) : null);
             var strategy = SearchStrategyFactory.Create(SearchOptions.FindPattern, !SearchOptions.MatchCase, SearchOptions.MatchWholeWord, SearchOptions.SearchMode);
             var results  = SearchManager.FindAllParallel(strategy, location, monitor);
             SearchManager.MarkAll(results);
         } catch (SearchPatternException ex) {
             MessageService.ShowError(ex.Message);
         } catch (OperationCanceledException) {}
     }
 }
コード例 #8
0
        /// <summary>
        /// Causes the background renderer to draw.
        /// </summary>
        /// <param name="textView"></param>
        /// <param name="drawingContext"></param>
        public void Draw(TextView textView, DrawingContext drawingContext)
        {
            if (String.IsNullOrWhiteSpace(editor.SelectedText) ||
                !editor.SelectedText.All(Char.IsLetterOrDigit))
            {
                return;
            }
            ISearchStrategy strategy = SearchStrategyFactory.Create(editor.SelectedText, false, true, SearchMode.Normal);

            foreach (ISearchResult result in strategy.FindAll(textView.Document, 0, textView.Document.TextLength))
            {
                BackgroundGeometryBuilder builder = new BackgroundGeometryBuilder()
                {
                    CornerRadius = 1
                };
                builder.AddSegment(textView, result);
                drawingContext.DrawGeometry(BrushStyle, PenStyle, builder.CreateGeometry());
            }
        }
コード例 #9
0
        void FindAllButtonClicked(object sender, EventArgs e)
        {
            WritebackOptions();
            var             location = new SearchLocation(SearchOptions.SearchTarget, SearchOptions.LookIn, SearchOptions.LookInFiletypes, SearchOptions.IncludeSubdirectories, SearchOptions.SearchTarget == SearchTarget.CurrentSelection ? SearchManager.GetActiveSelection(false) : null);
            ISearchStrategy strategy;

            try {
                strategy = SearchStrategyFactory.Create(SearchOptions.FindPattern, !SearchOptions.MatchCase, SearchOptions.MatchWholeWord, SearchOptions.SearchMode);
            } catch (SearchPatternException ex) {
                MessageService.ShowError(ex.Message);
                return;
            }
            // No using block for the monitor; it is disposed when the asynchronous search finishes
            var monitor = WorkbenchSingleton.StatusBar.CreateProgressMonitor();

            monitor.TaskName = StringParser.Parse("${res:AddIns.SearchReplace.SearchProgressTitle}");
            var results = SearchManager.FindAllParallel(strategy, location, monitor);

            SearchManager.ShowSearchResults(SearchOptions.FindPattern, results);
        }
        public override void FixtureSetUp()
        {
            base.FixtureSetUp();
            SD.Services.AddService(typeof(IWorkbench), MockRepository.GenerateStub <IWorkbench>());

            // Set up SearchOptions required by the BruteForceSearchStrategy.
            SearchOptions.CurrentFindPattern = "foo";
            SearchOptions.MatchCase          = false;
            SearchOptions.MatchWholeWord     = false;

            // Create the document to be searched.
            var doc = new ReadOnlyDocument("foo");

            var location = MockRepository.GenerateStub <SearchLocation>(SearchOptions.SearchTarget, SearchOptions.LookIn, SearchOptions.LookInFiletypes, SearchOptions.IncludeSubdirectories, null);

            location.Stub(l => l.GenerateFileList()).Return(new[] { new FileName(@"C:\Temp\test.txt") });

            // Search the document.
            var strategy = SearchStrategyFactory.Create(SearchOptions.FindPattern, !SearchOptions.MatchCase, SearchOptions.MatchWholeWord, SearchOptions.SearchMode);

            result = SearchManager.FindNext(strategy, location);
        }
コード例 #11
0
        void ReplaceAllButtonClicked(object sender, EventArgs e)
        {
            WritebackOptions();
            int count = -1;

            try {
                AsynchronousWaitDialog.RunInCancellableWaitDialog(
                    StringParser.Parse("${res:AddIns.SearchReplace.SearchProgressTitle}"), null,
                    monitor => {
                    var location = new SearchLocation(SearchOptions.SearchTarget, SearchOptions.LookIn, SearchOptions.LookInFiletypes, SearchOptions.IncludeSubdirectories, SearchOptions.SearchTarget == SearchTarget.CurrentSelection ? SearchManager.GetActiveSelection(true) : null);
                    var strategy = SearchStrategyFactory.Create(SearchOptions.FindPattern, !SearchOptions.MatchCase, SearchOptions.MatchWholeWord, SearchOptions.SearchMode);
                    var results  = SearchManager.FindAll(strategy, location, monitor);
                    count        = SearchManager.ReplaceAll(results, SearchOptions.ReplacePattern, monitor.CancellationToken);
                });
                if (count != -1)
                {
                    SearchManager.ShowReplaceDoneMessage(count);
                }
            } catch (SearchPatternException ex) {
                MessageService.ShowError(ex.Message);
            }
        }