Skip to content

Commit

Permalink
Minor refactor
Browse files Browse the repository at this point in the history
  • Loading branch information
rampaa committed Jul 21, 2023
1 parent 58a59ac commit 97e3f63
Show file tree
Hide file tree
Showing 3 changed files with 15 additions and 21 deletions.
15 changes: 2 additions & 13 deletions JL.Windows/GUI/MainWindow.xaml.cs
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down Expand Up @@ -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);
}
}

Expand Down
9 changes: 1 addition & 8 deletions JL.Windows/GUI/PopupWindow.xaml.cs
Original file line number Diff line number Diff line change
Expand Up @@ -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()
Expand Down
12 changes: 12 additions & 0 deletions JL.Windows/Utilities/WindowsUtils.cs
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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))
Expand Down

0 comments on commit 97e3f63

Please sign in to comment.