diff --git a/OneMore/Commands/Page/DuplicatePageCommand.cs b/OneMore/Commands/Page/DuplicatePageCommand.cs index 8a23b10be0..407423e5ff 100644 --- a/OneMore/Commands/Page/DuplicatePageCommand.cs +++ b/OneMore/Commands/Page/DuplicatePageCommand.cs @@ -33,6 +33,7 @@ public override async Task Execute(params object[] args) // set the page ID to the new page's ID page.Root.Attribute("ID").Value = newId; + // remove all objectID values and let OneNote generate new IDs page.Root.Descendants().Attributes("objectID").Remove(); page = new Page(page.Root); // reparse to refresh PageId @@ -40,10 +41,25 @@ public override async Task Execute(params object[] args) var section = await one.GetSection(sectionId); var editor = new SectionEditor(section); + + // restore Title if it's hidden; the Interop API doesn't let us delete Title! + if (page.Title is null) + { + page.SetTitle(page.Root.Attribute("name").Value); + } + editor.SetUniquePageTitle(page); await one.Update(page); + // FOLLOWING DOESN'T WORK; INTEROP API DOESN'T LET US HIDE (DELETE) Title + //if (hiddenTitle) + //{ + // page = await one.GetPage(page.PageId); + // page.Root.Elements(ns + "Title").Remove(); + // await one.Update(page); + //} + if (editor.MovePageAfterAnchor(page.PageId, originalId)) { one.UpdateHierarchy(section); diff --git a/OneMore/Commands/Page/ExtractContentCommand.cs b/OneMore/Commands/Page/ExtractContentCommand.cs index c0b79571a9..091bde6dd2 100644 --- a/OneMore/Commands/Page/ExtractContentCommand.cs +++ b/OneMore/Commands/Page/ExtractContentCommand.cs @@ -54,6 +54,12 @@ public override async Task Execute(params object[] args) return; } + // restore Title if it's hidden; the Interop API doesn't let us delete Title! + if (page.Title is null) + { + page.SetTitle(page.Root.Attribute("name").Value); + } + var editor = new PageEditor(page); var content = await editor.ExtractSelectedContent(); diff --git a/OneMore/Models/Page.cs b/OneMore/Models/Page.cs index e573c4cfbf..4b0a971f5c 100644 --- a/OneMore/Models/Page.cs +++ b/OneMore/Models/Page.cs @@ -1366,12 +1366,17 @@ public void SetTitle(string title) block = new XElement(ns + "Title", new Paragraph(title).SetQuickStyle(style.Index)); - var outline = Root.Elements(ns + "Outline") - .FirstOrDefault(e => !e.Elements(ns + "Meta") - .Any(m => m.Attribute("name").Value.Equals(MetaNames.TaggingBank))); - - outline ??= EnsureContentContainer(); - outline.AddBeforeSelf(block); + var anchor = Root.Elements(ns + "PageSettings").FirstOrDefault(); + if (anchor is not null) + { + anchor.AddAfterSelf(block); + } + else + { + anchor = Root.Elements(ns + "Outline").FirstOrDefault(); + anchor ??= EnsureContentContainer(); + anchor.AddBeforeSelf(block); + } } else { diff --git a/OneMore/Models/SectionEditor.cs b/OneMore/Models/SectionEditor.cs index 5144332fc8..9e18914b2f 100644 --- a/OneMore/Models/SectionEditor.cs +++ b/OneMore/Models/SectionEditor.cs @@ -177,6 +177,7 @@ public bool SetUniquePageTitle(Page page) { // shouldn't happen? page.Title = $"{page.Title} ({index})"; + page.Root.SetAttributeValue("name", page.Title); return false; } @@ -222,6 +223,7 @@ public bool SetUniquePageTitle(Page page) } page.Title = title; + page.Root.SetAttributeValue("name", title); return true; } }