internal static void CheckSearchReplacePanel(Form1 form, bool makeVisible, bool refreshConfig) { ToolStripButton showSearchPanelToolStripButton = form.showSearchPanelToolStripButton; //ToolStripMenuItem showSearchPanelToolStripMenuItem = form.showSearchPanelToolStripMenuItem; Panel searchReplacePanel = form.searchReplacePanel; TextBox searchTextBox = form.searchPanel.searchTextBox; ToolStripButton highlightsResultsToolStripButton = form.searchPanel.highlightsResultsToolStripButton; CustomRichTextBox pageTextBox = ProgramUtil.GetPageTextBox(form.pagesTabControl.SelectedTabPage); highlightsResultsToolStripButton.Checked = ConfigUtil.GetBoolParameter("SearchHighlightsResults"); searchReplacePanel.Visible = makeVisible; showSearchPanelToolStripButton.Checked = makeVisible; //showSearchPanelToolStripMenuItem.Checked = makeVisible; UpdateConfigParameter("SearchReplacePanelDisabled", (!makeVisible).ToString(), refreshConfig); switch (ConfigUtil.GetIntParameter("SearchReturn")) { case 0: form.searchPanel.searchTextBox.ReturnActionType = CustomTextBox.ReturnAction.StartSearch; form.searchPanel.replaceTextBox.ReturnActionType = CustomTextBox.ReturnAction.StartReplace; break; case 1: form.searchPanel.searchTextBox.ReturnActionType = CustomTextBox.ReturnAction.InsertCR; form.searchPanel.replaceTextBox.ReturnActionType = CustomTextBox.ReturnAction.InsertCR; break; } pageTextBox.Refresh(); if (!makeVisible) // && !form.IsOpening) { //if (refreshConfig) //{ // StringUtil.ClearHighlightsResults(form); //} pageTextBox.Focus(); return; } FileListManager.LoadSearchHistory(form); searchTextBox.Focus(); searchTextBox.SelectAll(); }
internal static void FocusOnEditor(Form1 form) { CustomRichTextBox pageTextBox = ProgramUtil.GetPageTextBox(form.pagesTabControl.SelectedTabPage); pageTextBox.Focus(); }
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 void OpenPanel(Form1 form, XtraTabPage tabPage) { CustomRichTextBox pageTextBox = ProgramUtil.GetPageTextBox(tabPage); CustomLineNumbers customLineNumbers = ProgramUtil.GetCustomLineNumbers(tabPage); bool wasHostsSectionOpen = false; if (CustomFilesManager.IsHostsSectionPanelOpen(form)) { wasHostsSectionOpen = true; CustomFilesManager.ToggleHostsSectionPanel(form, true); } String annotationText = String.Empty; if (CustomFilesManager.IsAnnotationPanelOpen(form)) { annotationText = CustomFilesManager.GetAnnotationPanelText(form); CustomFilesManager.ToggleAnnotationPanel(form, true); } int left = 0; if (ConfigUtil.GetBoolParameter("LineNumbersVisible")) { left = customLineNumbers.Width; } //Panel RichTextBox columnRulerTextBox = new RichTextBox { Anchor = AnchorStyles.Top | AnchorStyles.Right | AnchorStyles.Bottom | AnchorStyles.Left, BackColor = pageTextBox.BackColor, BorderStyle = BorderStyle.None, Font = pageTextBox.Font, //ForeColor = pageTextBox.ForeColor, ForeColor = SystemColors.AppWorkspace, Height = Convert.ToInt32(pageTextBox.Font.GetHeight() * 2 + 5), //35 Left = left, Multiline = true, Name = "columnRulerTextBox", ReadOnly = true, ScrollBars = RichTextBoxScrollBars.None, ShortcutsEnabled = false, Text = ConstantUtil.columnsHeader, Width = pageTextBox.Width + 1, WordWrap = false }; CustomPanel columnRulerPanel = new CustomPanel { Dock = DockStyle.Top, Height = columnRulerTextBox.Height + 1, Name = "columnRulerPanel", Width = tabPage.Width, HorizontalLine = true, MarginLeftHorizontalLine = tabPage.Width - columnRulerTextBox.Width - 5 }; columnRulerPanel.Controls.Add(columnRulerTextBox); tabPage.Controls.Add(columnRulerPanel); if (wasHostsSectionOpen) { CustomFilesManager.ToggleHostsSectionPanel(form, true); } if (!String.IsNullOrEmpty(annotationText)) { CustomFilesManager.ToggleAnnotationPanel(form); CustomFilesManager.SetAnnotationPanelText(form, annotationText); } pageTextBox.Focus(); }
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 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); }