From ea8e52848558cb30aa9d5b5ade0ea514cfaa7bfc Mon Sep 17 00:00:00 2001 From: Steven Date: Wed, 25 Aug 2021 18:13:34 -0400 Subject: [PATCH] Bgcolor (#257) --- OneMore.sln | 11 +- OneMore/AddInCommands.cs | 3 + OneMore/AddInStyleGallery.cs | 12 +- .../Commands/Clean/ClearBackgroundCommand.cs | 1 + OneMore/Commands/Clean/RemoveEmptyCommand.cs | 3 +- .../Commands/Clean/RemoveSpacingCommand.cs | 3 +- OneMore/Commands/Edit/AlterSizeCommand.cs | 1 + OneMore/Commands/Extras/StrikeoutCommand.cs | 1 + OneMore/Commands/Images/AddCaptionCommand.cs | 5 +- OneMore/Commands/Images/GetImagesCommand.cs | 1 + OneMore/Commands/Styles/ApplyStyleCommand.cs | 7 +- OneMore/Commands/Styles/ApplyStylesCommand.cs | 53 +- .../Commands/Styles/ChangePageColorCommand.cs | 83 +- .../Styles/ChangePageColorDialog.Designer.cs | 197 ++-- .../Commands/Styles/ChangePageColorDialog.cs | 133 ++- OneMore/Commands/Styles/EditStylesCommand.cs | 16 +- OneMore/Commands/Styles/LoadStylesCommand.cs | 70 ++ OneMore/Commands/Styles/NewStyleCommand.cs | 7 +- OneMore/Commands/Styles/ReorderDialog.cs | 1 + .../Commands/Styles/StyleDialog.Designer.cs | 6 +- OneMore/Commands/Styles/StyleDialog.cs | 103 +- OneMore/Commands/Styles/StyleDialog.resx | 942 +++++++++--------- OneMore/Helpers/Extensions/ColorExtensions.cs | 18 + OneMore/Models/Heading.cs | 1 + OneMore/Models/PageHeadings.cs | 3 +- OneMore/Models/QuickStyleMapping.cs | 1 + OneMore/Models/SelectionRange.cs | 1 + OneMore/OneMore.csproj | 11 +- OneMore/Properties/AssemblyInfo.cs | 2 +- .../{CustomStyles.xml => DefaultStyles.xml} | 4 +- OneMore/Properties/Resources.Designer.cs | 104 +- OneMore/Properties/Resources.ar-SA.resx | 59 +- OneMore/Properties/Resources.de-DE.resx | 127 ++- OneMore/Properties/Resources.es-ES.resx | 59 +- OneMore/Properties/Resources.fr-FR.resx | 127 ++- OneMore/Properties/Resources.nl-NL.resx | 127 ++- OneMore/Properties/Resources.pt-BR.resx | 59 +- OneMore/Properties/Resources.resx | 58 +- OneMore/Properties/Resources.zh-CN.resx | 59 +- OneMore/Properties/Ribbon.xml | 5 + OneMore/Styles/GraphicStyle.cs | 2 +- OneMore/Styles/QuickStyleDef.cs | 2 +- OneMore/Styles/Style.cs | 2 +- OneMore/Styles/StyleAnalyzer.cs | 2 +- OneMore/Styles/StyleBase.cs | 2 +- OneMore/Styles/StyleProvider.cs | 174 ---- OneMore/Styles/StyleRecord.cs | 2 +- OneMore/Styles/StyleType.cs | 2 +- OneMore/Styles/Stylizer.cs | 2 +- OneMore/Styles/Theme.cs | 189 ++++ OneMore/Styles/ThemeProvider.cs | 197 ++++ OneMore/Styles/XmlStyleBase.cs | 2 +- OneMore/UI/BasicColors.cs | 9 +- OneMore/UI/ColorsComboBox.cs | 295 ++++++ .../TileFactory.cs} | 13 +- OneMoreSetup/OneMoreSetup.vdproj | Bin 644282 -> 660460 bytes ...{ConfluenceStyles6.xml => Confluence6.xml} | 4 +- ...{ConfluenceStyles7.xml => Confluence7.xml} | 4 +- Themes/{DarkStyles.xml => DarkBlue.xml} | 22 +- Themes/{BlackStyles.xml => DarkGreen.xml} | 28 +- Themes/DarkOrange.xml | 18 + Themes/{OrangeStyles.xml => Orange.xml} | 4 +- Themes/Standard.xml | 18 + 63 files changed, 2267 insertions(+), 1210 deletions(-) create mode 100644 OneMore/Commands/Styles/LoadStylesCommand.cs rename OneMore/Properties/{CustomStyles.xml => DefaultStyles.xml} (98%) delete mode 100644 OneMore/Styles/StyleProvider.cs create mode 100644 OneMore/Styles/Theme.cs create mode 100644 OneMore/Styles/ThemeProvider.cs create mode 100644 OneMore/UI/ColorsComboBox.cs rename OneMore/{Helpers/GalleryTileFactory.cs => UI/TileFactory.cs} (93%) rename Themes/{ConfluenceStyles6.xml => Confluence6.xml} (98%) rename Themes/{ConfluenceStyles7.xml => Confluence7.xml} (98%) rename Themes/{DarkStyles.xml => DarkBlue.xml} (69%) rename Themes/{BlackStyles.xml => DarkGreen.xml} (59%) create mode 100644 Themes/DarkOrange.xml rename Themes/{OrangeStyles.xml => Orange.xml} (98%) create mode 100644 Themes/Standard.xml diff --git a/OneMore.sln b/OneMore.sln index c4ee1b1ad0..5b810607a7 100644 --- a/OneMore.sln +++ b/OneMore.sln @@ -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}" diff --git a/OneMore/AddInCommands.cs b/OneMore/AddInCommands.cs index f441610acb..80e0d23cff 100644 --- a/OneMore/AddInCommands.cs +++ b/OneMore/AddInCommands.cs @@ -177,6 +177,9 @@ public async Task InvertSelectionCmd(IRibbonControl control) public async Task LinkReferencesCmd(IRibbonControl control) => await factory.Run(); + public async Task LoadStylesCmd(IRibbonControl control) + => await factory.Run(); + public async Task JoinParagraphCmd(IRibbonControl control) => await factory.Run(); diff --git a/OneMore/AddInStyleGallery.cs b/OneMore/AddInStyleGallery.cs index 855a0ee6aa..18f0557a56 100644 --- a/OneMore/AddInStyleGallery.cs +++ b/OneMore/AddInStyleGallery.cs @@ -9,6 +9,7 @@ namespace River.OneMoreAddIn { using Microsoft.Office.Core; + using River.OneMoreAddIn.Styles; using System.Drawing; using System.Runtime.InteropServices.ComTypes; @@ -16,6 +17,7 @@ namespace River.OneMoreAddIn public partial class AddIn { private static Color pageColor; + private static Theme theme; /* @@ -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; } @@ -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); } @@ -85,7 +91,7 @@ public IStream GetStyleGalleryItemImage(IRibbonControl control, int itemIndex) /// public string GetStyleGalleryItemScreentip(IRibbonControl control, int itemIndex) { - var tip = new StyleProvider().GetName(itemIndex); + var tip = theme.GetName(itemIndex); if (itemIndex < 9) { diff --git a/OneMore/Commands/Clean/ClearBackgroundCommand.cs b/OneMore/Commands/Clean/ClearBackgroundCommand.cs index 5462079d07..f74364a3ba 100644 --- a/OneMore/Commands/Clean/ClearBackgroundCommand.cs +++ b/OneMore/Commands/Clean/ClearBackgroundCommand.cs @@ -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; diff --git a/OneMore/Commands/Clean/RemoveEmptyCommand.cs b/OneMore/Commands/Clean/RemoveEmptyCommand.cs index 1c842d4ed5..99ef70c956 100644 --- a/OneMore/Commands/Clean/RemoveEmptyCommand.cs +++ b/OneMore/Commands/Clean/RemoveEmptyCommand.cs @@ -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; @@ -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(); diff --git a/OneMore/Commands/Clean/RemoveSpacingCommand.cs b/OneMore/Commands/Clean/RemoveSpacingCommand.cs index 8a1ab05a98..90452f5e73 100644 --- a/OneMore/Commands/Clean/RemoveSpacingCommand.cs +++ b/OneMore/Commands/Clean/RemoveSpacingCommand.cs @@ -4,6 +4,7 @@ namespace River.OneMoreAddIn.Commands { + using River.OneMoreAddIn.Styles; using System.Globalization; using System.Linq; using System.Threading.Tasks; @@ -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(); diff --git a/OneMore/Commands/Edit/AlterSizeCommand.cs b/OneMore/Commands/Edit/AlterSizeCommand.cs index f41461b533..2bc376a0a7 100644 --- a/OneMore/Commands/Edit/AlterSizeCommand.cs +++ b/OneMore/Commands/Edit/AlterSizeCommand.cs @@ -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; diff --git a/OneMore/Commands/Extras/StrikeoutCommand.cs b/OneMore/Commands/Extras/StrikeoutCommand.cs index 8ea03a63d1..5385d1812a 100644 --- a/OneMore/Commands/Extras/StrikeoutCommand.cs +++ b/OneMore/Commands/Extras/StrikeoutCommand.cs @@ -4,6 +4,7 @@ namespace River.OneMoreAddIn.Commands { + using River.OneMoreAddIn.Styles; using System.Collections.Generic; using System.Linq; using System.Threading.Tasks; diff --git a/OneMore/Commands/Images/AddCaptionCommand.cs b/OneMore/Commands/Images/AddCaptionCommand.cs index 1f16556881..f1fc64b7b6 100644 --- a/OneMore/Commands/Images/AddCaptionCommand.cs +++ b/OneMore/Commands/Images/AddCaptionCommand.cs @@ -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; @@ -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")); diff --git a/OneMore/Commands/Images/GetImagesCommand.cs b/OneMore/Commands/Images/GetImagesCommand.cs index fcb632a42b..475083dbae 100644 --- a/OneMore/Commands/Images/GetImagesCommand.cs +++ b/OneMore/Commands/Images/GetImagesCommand.cs @@ -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; diff --git a/OneMore/Commands/Styles/ApplyStyleCommand.cs b/OneMore/Commands/Styles/ApplyStyleCommand.cs index 6f561695c4..2275149a26 100644 --- a/OneMore/Commands/Styles/ApplyStyleCommand.cs +++ b/OneMore/Commands/Styles/ApplyStyleCommand.cs @@ -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; @@ -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 @@ -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()) { @@ -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()) { diff --git a/OneMore/Commands/Styles/ApplyStylesCommand.cs b/OneMore/Commands/Styles/ApplyStylesCommand.cs index 36a2401a70..1b3817fa9d 100644 --- a/OneMore/Commands/Styles/ApplyStylesCommand.cs +++ b/OneMore/Commands/Styles/ApplyStylesCommand.cs @@ -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; @@ -20,6 +21,7 @@ internal class ApplyStylesCommand : Command { private Page page; + private XNamespace ns; private readonly Stylizer stylizer; @@ -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); @@ -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