inhibit logout/shutdown if there are unsaved documents

This commit is contained in:
Michael Becker 2021-05-16 07:07:12 -04:00
parent a1c879975a
commit dcdfd4c8b8
No known key found for this signature in database
GPG Key ID: 98C333A81F18C22C

View File

@ -196,6 +196,7 @@ namespace UniversalEditor.UserInterface
{
Layout = new BoxLayout(Orientation.Vertical);
this.IconName = "universal-editor";
LogoutInhibitor = new Inhibitor(InhibitorType.SystemLogout, "There are unsaved documents", this);
this.CommandDisplayMode = CommandDisplayMode.CommandBar;
@ -1041,6 +1042,9 @@ namespace UniversalEditor.UserInterface
OpenFile(documents);
}
private Inhibitor LogoutInhibitor = null;
private int logoutInhibitorI = 0;
public void OpenFile(params Document[] documents)
{
foreach (Document doc in documents)
@ -1049,6 +1053,12 @@ namespace UniversalEditor.UserInterface
{
InitEditorPage(doc);
if (logoutInhibitorI == 0)
{
(Application.Instance as UIApplication).Inhibitors.Add(LogoutInhibitor);
}
logoutInhibitorI++;
if (doc == null)
continue;
@ -1439,6 +1449,12 @@ namespace UniversalEditor.UserInterface
dckContainer.Items.Remove(dw);
documentWindowCount--;
logoutInhibitorI--;
if (logoutInhibitorI == 0)
{
(Application.Instance as UIApplication).Inhibitors.Remove(LogoutInhibitor);
}
if (documentWindowCount == 0)
{
CloseWindow ();