/// <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);
        }
示例#2
0
        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;
                }
            }
        }
        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;
            }
        }