From 97e3f630c88f484d2345ff39d54ba8a52ef9459c Mon Sep 17 00:00:00 2001 From: rampaa Date: Fri, 21 Jul 2023 10:54:45 +0300 Subject: [PATCH] Minor refactor --- JL.Windows/GUI/MainWindow.xaml.cs | 15 ++------------- JL.Windows/GUI/PopupWindow.xaml.cs | 9 +-------- JL.Windows/Utilities/WindowsUtils.cs | 12 ++++++++++++ 3 files changed, 15 insertions(+), 21 deletions(-) diff --git a/JL.Windows/GUI/MainWindow.xaml.cs b/JL.Windows/GUI/MainWindow.xaml.cs index 4896abd3..e6561777 100644 --- a/JL.Windows/GUI/MainWindow.xaml.cs +++ b/JL.Windows/GUI/MainWindow.xaml.cs @@ -178,7 +178,7 @@ private void HandlePostCopy(string text) BacklogUtils.AddToBacklog(text); - HidePopups(); + WindowsUtils.HidePopups(FirstPopupWindow); Stats.IncrementStat(StatType.Lines); Stats.IncrementStat(StatType.Characters, new StringInfo(JapaneseUtils.RemovePunctuation(text)).LengthInTextElements); @@ -915,18 +915,7 @@ private void Window_PreviewMouseDown(object sender, MouseButtonEventArgs e) } else { - HidePopups(); - } - } - - private void HidePopups() - { - PopupWindow? currentPopupWindow = FirstPopupWindow; - - while (currentPopupWindow?.IsVisible ?? false) - { - currentPopupWindow.HidePopup(); - currentPopupWindow = currentPopupWindow.ChildPopupWindow; + WindowsUtils.HidePopups(FirstPopupWindow); } } diff --git a/JL.Windows/GUI/PopupWindow.xaml.cs b/JL.Windows/GUI/PopupWindow.xaml.cs index 005b9200..bb6642ec 100644 --- a/JL.Windows/GUI/PopupWindow.xaml.cs +++ b/JL.Windows/GUI/PopupWindow.xaml.cs @@ -1766,14 +1766,7 @@ private void Window_ContextMenuOpening(object sender, ContextMenuEventArgs e) private void Window_PreviewMouseDown(object sender, MouseButtonEventArgs e) { - PopupWindow? childPopupWindow = ChildPopupWindow; - - while (childPopupWindow?.IsVisible ?? false) - { - childPopupWindow.HidePopup(); - - childPopupWindow = childPopupWindow.ChildPopupWindow; - } + WindowsUtils.HidePopups(ChildPopupWindow); } public void HidePopup() diff --git a/JL.Windows/Utilities/WindowsUtils.cs b/JL.Windows/Utilities/WindowsUtils.cs index 80a8d65a..d71afddc 100644 --- a/JL.Windows/Utilities/WindowsUtils.cs +++ b/JL.Windows/Utilities/WindowsUtils.cs @@ -23,6 +23,7 @@ using NAudio.Wave; using Application = System.Windows.Application; using Button = System.Windows.Controls.Button; +using PopupWindow = JL.Windows.GUI.PopupWindow; using Window = System.Windows.Window; namespace JL.Windows.Utilities; @@ -572,6 +573,17 @@ public static void SetSizeToContent(bool dynamicWidth, bool dynamicHeight, Windo } } + public static void HidePopups(PopupWindow? rootPopup) + { + PopupWindow? currentPopupWindow = rootPopup; + + while (currentPopupWindow?.IsVisible ?? false) + { + currentPopupWindow.HidePopup(); + currentPopupWindow = currentPopupWindow.ChildPopupWindow; + } + } + public static void CopyTextToClipboard(string? text) { if (string.IsNullOrEmpty(text))