2024-02-05 23:08:37 -08:00
|
|
|
|
using CommunityToolkit.Mvvm.ComponentModel;
|
|
|
|
|
|
2024-03-17 18:37:06 -07:00
|
|
|
|
namespace SourceGit.ViewModels
|
|
|
|
|
{
|
|
|
|
|
public class PopupHost : ObservableObject
|
|
|
|
|
{
|
|
|
|
|
public static PopupHost Active
|
|
|
|
|
{
|
2024-02-05 23:08:37 -08:00
|
|
|
|
get;
|
|
|
|
|
set;
|
|
|
|
|
} = null;
|
|
|
|
|
|
2024-03-17 18:37:06 -07:00
|
|
|
|
public Popup Popup
|
|
|
|
|
{
|
2024-02-05 23:08:37 -08:00
|
|
|
|
get => _popup;
|
|
|
|
|
set => SetProperty(ref _popup, value);
|
|
|
|
|
}
|
|
|
|
|
|
2024-03-17 18:37:06 -07:00
|
|
|
|
public static bool CanCreatePopup()
|
|
|
|
|
{
|
2024-02-05 23:08:37 -08:00
|
|
|
|
return Active != null && (Active._popup == null || !Active._popup.InProgress);
|
|
|
|
|
}
|
|
|
|
|
|
2024-03-17 18:37:06 -07:00
|
|
|
|
public static void ShowPopup(Popup popup)
|
|
|
|
|
{
|
2024-02-05 23:08:37 -08:00
|
|
|
|
popup.HostPageId = Active.GetId();
|
|
|
|
|
Active.Popup = popup;
|
|
|
|
|
}
|
|
|
|
|
|
2024-03-17 18:37:06 -07:00
|
|
|
|
public static void ShowAndStartPopup(Popup popup)
|
|
|
|
|
{
|
2024-03-05 01:15:09 -08:00
|
|
|
|
var dumpPage = Active;
|
|
|
|
|
popup.HostPageId = dumpPage.GetId();
|
|
|
|
|
dumpPage.Popup = popup;
|
|
|
|
|
dumpPage.ProcessPopup();
|
2024-02-05 23:08:37 -08:00
|
|
|
|
}
|
|
|
|
|
|
2024-03-17 18:37:06 -07:00
|
|
|
|
public virtual string GetId()
|
|
|
|
|
{
|
2024-02-05 23:08:37 -08:00
|
|
|
|
return string.Empty;
|
|
|
|
|
}
|
|
|
|
|
|
2024-03-17 18:37:06 -07:00
|
|
|
|
public async void ProcessPopup()
|
|
|
|
|
{
|
|
|
|
|
if (_popup != null)
|
|
|
|
|
{
|
2024-02-05 23:08:37 -08:00
|
|
|
|
if (!_popup.Check()) return;
|
|
|
|
|
|
|
|
|
|
_popup.InProgress = true;
|
|
|
|
|
var task = _popup.Sure();
|
2024-03-17 18:37:06 -07:00
|
|
|
|
if (task != null)
|
|
|
|
|
{
|
2024-02-05 23:08:37 -08:00
|
|
|
|
var finished = await task;
|
2024-03-17 18:37:06 -07:00
|
|
|
|
if (finished)
|
|
|
|
|
{
|
2024-02-05 23:08:37 -08:00
|
|
|
|
Popup = null;
|
2024-03-17 18:37:06 -07:00
|
|
|
|
}
|
|
|
|
|
else
|
|
|
|
|
{
|
2024-02-05 23:08:37 -08:00
|
|
|
|
_popup.InProgress = false;
|
|
|
|
|
}
|
2024-03-17 18:37:06 -07:00
|
|
|
|
}
|
|
|
|
|
else
|
|
|
|
|
{
|
2024-02-05 23:08:37 -08:00
|
|
|
|
Popup = null;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2024-03-17 18:37:06 -07:00
|
|
|
|
public void CancelPopup()
|
|
|
|
|
{
|
2024-02-05 23:08:37 -08:00
|
|
|
|
if (_popup == null) return;
|
|
|
|
|
if (_popup.InProgress) return;
|
|
|
|
|
Popup = null;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
private Popup _popup = null;
|
|
|
|
|
}
|
2024-03-17 18:37:06 -07:00
|
|
|
|
}
|