void ReplaceInSelection()
        {
            int startOffset = Math.Min(selection.Offset, selection.EndOffset);
            int endOffset   = Math.Max(selection.Offset, selection.EndOffset);

            if (findFirst)
            {
                SetCaretPosition(textEditor.ActiveTextAreaControl.TextArea, startOffset);
            }

            try {
                ignoreSelectionChanges = true;
                if (findFirst)
                {
                    findFirst = false;
                    SearchReplaceManager.ReplaceFirstInSelection(startOffset, endOffset - startOffset, null);
                }
                else
                {
                    findFirst = !SearchReplaceManager.ReplaceNextInSelection(null);
                    if (findFirst)
                    {
                        SearchReplaceUtilities.SelectText(textEditor, startOffset, endOffset);
                    }
                }
            } finally {
                ignoreSelectionChanges = false;
            }
        }
Beispiel #2
0
 int InternalFindNext(ITextIterator textIterator, int offset, int length)
 {
     while (textIterator.MoveAhead(1))
     {
         if (textIterator.Position >= offset + length)
         {
             textIterator.Position = offset;
         }
         int position = textIterator.Position;
         if (Match(textIterator.Document, position, !SearchOptions.MatchCase, 0))
         {
             if (!SearchOptions.MatchWholeWord || SearchReplaceUtilities.IsWholeWordAt(textIterator.Document, position, curMatchEndOffset - position))
             {
                 if (TextSelection.IsInsideRange(curMatchEndOffset - 1, offset, length))
                 {
                     textIterator.MoveAhead(curMatchEndOffset - position - 1);
                     return(position);
                 }
                 else
                 {
                     return(-1);
                 }
             }
         }
     }
     return(-1);
 }
        /// <summary>
        /// action: 0 = find, 1 = mark, 2 = replace
        /// </summary>
        void RunAllInSelection(int action)
        {
            const IProgressMonitor monitor = null;

            int startOffset = Math.Min(selection.Offset, selection.EndOffset);
            int endOffset   = Math.Max(selection.Offset, selection.EndOffset);

            SearchReplaceUtilities.SelectText(textEditor, startOffset, endOffset);
            SetCaretPosition(textEditor.ActiveTextAreaControl.TextArea, startOffset);

            try {
                ignoreSelectionChanges = true;
                if (action == 0)
                {
                    SearchInFilesManager.FindAll(startOffset, endOffset - startOffset, monitor);
                }
                else if (action == 1)
                {
                    SearchReplaceManager.MarkAll(startOffset, endOffset - startOffset, monitor);
                }
                else if (action == 2)
                {
                    SearchReplaceManager.ReplaceAll(startOffset, endOffset - startOffset, monitor);
                }
                SearchReplaceUtilities.SelectText(textEditor, startOffset, endOffset);
            } finally {
                ignoreSelectionChanges = false;
            }
        }
 void InitSelectionSearch()
 {
     findFirst = true;
     selection = GetCurrentTextSelection();
     AddSelectionChangedHandler(SearchReplaceUtilities.GetActiveTextEditor());
     WorkbenchSingleton.Workbench.ActiveWorkbenchWindowChanged += WorkbenchWindowChanged;
 }
 void InitSelectionSearch()
 {
     findFirst = true;
     selection = GetCurrentTextSelection();
     AddSelectionChangedHandler(SearchReplaceUtilities.GetActiveTextEditor());
     WorkbenchSingleton.DockContainer.ActiveDocumentChanged += WorkbenchActiveViewContentChanged;
 }
        void WorkbenchActiveViewContentChanged(object source, EventArgs e)
        {
            TextEditorControl activeTextEditorControl = SearchReplaceUtilities.GetActiveTextEditor();

            if (activeTextEditorControl != this.textEditor)
            {
                AddSelectionChangedHandler(activeTextEditorControl);
                TextSelectionChanged(source, e);
            }
        }
Beispiel #7
0
        /// <summary>
        /// Returns the first ISelection object from the currently active text editor
        /// </summary>
        static StoredSelection GetCurrentTextSelection()
        {
            ITextEditor textArea = SearchReplaceUtilities.GetActiveTextEditor();

            if (textArea != null)
            {
                return(new StoredSelection(textArea.SelectionStart, textArea.SelectionLength));
            }
            return(null);
        }
        /// <summary>
        /// Returns the first ISelection object from the currently active text editor
        /// </summary>
        static ISelection GetCurrentTextSelection()
        {
            TextEditorControl textArea = SearchReplaceUtilities.GetActiveTextEditor();

            if (textArea != null)
            {
                SelectionManager selectionManager = textArea.ActiveTextAreaControl.SelectionManager;
                if (selectionManager.HasSomethingSelected)
                {
                    return(selectionManager.SelectionCollection[0]);
                }
            }
            return(null);
        }
        public static void SetSearchPattern()
        {
            // Get Highlighted value and set it to FindDialog.searchPattern
            ITextEditor textArea = SearchReplaceUtilities.GetActiveTextEditor();

            if (textArea != null)
            {
                string selectedText = textArea.SelectedText;
                if (selectedText != null && selectedText.Length > 0 && !IsMultipleLines(selectedText))
                {
                    SearchOptions.CurrentFindPattern = selectedText;
                }
            }
        }
        public static void FindNext(IProgressMonitor monitor)
        {
            SetSearchOptions(monitor);
            if (find == null ||
                SearchOptions.FindPattern == null ||
                SearchOptions.FindPattern.Length == 0)
            {
                return;
            }

            if (!find.SearchStrategy.CompilePattern(monitor))
            {
                find.Reset();
                lastResult = null;
                return;
            }

            TextEditorControl textArea = null;

            while (textArea == null)
            {
                SearchResultMatch result = find.FindNext(monitor);
                if (result == null)
                {
                    ShowNotFoundMessage(monitor);
                    find.Reset();
                    lastResult = null;
                    return;
                }
                else
                {
                    textArea = OpenTextArea(result.FileName);
                    if (textArea != null)
                    {
                        if (lastResult != null && lastResult.FileName == result.FileName &&
                            textArea.ActiveTextAreaControl.Caret.Offset != lastResult.Offset + lastResult.Length)
                        {
                            find.Reset();
                        }
                        int startPos = Math.Min(textArea.Document.TextLength, Math.Max(0, result.Offset));
                        int endPos   = Math.Min(textArea.Document.TextLength, startPos + result.Length);

                        SearchReplaceUtilities.SelectText(textArea, startPos, endPos);
                        lastResult = result;
                    }
                }
            }
        }
 int InternalFindNext(ITextIterator textIterator)
 {
     while (textIterator.MoveAhead(1))
     {
         int position = textIterator.Position;
         if (Match(textIterator.TextBuffer, position, !SearchOptions.MatchCase, 0))
         {
             if (!SearchOptions.MatchWholeWord || SearchReplaceUtilities.IsWholeWordAt(textIterator.TextBuffer, position, curMatchEndOffset - position))
             {
                 textIterator.MoveAhead(curMatchEndOffset - position - 1);
                 return(position);
             }
         }
     }
     return(-1);
 }
Beispiel #12
0
        public void Reset()
        {
            files.Clear();
            if (ProjectService.CurrentProject != null)
            {
                foreach (ProjectItem item in ProjectService.CurrentProject.Items)
                {
                    if (item is FileProjectItem && SearchReplaceUtilities.IsSearchable(item.FileName))
                    {
                        files.Add(item.FileName);
                    }
                }
            }

            curIndex = -1;
        }
        public void Reset()
        {
            files.Clear();
            if (ProjectService.OpenSolution != null)
            {
                foreach (IProject project in ProjectService.OpenSolution.Projects)
                {
                    foreach (ProjectItem item in project.Items)
                    {
                        if (item is FileProjectItem && SearchReplaceUtilities.IsSearchable(item.FileName))
                        {
                            files.Add(item.FileName);
                        }
                    }
                }
            }

            curIndex = -1;
        }
        public override void Run()
        {
            ITextEditor textArea = SearchReplaceUtilities.GetActiveTextEditor();

            if (textArea == null)
            {
                return;
            }

            // Determine what text we should search for.
            string textToFind;

            string selectedText = textArea.SelectedText;

            if (selectedText.Length > 0)
            {
                if (Find.IsMultipleLines(selectedText))
                {
                    // Locate the nearest word at the selection start.
                    textToFind = textArea.Document.GetWordAt(textArea.SelectionStart);
                }
                else
                {
                    // Search for selected text.
                    textToFind = selectedText;
                }
            }
            else
            {
                textToFind = textArea.Document.GetWordAt(textArea.Caret.Offset);
            }

            if (textToFind != null && textToFind.Length > 0)
            {
                SearchOptions.CurrentFindPattern = textToFind;
                if (SearchOptions.DocumentIteratorType == DocumentIteratorType.CurrentSelection)
                {
                    SearchOptions.DocumentIteratorType = DocumentIteratorType.CurrentDocument;
                }
                SearchReplaceManager.FindNext(null);
            }
        }
        public static bool FindNextInSelection(IProgressMonitor monitor)
        {
            TextEditorControl textArea = null;

            while (textArea == null)
            {
                SearchResultMatch result = find.FindNext(textSelection.Offset, textSelection.Length);
                if (result == null)
                {
                    if (!foundAtLeastOneItem)
                    {
                        ShowNotFoundMessage(monitor);
                    }
                    find.Reset();
                    lastResult          = null;
                    foundAtLeastOneItem = false;
                    return(false);
                }
                else
                {
                    textArea = OpenTextArea(result.FileName);
                    if (textArea != null)
                    {
                        foundAtLeastOneItem = true;
                        if (lastResult != null && lastResult.FileName == result.FileName &&
                            textArea.ActiveTextAreaControl.Caret.Offset != lastResult.Offset + lastResult.Length)
                        {
                        }
                        int startPos = Math.Min(textArea.Document.TextLength, Math.Max(0, result.Offset));
                        int endPos   = Math.Min(textArea.Document.TextLength, startPos + result.Length);
                        SearchReplaceUtilities.SelectText(textArea, startPos, endPos);
                        lastResult = result;
                    }
                }
            }
            return(true);
        }
 static void SetSearchOptions(IProgressMonitor monitor)
 {
     find.SearchStrategy   = SearchReplaceUtilities.CreateSearchStrategy(SearchOptions.SearchStrategyType);
     find.DocumentIterator = SearchReplaceUtilities.CreateDocumentIterator(SearchOptions.DocumentIteratorType, monitor);
 }
Beispiel #17
0
        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;
            string[] lookInTexts =
            {
                // must be in the same order as the DocumentIteratorType enum
                "${res:Dialog.NewProject.SearchReplace.LookIn.CurrentDocument}",
                "${res:Dialog.NewProject.SearchReplace.LookIn.CurrentSelection}",
                "${res:Dialog.NewProject.SearchReplace.LookIn.AllOpenDocuments}",
                "${res:Dialog.NewProject.SearchReplace.LookIn.WholeProject}",
                "${res:Dialog.NewProject.SearchReplace.LookIn.WholeSolution}"
            };
            foreach (string lookInText in lookInTexts)
            {
                Get <ComboBox>("lookIn").Items.Add(StringParser.Parse(lookInText));
            }
            Get <ComboBox>("lookIn").Items.Add(SearchOptions.LookIn);
            Get <ComboBox>("lookIn").SelectedIndexChanged += new EventHandler(LookInSelectedIndexChanged);

            if (IsMultipleLineSelection(SearchReplaceUtilities.GetActiveTextEditor()))
            {
                DocumentIteratorType = DocumentIteratorType.CurrentSelection;
            }
            else
            {
                if (SearchOptions.DocumentIteratorType == DocumentIteratorType.CurrentSelection)
                {
                    SearchOptions.DocumentIteratorType = DocumentIteratorType.CurrentDocument;
                }
                DocumentIteratorType = SearchOptions.DocumentIteratorType;
            }

            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.SearchStrategyType)
            {
            case SearchStrategyType.RegEx:
                Get <ComboBox>("use").SelectedIndex = 1;
                break;

            case SearchStrategyType.Wildcard:
                Get <ComboBox>("use").SelectedIndex = 2;
                break;

            default:
                Get <ComboBox>("use").SelectedIndex = 0;
                break;
            }
        }