예제 #1
0
        private static bool ReplaceAllInOneFile(Form1 form, bool searchInAllFiles)
        {
            CustomRichTextBox    textBox                       = ProgramUtil.GetPageTextBox(form.pagesTabControl.SelectedTabPage);
            TextBox              searchTextBox                 = form.searchPanel.searchTextBox;
            TextBox              replaceTextBox                = form.searchPanel.replaceTextBox;
            ToolStripStatusLabel toolStripStatusLabel          = form.toolStripStatusLabel;
            CheckBox             caseCheckBox                  = form.searchPanel.caseCheckBox;
            CheckBox             useRegularExpressionsCheckBox = form.searchPanel.regularExpressionsCheckBox;

            if (String.IsNullOrEmpty(searchTextBox.Text))
            {
                return(false);
            }

            FileListManager.SetNewSearchHistory(form, searchTextBox.Text);

            String textWhereToSearch;
            String textToSearch;

            GetTextCaseNormalization(form, out textWhereToSearch, out textToSearch);

            int positionSearchedText;
            int selectionLength;

            SearchReplaceUtil.FindStringPositionAndLength(textWhereToSearch, textToSearch, SearchReplaceUtil.SearchType.First, useRegularExpressionsCheckBox.Checked, textBox, out positionSearchedText, out selectionLength);

            if (positionSearchedText != -1)
            {
                int counter = SearchReplaceUtil.SearchCountOccurency(form, false, true);
                textBox.SelectAll();

                if (caseCheckBox.Checked)
                {
                    textBox.SelectedText = Replace(useRegularExpressionsCheckBox.Checked, textBox.Text, GetTextNewLineNormalization(searchTextBox.Text), GetTextNewLineNormalization(replaceTextBox.Text), StringComparison.Ordinal);
                }
                else
                {
                    textBox.SelectedText = Replace(useRegularExpressionsCheckBox.Checked, textBox.Text, GetTextNewLineNormalization(searchTextBox.Text), GetTextNewLineNormalization(replaceTextBox.Text), StringComparison.OrdinalIgnoreCase);
                }

                TextManager.RefreshUndoRedoExternal(form);
                textBox.Select(0, 0);

                toolStripStatusLabel.Text = String.Format("{0} {1}", counter, LanguageUtil.GetCurrentLanguageString("Replaced", className, counter));

                return(true);
            }
            if (!searchInAllFiles)
            {
                String notFoundMessage = LanguageUtil.GetCurrentLanguageString("NotFound", className);
                WindowManager.ShowInfoBox(form, notFoundMessage);
                toolStripStatusLabel.Text = notFoundMessage;
            }

            return(false);
        }
예제 #2
0
        private static bool SearchPrevious(Form1 form, bool loopAtEOF, bool searchInAllFiles)
        {
            XtraTabControl       pagesTabControl = form.pagesTabControl;
            TextBox              searchTextBox   = form.searchPanel.searchTextBox;
            CheckBox             caseCheckBox    = form.searchPanel.caseCheckBox;
            CheckBox             useRegularExpressionsCheckBox = form.searchPanel.regularExpressionsCheckBox;
            ToolStripStatusLabel toolStripStatusLabel          = form.toolStripStatusLabel;
            CustomRichTextBox    pageTextBox = ProgramUtil.GetPageTextBox(pagesTabControl.SelectedTabPage);

            bool valueFounded = false;

            if (String.IsNullOrEmpty(searchTextBox.Text))
            {
                return(false);
            }

            String textWhereToSearch = pageTextBox.Text;
            String textToSearch      = searchTextBox.Text.Replace(ConstantUtil.newLineNotCompatible, ConstantUtil.newLine);

            FileListManager.SetNewSearchHistory(form, textToSearch);

            if (!caseCheckBox.Checked)
            {
                textWhereToSearch = textWhereToSearch.ToLower();
                textToSearch      = textToSearch.ToLower();
            }

            //int selectionLength = -1;
            //int positionSearchedText = -1;
            //if (useRegularExpressionsCheckBox.Checked == false)
            //{
            //    selectionLength = textToSearch.Length;
            //    positionSearchedText = subString.LastIndexOf(textToSearch);
            //}
            //else
            //{
            //    Match regexMatch = Regex.Match(subString, textToSearch, RegexOptions.RightToLeft);
            //    if (regexMatch.Success)
            //    {
            //        positionSearchedText = regexMatch.Index;
            //        selectionLength = regexMatch.Value.Length;
            //    }
            //}
            String subString = textWhereToSearch.Substring(0, pageTextBox.SelectionStart);

            int positionSearchedText;
            int selectionLength;

            SearchReplaceUtil.FindStringPositionAndLength(subString, textToSearch, SearchReplaceUtil.SearchType.Previous, useRegularExpressionsCheckBox.Checked, pageTextBox, out positionSearchedText, out selectionLength);

            if (positionSearchedText != -1)
            {
                int occurences = SearchReplaceUtil.SearchCountOccurency(form, searchInAllFiles);
                toolStripStatusLabel.Text = String.Format("{0} {1}", occurences, LanguageUtil.GetCurrentLanguageString("Occurences", className, occurences));

                pageTextBox.Focus();
                pageTextBox.Select(positionSearchedText, selectionLength);
                pageTextBox.ScrollToCaret();
                valueFounded = true;
            }
            else if (!searchInAllFiles)
            {
                if (SearchReplaceUtil.GetNoMatchesInFile(textWhereToSearch, textToSearch, useRegularExpressionsCheckBox.Checked))
                {
                    String notFoundMessage = LanguageUtil.GetCurrentLanguageString("NotFound", className);
                    WindowManager.ShowInfoBox(form, notFoundMessage);
                    toolStripStatusLabel.Text = notFoundMessage;
                }
                else
                {
                    if (loopAtEOF)
                    {
                        return(SearchLast(form, false));
                    }

                    if (WindowManager.ShowQuestionBox(form, LanguageUtil.GetCurrentLanguageString("SOF", className)) == DialogResult.Yes)
                    {
                        return(SearchLast(form, false));
                    }
                }
            }

            return(valueFounded);
        }
예제 #3
0
        private static bool ReplacePrevious(Form1 form, bool loopAtEOF, bool searchInAllFiles)
        {
            XtraTabControl       pagesTabControl               = form.pagesTabControl;
            TextBox              searchTextBox                 = form.searchPanel.searchTextBox;
            CheckBox             caseCheckBox                  = form.searchPanel.caseCheckBox;
            ToolStripStatusLabel toolStripStatusLabel          = form.toolStripStatusLabel;
            TextBox              replaceTextBox                = form.searchPanel.replaceTextBox;
            CustomRichTextBox    pageTextBox                   = ProgramUtil.GetPageTextBox(pagesTabControl.SelectedTabPage);
            CheckBox             useRegularExpressionsCheckBox = form.searchPanel.regularExpressionsCheckBox;

            bool valueFounded = false;

            if (String.IsNullOrEmpty(searchTextBox.Text))
            {
                return(false);
            }

            String textWhereToSearch = pageTextBox.Text;
            String textToSearch      = searchTextBox.Text.Replace(ConstantUtil.newLineNotCompatible, ConstantUtil.newLine);

            FileListManager.SetNewSearchHistory(form, textToSearch);

            if (!caseCheckBox.Checked)
            {
                textWhereToSearch = textWhereToSearch.ToLower();
                textToSearch      = textToSearch.ToLower();
            }

            String subString = textWhereToSearch.Substring(0, pageTextBox.SelectionStart);

            int positionSearchedText;
            int selectionLength;

            SearchReplaceUtil.FindStringPositionAndLength(subString, textToSearch, SearchReplaceUtil.SearchType.Previous, useRegularExpressionsCheckBox.Checked, pageTextBox, out positionSearchedText, out selectionLength);

            if (positionSearchedText != -1)
            {
                toolStripStatusLabel.Text = String.Format("1 {0}", LanguageUtil.GetCurrentLanguageString("Replaced", className, 1));
                pageTextBox.Focus();
                pageTextBox.Select(positionSearchedText, selectionLength);
                pageTextBox.SelectedText = replaceTextBox.Text.Replace(ConstantUtil.newLineNotCompatible, ConstantUtil.newLine);
                TextManager.RefreshUndoRedoExternal(form);

                pageTextBox.ScrollToCaret();
                valueFounded = true;
            }
            else if (!searchInAllFiles)
            {
                if (SearchReplaceUtil.GetNoMatchesInFile(textWhereToSearch, textToSearch, useRegularExpressionsCheckBox.Checked))
                {
                    String notFoundMessage = LanguageUtil.GetCurrentLanguageString("NotFound", className);
                    WindowManager.ShowInfoBox(form, notFoundMessage);
                    toolStripStatusLabel.Text = notFoundMessage;
                }
                else
                {
                    if (loopAtEOF)
                    {
                        pageTextBox.SelectionStart = pageTextBox.Text.Length - 1;
                        return(ReplacePrevious(form, false, false));
                    }

                    if (WindowManager.ShowQuestionBox(form, LanguageUtil.GetCurrentLanguageString("SOF", className)) == DialogResult.Yes)
                    {
                        pageTextBox.SelectionStart = pageTextBox.Text.Length - 1;
                        return(ReplacePrevious(form, false, false));
                    }
                }
            }

            return(valueFounded);
        }
예제 #4
0
        private static bool SearchFirst(Form1 form, bool searchInAllFiles, String specificTextToSearch = null)
        {
            XtraTabControl       pagesTabControl = form.pagesTabControl;
            TextBox              searchTextBox   = form.searchPanel.searchTextBox;
            CheckBox             caseCheckBox    = form.searchPanel.caseCheckBox;
            CheckBox             useRegularExpressionsCheckBox = form.searchPanel.regularExpressionsCheckBox;
            ToolStripStatusLabel toolStripStatusLabel          = form.toolStripStatusLabel;
            CustomRichTextBox    pageTextBox = ProgramUtil.GetPageTextBox(pagesTabControl.SelectedTabPage);

            bool valueFounded = false;

            if (String.IsNullOrEmpty(searchTextBox.Text) && String.IsNullOrEmpty(specificTextToSearch))
            {
                return(false);
            }

            String textWhereToSearch = pageTextBox.Text;
            String textToSearch      = !String.IsNullOrEmpty(specificTextToSearch) ? specificTextToSearch : searchTextBox.Text.Replace(ConstantUtil.newLineNotCompatible, ConstantUtil.newLine);

            FileListManager.SetNewSearchHistory(form, textToSearch);

            if (!caseCheckBox.Checked)
            {
                textWhereToSearch = textWhereToSearch.ToLower();
                textToSearch      = textToSearch.ToLower();
            }

            //int positionSearchedText = -1;
            //int selectionLength = -1;
            //if (useRegularExpressionsCheckBox.Checked == false)
            //{
            //    positionSearchedText = textWhereToSearch.IndexOf(textToSearch);
            //    selectionLength = textToSearch.Length;
            //}
            //else
            //{
            //    Regex regex = new Regex(textToSearch);
            //    Match regexMatch = regex.Match(textWhereToSearch, 0);
            //    if (regexMatch.Success)
            //    {
            //        positionSearchedText = regexMatch.Index;
            //        selectionLength = regexMatch.Value.Length;
            //    }
            //}
            int positionSearchedText;
            int selectionLength;

            SearchReplaceUtil.FindStringPositionAndLength(textWhereToSearch, textToSearch, SearchReplaceUtil.SearchType.First, useRegularExpressionsCheckBox.Checked, pageTextBox, out positionSearchedText, out selectionLength);

            if (positionSearchedText != -1)
            {
                int occurences = SearchReplaceUtil.SearchCountOccurency(form, searchInAllFiles, false, specificTextToSearch);
                toolStripStatusLabel.Text = String.Format("{0} {1}", occurences, LanguageUtil.GetCurrentLanguageString("Occurences", className, occurences));

                pageTextBox.Focus();
                pageTextBox.Select(positionSearchedText, selectionLength);
                pageTextBox.ScrollToCaret();
                valueFounded = true;
            }
            else if (!searchInAllFiles)
            {
                String notFoundMessage = LanguageUtil.GetCurrentLanguageString("NotFound", className);
                WindowManager.ShowInfoBox(form, notFoundMessage);
                toolStripStatusLabel.Text = notFoundMessage;
            }

            return(valueFounded);
        }