Skip to content

Commit

Permalink
v5.4.2 Fixes
Browse files Browse the repository at this point in the history
  • Loading branch information
stevencohn committed Dec 10, 2022
1 parent 5921bd0 commit 84973c8
Show file tree
Hide file tree
Showing 7 changed files with 90 additions and 0 deletions.
89 changes: 89 additions & 0 deletions OneMore/Models/PageReader.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,89 @@
//************************************************************************************************
// Copyright © 2022 Steven M Cohn. All rights reserved.
//************************************************************************************************

namespace River.OneMoreAddIn.Models
{
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Xml.Linq;

internal class PageReader
{
#region Types

private sealed class DeepNode
{
public XElement Element;
public int Depth;
}

#endregion Types

private Page page;
private XNamespace ns;


/// <summary>
/// Initialize a new editor for the given page
/// </summary>
/// <param name="page"></param>
public PageReader(Page page)
{
this.page = page;
ns = page.Namespace;
}


/// <summary>
/// Removes the selected content on the current page, wraps it inside a new OEChildren
/// container, and returns the container.
/// </summary>
/// <returns>A new OEChildren element containing the extracted content</returns>
/// <remarks>
/// Normalizes the content to include selected items in a partially selected bullet or
/// number list and excludes the unselected items. Similarlly, this applies to indented
/// paragraphs where not all sibilings or even child thereof are selected.
/// </remarks>
public XElement ExtractSelectedContent()
{
var content = new XElement(ns + "OEChildren");

var selections = page.Root.Elements(ns+ "Outline")
.Descendants(ns+ "T")
.Where(e => e.Attributes().Any(a => a.Name == "selected" && a.Value == "all"))
.Select(e => new DeepNode
{
Element = e,
Depth = e.Ancestors().Count()
})
.ToList();

if (!selections.Any())
{
// no T runs selected but check for selected images
selections = page.Root.Elements(ns + "Outline")
.Descendants(ns + "Image")
.Where(e => e.Attributes().Any(a => a.Name == "selected" && a.Value == "all"))
.Select(e => new DeepNode
{
Element = e,
Depth = e.Ancestors().Count()
})
.ToList();
}

if (!selections.Any())
{
return content;
}

var minDepth = selections.Min(e => e.Depth);

return content;
}
}
}
1 change: 1 addition & 0 deletions OneMore/OneMore.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -156,6 +156,7 @@
<Compile Include="Commands\Tables\TableThemePainter.cs" />
<Compile Include="Helpers\Extensions\GraphicsExtensions.cs" />
<Compile Include="Models\KnownSchemaAttributes.cs" />
<Compile Include="Models\PageReader.cs" />
<Compile Include="Ribbon\AddInRibbonEnablers.cs" />
<Compile Include="AddInHotkeys.cs" />
<Compile Include="Ribbon\AddInRibbon.cs" />
Expand Down
Binary file modified OneMore/Properties/AssemblyInfo.cs
Binary file not shown.
Binary file modified OneMoreCalendar/Properties/AssemblyInfo.cs
Binary file not shown.
Binary file modified OneMoreProtocolHandler/Properties/AssemblyInfo.cs
Binary file not shown.
Binary file modified OneMoreSetup/OneMoreSetup.vdproj
Binary file not shown.
Binary file modified OneMoreSetupActions/Properties/AssemblyInfo.cs
Binary file not shown.

0 comments on commit 84973c8

Please sign in to comment.