Skip to content

Commit

Permalink
clean
Browse files Browse the repository at this point in the history
  • Loading branch information
stevencohn committed Dec 22, 2024
1 parent b6fbd6c commit b9f4226
Showing 1 changed file with 23 additions and 18 deletions.
41 changes: 23 additions & 18 deletions OneMore/Commands/Snippets/TocGenerators/PageTocGenerator.cs
Original file line number Diff line number Diff line change
Expand Up @@ -44,24 +44,7 @@ public override async Task<bool> 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;
}

Expand Down Expand Up @@ -170,6 +153,28 @@ private List<Heading> 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
Expand Down

0 comments on commit b9f4226

Please sign in to comment.