From 7ed7de250d295cf23e4f3d6a69cb091fc26fe715 Mon Sep 17 00:00:00 2001 From: Steven Cohn Date: Thu, 21 Dec 2023 07:46:52 -0500 Subject: [PATCH] Allow only single instance of HashtagDialog #1228 --- OneMore/Commands/Tagging/HashtagCommand.cs | 23 +++++++++++++++++++++- 1 file changed, 22 insertions(+), 1 deletion(-) diff --git a/OneMore/Commands/Tagging/HashtagCommand.cs b/OneMore/Commands/Tagging/HashtagCommand.cs index f758536bff..3fc959fd9a 100644 --- a/OneMore/Commands/Tagging/HashtagCommand.cs +++ b/OneMore/Commands/Tagging/HashtagCommand.cs @@ -16,6 +16,8 @@ internal class HashtagCommand : Command private HashtagDialog.Commands command; private IEnumerable pageIds; + private static HashtagDialog dialog; + public HashtagCommand() { // prevent replay @@ -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) => { @@ -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) {