1param([Parameter(Mandatory=$true)][string]$Root, [Parameter(Mandatory=$true)][string]$CloneHost)
2Set-StrictMode -Version Latest
3$ErrorActionPreference = 'Stop'
4& "$PSScriptRoot\cold-current.ps1" -Root $Root -CloneHost $CloneHost
5$app = New-Object -ComObject OneNote.Application
6$notebook = ''
7try {
8 $app.OpenHierarchy((Join-Path $Root 'notebook'), '', [ref]$notebook, 0)
9 $section = ''
10 $app.OpenHierarchy('synthetic.one', $notebook, [ref]$section, 0)
11 $cases = @(
12 @{ name='Move leaf down'; keys='{Left}^+{-}!+{Down}'; leaf=$true },
13 @{ name='Move subtree down'; keys='{Left}^+{-}!+{Down}' },
14 @{ name='Move subtree up'; keys='{Left}^+{-}!+{Up}' },
15 @{ name='Indent subtree'; keys='{Left}^+{-}!+{Right}' },
16 @{ name='Outdent subtree'; keys='{Left}^+{-}!+{Left}'; nested=$true },
17 @{ name='Collapse subtree'; collapse=$true },
18 @{ name='Expand subtree'; collapse=$false; collapsed=$true },
19 @{ name='Delete leaf'; keys='{Left}^+{-}{Delete}'; leaf=$true },
20 @{ name='Delete subtree'; keys='{Left}^+{-}{Delete}' },
21 @{ name='Delete only paragraph'; keys='{Left}^+{-}{Delete}'; only=$true; leaf=$true },
22 @{ name='Delete outline'; delete='outline' },
23 @{ name='Move outline'; position=@{ x=180; y=216 } },
24 @{ name='Resize outline'; size=@{ width=144; height=180; isSetByUser=$true } },
25 @{ name='Automatic outline size'; size=@{ width=360; height=180; isSetByUser=$false }; fixed=$true }
26 )
27 $inputs = Join-Path $Root 'inputs'
28 [void](New-Item -ItemType Directory -Path $inputs)
29 foreach ($case in $cases) {
30 $page = ''
31 $app.CreateNewPage($section, [ref]$page, 0)
32 $label = 'Target ' + [char]::ConvertFromUtf32(0x1F980) + ' e' + [char]0x0301
33 $target = '<one:OE' + $(if ($case.ContainsKey('collapsed')) { ' collapsed="true"' } else { '' }) + '><one:Tag index="0" completed="true" disabled="false" creationDate="2020-01-02T03:04:05.000Z" completionDate="2020-01-02T04:05:06.000Z"/><one:T><![CDATA[<b>' + $label + '</b> <a href="https://example.invalid/outline">Link label</a>]]></one:T>'
34 if (-not $case.ContainsKey('leaf')) {
35 $target += '<one:OEChildren><one:OE><one:T><![CDATA[<i>Child</i>]]></one:T><one:OEChildren><one:OE><one:T>Grandchild</one:T></one:OE></one:OEChildren></one:OE></one:OEChildren>'
36 }
37 $target += '</one:OE>'
38 $body = if ($case.ContainsKey('only')) { $target } elseif ($case.ContainsKey('nested')) {
39 '<one:OE><one:T>Anchor</one:T><one:OEChildren>' + $target + '</one:OEChildren></one:OE><one:OE><one:T>Trailing sibling</one:T></one:OE>'
40 } else { '<one:OE><one:T>Anchor</one:T></one:OE>' + $target + '<one:OE><one:T>Trailing sibling</one:T></one:OE>' }
41 $size = if ($case.ContainsKey('fixed')) { '<one:Size width="180" height="144" isSetByUser="true"/>' } else { '' }
42 $xml = '<one:Page xmlns:one="http://schemas.microsoft.com/office/onenote/2010/onenote" ID="' + $page + '"><one:TagDef index="0" type="0" symbol="3" fontColor="automatic" highlightColor="none" name="Preserved task"/><one:Title><one:OE><one:T>' + $case.name + '</one:T></one:OE></one:Title><one:Outline><one:Position x="72" y="108"/>' + $size + '<one:OEChildren>' + $body + '</one:OEChildren></one:Outline><one:Outline><one:Position x="480" y="108"/><one:OEChildren><one:OE><one:T>Other outline</one:T></one:OE></one:OEChildren></one:Outline></one:Page>'
43 [IO.File]::WriteAllText((Join-Path $inputs ($case.name + '.xml')), $xml, [Text.Encoding]::UTF8)
44 $app.UpdatePageContent($xml, [DateTime]::MinValue, 1, $false)
45 }
46 $cases | ConvertTo-Json -Depth 6 | Set-Content (Join-Path $Root 'cases.json') -Encoding UTF8
47 $app.SyncHierarchy($notebook)
48} finally {
49 if ($notebook) { $app.CloseNotebook($notebook, $false) }
50 [void][Runtime.InteropServices.Marshal]::FinalReleaseComObject($app)
51 $app = $null
52 [GC]::Collect()
53 [GC]::WaitForPendingFinalizers()
54}