From 7873ce9bc90eeae47bf84540dcd4fd87ec9a9e39 Mon Sep 17 00:00:00 2001 From: Steven Cohn Date: Sat, 20 Jul 2024 21:54:46 -0400 Subject: [PATCH] add settings option to reset legacy tag converter state --- .../Settings/HashtagSheet.Designer.cs | 69 +++++++++++++------ OneMore/Commands/Settings/HashtagSheet.cs | 19 ++++- OneMore/Commands/Settings/HashtagSheet.resx | 3 + .../Tagging/LegacyTaggingConverter.cs | 28 ++++++-- 4 files changed, 92 insertions(+), 27 deletions(-) diff --git a/OneMore/Commands/Settings/HashtagSheet.Designer.cs b/OneMore/Commands/Settings/HashtagSheet.Designer.cs index 615aede0b2..c06aea1380 100644 --- a/OneMore/Commands/Settings/HashtagSheet.Designer.cs +++ b/OneMore/Commands/Settings/HashtagSheet.Designer.cs @@ -29,11 +29,14 @@ protected override void Dispose(bool disposing) /// private void InitializeComponent() { + this.components = new System.ComponentModel.Container(); this.introBox = new River.OneMoreAddIn.UI.MoreMultilineLabel(); this.intervalLabel = new System.Windows.Forms.Label(); this.intervalBox = new System.Windows.Forms.NumericUpDown(); this.minLabel = new System.Windows.Forms.Label(); this.advancedGroup = new River.OneMoreAddIn.UI.MoreGroupBox(); + this.resetLink = new River.OneMoreAddIn.UI.MoreLinkLabel(); + this.upgradeLink = new River.OneMoreAddIn.UI.MoreLinkLabel(); this.warningLabel = new River.OneMoreAddIn.UI.MoreMultilineLabel(); this.scheduleLink = new River.OneMoreAddIn.UI.MoreLinkLabel(); this.disabledBox = new River.OneMoreAddIn.UI.MoreCheckBox(); @@ -44,7 +47,7 @@ private void InitializeComponent() this.delayBox = new System.Windows.Forms.NumericUpDown(); this.msLabel = new System.Windows.Forms.Label(); this.layoutPanel = new System.Windows.Forms.Panel(); - this.upgradeLink = new River.OneMoreAddIn.UI.MoreLinkLabel(); + this.tooltip = new System.Windows.Forms.ToolTip(this.components); ((System.ComponentModel.ISupportInitialize)(this.intervalBox)).BeginInit(); this.advancedGroup.SuspendLayout(); ((System.ComponentModel.ISupportInitialize)(this.delayBox)).BeginInit(); @@ -109,6 +112,7 @@ private void InitializeComponent() // this.advancedGroup.Anchor = ((System.Windows.Forms.AnchorStyles)(((System.Windows.Forms.AnchorStyles.Top | System.Windows.Forms.AnchorStyles.Left) | System.Windows.Forms.AnchorStyles.Right))); + this.advancedGroup.Controls.Add(this.resetLink); this.advancedGroup.Controls.Add(this.upgradeLink); this.advancedGroup.Controls.Add(this.warningLabel); this.advancedGroup.Controls.Add(this.scheduleLink); @@ -120,6 +124,48 @@ private void InitializeComponent() this.advancedGroup.TabIndex = 6; this.advancedGroup.TabStop = false; this.advancedGroup.Text = "Advanced Options"; + this.advancedGroup.ThemedBorder = null; + this.advancedGroup.ThemedFore = null; + // + // resetLink + // + this.resetLink.ActiveLinkColor = System.Drawing.Color.MediumOrchid; + this.resetLink.AutoSize = true; + this.resetLink.Cursor = System.Windows.Forms.Cursors.Hand; + this.resetLink.HoverColor = System.Drawing.Color.Orchid; + this.resetLink.LinkColor = System.Drawing.Color.MediumOrchid; + this.resetLink.Location = new System.Drawing.Point(522, 144); + this.resetLink.Name = "resetLink"; + this.resetLink.Size = new System.Drawing.Size(52, 20); + this.resetLink.StrictColors = false; + this.resetLink.TabIndex = 4; + this.resetLink.TabStop = true; + this.resetLink.Text = "Reset"; + this.resetLink.ThemedBack = null; + this.resetLink.ThemedFore = null; + this.tooltip.SetToolTip(this.resetLink, "Advanced: reset the upgrade flag"); + this.resetLink.Visible = false; + this.resetLink.VisitedLinkColor = System.Drawing.Color.MediumOrchid; + this.resetLink.LinkClicked += new System.Windows.Forms.LinkLabelLinkClickedEventHandler(this.ResetUpgradeCheck); + // + // upgradeLink + // + this.upgradeLink.ActiveLinkColor = System.Drawing.Color.MediumOrchid; + this.upgradeLink.AutoSize = true; + this.upgradeLink.Cursor = System.Windows.Forms.Cursors.Hand; + this.upgradeLink.HoverColor = System.Drawing.Color.Orchid; + this.upgradeLink.LinkColor = System.Drawing.Color.MediumOrchid; + this.upgradeLink.Location = new System.Drawing.Point(18, 144); + this.upgradeLink.Name = "upgradeLink"; + this.upgradeLink.Size = new System.Drawing.Size(274, 20); + this.upgradeLink.StrictColors = false; + this.upgradeLink.TabIndex = 3; + this.upgradeLink.TabStop = true; + this.upgradeLink.Text = "Upgrade page tags to inline hashtags"; + this.upgradeLink.ThemedBack = null; + this.upgradeLink.ThemedFore = null; + this.upgradeLink.VisitedLinkColor = System.Drawing.Color.MediumOrchid; + this.upgradeLink.LinkClicked += new System.Windows.Forms.LinkLabelLinkClickedEventHandler(this.UpgradeTags); // // warningLabel // @@ -254,25 +300,6 @@ private void InitializeComponent() this.layoutPanel.Size = new System.Drawing.Size(772, 476); this.layoutPanel.TabIndex = 4; // - // upgradeLink - // - this.upgradeLink.ActiveLinkColor = System.Drawing.Color.MediumOrchid; - this.upgradeLink.AutoSize = true; - this.upgradeLink.Cursor = System.Windows.Forms.Cursors.Hand; - this.upgradeLink.HoverColor = System.Drawing.Color.Orchid; - this.upgradeLink.LinkColor = System.Drawing.Color.MediumOrchid; - this.upgradeLink.Location = new System.Drawing.Point(18, 144); - this.upgradeLink.Name = "upgradeLink"; - this.upgradeLink.Size = new System.Drawing.Size(274, 20); - this.upgradeLink.StrictColors = false; - this.upgradeLink.TabIndex = 3; - this.upgradeLink.TabStop = true; - this.upgradeLink.Text = "Upgrade page tags to inline hashtags"; - this.upgradeLink.ThemedBack = null; - this.upgradeLink.ThemedFore = null; - this.upgradeLink.VisitedLinkColor = System.Drawing.Color.MediumOrchid; - this.upgradeLink.LinkClicked += new System.Windows.Forms.LinkLabelLinkClickedEventHandler(this.UpgradeTags); - // // HashtagSheet // this.AutoScaleDimensions = new System.Drawing.SizeF(9F, 20F); @@ -312,5 +339,7 @@ private void InitializeComponent() private UI.MoreMultilineLabel warningLabel; private UI.MoreLinkLabel scheduleLink; private UI.MoreLinkLabel upgradeLink; + private UI.MoreLinkLabel resetLink; + private System.Windows.Forms.ToolTip tooltip; } } diff --git a/OneMore/Commands/Settings/HashtagSheet.cs b/OneMore/Commands/Settings/HashtagSheet.cs index ccc304ba8a..ff45df5032 100644 --- a/OneMore/Commands/Settings/HashtagSheet.cs +++ b/OneMore/Commands/Settings/HashtagSheet.cs @@ -36,6 +36,7 @@ public HashtagSheet(SettingsProvider provider) : base(provider) "scheduleLink", "warningBox", "upgradeLink", + "resetLink=word_Reset", "disabledBox" }); } @@ -94,7 +95,9 @@ protected override async void OnLoad(EventArgs e) base.OnLoad(e); var converter = new LegacyTaggingConverter(); - upgradeLink.Enabled = await converter.NeedsConversion(); + var needsConversion = await converter.NeedsConversion(); + upgradeLink.Enabled = needsConversion; + resetLink.Visible = !needsConversion; } @@ -116,10 +119,24 @@ private async void UpgradeTags(object sender, LinkLabelLinkClickedEventArgs e) if (upgraded) { upgradeLink.Enabled = false; + resetLink.Visible = true; } } + private void ResetUpgradeCheck(object sender, LinkLabelLinkClickedEventArgs e) + { + // this will save settings.xml + LegacyTaggingConverter.ResetUpgradeCheck(); + + // now update local in-memory copy of settings + provider.RemoveCollection("tagging"); + + upgradeLink.Enabled = true; + resetLink.Visible = false; + } + + public override bool CollectSettings() { // general... diff --git a/OneMore/Commands/Settings/HashtagSheet.resx b/OneMore/Commands/Settings/HashtagSheet.resx index 1af7de150c..023cd0c7dc 100644 --- a/OneMore/Commands/Settings/HashtagSheet.resx +++ b/OneMore/Commands/Settings/HashtagSheet.resx @@ -117,4 +117,7 @@ System.Resources.ResXResourceWriter, System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089 + + 17, 17 + \ No newline at end of file diff --git a/OneMore/Commands/Tagging/LegacyTaggingConverter.cs b/OneMore/Commands/Tagging/LegacyTaggingConverter.cs index ddff25777b..ce04686adc 100644 --- a/OneMore/Commands/Tagging/LegacyTaggingConverter.cs +++ b/OneMore/Commands/Tagging/LegacyTaggingConverter.cs @@ -53,15 +53,19 @@ internal class LegacyTaggingConverter : Loggable /// True if tags are or have been upgraded, otherwise false. public async Task UpgradeLegacyTags(IWin32Window owner) { - if (!await NeedsConversion()) + var provider = new SettingsProvider(); + var settings = provider.GetCollection("tagging"); + + if (!await NeedsConversion(settings)) { + settings.Add("converted", true); + provider.SetCollection(settings); + provider.Save(); + Converted = true; return false; } - var provider = new SettingsProvider(); - var settings = provider.GetCollection("tagging"); - using var ltdialog = new LegacyTaggingDialog(); if (ltdialog.ShowDialog(owner) == DialogResult.OK) @@ -103,8 +107,12 @@ public async Task UpgradeLegacyTags(IWin32Window owner) public async Task NeedsConversion() { - var provider = new SettingsProvider(); - var settings = provider.GetCollection("tagging"); + return await NeedsConversion(new SettingsProvider().GetCollection("tagging")); + } + + + private async Task NeedsConversion(SettingsCollection settings) + { if (settings.Get("converted", false)) { return false; @@ -249,5 +257,13 @@ private async Task UpgradeLegacyTags(ProgressDialog dialog, CancellationTo return !token.IsCancellationRequested; } + + + public static void ResetUpgradeCheck() + { + var provider = new SettingsProvider(); + provider.RemoveCollection("tagging"); + provider.Save(); + } } }