-
-
Notifications
You must be signed in to change notification settings - Fork 223
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
1465 extract selected content command (#1475)
- Loading branch information
1 parent
b36c42b
commit 27463fc
Showing
20 changed files
with
558 additions
and
99 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,100 @@ | ||
//************************************************************************************************ | ||
// Copyright © 2024 Steven M Cohn. All rights reserved. | ||
//************************************************************************************************ | ||
|
||
namespace River.OneMoreAddIn.Commands | ||
{ | ||
using River.OneMoreAddIn.Models; | ||
using System.Threading.Tasks; | ||
|
||
|
||
#region Wrappers | ||
internal class CopyPageContentCommand : ExtractContentCommand | ||
{ | ||
public CopyPageContentCommand() : base() { } | ||
public override Task Execute(params object[] args) | ||
{ | ||
return base.Execute(false); | ||
} | ||
} | ||
internal class MovePageContentCommand : ExtractContentCommand | ||
{ | ||
public MovePageContentCommand() : base() { } | ||
public override Task Execute(params object[] args) | ||
{ | ||
return base.Execute(true); | ||
} | ||
} | ||
#endregion Wrappers | ||
|
||
/// <summary> | ||
/// Copy or move selected content from the current page into a new page, providing a | ||
/// quick and easy way to arbitrarily split up a page into mutliple subpages or extract | ||
/// portions of a page into new subpages. | ||
/// </summary> | ||
internal class ExtractContentCommand : Command | ||
{ | ||
public ExtractContentCommand() | ||
{ | ||
} | ||
|
||
|
||
public override async Task Execute(params object[] args) | ||
{ | ||
bool move = (bool)args[0]; | ||
|
||
await using var one = new OneNote(out var page, out _, OneNote.PageDetail.All); | ||
|
||
var editor = new PageEditor(page); | ||
var content = await editor.ExtractSelectedContent(); | ||
if (!content.HasElements) | ||
{ | ||
return; | ||
} | ||
|
||
var sectionEditor = new SectionEditor(await one.GetSection()); | ||
|
||
// current page is the initial anchor | ||
var anchorID = sectionEditor.FindLastIndexedPageIDByTitle(page.Title); | ||
|
||
// make target page... | ||
|
||
// create a page in this section to capture heading content | ||
one.CreatePage(one.CurrentSectionId, out var targetID); | ||
var target = await one.GetPage(targetID); | ||
target.Title = page.Title; // temp | ||
|
||
// refresh the editor | ||
sectionEditor = new SectionEditor(await one.GetSection()); | ||
sectionEditor.SetUniquePageTitle(target); | ||
|
||
var container = target.EnsureContentContainer(); | ||
container.Add(content.Elements()); | ||
|
||
var map = target.MergeQuickStyles(page); | ||
target.ApplyStyleMapping(map, container); | ||
|
||
await one.Update(target); | ||
|
||
// place the page in index-order after the source page... | ||
|
||
if (anchorID is not null) | ||
{ | ||
// refresh the editor | ||
sectionEditor = new SectionEditor(await one.GetSection()); | ||
if (sectionEditor.MovePageAfterAnchor(target.PageId, anchorID)) | ||
{ | ||
one.UpdateHierarchy(sectionEditor.Section); | ||
} | ||
} | ||
|
||
if (move) | ||
{ | ||
// update the source page, removing the moved content | ||
await one.Update(page); | ||
} | ||
|
||
//await one.NavigateTo(page.PageId); | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.