diff --git a/OneMore/Commands/Snippets/TocGenerators/PageTocGenerator.cs b/OneMore/Commands/Snippets/TocGenerators/PageTocGenerator.cs index 1fc81055f2..1688689663 100644 --- a/OneMore/Commands/Snippets/TocGenerators/PageTocGenerator.cs +++ b/OneMore/Commands/Snippets/TocGenerators/PageTocGenerator.cs @@ -44,24 +44,7 @@ public override async Task Build() var headings = CollectHeadings(one, out var titleID); if (!headings.Any()) { - if (FindMetaElement() is XElement meta) - { - var result = UI.MoreMessageBox.ShowQuestion( - one.OwnerWindow, Resx.InsertTocForPage_ClearToc); - - if (result == System.Windows.Forms.DialogResult.Yes) - { - meta.Parent.Remove(); - page.EnsureContentContainer(); - await one.Update(page); - } - } - else - { - logger.WriteLine($"{nameof(PageTocGenerator)} found no headings"); - UI.MoreMessageBox.ShowError(one.OwnerWindow, Resx.InsertTocCommand_NoHeadings); - } - + await ClearToC(one); return false; } @@ -170,6 +153,28 @@ private List CollectHeadings(OneNote one, out string titleID) } + private async Task ClearToC(OneNote one) + { + if (FindMetaElement() is XElement meta) + { + var result = UI.MoreMessageBox.ShowQuestion( + one.OwnerWindow, Resx.InsertTocForPage_ClearToc); + + if (result == System.Windows.Forms.DialogResult.Yes) + { + meta.Parent.Remove(); + page.EnsureContentContainer(); + await one.Update(page); + } + } + else + { + logger.WriteLine($"{nameof(PageTocGenerator)} found no headings"); + UI.MoreMessageBox.ShowError(one.OwnerWindow, Resx.InsertTocCommand_NoHeadings); + } + } + + private XElement FindMetaElement() { return page.BodyOutlines