/// <summary> /// Returns the first ISelection object from the currently active text editor /// </summary> static ISegment GetCurrentTextSelection() { ITextEditor textArea = SearchManager.GetActiveTextEditor(); if (textArea != null) { return(new TextSegment { StartOffset = textArea.SelectionStart, Length = textArea.SelectionLength }); } return(null); }
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); } }
public static void SetSearchPattern() { // Get Highlighted value and set it to FindDialog.searchPattern ITextEditor textArea = SearchManager.GetActiveTextEditor(); if (textArea != null) { string selectedText = textArea.SelectedText; if (selectedText != null && selectedText.Length > 0 && !IsMultipleLines(selectedText)) { SearchOptions.CurrentFindPattern = selectedText; } } }
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(); } }
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) {} } }
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); }
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); } }
void SetOptions() { Get <ComboBox>("find").Text = SearchOptions.FindPattern; Get <ComboBox>("find").Items.Clear(); Get <ComboBox>("find").Text = SearchOptions.FindPattern; Get <ComboBox>("find").Items.Clear(); foreach (string findPattern in SearchOptions.FindPatterns) { Get <ComboBox>("find").Items.Add(findPattern); } if (searchAndReplaceMode == SearchAndReplaceMode.Replace) { Get <ComboBox>("replace").Text = SearchOptions.ReplacePattern; Get <ComboBox>("replace").Items.Clear(); foreach (string replacePattern in SearchOptions.ReplacePatterns) { Get <ComboBox>("replace").Items.Add(replacePattern); } } Get <ComboBox>("lookIn").Text = SearchOptions.LookIn; foreach (string lookInText in typeof(SearchTarget).GetFields().SelectMany(f => f.GetCustomAttributes(false).OfType <DescriptionAttribute>()).Select(da => da.Description)) { Get <ComboBox>("lookIn").Items.Add(StringParser.Parse(lookInText)); } Get <ComboBox>("lookIn").Items.Add(SearchOptions.LookIn); Get <ComboBox>("lookIn").SelectedIndexChanged += new EventHandler(LookInSelectedIndexChanged); if (IsMultipleLineSelection(SearchManager.GetActiveTextEditor())) { SearchTarget = SearchTarget.CurrentSelection; } else { if (SearchOptions.SearchTarget == SearchTarget.CurrentSelection) { SearchOptions.SearchTarget = SearchTarget.CurrentDocument; } SearchTarget = SearchOptions.SearchTarget; } Get <ComboBox>("fileTypes").Text = SearchOptions.LookInFiletypes; Get <CheckBox>("matchCase").Checked = SearchOptions.MatchCase; Get <CheckBox>("matchWholeWord").Checked = SearchOptions.MatchWholeWord; Get <CheckBox>("includeSubFolder").Checked = SearchOptions.IncludeSubdirectories; Get <ComboBox>("use").Items.Clear(); Get <ComboBox>("use").Items.Add(StringParser.Parse("${res:Dialog.NewProject.SearchReplace.SearchStrategy.Standard}")); Get <ComboBox>("use").Items.Add(StringParser.Parse("${res:Dialog.NewProject.SearchReplace.SearchStrategy.RegexSearch}")); Get <ComboBox>("use").Items.Add(StringParser.Parse("${res:Dialog.NewProject.SearchReplace.SearchStrategy.WildcardSearch}")); switch (SearchOptions.SearchMode) { case SearchMode.RegEx: Get <ComboBox>("use").SelectedIndex = 1; break; case SearchMode.Wildcard: Get <ComboBox>("use").SelectedIndex = 2; break; default: Get <ComboBox>("use").SelectedIndex = 0; break; } }