コード例 #1
0
        /// <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();
            }
        }
コード例 #2
0
ファイル: frmFind.cs プロジェクト: Bloodknight/TorqueDev
        /// <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();
            }
        }