internal static void ChangeSection(Form1 form, int index, bool active) { XtraTabControl pagesTabControl = form.pagesTabControl; CustomRichTextBox pageTextBox = ProgramUtil.GetPageTextBox(pagesTabControl.SelectedTabPage); CustomPanel sectionsPanel = ProgramUtil.GetSectionsPanel(pagesTabControl.SelectedTabPage); CheckedListBox sectionsCheckedListBox = (CheckedListBox)sectionsPanel.Controls["sectionsCheckedListBox"]; String content = pageTextBox.Text; String section = sectionsCheckedListBox.Items[index].ToString(); bool flag = false; StringBuilder builder = new StringBuilder(); foreach (String str in content.Split(new[] { Convert.ToChar(ConstantUtil.newLine) })) { if (builder.Length > 0) { builder.Append(ConstantUtil.newLine); //builder.AppendLine(); } if (String.IsNullOrEmpty(str)) { continue; } if (str.StartsWith("#SECTION ", StringComparison.OrdinalIgnoreCase)) { //flag = str.EndsWith(" " + section, StringComparison.OrdinalIgnoreCase); flag = (str == ("#SECTION " + section)); builder.Append(str); } else if (flag) { if (active) { builder.Append(str.StartsWith(ConstantUtil.hostsComments) ? str.Substring(ConstantUtil.hostsComments.Length) : str); } else if (!str.StartsWith(ConstantUtil.hostsComments)) { builder.Append(ConstantUtil.hostsComments).Append(str); } else { builder.Append(str); } } else { builder.Append(str); } } pageTextBox.SelectAll(); pageTextBox.SelectedText = builder.ToString(); TextManager.RefreshUndoRedoExternal(form); pageTextBox.ScrollToCaret(); }
internal static void ReplaceAll(Form1 form) { CheckBox searchAllTabsCheckBox = form.searchPanel.searchAllTabsCheckBox; CustomRichTextBox textBox = ProgramUtil.GetPageTextBox(form.pagesTabControl.SelectedTabPage); if (searchAllTabsCheckBox.Checked) { ReplaceAllInAllFiles(form); } else { ReplaceAllInOneFile(form, false); } textBox.ScrollToCaret(); }
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); }
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); }
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); }