Skip to content

Commit

Permalink
Merge pull request #1232 from stevencohn/1228-singleton-dialog
Browse files Browse the repository at this point in the history
Allow only single instance of HashtagDialog
  • Loading branch information
stevencohn authored Dec 21, 2023
2 parents 78d2e55 + f49397b commit 35de45c
Showing 1 changed file with 22 additions and 1 deletion.
23 changes: 22 additions & 1 deletion OneMore/Commands/Tagging/HashtagCommand.cs
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,8 @@ internal class HashtagCommand : Command
private HashtagDialog.Commands command;
private IEnumerable<string> pageIds;

private static HashtagDialog dialog;

public HashtagCommand()
{
// prevent replay
Expand All @@ -25,7 +27,17 @@ public HashtagCommand()

public override async Task Execute(params object[] args)
{
using var dialog = new HashtagDialog();
if (dialog != null)
{
logger.WriteLine("+++ dialog exists");
dialog.ForceTopMost();
dialog.Activate();
dialog.TopMost = false;
return;
}

dialog = new HashtagDialog();
dialog.FormClosed += Dialog_FormClosed;

await dialog.RunModeless((sender, e) =>
{
Expand All @@ -46,6 +58,15 @@ await dialog.RunModeless((sender, e) =>
20);
}

private void Dialog_FormClosed(object sender, FormClosedEventArgs e)
{
if (dialog != null)
{
dialog.FormClosed -= Dialog_FormClosed;
dialog.Dispose();
dialog = null;
}
}

private async Task Callback(string sectionId)
{
Expand Down

0 comments on commit 35de45c

Please sign in to comment.