From feec17723b4e467c262127c1da41dac5ad8b76d5 Mon Sep 17 00:00:00 2001 From: Steven Cohn Date: Sat, 2 Dec 2023 02:09:28 -0500 Subject: [PATCH 1/5] Update page color dialog #1196 --- OneMore/Commands/Styles/PageColorCommand.cs | 27 ++++++---- .../Styles/PageColorDialog.Designer.cs | 51 +++++++++++++++---- OneMore/Commands/Styles/PageColorDialog.cs | 26 ++++++++-- OneMore/Properties/Resources.Designer.cs | 11 ++++ OneMore/Properties/Resources.ar-SA.resx | 6 +++ OneMore/Properties/Resources.de-DE.resx | 6 +++ OneMore/Properties/Resources.es-ES.resx | 6 +++ OneMore/Properties/Resources.fr-FR.resx | 6 +++ OneMore/Properties/Resources.he-IL.resx | 6 +++ OneMore/Properties/Resources.nl-NL.resx | 6 +++ OneMore/Properties/Resources.pl-PL.resx | 6 +++ OneMore/Properties/Resources.pt-BR.resx | 6 +++ OneMore/Properties/Resources.resx | 6 +++ OneMore/Properties/Resources.zh-CN.resx | 6 +++ OneMore/UI/MoreExpander.Designer.cs | 1 + OneMore/UI/MoreExpander.cs | 10 +++- 16 files changed, 161 insertions(+), 25 deletions(-) diff --git a/OneMore/Commands/Styles/PageColorCommand.cs b/OneMore/Commands/Styles/PageColorCommand.cs index a0705bedc2..038662ffec 100644 --- a/OneMore/Commands/Styles/PageColorCommand.cs +++ b/OneMore/Commands/Styles/PageColorCommand.cs @@ -41,19 +41,28 @@ public override async Task Execute(params object[] args) using var dialog = new PageColorDialog(color, new ThemeProvider().Theme.Name); if (dialog.ShowDialog(owner) == DialogResult.OK) { - UpdatePageColor(page, MakePageColor(dialog.Color)); + var pageColor = MakePageColor(dialog.Color); - if (dialog.ApplyStyle) + if (dialog.Target == OneNote.NodeType.Page) { - ThemeProvider.RecordTheme(dialog.ThemeKey); + UpdatePageColor(page, pageColor); - var cmd = new ApplyStylesCommand(); - cmd.SetLogger(logger); - cmd.Apply(page); - } + if (dialog.ApplyStyle) + { + ThemeProvider.RecordTheme(dialog.ThemeKey); + + var cmd = new ApplyStylesCommand(); + cmd.SetLogger(logger); + cmd.Apply(page); + } - using var one = new OneNote(); - await one.Update(page); + using var one = new OneNote(); + await one.Update(page); + } + else + { + // + } } } diff --git a/OneMore/Commands/Styles/PageColorDialog.Designer.cs b/OneMore/Commands/Styles/PageColorDialog.Designer.cs index 64793a83ca..4bf8083c90 100644 --- a/OneMore/Commands/Styles/PageColorDialog.Designer.cs +++ b/OneMore/Commands/Styles/PageColorDialog.Designer.cs @@ -46,10 +46,13 @@ private void InitializeComponent() this.noButton = new System.Windows.Forms.RadioButton(); this.statusLabel = new System.Windows.Forms.Label(); this.tooltip = new System.Windows.Forms.ToolTip(this.components); + this.targetBox = new System.Windows.Forms.ComboBox(); + this.detailPanel = new System.Windows.Forms.Panel(); ((System.ComponentModel.ISupportInitialize)(this.omBox)).BeginInit(); ((System.ComponentModel.ISupportInitialize)(this.customBox)).BeginInit(); this.noPanel.SuspendLayout(); this.optionsPanel.SuspendLayout(); + this.detailPanel.SuspendLayout(); this.SuspendLayout(); // // omBox @@ -96,7 +99,7 @@ private void InitializeComponent() // this.cancelButton.Anchor = ((System.Windows.Forms.AnchorStyles)((System.Windows.Forms.AnchorStyles.Bottom | System.Windows.Forms.AnchorStyles.Right))); this.cancelButton.DialogResult = System.Windows.Forms.DialogResult.Cancel; - this.cancelButton.Location = new System.Drawing.Point(497, 484); + this.cancelButton.Location = new System.Drawing.Point(497, 545); this.cancelButton.Name = "cancelButton"; this.cancelButton.Size = new System.Drawing.Size(130, 40); this.cancelButton.TabIndex = 9; @@ -111,21 +114,21 @@ private void InitializeComponent() this.expander.Cursor = System.Windows.Forms.Cursors.Hand; this.expander.Expanded = false; this.expander.ForeColor = System.Drawing.SystemColors.ActiveCaption; - this.expander.Location = new System.Drawing.Point(67, 289); + this.expander.Location = new System.Drawing.Point(23, 65); this.expander.MaxContentHeight = 130; this.expander.Name = "expander"; - this.expander.Size = new System.Drawing.Size(547, 44); + this.expander.Size = new System.Drawing.Size(521, 44); this.expander.TabIndex = 10; this.expander.Title = "Options"; // // optionsPanel // - this.optionsPanel.Anchor = ((System.Windows.Forms.AnchorStyles)(((System.Windows.Forms.AnchorStyles.Bottom | System.Windows.Forms.AnchorStyles.Left) + this.optionsPanel.Anchor = ((System.Windows.Forms.AnchorStyles)(((System.Windows.Forms.AnchorStyles.Top | System.Windows.Forms.AnchorStyles.Left) | System.Windows.Forms.AnchorStyles.Right))); this.optionsPanel.Controls.Add(this.loadThemeLink); this.optionsPanel.Controls.Add(this.currentThemeLabel); this.optionsPanel.Controls.Add(this.applyThemeBox); - this.optionsPanel.Location = new System.Drawing.Point(33, 341); + this.optionsPanel.Location = new System.Drawing.Point(44, 412); this.optionsPanel.Name = "optionsPanel"; this.optionsPanel.Padding = new System.Windows.Forms.Padding(4); this.optionsPanel.Size = new System.Drawing.Size(583, 122); @@ -167,7 +170,7 @@ private void InitializeComponent() // this.okButton.Anchor = ((System.Windows.Forms.AnchorStyles)((System.Windows.Forms.AnchorStyles.Bottom | System.Windows.Forms.AnchorStyles.Right))); this.okButton.DialogResult = System.Windows.Forms.DialogResult.OK; - this.okButton.Location = new System.Drawing.Point(361, 484); + this.okButton.Location = new System.Drawing.Point(361, 545); this.okButton.Name = "okButton"; this.okButton.Size = new System.Drawing.Size(130, 40); this.okButton.TabIndex = 12; @@ -210,26 +213,51 @@ private void InitializeComponent() // this.statusLabel.AutoSize = true; this.statusLabel.ForeColor = System.Drawing.Color.Brown; - this.statusLabel.Location = new System.Drawing.Point(110, 266); + this.statusLabel.Location = new System.Drawing.Point(110, 262); this.statusLabel.Name = "statusLabel"; this.statusLabel.Size = new System.Drawing.Size(31, 20); this.statusLabel.TabIndex = 16; this.statusLabel.Text = "OK"; // + // targetBox + // + this.targetBox.DropDownStyle = System.Windows.Forms.ComboBoxStyle.DropDownList; + this.targetBox.FormattingEnabled = true; + this.targetBox.Items.AddRange(new object[] { + "Apply to this page", + "Apply to pages in this section", + "Apply to pages in this notebook"}); + this.targetBox.Location = new System.Drawing.Point(23, 3); + this.targetBox.Name = "targetBox"; + this.targetBox.Size = new System.Drawing.Size(352, 28); + this.targetBox.TabIndex = 17; + this.targetBox.SelectedIndexChanged += new System.EventHandler(this.ChangeTarget); + // + // detailPanel + // + this.detailPanel.Anchor = ((System.Windows.Forms.AnchorStyles)(((System.Windows.Forms.AnchorStyles.Top | System.Windows.Forms.AnchorStyles.Left) + | System.Windows.Forms.AnchorStyles.Right))); + this.detailPanel.Controls.Add(this.targetBox); + this.detailPanel.Controls.Add(this.expander); + this.detailPanel.Location = new System.Drawing.Point(44, 294); + this.detailPanel.Name = "detailPanel"; + this.detailPanel.Size = new System.Drawing.Size(583, 112); + this.detailPanel.TabIndex = 18; + // // PageColorDialog // this.AcceptButton = this.okButton; this.AutoScaleDimensions = new System.Drawing.SizeF(9F, 20F); this.AutoScaleMode = System.Windows.Forms.AutoScaleMode.Font; this.CancelButton = this.cancelButton; - this.ClientSize = new System.Drawing.Size(640, 537); + this.ClientSize = new System.Drawing.Size(640, 598); + this.Controls.Add(this.detailPanel); this.Controls.Add(this.statusLabel); + this.Controls.Add(this.optionsPanel); this.Controls.Add(this.noButton); this.Controls.Add(this.customButton); this.Controls.Add(this.omButton); this.Controls.Add(this.okButton); - this.Controls.Add(this.optionsPanel); - this.Controls.Add(this.expander); this.Controls.Add(this.cancelButton); this.Controls.Add(this.noPanel); this.Controls.Add(this.omBox); @@ -250,6 +278,7 @@ private void InitializeComponent() this.noPanel.PerformLayout(); this.optionsPanel.ResumeLayout(false); this.optionsPanel.PerformLayout(); + this.detailPanel.ResumeLayout(false); this.ResumeLayout(false); this.PerformLayout(); @@ -273,5 +302,7 @@ private void InitializeComponent() private System.Windows.Forms.RadioButton noButton; private System.Windows.Forms.Label statusLabel; private System.Windows.Forms.ToolTip tooltip; + private System.Windows.Forms.ComboBox targetBox; + private System.Windows.Forms.Panel detailPanel; } } \ No newline at end of file diff --git a/OneMore/Commands/Styles/PageColorDialog.cs b/OneMore/Commands/Styles/PageColorDialog.cs index 0764494a39..daed1335f3 100644 --- a/OneMore/Commands/Styles/PageColorDialog.cs +++ b/OneMore/Commands/Styles/PageColorDialog.cs @@ -35,6 +35,7 @@ public PageColorDialog() "noLabel", "expander.Title=word_Options", "currentThemeLabel", + "targetBox", "loadThemeLink", "applyThemeBox", "okButton=word_OK", @@ -44,11 +45,13 @@ public PageColorDialog() VerticalOffset = -(Height / 3); Height -= optionsPanel.Height; + //detailPanel.Height -= optionsPanel.Height; optionsPanel.Height = 0; optionsAvailable = true; darkMode = Office.IsBlackThemeEnabled(); statusLabel.Text = string.Empty; + targetBox.SelectedIndex = 0; } @@ -147,6 +150,14 @@ public PageColorDialog(Color color, string themeKey) public Color Color { get; private set; } + public OneNote.NodeType Target => targetBox.SelectedIndex switch + { + 1 => OneNote.NodeType.Section, + 2 => OneNote.NodeType.Notebook, + _ => OneNote.NodeType.Page + }; + + public string ThemeKey => theme.Key; @@ -158,10 +169,8 @@ private Color EstimateOneNoteColor(Color color) public void HideOptions() { - Height -= expander.Height - statusLabel.Height; - expander.Visible = false; - statusLabel.Visible = false; - optionsAvailable = false; + Height -= detailPanel.Height; + detailPanel.Visible = false; } @@ -262,6 +271,15 @@ private void ChangeColorOption(object sender, EventArgs e) } + private void ChangeTarget(object sender, EventArgs e) + { + var enabled = targetBox.SelectedIndex == 0; + expander.Enabled = enabled; + currentThemeLabel.Enabled = enabled; + loadThemeLink.Enabled = enabled; + applyThemeBox.Enabled = enabled; + } + private void LoadTheme(object sender, LinkLabelLinkClickedEventArgs e) { diff --git a/OneMore/Properties/Resources.Designer.cs b/OneMore/Properties/Resources.Designer.cs index 5091a48665..dac7386ff4 100644 --- a/OneMore/Properties/Resources.Designer.cs +++ b/OneMore/Properties/Resources.Designer.cs @@ -4461,6 +4461,17 @@ internal static string PageColorDialog_omLabel { } } + /// + /// Looks up a localized string similar to Apply to this page + ///Apply to this section + ///Apply to this notebook. + /// + internal static string PageColorDialog_targetBox_Text { + get { + return ResourceManager.GetString("PageColorDialog_targetBox.Text", resourceCulture); + } + } + /// /// Looks up a localized string similar to Page Color. /// diff --git a/OneMore/Properties/Resources.ar-SA.resx b/OneMore/Properties/Resources.ar-SA.resx index f0fc85ded4..50ae754e24 100644 --- a/OneMore/Properties/Resources.ar-SA.resx +++ b/OneMore/Properties/Resources.ar-SA.resx @@ -1801,6 +1801,12 @@ انقر هنا لتحديد لون محدد مسبقًا label + + تنطبق على هذه الصفحة +تنطبق على هذا القسم +تنطبق على هذا دفتر الملاحظات + combobox + لا يوجد محتوى للصقه ؛ message box diff --git a/OneMore/Properties/Resources.de-DE.resx b/OneMore/Properties/Resources.de-DE.resx index 5108f2121f..ae541a5b75 100644 --- a/OneMore/Properties/Resources.de-DE.resx +++ b/OneMore/Properties/Resources.de-DE.resx @@ -1798,6 +1798,12 @@ Aufgeschoben Klicken Sie hier, um eine vordefinierte Farbe auszuwählen label + + Bewerben Sie sich auf dieser Seite +Bewerben Sie sich für diesen Abschnitt +Bewerben Sie sich auf dieses Notizbuch + combobox + Kein Inhalt zum Einfügen; message box diff --git a/OneMore/Properties/Resources.es-ES.resx b/OneMore/Properties/Resources.es-ES.resx index 250286b03a..113514794a 100644 --- a/OneMore/Properties/Resources.es-ES.resx +++ b/OneMore/Properties/Resources.es-ES.resx @@ -1801,6 +1801,12 @@ Diferido Haga clic aquí para seleccionar un color predefinido label + + Aplicar a esta página +Aplicar a esta sección +Aplicar a este cuaderno + combobox + Sin contenido para pegar; message box diff --git a/OneMore/Properties/Resources.fr-FR.resx b/OneMore/Properties/Resources.fr-FR.resx index 12ebc01969..7130a29592 100644 --- a/OneMore/Properties/Resources.fr-FR.resx +++ b/OneMore/Properties/Resources.fr-FR.resx @@ -1798,6 +1798,12 @@ Différé Cliquez ici pour sélectionner une couleur prédéfinie label + + Postuler sur cette page +Postuler à cette section +Postuler à ce carnet + combobox + Aucun contenu à coller ; message box diff --git a/OneMore/Properties/Resources.he-IL.resx b/OneMore/Properties/Resources.he-IL.resx index a287906260..985c1bcf46 100644 --- a/OneMore/Properties/Resources.he-IL.resx +++ b/OneMore/Properties/Resources.he-IL.resx @@ -1812,6 +1812,12 @@ Total Row Font לחץ כאן כדי לבחור צבע מוגדר מראש label + + הגש בקשה לדף זה +הגש על סעיף זה +החל על מחברת זו + combobox + אין תוכן להדביק; העתק תא טבלה אחד או יותר להדבקה message box diff --git a/OneMore/Properties/Resources.nl-NL.resx b/OneMore/Properties/Resources.nl-NL.resx index a160e13149..50d8c1c9dc 100644 --- a/OneMore/Properties/Resources.nl-NL.resx +++ b/OneMore/Properties/Resources.nl-NL.resx @@ -1802,6 +1802,12 @@ Verschoven Klik hier om een ​​voorgedefinieerde kleur te selecteren label + + Solliciteer op deze pagina +Toepassen op deze sectie +Toepassen op dit notitieboekje + combobox + Geen inhoud om te plakken; message box diff --git a/OneMore/Properties/Resources.pl-PL.resx b/OneMore/Properties/Resources.pl-PL.resx index 6d0d9744a9..d3f65e0938 100644 --- a/OneMore/Properties/Resources.pl-PL.resx +++ b/OneMore/Properties/Resources.pl-PL.resx @@ -1810,6 +1810,12 @@ Odroczony Kliknij tutaj, aby wybrać predefiniowany kolor label + + Aplikuj na tę stronę +Zastosuj się do tej sekcji +Zastosuj do tego notatnika + combobox + Brak treści do pasty; skopiuj jedną lub więcej komórek tabeli do pasty message box diff --git a/OneMore/Properties/Resources.pt-BR.resx b/OneMore/Properties/Resources.pt-BR.resx index 98b391f217..b176d98544 100644 --- a/OneMore/Properties/Resources.pt-BR.resx +++ b/OneMore/Properties/Resources.pt-BR.resx @@ -1802,6 +1802,12 @@ Diferido Clique aqui para selecionar uma cor pré-definida label + + Inscreva-se nesta página +Inscreva-se nesta seção +Aplicar a este caderno + combobox + Nenhum conteúdo para colar; message box diff --git a/OneMore/Properties/Resources.resx b/OneMore/Properties/Resources.resx index cf6ea9328e..2c66b7bb2a 100644 --- a/OneMore/Properties/Resources.resx +++ b/OneMore/Properties/Resources.resx @@ -1828,6 +1828,12 @@ Deferred Click here to select a pre-defined color label + + Apply to this page +Apply to this section +Apply to this notebook + combobox + No content to paste; copy one or more table cells to paste message box diff --git a/OneMore/Properties/Resources.zh-CN.resx b/OneMore/Properties/Resources.zh-CN.resx index b1aa23bb56..182a535a41 100644 --- a/OneMore/Properties/Resources.zh-CN.resx +++ b/OneMore/Properties/Resources.zh-CN.resx @@ -1811,6 +1811,12 @@ OneNote 文件 (*.one) 单击此处选择预定义颜色 label + + 申请此页面 +适用于本部分 +适用于本笔记本 + combobox + 没有要粘贴的内容; message box diff --git a/OneMore/UI/MoreExpander.Designer.cs b/OneMore/UI/MoreExpander.Designer.cs index 582b5e17a1..006e0f15a9 100644 --- a/OneMore/UI/MoreExpander.Designer.cs +++ b/OneMore/UI/MoreExpander.Designer.cs @@ -18,6 +18,7 @@ protected override void Dispose(bool disposing) components.Dispose(); image?.Dispose(); + grayed?.Dispose(); } base.Dispose(disposing); } diff --git a/OneMore/UI/MoreExpander.cs b/OneMore/UI/MoreExpander.cs index 75d88dbd6f..85b7654243 100644 --- a/OneMore/UI/MoreExpander.cs +++ b/OneMore/UI/MoreExpander.cs @@ -4,6 +4,7 @@ namespace River.OneMoreAddIn.UI { + using System; using System.ComponentModel; using System.Drawing; using System.Windows.Forms; @@ -13,6 +14,7 @@ namespace River.OneMoreAddIn.UI internal partial class MoreExpander : UserControl { private readonly Image image; + private readonly Image grayed; private string title; private bool expanded; private bool expandedIcon; @@ -24,6 +26,7 @@ public MoreExpander() header.Image = new Bitmap(header.Width, header.Height); image = (Bitmap)Resx.ExpandArrow.Clone(); + grayed = image.ToGrayscale(); expanded = expandedIcon = false; } @@ -83,17 +86,20 @@ private void Repaint(object sender, PaintEventArgs e) if (Expanded != expandedIcon) { image.RotateFlip(RotateFlipType.RotateNoneFlipY); + grayed.RotateFlip(RotateFlipType.RotateNoneFlipY); expandedIcon = Expanded; } var g = e.Graphics; g.Clear(BackColor); - g.DrawImage(image, 5, 5, 30, 30); + g.DrawImage(Enabled ? image : grayed, 5, 5, 30, 30); using var font = new Font(Font, FontStyle.Bold); var size = g.MeasureString(Title, font); - g.DrawString(Title, font, new SolidBrush(ForeColor), + var fore = Enabled ? ForeColor : Color.Gray; + + g.DrawString(Title, font, new SolidBrush(fore), 45, (header.Height / 2) - size.Height + 5); var y = header.Height / 2 + 10; From 33b18e1931c8382de59578256de3abfbbdbdedae Mon Sep 17 00:00:00 2001 From: Steven Cohn Date: Sat, 2 Dec 2023 09:44:48 -0500 Subject: [PATCH 2/5] apply color --- OneMore/Commands/Styles/PageColorCommand.cs | 103 ++++++++++++------ .../Styles/PageColorDialog.Designer.cs | 24 ++-- OneMore/Commands/Styles/PageColorDialog.cs | 16 +-- OneMore/OneNote.cs | 2 +- OneMore/Properties/Resources.Designer.cs | 4 +- OneMore/Properties/Resources.ar-SA.resx | 2 +- OneMore/Properties/Resources.de-DE.resx | 2 +- OneMore/Properties/Resources.es-ES.resx | 2 +- OneMore/Properties/Resources.fr-FR.resx | 2 +- OneMore/Properties/Resources.he-IL.resx | 2 +- OneMore/Properties/Resources.nl-NL.resx | 2 +- OneMore/Properties/Resources.pl-PL.resx | 2 +- OneMore/Properties/Resources.pt-BR.resx | 2 +- OneMore/Properties/Resources.resx | 2 +- OneMore/Properties/Resources.zh-CN.resx | 2 +- 15 files changed, 100 insertions(+), 69 deletions(-) diff --git a/OneMore/Commands/Styles/PageColorCommand.cs b/OneMore/Commands/Styles/PageColorCommand.cs index 038662ffec..f8d0b22d45 100644 --- a/OneMore/Commands/Styles/PageColorCommand.cs +++ b/OneMore/Commands/Styles/PageColorCommand.cs @@ -39,31 +39,73 @@ public override async Task Execute(params object[] args) } using var dialog = new PageColorDialog(color, new ThemeProvider().Theme.Name); - if (dialog.ShowDialog(owner) == DialogResult.OK) + if (dialog.ShowDialog(owner) != DialogResult.OK) { - var pageColor = MakePageColor(dialog.Color); + return; + } - if (dialog.Target == OneNote.NodeType.Page) - { - UpdatePageColor(page, pageColor); + var pageColor = MakePageColor(dialog.Color); - if (dialog.ApplyStyle) - { - ThemeProvider.RecordTheme(dialog.ThemeKey); + if (dialog.Scope == OneNote.Scope.Self) + { + UpdatePageColor(page, pageColor); - var cmd = new ApplyStylesCommand(); - cmd.SetLogger(logger); - cmd.Apply(page); - } + if (dialog.ApplyStyle) + { + ThemeProvider.RecordTheme(dialog.ThemeKey); - using var one = new OneNote(); - await one.Update(page); + var styler = new ApplyStylesCommand(); + styler.SetLogger(logger); + styler.Apply(page); } - else + + using var one = new OneNote(); + await one.Update(page); + } + else + { + await ColorPages(dialog.Scope, pageColor); + } + } + + + private async Task ColorPages(OneNote.Scope scope, string pageColor) + { + + using var one = new OneNote(); + + var root = scope == OneNote.Scope.Pages + ? one.GetSection() + : await one.GetNotebook(OneNote.Scope.Pages); + + var ns = root.GetNamespaceOfPrefix(OneNote.Prefix); + + var nodes = root.Descendants(ns + "Page") + .Where(e => e.Attribute("isInRecycleBin") == null); + + using var progress = new UI.ProgressDialog(); + progress.SetMaximum(nodes.Count()); + + progress.ShowDialogWithCancel(async (dialog, token) => + { + foreach (var node in nodes) { - // + var page = one.GetPage(node.Attribute("ID").Value, OneNote.PageDetail.Basic); + if (token.IsCancellationRequested) break; + + progress.SetMessage(page.Title); + + UpdatePageColor(page, pageColor); + if (token.IsCancellationRequested) break; + + await one.Update(page); + + progress.Increment(); + if (token.IsCancellationRequested) break; } - } + + return true; + }); } @@ -97,36 +139,25 @@ public bool UpdatePageColor(Page page, string color) var changed = false; - var attr = element.Attribute("color"); - if (attr != null) + var attribute = element.Attribute("color"); + if (attribute == null) { - if (attr.Value != color) - { - attr.Value = color; - changed = true; - } + element.Add(new XAttribute("color", color)); + changed = true; } - else + else if (attribute.Value != color) { - element.Add(new XAttribute("color", color)); + attribute.Value = color; changed = true; } if (changed) { - // if light->dark or dark->light, apply appropriate theme... - - var dark = false; - if (color != StyleBase.Automatic) - { - dark = ColorTranslator.FromHtml(color).IsDark(); - } - - logger.WriteLine($"color set to {color} (dark:{dark})"); + logger.WriteLine($"page color set to {color} for {page.Title}"); } else { - logger.WriteLine($"page color unchanged"); + logger.WriteLine($"page color unchanged on {page.Title}"); } return changed; diff --git a/OneMore/Commands/Styles/PageColorDialog.Designer.cs b/OneMore/Commands/Styles/PageColorDialog.Designer.cs index 4bf8083c90..48067b43a3 100644 --- a/OneMore/Commands/Styles/PageColorDialog.Designer.cs +++ b/OneMore/Commands/Styles/PageColorDialog.Designer.cs @@ -46,7 +46,7 @@ private void InitializeComponent() this.noButton = new System.Windows.Forms.RadioButton(); this.statusLabel = new System.Windows.Forms.Label(); this.tooltip = new System.Windows.Forms.ToolTip(this.components); - this.targetBox = new System.Windows.Forms.ComboBox(); + this.scopeBox = new System.Windows.Forms.ComboBox(); this.detailPanel = new System.Windows.Forms.Panel(); ((System.ComponentModel.ISupportInitialize)(this.omBox)).BeginInit(); ((System.ComponentModel.ISupportInitialize)(this.customBox)).BeginInit(); @@ -219,25 +219,25 @@ private void InitializeComponent() this.statusLabel.TabIndex = 16; this.statusLabel.Text = "OK"; // - // targetBox + // scopeBox // - this.targetBox.DropDownStyle = System.Windows.Forms.ComboBoxStyle.DropDownList; - this.targetBox.FormattingEnabled = true; - this.targetBox.Items.AddRange(new object[] { + this.scopeBox.DropDownStyle = System.Windows.Forms.ComboBoxStyle.DropDownList; + this.scopeBox.FormattingEnabled = true; + this.scopeBox.Items.AddRange(new object[] { "Apply to this page", "Apply to pages in this section", "Apply to pages in this notebook"}); - this.targetBox.Location = new System.Drawing.Point(23, 3); - this.targetBox.Name = "targetBox"; - this.targetBox.Size = new System.Drawing.Size(352, 28); - this.targetBox.TabIndex = 17; - this.targetBox.SelectedIndexChanged += new System.EventHandler(this.ChangeTarget); + this.scopeBox.Location = new System.Drawing.Point(23, 3); + this.scopeBox.Name = "scopeBox"; + this.scopeBox.Size = new System.Drawing.Size(352, 28); + this.scopeBox.TabIndex = 17; + this.scopeBox.SelectedIndexChanged += new System.EventHandler(this.ChangeScope); // // detailPanel // this.detailPanel.Anchor = ((System.Windows.Forms.AnchorStyles)(((System.Windows.Forms.AnchorStyles.Top | System.Windows.Forms.AnchorStyles.Left) | System.Windows.Forms.AnchorStyles.Right))); - this.detailPanel.Controls.Add(this.targetBox); + this.detailPanel.Controls.Add(this.scopeBox); this.detailPanel.Controls.Add(this.expander); this.detailPanel.Location = new System.Drawing.Point(44, 294); this.detailPanel.Name = "detailPanel"; @@ -302,7 +302,7 @@ private void InitializeComponent() private System.Windows.Forms.RadioButton noButton; private System.Windows.Forms.Label statusLabel; private System.Windows.Forms.ToolTip tooltip; - private System.Windows.Forms.ComboBox targetBox; + private System.Windows.Forms.ComboBox scopeBox; private System.Windows.Forms.Panel detailPanel; } } \ No newline at end of file diff --git a/OneMore/Commands/Styles/PageColorDialog.cs b/OneMore/Commands/Styles/PageColorDialog.cs index daed1335f3..91a1731e5f 100644 --- a/OneMore/Commands/Styles/PageColorDialog.cs +++ b/OneMore/Commands/Styles/PageColorDialog.cs @@ -35,7 +35,7 @@ public PageColorDialog() "noLabel", "expander.Title=word_Options", "currentThemeLabel", - "targetBox", + "scopeBox", "loadThemeLink", "applyThemeBox", "okButton=word_OK", @@ -51,7 +51,7 @@ public PageColorDialog() darkMode = Office.IsBlackThemeEnabled(); statusLabel.Text = string.Empty; - targetBox.SelectedIndex = 0; + scopeBox.SelectedIndex = 0; } @@ -150,11 +150,11 @@ public PageColorDialog(Color color, string themeKey) public Color Color { get; private set; } - public OneNote.NodeType Target => targetBox.SelectedIndex switch + public OneNote.Scope Scope => scopeBox.SelectedIndex switch { - 1 => OneNote.NodeType.Section, - 2 => OneNote.NodeType.Notebook, - _ => OneNote.NodeType.Page + 1 => OneNote.Scope.Pages, // Apply to pages in this section + 2 => OneNote.Scope.Sections, // Apply to pages in this notebook + _ => OneNote.Scope.Self // Apply to this page }; @@ -271,9 +271,9 @@ private void ChangeColorOption(object sender, EventArgs e) } - private void ChangeTarget(object sender, EventArgs e) + private void ChangeScope(object sender, EventArgs e) { - var enabled = targetBox.SelectedIndex == 0; + var enabled = scopeBox.SelectedIndex == 0; expander.Enabled = enabled; currentThemeLabel.Enabled = enabled; loadThemeLink.Enabled = enabled; diff --git a/OneMore/OneNote.cs b/OneMore/OneNote.cs index 8b00f601ff..851c355611 100644 --- a/OneMore/OneNote.cs +++ b/OneMore/OneNote.cs @@ -765,7 +765,7 @@ public Page GetPage(string pageId, PageDetail detail = PageDetail.All) return new Page(XElement.Parse(xml)); } } - catch (Exception exc) + catch (Exception exc) when (exc is not ThreadAbortException) { if (FallThrough) { diff --git a/OneMore/Properties/Resources.Designer.cs b/OneMore/Properties/Resources.Designer.cs index dac7386ff4..a9bf3ca081 100644 --- a/OneMore/Properties/Resources.Designer.cs +++ b/OneMore/Properties/Resources.Designer.cs @@ -4466,9 +4466,9 @@ internal static string PageColorDialog_omLabel { ///Apply to this section ///Apply to this notebook. /// - internal static string PageColorDialog_targetBox_Text { + internal static string PageColorDialog_scopeBox_Text { get { - return ResourceManager.GetString("PageColorDialog_targetBox.Text", resourceCulture); + return ResourceManager.GetString("PageColorDialog_scopeBox.Text", resourceCulture); } } diff --git a/OneMore/Properties/Resources.ar-SA.resx b/OneMore/Properties/Resources.ar-SA.resx index 50ae754e24..c2f3d28feb 100644 --- a/OneMore/Properties/Resources.ar-SA.resx +++ b/OneMore/Properties/Resources.ar-SA.resx @@ -1801,7 +1801,7 @@ انقر هنا لتحديد لون محدد مسبقًا label - + تنطبق على هذه الصفحة تنطبق على هذا القسم تنطبق على هذا دفتر الملاحظات diff --git a/OneMore/Properties/Resources.de-DE.resx b/OneMore/Properties/Resources.de-DE.resx index ae541a5b75..e7838ef49a 100644 --- a/OneMore/Properties/Resources.de-DE.resx +++ b/OneMore/Properties/Resources.de-DE.resx @@ -1798,7 +1798,7 @@ Aufgeschoben Klicken Sie hier, um eine vordefinierte Farbe auszuwählen label - + Bewerben Sie sich auf dieser Seite Bewerben Sie sich für diesen Abschnitt Bewerben Sie sich auf dieses Notizbuch diff --git a/OneMore/Properties/Resources.es-ES.resx b/OneMore/Properties/Resources.es-ES.resx index 113514794a..569049d9ab 100644 --- a/OneMore/Properties/Resources.es-ES.resx +++ b/OneMore/Properties/Resources.es-ES.resx @@ -1801,7 +1801,7 @@ Diferido Haga clic aquí para seleccionar un color predefinido label - + Aplicar a esta página Aplicar a esta sección Aplicar a este cuaderno diff --git a/OneMore/Properties/Resources.fr-FR.resx b/OneMore/Properties/Resources.fr-FR.resx index 7130a29592..52fe230fc5 100644 --- a/OneMore/Properties/Resources.fr-FR.resx +++ b/OneMore/Properties/Resources.fr-FR.resx @@ -1798,7 +1798,7 @@ Différé Cliquez ici pour sélectionner une couleur prédéfinie label - + Postuler sur cette page Postuler à cette section Postuler à ce carnet diff --git a/OneMore/Properties/Resources.he-IL.resx b/OneMore/Properties/Resources.he-IL.resx index 985c1bcf46..24dce23125 100644 --- a/OneMore/Properties/Resources.he-IL.resx +++ b/OneMore/Properties/Resources.he-IL.resx @@ -1812,7 +1812,7 @@ Total Row Font לחץ כאן כדי לבחור צבע מוגדר מראש label - + הגש בקשה לדף זה הגש על סעיף זה החל על מחברת זו diff --git a/OneMore/Properties/Resources.nl-NL.resx b/OneMore/Properties/Resources.nl-NL.resx index 50d8c1c9dc..8e00316c1a 100644 --- a/OneMore/Properties/Resources.nl-NL.resx +++ b/OneMore/Properties/Resources.nl-NL.resx @@ -1802,7 +1802,7 @@ Verschoven Klik hier om een ​​voorgedefinieerde kleur te selecteren label - + Solliciteer op deze pagina Toepassen op deze sectie Toepassen op dit notitieboekje diff --git a/OneMore/Properties/Resources.pl-PL.resx b/OneMore/Properties/Resources.pl-PL.resx index d3f65e0938..aa3be7b784 100644 --- a/OneMore/Properties/Resources.pl-PL.resx +++ b/OneMore/Properties/Resources.pl-PL.resx @@ -1810,7 +1810,7 @@ Odroczony Kliknij tutaj, aby wybrać predefiniowany kolor label - + Aplikuj na tę stronę Zastosuj się do tej sekcji Zastosuj do tego notatnika diff --git a/OneMore/Properties/Resources.pt-BR.resx b/OneMore/Properties/Resources.pt-BR.resx index b176d98544..075b37cc74 100644 --- a/OneMore/Properties/Resources.pt-BR.resx +++ b/OneMore/Properties/Resources.pt-BR.resx @@ -1802,7 +1802,7 @@ Diferido Clique aqui para selecionar uma cor pré-definida label - + Inscreva-se nesta página Inscreva-se nesta seção Aplicar a este caderno diff --git a/OneMore/Properties/Resources.resx b/OneMore/Properties/Resources.resx index 2c66b7bb2a..607300be2d 100644 --- a/OneMore/Properties/Resources.resx +++ b/OneMore/Properties/Resources.resx @@ -1828,7 +1828,7 @@ Deferred Click here to select a pre-defined color label - + Apply to this page Apply to this section Apply to this notebook diff --git a/OneMore/Properties/Resources.zh-CN.resx b/OneMore/Properties/Resources.zh-CN.resx index 182a535a41..1913ca8d9a 100644 --- a/OneMore/Properties/Resources.zh-CN.resx +++ b/OneMore/Properties/Resources.zh-CN.resx @@ -1811,7 +1811,7 @@ OneNote 文件 (*.one) 单击此处选择预定义颜色 label - + 申请此页面 适用于本部分 适用于本笔记本 From e63542940ed37320c9532a303fba1629badac87a Mon Sep 17 00:00:00 2001 From: Steven Cohn Date: Sat, 2 Dec 2023 10:12:41 -0500 Subject: [PATCH 3/5] apply theme --- OneMore/Commands/Styles/ApplyStylesCommand.cs | 54 ++++++++++--------- OneMore/Commands/Styles/PageColorCommand.cs | 25 +++++---- .../Styles/PageColorDialog.Designer.cs | 1 - OneMore/Commands/Styles/PageColorDialog.cs | 10 ---- OneMore/Properties/Resources.Designer.cs | 2 +- OneMore/Properties/Resources.ar-SA.resx | 2 +- OneMore/Properties/Resources.de-DE.resx | 2 +- OneMore/Properties/Resources.es-ES.resx | 2 +- OneMore/Properties/Resources.fr-FR.resx | 2 +- OneMore/Properties/Resources.he-IL.resx | 2 +- OneMore/Properties/Resources.nl-NL.resx | 2 +- OneMore/Properties/Resources.pl-PL.resx | 2 +- OneMore/Properties/Resources.pt-BR.resx | 2 +- OneMore/Properties/Resources.resx | 2 +- OneMore/Properties/Resources.zh-CN.resx | 2 +- 15 files changed, 55 insertions(+), 57 deletions(-) diff --git a/OneMore/Commands/Styles/ApplyStylesCommand.cs b/OneMore/Commands/Styles/ApplyStylesCommand.cs index 29d8864e6e..9cd4450e7e 100644 --- a/OneMore/Commands/Styles/ApplyStylesCommand.cs +++ b/OneMore/Commands/Styles/ApplyStylesCommand.cs @@ -26,6 +26,7 @@ internal class ApplyStylesCommand : Command private Page page; private XNamespace ns; + private readonly Theme theme; private readonly Stylizer stylizer; @@ -33,6 +34,7 @@ public ApplyStylesCommand() { // using blank Style just so we have a valid Stylizer stylizer = new Stylizer(new Style()); + theme = new ThemeProvider().Theme; } @@ -44,7 +46,25 @@ public ApplyStylesCommand() public override async Task Execute(params object[] args) { using var one = new OneNote(out page, out ns); - if (ApplyCurrentTheme()) + + // apply theme page color.. + + var changed = false; + if (!string.IsNullOrWhiteSpace(theme.Color)) + { + var cmd = new PageColorCommand(); + cmd.SetLogger(logger); + changed = cmd.UpdatePageColor(page, theme.Color); + } + + // apply theme styles... + + if (ApplyThemeStyles()) + { + changed = true; + } + + if (changed) { await one.Update(page); } @@ -52,23 +72,20 @@ public override async Task Execute(params object[] args) /// - /// Invoked from PageColorCommand + /// Invoked from PageColorCommand. Sets only the theme styles, presuming + /// PageColorCommand has already set the page background color. /// - /// - public void Apply(Page page) + /// The page to modify + public void ApplyTheme(Page page) { this.page = page; ns = page.Namespace; - ApplyCurrentTheme(); + ApplyThemeStyles(); } - private bool ApplyCurrentTheme() + private bool ApplyThemeStyles() { - var theme = new ThemeProvider().Theme; - - var changed = ApplyPageColor(theme.Color); - var styles = theme.GetStyles(); if (ApplyStyles(styles)) { @@ -81,23 +98,10 @@ private bool ApplyCurrentTheme() ApplyToHyperlinks(); } - changed = true; - } - - return changed; - } - - - private bool ApplyPageColor(string color) - { - if (string.IsNullOrWhiteSpace(color)) - { - return false; + return true; } - var cmd = new PageColorCommand(); - cmd.SetLogger(logger); - return cmd.UpdatePageColor(page, color); + return false; } diff --git a/OneMore/Commands/Styles/PageColorCommand.cs b/OneMore/Commands/Styles/PageColorCommand.cs index f8d0b22d45..789179df3e 100644 --- a/OneMore/Commands/Styles/PageColorCommand.cs +++ b/OneMore/Commands/Styles/PageColorCommand.cs @@ -20,6 +20,10 @@ namespace River.OneMoreAddIn.Commands /// internal class PageColorCommand : Command { + private string pageColor; + private ApplyStylesCommand styler; + + public PageColorCommand() { } @@ -44,20 +48,19 @@ public override async Task Execute(params object[] args) return; } - var pageColor = MakePageColor(dialog.Color); + pageColor = MakePageColor(dialog.Color); + + if (dialog.ApplyStyle) + { + ThemeProvider.RecordTheme(dialog.ThemeKey); + styler = new ApplyStylesCommand(); + styler.SetLogger(logger); + } if (dialog.Scope == OneNote.Scope.Self) { UpdatePageColor(page, pageColor); - - if (dialog.ApplyStyle) - { - ThemeProvider.RecordTheme(dialog.ThemeKey); - - var styler = new ApplyStylesCommand(); - styler.SetLogger(logger); - styler.Apply(page); - } + styler?.ApplyTheme(page); using var one = new OneNote(); await one.Update(page); @@ -96,6 +99,8 @@ private async Task ColorPages(OneNote.Scope scope, string pageColor) progress.SetMessage(page.Title); UpdatePageColor(page, pageColor); + styler?.ApplyTheme(page); + if (token.IsCancellationRequested) break; await one.Update(page); diff --git a/OneMore/Commands/Styles/PageColorDialog.Designer.cs b/OneMore/Commands/Styles/PageColorDialog.Designer.cs index 48067b43a3..5f3c34b620 100644 --- a/OneMore/Commands/Styles/PageColorDialog.Designer.cs +++ b/OneMore/Commands/Styles/PageColorDialog.Designer.cs @@ -231,7 +231,6 @@ private void InitializeComponent() this.scopeBox.Name = "scopeBox"; this.scopeBox.Size = new System.Drawing.Size(352, 28); this.scopeBox.TabIndex = 17; - this.scopeBox.SelectedIndexChanged += new System.EventHandler(this.ChangeScope); // // detailPanel // diff --git a/OneMore/Commands/Styles/PageColorDialog.cs b/OneMore/Commands/Styles/PageColorDialog.cs index 91a1731e5f..bea3953953 100644 --- a/OneMore/Commands/Styles/PageColorDialog.cs +++ b/OneMore/Commands/Styles/PageColorDialog.cs @@ -271,16 +271,6 @@ private void ChangeColorOption(object sender, EventArgs e) } - private void ChangeScope(object sender, EventArgs e) - { - var enabled = scopeBox.SelectedIndex == 0; - expander.Enabled = enabled; - currentThemeLabel.Enabled = enabled; - loadThemeLink.Enabled = enabled; - applyThemeBox.Enabled = enabled; - } - - private void LoadTheme(object sender, LinkLabelLinkClickedEventArgs e) { var candidate = new LoadStylesCommand().LoadTheme(); diff --git a/OneMore/Properties/Resources.Designer.cs b/OneMore/Properties/Resources.Designer.cs index a9bf3ca081..7d46026cde 100644 --- a/OneMore/Properties/Resources.Designer.cs +++ b/OneMore/Properties/Resources.Designer.cs @@ -4390,7 +4390,7 @@ internal static string OutlookTaskReport_Week { } /// - /// Looks up a localized string similar to Apply styles to this page. + /// Looks up a localized string similar to Apply styles and page color. /// internal static string PageColorDialog_applyThemeBox_Text { get { diff --git a/OneMore/Properties/Resources.ar-SA.resx b/OneMore/Properties/Resources.ar-SA.resx index c2f3d28feb..a8a2839adb 100644 --- a/OneMore/Properties/Resources.ar-SA.resx +++ b/OneMore/Properties/Resources.ar-SA.resx @@ -1770,7 +1770,7 @@ color popup dialog title - تطبيق الأنماط على هذه الصفحة + تطبيق الأنماط ولون الصفحة checkbox diff --git a/OneMore/Properties/Resources.de-DE.resx b/OneMore/Properties/Resources.de-DE.resx index e7838ef49a..f9df5483a6 100644 --- a/OneMore/Properties/Resources.de-DE.resx +++ b/OneMore/Properties/Resources.de-DE.resx @@ -1767,7 +1767,7 @@ Aufgeschoben color popup dialog title - Wenden Sie Stile auf diese Seite an + Wenden Sie Stile und Seitenfarben an checkbox diff --git a/OneMore/Properties/Resources.es-ES.resx b/OneMore/Properties/Resources.es-ES.resx index 569049d9ab..fb0bf97a08 100644 --- a/OneMore/Properties/Resources.es-ES.resx +++ b/OneMore/Properties/Resources.es-ES.resx @@ -1770,7 +1770,7 @@ Diferido color popup dialog title - Aplicar estilos a esta página + Aplicar estilos y color de página. checkbox diff --git a/OneMore/Properties/Resources.fr-FR.resx b/OneMore/Properties/Resources.fr-FR.resx index 52fe230fc5..5eb0357d94 100644 --- a/OneMore/Properties/Resources.fr-FR.resx +++ b/OneMore/Properties/Resources.fr-FR.resx @@ -1767,7 +1767,7 @@ Différé color popup dialog title - Appliquer des styles à cette page + Appliquer des styles et des couleurs de page checkbox diff --git a/OneMore/Properties/Resources.he-IL.resx b/OneMore/Properties/Resources.he-IL.resx index 24dce23125..2d61433a4d 100644 --- a/OneMore/Properties/Resources.he-IL.resx +++ b/OneMore/Properties/Resources.he-IL.resx @@ -1781,7 +1781,7 @@ Total Row Font color popup dialog title - החל סגנונות על דף זה + החל סגנונות וצבע עמוד checkbox diff --git a/OneMore/Properties/Resources.nl-NL.resx b/OneMore/Properties/Resources.nl-NL.resx index 8e00316c1a..f62f5ae3ef 100644 --- a/OneMore/Properties/Resources.nl-NL.resx +++ b/OneMore/Properties/Resources.nl-NL.resx @@ -1771,7 +1771,7 @@ Verschoven color popup dialog title - Pas stijlen toe op deze pagina + Pas stijlen en paginakleur toe checkbox diff --git a/OneMore/Properties/Resources.pl-PL.resx b/OneMore/Properties/Resources.pl-PL.resx index aa3be7b784..e826593eaf 100644 --- a/OneMore/Properties/Resources.pl-PL.resx +++ b/OneMore/Properties/Resources.pl-PL.resx @@ -1779,7 +1779,7 @@ Odroczony color popup dialog title - Zastosuj style do tej strony + Zastosuj style i kolor strony checkbox diff --git a/OneMore/Properties/Resources.pt-BR.resx b/OneMore/Properties/Resources.pt-BR.resx index 075b37cc74..89f72a9899 100644 --- a/OneMore/Properties/Resources.pt-BR.resx +++ b/OneMore/Properties/Resources.pt-BR.resx @@ -1771,7 +1771,7 @@ Diferido color popup dialog title - Aplicar estilos a esta página + Aplicar estilos e cores de página checkbox diff --git a/OneMore/Properties/Resources.resx b/OneMore/Properties/Resources.resx index 607300be2d..e2e88d2bf1 100644 --- a/OneMore/Properties/Resources.resx +++ b/OneMore/Properties/Resources.resx @@ -1797,7 +1797,7 @@ Deferred dialog title - Apply styles to this page + Apply styles and page color checkbox diff --git a/OneMore/Properties/Resources.zh-CN.resx b/OneMore/Properties/Resources.zh-CN.resx index 1913ca8d9a..186b6882be 100644 --- a/OneMore/Properties/Resources.zh-CN.resx +++ b/OneMore/Properties/Resources.zh-CN.resx @@ -1780,7 +1780,7 @@ OneNote 文件 (*.one) color popup dialog title - 将样式应用于此页面 + 应用样式和页面颜色 checkbox From 1c921f8829f076cb00a222908afdd617b8b559ba Mon Sep 17 00:00:00 2001 From: Steven Cohn Date: Sat, 2 Dec 2023 10:15:29 -0500 Subject: [PATCH 4/5] clean --- OneMore/UI/MoreExpander.cs | 1 - 1 file changed, 1 deletion(-) diff --git a/OneMore/UI/MoreExpander.cs b/OneMore/UI/MoreExpander.cs index 85b7654243..2b434e5921 100644 --- a/OneMore/UI/MoreExpander.cs +++ b/OneMore/UI/MoreExpander.cs @@ -4,7 +4,6 @@ namespace River.OneMoreAddIn.UI { - using System; using System.ComponentModel; using System.Drawing; using System.Windows.Forms; From 81fadefd4c45159eb0421e487ba4923f514698b5 Mon Sep 17 00:00:00 2001 From: Steven Cohn Date: Sat, 2 Dec 2023 10:16:47 -0500 Subject: [PATCH 5/5] clean --- OneMore/Commands/Styles/PageColorDialog.cs | 1 - 1 file changed, 1 deletion(-) diff --git a/OneMore/Commands/Styles/PageColorDialog.cs b/OneMore/Commands/Styles/PageColorDialog.cs index bea3953953..71165cea06 100644 --- a/OneMore/Commands/Styles/PageColorDialog.cs +++ b/OneMore/Commands/Styles/PageColorDialog.cs @@ -45,7 +45,6 @@ public PageColorDialog() VerticalOffset = -(Height / 3); Height -= optionsPanel.Height; - //detailPanel.Height -= optionsPanel.Height; optionsPanel.Height = 0; optionsAvailable = true;