void InitSelectionSearch()
 {
     findFirst = true;
     selection = GetCurrentTextSelection();
     AddSelectionChangedHandler(SearchReplaceUtilities.GetActiveTextEditor());
     WorkbenchSingleton.DockContainer.ActiveDocumentChanged += WorkbenchActiveViewContentChanged;
 }
 void InitSelectionSearch()
 {
     findFirst = true;
     selection = GetCurrentTextSelection();
     AddSelectionChangedHandler(SearchReplaceUtilities.GetActiveTextEditor());
     WorkbenchSingleton.Workbench.ActiveWorkbenchWindowChanged += WorkbenchWindowChanged;
 }
        void WorkbenchActiveViewContentChanged(object source, EventArgs e)
        {
            TextEditorControl activeTextEditorControl = SearchReplaceUtilities.GetActiveTextEditor();

            if (activeTextEditorControl != this.textEditor)
            {
                AddSelectionChangedHandler(activeTextEditorControl);
                TextSelectionChanged(source, e);
            }
        }
Exemple #4
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 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);
            }
        }
Exemple #8
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;
            }
        }