private void SearchAndReplace()
        {
            DialogResult result = DialogResult.None;
            string       whatText;
            string       withText;
            bool         matchCase;

            using (var dialog = new SearchAndReplaceDialog())
            {
                result = dialog.ShowDialog(owner);

                whatText  = dialog.WhatText;
                withText  = dialog.WithText;
                matchCase = dialog.MatchCase;
            }

            if (result == DialogResult.OK)
            {
                using (var manager = new ApplicationManager())
                {
                    var page = manager.CurrentPage();
                    var ns   = page.GetNamespaceOfPrefix("one");

                    var elements = page.Elements(ns + "Outline").Descendants(ns + "T")
                                   .Select(e => e.Parent)
                                   .Distinct()
                                   .Cast <XElement>();

                    if (elements.Any())
                    {
                        // if there is a selection range...
                        var countRange = elements.Elements(ns + "T").Count(e =>
                                                                           e.Attribute("selected")?.Value == "all" &&
                                                                           e.FirstNode is XCData && (e.FirstNode as XCData).Value.Length > 0);

                        if (countRange > 0)
                        {
                            // ...then further filter out only the selected range
                            elements = elements.Elements(ns + "T")
                                       .Where(t => t.Attribute("selected")?.Value == "all")
                                       .Select(t => t.Parent);
                        }
                    }

                    if (elements.Any())
                    {
                        int count  = 0;
                        var editor = new SearchAndReplaceEditor(ns, whatText, withText, matchCase);

                        // use ToList to avoid null ref exception while updating IEnumerated collection
                        var list = elements.ToList();
                        for (var i = 0; i < list.Count(); i++)
                        {
                            count += editor.SearchAndReplace(list[i]);
                        }

                        manager.UpdatePageContent(page);

                        //var msg = count == 1 ? "occurance was" : "occurances were";
                        //MessageBox.Show($"{count} {msg} replaced", "Replaced",
                        //	MessageBoxButtons.OK, MessageBoxIcon.Information);
                    }
                }
            }
        }
        public override void Execute(params object[] args)
        {
            DialogResult result;
            string       whatText;
            string       withText;
            bool         matchCase;

            using (var dialog = new Dialogs.SearchAndReplaceDialog())
            {
                result = dialog.ShowDialog(owner);

                whatText  = dialog.WhatText;
                withText  = dialog.WithText;
                matchCase = dialog.MatchCase;
            }

            if (result == DialogResult.OK)
            {
                using (var one = new OneNote(out var page, out var ns))
                {
                    var elements = page.Root.Elements(ns + "Outline").Descendants(ns + "T")
                                   .Select(e => e.Parent)
                                   .Distinct();

                    if (elements.Any())
                    {
                        // if there is a selection range...
                        var countRange = elements.Elements(ns + "T").Count(e =>
                                                                           e.Attribute("selected")?.Value == "all" &&
                                                                           e.FirstNode is XCData && (e.FirstNode as XCData).Value.Length > 0);

                        if (countRange > 0)
                        {
                            // ...then further filter out only the selected range
                            elements = elements.Elements(ns + "T")
                                       .Where(t => t.Attribute("selected")?.Value == "all")
                                       .Select(t => t.Parent);
                        }
                    }

                    if (elements.Any())
                    {
                        int count  = 0;
                        var editor = new SearchAndReplaceEditor(ns, whatText, withText, matchCase);

                        // use ToList to avoid null ref exception while updating IEnumerated collection
                        var list = elements.ToList();
                        for (var i = 0; i < list.Count; i++)
                        {
                            count += editor.SearchAndReplace(list[i]);
                        }

                        one.Update(page);

                        //var msg = count == 1 ? "occurance was" : "occurances were";
                        //MessageBox.Show($"{count} {msg} replaced", "Replaced",
                        //	MessageBoxButtons.OK, MessageBoxIcon.Information);
                    }
                }
            }
        }