public int Find(string findText, bool matchCase, bool searchReverse) { if (this.editor == null) { return(-1); } FindReplaceResultSet replaceResultSet = this.editor.SelectedView.FindReplace.Find(new FindReplaceOptions() { ChangeSelection = true, FindText = findText, MatchCase = matchCase, SearchUp = searchReverse }); if (replaceResultSet.Count == 0) { return(-1); } return(replaceResultSet[0].StartOffset); }
public int Replace(string findText, string replaceText, bool matchCase) { if (this.editor == null) { return(-1); } FindReplaceResultSet replaceResultSet = this.editor.SelectedView.FindReplace.Replace(new FindReplaceOptions() { ChangeSelection = true, FindText = findText, MatchCase = matchCase, ReplaceText = replaceText }); if (replaceResultSet.Count == 0) { return(-1); } return(replaceResultSet[0].StartOffset); }
/// <summary> /// Occurs when the button is clicked. /// </summary> /// <param name="sender">Sender of the event.</param> /// <param name="e">Event arguments.</param> private void findButton_Click(object sender, System.EventArgs e) { // Update find/replace options //if ((this.owner as UCEditor)._ParentTab.Selected != true) // (this.owner as UCEditor)._ParentTab.Selected = true; this.UpdateFindReplaceOptions(); if (editor == null && optEntireProject.Checked == false) { MessageBox.Show("No open windows.", "Error", MessageBoxButtons.OK, MessageBoxIcon.Exclamation); return; } // Save this last search in the list if (!g.Project.Finds.Contains(findTextBox.Text)) { // Remove old stuff if (g.Project.Finds.Count == 10) { g.Project.Finds.RemoveAt(0); } g.Project.Finds.Add(findTextBox.Text); g.Main.cboRecentSearches.Text = findTextBox.Text; RehashRecent(); } // Set the status //owner.SetStatusMessage("Find: \"" + options.FindText + "\""); if (this.optCurFile.Checked || this.optSelection.Checked) { // Perform find operation on currently open file FindReplaceResultSet resultSet = null; options.SearchInSelection = this.optSelection.Checked; try { resultSet = editor.SelectedView.FindReplace.Find(options); } catch { return; } if (resultSet.PastEndOfDocument) { MessageBox.Show(this, "Search past end of file; jumping to beginning.", "Find", MessageBoxButtons.OK, MessageBoxIcon.Information); } if (resultSet.Count == 0) { MessageBox.Show(this, "Cannot find search string.", "Find", MessageBoxButtons.OK, MessageBoxIcon.Information); } } else if (this.optAllFiles.Checked) { // Perform search on all open files PrimaryTab <UCEditor> ed = g.Editors[ActiveDocument]; SyntaxEditor actdoc = ed.Control.txtEditor; ed.page.Selected = true; FindReplaceResultSet resultSet = null; try { resultSet = actdoc.SelectedView.FindReplace.Find(options); } catch { return; } if (resultSet.PastEndOfDocument || resultSet.Count == 0) { if (g.Editors.Count == (ActiveDocument + 1)) { MessageBox.Show(this, "All open files searched; jumping to beginning.", "Find", MessageBoxButtons.OK, MessageBoxIcon.Information); ActiveDocument = 0; return; } else { ActiveDocument++; } if (resultSet.Count == 0) { findButton_Click(null, null); } } } else if (this.optEntireProject.Checked) { // Perform search on all files UCFindResults fFindResults = new UCFindResults(); fFindResults.lvFind.BeginUpdate(); System.IO.Directory.SetCurrentDirectory(g.Project.ProjectPath); foreach (CProject.File file in g.Project.FileList) { Document doc = new Document(); try { doc.LoadFile(System.IO.Path.GetFullPath(file.RelativePath)); } catch { continue; } FindReplaceResultSet results = doc.FindReplace.FindAll(options); foreach (FindReplaceResult result in results) { ListViewItem item = new ListViewItem(file.RelativePath); item.SubItems.Add(Convert.ToString(doc.OffsetToPosition(result.Offset).Line + 1)); item.SubItems.Add(doc.Lines[doc.OffsetToPosition(result.Offset).Line].Text); item.Tag = file; fFindResults.lvFind.Items.Add(item); } doc.Dispose(); doc = null; } fFindResults.lvFind.EndUpdate(); g.Main.ShowFindResults(fFindResults); this.Close(); } }
public SyntaxEditorFindReplaceResultSet(FindReplaceResultSet results) { m_lstResults = new List<SyntaxEditorFindReplaceResult>(); foreach (FindReplaceResult result in results) m_lstResults.Add(new SyntaxEditorFindReplaceResult(result)); m_bPastDocumentEnd = results.PastDocumentEnd; m_bPastSearchStartOffset = results.PastSearchStartOffset; m_bReplaceOccurred = results.ReplaceOccurred; }
/// <summary> /// Occurs when the button is clicked. /// </summary> /// <param name="sender">Sender of the event.</param> /// <param name="e">Event arguments.</param> private void replaceButton_Click(object sender, System.EventArgs e) { //if ((owner as UCEditor)._ParentTab.Selected != true) // (owner as UCEditor)._ParentTab.Selected = true; // Update find/replace options this.UpdateFindReplaceOptions(); if (editor == null) { MessageBox.Show("No open windows.", "Error", MessageBoxButtons.OK, MessageBoxIcon.Exclamation); return; } if (!g.Project.Finds.Contains(findTextBox.Text)) { // Remove old stuff if (g.Project.Finds.Count == 10) { g.Project.Finds.RemoveAt(0); } g.Project.Finds.Add(findTextBox.Text); g.Main.cboRecentSearches.Text = findTextBox.Text; RehashRecent(); } if (!g.Project.Replaces.Contains(replaceTextBox.Text)) { // Remove old replaces if (g.Project.Replaces.Count == 10) { g.Project.Replaces.RemoveAt(0); } g.Project.Replaces.Add(replaceTextBox.Text); RehashRecent(); } if (this.optCurFile.Checked || this.optSelection.Checked) { // Perform find operation on currently open file FindReplaceResultSet resultSet = null; options.SearchInSelection = this.optSelection.Checked; try { resultSet = editor.SelectedView.FindReplace.Replace(options); } catch { return; } if (resultSet.PastEndOfDocument) { MessageBox.Show(this, "Search past end of file; jumping to beginning.", "Find", MessageBoxButtons.OK, MessageBoxIcon.Information); } if (resultSet.Count == 0) { MessageBox.Show(this, "Cannot find search string.", "Find", MessageBoxButtons.OK, MessageBoxIcon.Information); } } else if (this.optAllFiles.Checked) { // Perform search on all open files PrimaryTab <UCEditor> ed = g.Editors[ActiveDocument]; SyntaxEditor actdoc = ed.Control.txtEditor; ed.page.Selected = true; FindReplaceResultSet resultSet = null; try { resultSet = actdoc.SelectedView.FindReplace.Replace(options); } catch { return; } if (resultSet.PastEndOfDocument || resultSet.Count == 0) { if (g.Editors.Count == (ActiveDocument + 1)) { MessageBox.Show(this, "All open files searched; jumping to beginning.", "Find", MessageBoxButtons.OK, MessageBoxIcon.Information); ActiveDocument = 0; } else { ActiveDocument++; } if (resultSet.Count == 0) { replaceButton_Click(null, null); } } } }