Skip to content

Commit

Permalink
Bgcolor (stevencohn#257)
Browse files Browse the repository at this point in the history
  • Loading branch information
stevencohn authored Aug 25, 2021
1 parent b348e96 commit ea8e528
Show file tree
Hide file tree
Showing 63 changed files with 2,267 additions and 1,210 deletions.
11 changes: 7 additions & 4 deletions OneMore.sln
Original file line number Diff line number Diff line change
Expand Up @@ -20,10 +20,13 @@ Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = "Solution Items", "Solution
EndProject
Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = "Themes", "Themes", "{B33891C1-D812-4C1D-B6DC-2175A68C4ADC}"
ProjectSection(SolutionItems) = preProject
Themes\ConfluenceStyles6.xml = Themes\ConfluenceStyles6.xml
Themes\ConfluenceStyles7.xml = Themes\ConfluenceStyles7.xml
Themes\DarkStyles.xml = Themes\DarkStyles.xml
Themes\OrangeStyles.xml = Themes\OrangeStyles.xml
Themes\Confluence6.xml = Themes\Confluence6.xml
Themes\Confluence7.xml = Themes\Confluence7.xml
Themes\DarkBlue.xml = Themes\DarkBlue.xml
Themes\DarkGreen.xml = Themes\DarkGreen.xml
Themes\DarkOrange.xml = Themes\DarkOrange.xml
Themes\Orange.xml = Themes\Orange.xml
Themes\Standard.xml = Themes\Standard.xml
EndProjectSection
EndProject
Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = "Plugins", "Plugins", "{9D56ACB1-3CDF-48EB-B786-4F924E899CE2}"
Expand Down
3 changes: 3 additions & 0 deletions OneMore/AddInCommands.cs
Original file line number Diff line number Diff line change
Expand Up @@ -177,6 +177,9 @@ public async Task InvertSelectionCmd(IRibbonControl control)
public async Task LinkReferencesCmd(IRibbonControl control)
=> await factory.Run<LinkReferencesCommand>();

public async Task LoadStylesCmd(IRibbonControl control)
=> await factory.Run<LoadStylesCommand>();

public async Task JoinParagraphCmd(IRibbonControl control)
=> await factory.Run<JoinParagraphCommand>();

Expand Down
12 changes: 9 additions & 3 deletions OneMore/AddInStyleGallery.cs
Original file line number Diff line number Diff line change
Expand Up @@ -9,13 +9,15 @@
namespace River.OneMoreAddIn
{
using Microsoft.Office.Core;
using River.OneMoreAddIn.Styles;
using System.Drawing;
using System.Runtime.InteropServices.ComTypes;


public partial class AddIn
{
private static Color pageColor;
private static Theme theme;


/*
Expand All @@ -41,11 +43,15 @@ public int GetStyleGalleryItemCount(IRibbonControl control)
pageColor = page.GetPageColor(out _, out var black);
if (black)
{
// translate Black into a custom black smoke
pageColor = ColorTranslator.FromHtml("#201F1E");
}
}

var count = new StyleProvider().Count;
// load/reload cached theme
theme = new ThemeProvider().Theme;

var count = theme.GetCount();
//logger.WriteLine($"GetStyleGalleryItemCount() count:{count}");
return count;
}
Expand Down Expand Up @@ -73,7 +79,7 @@ public string GetStyleGalleryItemId(IRibbonControl control, int itemIndex)
public IStream GetStyleGalleryItemImage(IRibbonControl control, int itemIndex)
{
//logger.WriteLine($"GetStyleGalleryItemImage({control.Id}, {itemIndex})");
return new GalleryTileFactory().MakeTile(itemIndex, pageColor);
return new TileFactory().MakeTile(theme.GetStyle(itemIndex), pageColor);
}


Expand All @@ -85,7 +91,7 @@ public IStream GetStyleGalleryItemImage(IRibbonControl control, int itemIndex)
/// <returns></returns>
public string GetStyleGalleryItemScreentip(IRibbonControl control, int itemIndex)
{
var tip = new StyleProvider().GetName(itemIndex);
var tip = theme.GetName(itemIndex);

if (itemIndex < 9)
{
Expand Down
1 change: 1 addition & 0 deletions OneMore/Commands/Clean/ClearBackgroundCommand.cs
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
namespace River.OneMoreAddIn.Commands
{
using River.OneMoreAddIn.Models;
using River.OneMoreAddIn.Styles;
using System.Collections.Generic;
using System.Drawing;
using System.Linq;
Expand Down
3 changes: 2 additions & 1 deletion OneMore/Commands/Clean/RemoveEmptyCommand.cs
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
namespace River.OneMoreAddIn.Commands
{
using River.OneMoreAddIn.Models;
using River.OneMoreAddIn.Styles;
using System.Collections.Generic;
using System.Globalization;
using System.Linq;
Expand Down Expand Up @@ -125,7 +126,7 @@ public bool CollapseEmptyLines(Page page, XNamespace ns)
var quickStyles = page.GetQuickStyles()
.Where(s => s.StyleType == StyleType.Heading);

var customStyles = new StyleProvider().GetStyles()
var customStyles = new ThemeProvider().Theme.GetStyles()
.Where(e => e.StyleType == StyleType.Heading)
.ToList();

Expand Down
3 changes: 2 additions & 1 deletion OneMore/Commands/Clean/RemoveSpacingCommand.cs
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@

namespace River.OneMoreAddIn.Commands
{
using River.OneMoreAddIn.Styles;
using System.Globalization;
using System.Linq;
using System.Threading.Tasks;
Expand Down Expand Up @@ -65,7 +66,7 @@ private async Task RemoveSpacing()
var quickStyles = page.GetQuickStyles()
.Where(s => s.StyleType == StyleType.Heading);

var customStyles = new StyleProvider().GetStyles()
var customStyles = new ThemeProvider().Theme.GetStyles()
.Where(e => e.StyleType == StyleType.Heading)
.ToList();

Expand Down
1 change: 1 addition & 0 deletions OneMore/Commands/Edit/AlterSizeCommand.cs
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
namespace River.OneMoreAddIn.Commands
{
using River.OneMoreAddIn.Models;
using River.OneMoreAddIn.Styles;
using System.Collections.Generic;
using System.Globalization;
using System.Linq;
Expand Down
1 change: 1 addition & 0 deletions OneMore/Commands/Extras/StrikeoutCommand.cs
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@

namespace River.OneMoreAddIn.Commands
{
using River.OneMoreAddIn.Styles;
using System.Collections.Generic;
using System.Linq;
using System.Threading.Tasks;
Expand Down
5 changes: 3 additions & 2 deletions OneMore/Commands/Images/AddCaptionCommand.cs
Original file line number Diff line number Diff line change
Expand Up @@ -4,10 +4,11 @@

namespace River.OneMoreAddIn.Commands
{
using River.OneMoreAddIn.Models;
using River.OneMoreAddIn.Styles;
using System.Linq;
using System.Threading.Tasks;
using System.Xml.Linq;
using River.OneMoreAddIn.Models;
using Resx = River.OneMoreAddIn.Properties.Resources;


Expand Down Expand Up @@ -93,7 +94,7 @@ private static Style GetStyle()

// use custom Caption style if it exists

var styles = new StyleProvider().GetStyles();
var styles = new ThemeProvider().Theme.GetStyles();
if (styles?.Count > 0)
{
style = styles.FirstOrDefault(s => s.Name.Equals("Caption"));
Expand Down
1 change: 1 addition & 0 deletions OneMore/Commands/Images/GetImagesCommand.cs
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
namespace River.OneMoreAddIn.Commands
{
using River.OneMoreAddIn.Models;
using River.OneMoreAddIn.Styles;
using System;
using System.Collections.Concurrent;
using System.Collections.Generic;
Expand Down
7 changes: 4 additions & 3 deletions OneMore/Commands/Styles/ApplyStyleCommand.cs
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@
namespace River.OneMoreAddIn.Commands
{
using River.OneMoreAddIn.Models;
using River.OneMoreAddIn.Styles;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
Expand All @@ -32,7 +33,7 @@ public override async Task Execute(params object[] args)
{
var selectedIndex = (int)args[0];

style = new StyleProvider().GetStyle(selectedIndex);
style = new ThemeProvider().Theme.GetStyle(selectedIndex);
if (style == null)
{
// could be from a CtrlAltShift+# but that indexed style doesn't exist
Expand Down Expand Up @@ -118,7 +119,7 @@ private bool StylizeWords()

if (prev != null)
{
logger.WriteLine("prev:" + prev.ToString(SaveOptions.None));
//logger.WriteLine("prev:" + prev.ToString(SaveOptions.None));

if (!prev.GetCData().EndsWithWhitespace())
{
Expand All @@ -137,7 +138,7 @@ private bool StylizeWords()

if (next != null)
{
logger.WriteLine("next:" + next.ToString(SaveOptions.None));
//logger.WriteLine("next:" + next.ToString(SaveOptions.None));

if (!next.GetCData().StartsWithWhitespace())
{
Expand Down
53 changes: 44 additions & 9 deletions OneMore/Commands/Styles/ApplyStylesCommand.cs
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
namespace River.OneMoreAddIn.Commands
{
using River.OneMoreAddIn.Models;
using River.OneMoreAddIn.Styles;
using System.Collections.Generic;
using System.Linq;
using System.Text.RegularExpressions;
Expand All @@ -20,6 +21,7 @@ internal class ApplyStylesCommand : Command
{

private Page page;
private XNamespace ns;
private readonly Stylizer stylizer;


Expand All @@ -32,9 +34,9 @@ public ApplyStylesCommand()

public override async Task Execute(params object[] args)
{
using (var one = new OneNote(out page, out _))
using (var one = new OneNote(out page, out ns))
{
var styles = new StyleProvider().GetStyles();
var styles = new ThemeProvider().Theme.GetStyles();
if (ApplyStyles(styles))
{
ApplyToLists(styles);
Expand All @@ -50,12 +52,28 @@ public override async Task Execute(params object[] args)
}


public void Apply(Page page)
{
this.page = page;
ns = page.Namespace;

var styles = new ThemeProvider().Theme.GetStyles();
if (ApplyStyles(styles))
{
ApplyToLists(styles);

if (page.GetPageColor(out _, out _).GetBrightness() < 0.5)
{
ApplyToHyperlinks();
}
}
}


private bool ApplyStyles(List<Style> styles)
{
var applied = false;

var ns = page.Namespace;

var quickStyles = page.Root.Elements(ns + "QuickStyleDef");
if (quickStyles?.Any() == true)
{
Expand All @@ -75,17 +93,22 @@ private bool ApplyStyles(List<Style> styles)
// $"~ name:{quick.Attribute("name").Value} style:{style.Name}");

// could use QuickStyleDef class here but this is faster
// that replacing the element...
// than replacing the element...

quick.Attribute("font").Value = style.FontFamily;

// Why does OneNote screw these up?
//quick.Attribute("spaceBefore").Value = style.SpaceBefore;
//quick.Attribute("spaceAfter").Value = style.SpaceAfter;
quick.Attribute("spaceBefore").Value = style.SpaceBefore;
quick.Attribute("spaceAfter").Value = style.SpaceAfter;
// must also apply to paragraphs otherwise OneNote applies x10 values!
SetSpacing(quick.Attribute("index").Value, style.SpaceBefore, style.SpaceAfter);

quick.Attribute("fontColor").Value = style.Color;
quick.Attribute("highlightColor").Value = style.Highlight;

quick.SetAttributeValue("italic", style.IsItalic.ToString().ToLower());
quick.SetAttributeValue("bold", style.IsBold.ToString().ToLower());
quick.SetAttributeValue("underline", style.IsUnderline.ToString().ToLower());

if (name == "p")
{
if (!foundP)
Expand Down Expand Up @@ -162,6 +185,19 @@ private static Style FindStyle(List<Style> styles, string name)
}


private void SetSpacing(string index, string spaceBefore, string spaceAfter)
{
var paragraphs = page.Root.Descendants(ns + "OE")
.Where(e => e.Attribute("quickStyleIndex")?.Value == index);

foreach (var paragraph in paragraphs)
{
paragraph.SetAttributeValue("spaceBefore", spaceBefore);
paragraph.SetAttributeValue("spaceAfter", spaceAfter);
}
}


// when applying styles, we want to preserve any special treatments to paragraphs
// because that would be tedious for the user to restore manually if their intention
// was to keep those colors, but we want to clear all color styling from every other
Expand Down Expand Up @@ -196,7 +232,6 @@ private void ApplyToLists(List<Style> styles)
};
}

var ns = page.Namespace;
var elements = page.Root.Descendants(ns + "Bullet");
if (elements?.Any() == true)
{
Expand Down
Loading

0 comments on commit ea8e528

Please sign in to comment.