1
0
mirror of synced 2024-11-30 18:24:39 +01:00

Add notifcation on application close to prevent accidental loss of progress.

This commit is contained in:
KillzXGaming 2020-11-06 18:54:10 -05:00
parent cc4d1c7933
commit 4fed7876e4
7 changed files with 275 additions and 3 deletions

View File

@ -317,6 +317,9 @@ namespace Toolbox.Library
case "KCLUsePresetEditor":
bool.TryParse(node.InnerText, out Runtime.CollisionSettings.KCLUsePresetEditor);
break;
case "ShowCloseDialog":
bool.TryParse(node.InnerText, out Runtime.ShowCloseDialog);
break;
}
}
@ -482,6 +485,7 @@ namespace Toolbox.Library
mainSettingsNode.AppendChild(createNode(doc, "EnableVersionCheck", Runtime.EnableVersionCheck.ToString()));
mainSettingsNode.AppendChild(createNode(doc, "FormTheme", Toolbox.Library.Forms.FormThemes.ActivePreset.ToString()));
mainSettingsNode.AppendChild(createNode(doc, "MaximizeMdiWindow", Runtime.MaximizeMdiWindow.ToString()));
mainSettingsNode.AppendChild(createNode(doc, "ShowCloseDialog", Runtime.ShowCloseDialog.ToString()));
}
private static void AppendImageEditorSettings(XmlDocument doc, XmlNode parentNode)
{

View File

@ -40,6 +40,8 @@ namespace Toolbox.Library
public static string TpGamePath = "";
public static string BotwGamePath = "";
public static bool ShowCloseDialog = true;
public class UVEditor
{
public static Color UVColor = Color.FromArgb(255, 128, 0);

View File

@ -0,0 +1,101 @@
namespace Toolbox
{
partial class ApplicationCloseDialog
{
/// <summary>
/// Required designer variable.
/// </summary>
private System.ComponentModel.IContainer components = null;
/// <summary>
/// Clean up any resources being used.
/// </summary>
/// <param name="disposing">true if managed resources should be disposed; otherwise, false.</param>
protected override void Dispose(bool disposing)
{
if (disposing && (components != null))
{
components.Dispose();
}
base.Dispose(disposing);
}
#region Windows Form Designer generated code
/// <summary>
/// Required method for Designer support - do not modify
/// the contents of this method with the code editor.
/// </summary>
private void InitializeComponent()
{
this.label1 = new System.Windows.Forms.Label();
this.button1 = new System.Windows.Forms.Button();
this.button2 = new System.Windows.Forms.Button();
this.chkHideDialog = new System.Windows.Forms.CheckBox();
this.SuspendLayout();
//
// label1
//
this.label1.AutoSize = true;
this.label1.Location = new System.Drawing.Point(22, 20);
this.label1.MaximumSize = new System.Drawing.Size(300, 40);
this.label1.Name = "label1";
this.label1.Size = new System.Drawing.Size(286, 26);
this.label1.TabIndex = 0;
this.label1.Text = "Are you sure you want to close the program? You may lose unsaved progress!";
//
// button1
//
this.button1.DialogResult = System.Windows.Forms.DialogResult.Cancel;
this.button1.Location = new System.Drawing.Point(250, 76);
this.button1.Name = "button1";
this.button1.Size = new System.Drawing.Size(75, 23);
this.button1.TabIndex = 1;
this.button1.Text = "Cancel";
this.button1.UseVisualStyleBackColor = true;
//
// button2
//
this.button2.DialogResult = System.Windows.Forms.DialogResult.OK;
this.button2.Location = new System.Drawing.Point(169, 76);
this.button2.Name = "button2";
this.button2.Size = new System.Drawing.Size(75, 23);
this.button2.TabIndex = 2;
this.button2.Text = "Ok";
this.button2.UseVisualStyleBackColor = true;
//
// chkHideDialog
//
this.chkHideDialog.AutoSize = true;
this.chkHideDialog.Location = new System.Drawing.Point(12, 80);
this.chkHideDialog.Name = "chkHideDialog";
this.chkHideDialog.Size = new System.Drawing.Size(108, 17);
this.chkHideDialog.TabIndex = 3;
this.chkHideDialog.Text = "Don\'t show again";
this.chkHideDialog.UseVisualStyleBackColor = true;
this.chkHideDialog.CheckedChanged += new System.EventHandler(this.chkHideDialog_CheckedChanged);
//
// ApplicationCloseDialog
//
this.AutoScaleDimensions = new System.Drawing.SizeF(6F, 13F);
this.AutoScaleMode = System.Windows.Forms.AutoScaleMode.Font;
this.ClientSize = new System.Drawing.Size(337, 102);
this.Controls.Add(this.chkHideDialog);
this.Controls.Add(this.button2);
this.Controls.Add(this.button1);
this.Controls.Add(this.label1);
this.Name = "ApplicationCloseDialog";
this.Text = "Toolbox";
this.ResumeLayout(false);
this.PerformLayout();
}
#endregion
private System.Windows.Forms.Label label1;
private System.Windows.Forms.Button button1;
private System.Windows.Forms.Button button2;
private System.Windows.Forms.CheckBox chkHideDialog;
}
}

View File

@ -0,0 +1,26 @@
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows.Forms;
namespace Toolbox
{
public partial class ApplicationCloseDialog : Form
{
public ApplicationCloseDialog()
{
InitializeComponent();
this.FormBorderStyle = FormBorderStyle.FixedDialog;
}
private void chkHideDialog_CheckedChanged(object sender, EventArgs e)
{
Toolbox.Library.Runtime.ShowCloseDialog = !chkHideDialog.Checked;
}
}
}

View File

@ -0,0 +1,120 @@
<?xml version="1.0" encoding="utf-8"?>
<root>
<!--
Microsoft ResX Schema
Version 2.0
The primary goals of this format is to allow a simple XML format
that is mostly human readable. The generation and parsing of the
various data types are done through the TypeConverter classes
associated with the data types.
Example:
... ado.net/XML headers & schema ...
<resheader name="resmimetype">text/microsoft-resx</resheader>
<resheader name="version">2.0</resheader>
<resheader name="reader">System.Resources.ResXResourceReader, System.Windows.Forms, ...</resheader>
<resheader name="writer">System.Resources.ResXResourceWriter, System.Windows.Forms, ...</resheader>
<data name="Name1"><value>this is my long string</value><comment>this is a comment</comment></data>
<data name="Color1" type="System.Drawing.Color, System.Drawing">Blue</data>
<data name="Bitmap1" mimetype="application/x-microsoft.net.object.binary.base64">
<value>[base64 mime encoded serialized .NET Framework object]</value>
</data>
<data name="Icon1" type="System.Drawing.Icon, System.Drawing" mimetype="application/x-microsoft.net.object.bytearray.base64">
<value>[base64 mime encoded string representing a byte array form of the .NET Framework object]</value>
<comment>This is a comment</comment>
</data>
There are any number of "resheader" rows that contain simple
name/value pairs.
Each data row contains a name, and value. The row also contains a
type or mimetype. Type corresponds to a .NET class that support
text/value conversion through the TypeConverter architecture.
Classes that don't support this are serialized and stored with the
mimetype set.
The mimetype is used for serialized objects, and tells the
ResXResourceReader how to depersist the object. This is currently not
extensible. For a given mimetype the value must be set accordingly:
Note - application/x-microsoft.net.object.binary.base64 is the format
that the ResXResourceWriter will generate, however the reader can
read any of the formats listed below.
mimetype: application/x-microsoft.net.object.binary.base64
value : The object must be serialized with
: System.Runtime.Serialization.Formatters.Binary.BinaryFormatter
: and then encoded with base64 encoding.
mimetype: application/x-microsoft.net.object.soap.base64
value : The object must be serialized with
: System.Runtime.Serialization.Formatters.Soap.SoapFormatter
: and then encoded with base64 encoding.
mimetype: application/x-microsoft.net.object.bytearray.base64
value : The object must be serialized into a byte array
: using a System.ComponentModel.TypeConverter
: and then encoded with base64 encoding.
-->
<xsd:schema id="root" xmlns="" xmlns:xsd="http://www.w3.org/2001/XMLSchema" xmlns:msdata="urn:schemas-microsoft-com:xml-msdata">
<xsd:import namespace="http://www.w3.org/XML/1998/namespace" />
<xsd:element name="root" msdata:IsDataSet="true">
<xsd:complexType>
<xsd:choice maxOccurs="unbounded">
<xsd:element name="metadata">
<xsd:complexType>
<xsd:sequence>
<xsd:element name="value" type="xsd:string" minOccurs="0" />
</xsd:sequence>
<xsd:attribute name="name" use="required" type="xsd:string" />
<xsd:attribute name="type" type="xsd:string" />
<xsd:attribute name="mimetype" type="xsd:string" />
<xsd:attribute ref="xml:space" />
</xsd:complexType>
</xsd:element>
<xsd:element name="assembly">
<xsd:complexType>
<xsd:attribute name="alias" type="xsd:string" />
<xsd:attribute name="name" type="xsd:string" />
</xsd:complexType>
</xsd:element>
<xsd:element name="data">
<xsd:complexType>
<xsd:sequence>
<xsd:element name="value" type="xsd:string" minOccurs="0" msdata:Ordinal="1" />
<xsd:element name="comment" type="xsd:string" minOccurs="0" msdata:Ordinal="2" />
</xsd:sequence>
<xsd:attribute name="name" type="xsd:string" use="required" msdata:Ordinal="1" />
<xsd:attribute name="type" type="xsd:string" msdata:Ordinal="3" />
<xsd:attribute name="mimetype" type="xsd:string" msdata:Ordinal="4" />
<xsd:attribute ref="xml:space" />
</xsd:complexType>
</xsd:element>
<xsd:element name="resheader">
<xsd:complexType>
<xsd:sequence>
<xsd:element name="value" type="xsd:string" minOccurs="0" msdata:Ordinal="1" />
</xsd:sequence>
<xsd:attribute name="name" type="xsd:string" use="required" />
</xsd:complexType>
</xsd:element>
</xsd:choice>
</xsd:complexType>
</xsd:element>
</xsd:schema>
<resheader name="resmimetype">
<value>text/microsoft-resx</value>
</resheader>
<resheader name="version">
<value>2.0</value>
</resheader>
<resheader name="reader">
<value>System.Resources.ResXResourceReader, System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089</value>
</resheader>
<resheader name="writer">
<value>System.Resources.ResXResourceWriter, System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089</value>
</resheader>
</root>

View File

@ -876,9 +876,7 @@ namespace Toolbox
else if (e.Control && e.KeyCode == Keys.W) // Ctrl + W Exit
{
e.SuppressKeyPress = true;
var notify = MessageBox.Show("Are you sure you want to exit the application?", Application.ProductName, MessageBoxButtons.YesNo, MessageBoxIcon.Question, MessageBoxDefaultButton.Button1);
if (notify == DialogResult.OK)
Application.Exit();
Application.Exit();
}
}
@ -1338,6 +1336,18 @@ namespace Toolbox
}
private void MainForm_FormClosing(object sender, FormClosingEventArgs e) {
if (tabForms.TabPages.Count > 0)
{
if (Runtime.ShowCloseDialog)
{
var form = new ApplicationCloseDialog();
form.StartPosition = FormStartPosition.CenterParent;
if (form.ShowDialog() != DialogResult.OK)
e.Cancel = true;
Config.Save();
}
}
}
private void batchToolStripMenuItem_Click(object sender, EventArgs e)

View File

@ -87,6 +87,12 @@
</ItemGroup>
<ItemGroup>
<Compile Include="GUI\AF_FileAssociations.cs" />
<Compile Include="GUI\ApplicationCloseDialog.cs">
<SubType>Form</SubType>
</Compile>
<Compile Include="GUI\ApplicationCloseDialog.Designer.cs">
<DependentUpon>ApplicationCloseDialog.cs</DependentUpon>
</Compile>
<Compile Include="GUI\Credits.cs">
<SubType>Form</SubType>
</Compile>
@ -147,6 +153,9 @@
<Compile Include="UpdateProgram.cs" />
<Compile Include="VersionCheck.cs" />
<Compile Include="WindowsExplorer\ExplorerContextMeny.cs" />
<EmbeddedResource Include="GUI\ApplicationCloseDialog.resx">
<DependentUpon>ApplicationCloseDialog.cs</DependentUpon>
</EmbeddedResource>
<EmbeddedResource Include="GUI\Credits.resx">
<DependentUpon>Credits.cs</DependentUpon>
</EmbeddedResource>