Skip to content

Commit

Permalink
Allow only single instance of HashtagDialog
Browse files Browse the repository at this point in the history
  • Loading branch information
stevencohn authored and weissm committed Dec 22, 2023
1 parent 28a260c commit 9de2223
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 9de2223

Please sign in to comment.