Skip to content

Commit

Permalink
add settings option to reset legacy tag converter state
Browse files Browse the repository at this point in the history
  • Loading branch information
stevencohn committed Jul 21, 2024
1 parent 63cf046 commit 7873ce9
Show file tree
Hide file tree
Showing 4 changed files with 92 additions and 27 deletions.
69 changes: 49 additions & 20 deletions OneMore/Commands/Settings/HashtagSheet.Designer.cs

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

19 changes: 18 additions & 1 deletion OneMore/Commands/Settings/HashtagSheet.cs
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,7 @@ public HashtagSheet(SettingsProvider provider) : base(provider)
"scheduleLink",
"warningBox",
"upgradeLink",
"resetLink=word_Reset",
"disabledBox"
});
}
Expand Down Expand Up @@ -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;
}


Expand All @@ -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...
Expand Down
3 changes: 3 additions & 0 deletions OneMore/Commands/Settings/HashtagSheet.resx
Original file line number Diff line number Diff line change
Expand Up @@ -117,4 +117,7 @@
<resheader name="writer">
<value>System.Resources.ResXResourceWriter, System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089</value>
</resheader>
<metadata name="tooltip.TrayLocation" type="System.Drawing.Point, System.Drawing, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a">
<value>17, 17</value>
</metadata>
</root>
28 changes: 22 additions & 6 deletions OneMore/Commands/Tagging/LegacyTaggingConverter.cs
Original file line number Diff line number Diff line change
Expand Up @@ -53,15 +53,19 @@ internal class LegacyTaggingConverter : Loggable
/// <returns>True if tags are or have been upgraded, otherwise false.</returns>
public async Task<bool> 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)
Expand Down Expand Up @@ -103,8 +107,12 @@ public async Task<bool> UpgradeLegacyTags(IWin32Window owner)

public async Task<bool> NeedsConversion()
{
var provider = new SettingsProvider();
var settings = provider.GetCollection("tagging");
return await NeedsConversion(new SettingsProvider().GetCollection("tagging"));
}


private async Task<bool> NeedsConversion(SettingsCollection settings)
{
if (settings.Get("converted", false))
{
return false;
Expand Down Expand Up @@ -249,5 +257,13 @@ private async Task<bool> UpgradeLegacyTags(ProgressDialog dialog, CancellationTo

return !token.IsCancellationRequested;
}


public static void ResetUpgradeCheck()
{
var provider = new SettingsProvider();
provider.RemoveCollection("tagging");
provider.Save();
}
}
}

0 comments on commit 7873ce9

Please sign in to comment.