ファイル

43 行
1.2 KiB
C#

using System.Windows;
namespace UndoTree;
internal static class UndoTreeDispatch
{
public static void Post(Action action)
{
if (Application.Current is { } application && !application.Dispatcher.CheckAccess())
{
application.Dispatcher.InvokeAsync(action);
return;
}
action();
}
public static void Defer(Action action)
{
if (Application.Current is { } application)
application.Dispatcher.InvokeAsync(action);
else
action();
}
public static bool Confirm(string message)
=> Application.Current is null || MessageBox.Show(message, Texts.UndoTree, MessageBoxButton.YesNo, MessageBoxImage.Warning) == MessageBoxResult.Yes;
public static bool Review(UndoTreePlan plan)
{
if (Application.Current is not { } application)
return true;
var window = new UndoTreeReviewWindow(new UndoTreeReviewViewModel(plan));
if (application.MainWindow is { IsVisible: true } owner)
window.Owner = owner;
else
window.WindowStartupLocation = WindowStartupLocation.CenterScreen;
return window.ShowDialog() == true;
}
}