before candybox editor update

This commit is contained in:
meelstorm
2025-09-16 10:42:43 +02:00
parent e5746ef766
commit dc12b3e51a
103 changed files with 96379 additions and 343 deletions

View File

@@ -0,0 +1,37 @@
namespace MaterialSkin.Controls
{
partial class MaterialCancellableLoader
{
/// <summary>
/// Required designer variable.
/// </summary>
private System.ComponentModel.IContainer components = null;
#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()
{
SuspendLayout();
//
// MaterialCancellableLoader
//
AutoScaleDimensions = new System.Drawing.SizeF(7F, 15F);
AutoScaleMode = System.Windows.Forms.AutoScaleMode.Font;
ClientSize = new System.Drawing.Size(450, 108);
ControlBox = false;
MaximizeBox = false;
MinimizeBox = false;
Name = "MaterialCancellableLoader";
StartPosition = System.Windows.Forms.FormStartPosition.CenterScreen;
TopMost = true;
ResumeLayout(false);
}
#endregion
}
}

View File

@@ -0,0 +1,182 @@
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Drawing;
using System.Linq;
using System.Threading;
using System.Windows.Forms;
namespace MaterialSkin.Controls
{
public partial class MaterialCancellableLoader : MaterialForm
{
private readonly Dictionary<string, (MaterialProgressBar ProgressBar, Label Label, MaterialFlatButton CancelButton, CancellationTokenSource CancellationTokenSource)> _loadingProcesses;
public event EventHandler<string> LoadingCancelled;
public MaterialCancellableLoader()
{
InitializeComponent();
RemoveMessageFilter();
_loadingProcesses = new Dictionary<string, (MaterialProgressBar, Label, MaterialFlatButton, CancellationTokenSource)>();
this.MaximizeBox = false;
this.MinimizeBox = false;
this.StartPosition = FormStartPosition.CenterScreen;
this.Width = 450;
}
public CancellationToken StartLoading(string title)
{
if (_loadingProcesses.ContainsKey(title))
{
return _loadingProcesses[title].CancellationTokenSource.Token;
}
var cancellationTokenSource = new CancellationTokenSource();
var progressBar = new MaterialProgressBar
{
Width = this.ClientSize.Width - 120, // Leave space for cancel button
Height = 20,
Top = 50 + (_loadingProcesses.Count * 60),
Left = 10,
Style = ProgressBarStyle.Marquee,
MarqueeAnimationSpeed = 30,
Value = 50,
BackColor = Color.White
};
var label = new Label
{
Text = title,
AutoSize = true,
Top = progressBar.Top - 20,
Left = progressBar.Left,
BackColor = Color.White,
ForeColor = SkinManager.GetPrimaryTextColor()
};
var cancelButton = new MaterialFlatButton
{
Text = "Cancel",
Width = 80,
Height = 30,
Top = progressBar.Top - 5,
Left = progressBar.Right + 10,
UseVisualStyleBackColor = true
};
// Capture the title in the closure properly
var capturedTitle = title;
cancelButton.Click += (sender, e) =>
{
CancelLoading(capturedTitle);
};
_loadingProcesses[title] = (progressBar, label, cancelButton, cancellationTokenSource);
this.Controls.Add(label);
this.Controls.Add(progressBar);
this.Controls.Add(cancelButton);
if (!this.Visible)
{
this.Show();
}
this.Refresh();
return cancellationTokenSource.Token;
}
public void FinishLoading(string title)
{
if (_loadingProcesses.TryGetValue(title, out var components))
{
this.Controls.Remove(components.ProgressBar);
this.Controls.Remove(components.Label);
this.Controls.Remove(components.CancelButton);
components.CancellationTokenSource.Dispose();
_loadingProcesses.Remove(title);
RearrangeControls();
}
if (_loadingProcesses.Count == 0)
{
this.Hide();
}
}
public void CancelLoading(string title)
{
if (_loadingProcesses.TryGetValue(title, out var components))
{
components.CancellationTokenSource.Cancel();
LoadingCancelled?.Invoke(this, title);
FinishLoading(title);
}
}
public void CancelAllLoading()
{
var titles = _loadingProcesses.Keys.ToList();
foreach (var title in titles)
{
CancelLoading(title);
}
}
public bool IsLoading(string title)
{
return _loadingProcesses.ContainsKey(title);
}
public bool HasActiveLoading => _loadingProcesses.Count > 0;
public IEnumerable<string> ActiveLoadingTitles => _loadingProcesses.Keys.ToList();
private void RearrangeControls()
{
int index = 0;
foreach (var components in _loadingProcesses.Values)
{
var newTop = 50 + (index * 60);
components.ProgressBar.Top = newTop;
components.Label.Top = newTop - 20;
components.CancelButton.Top = newTop - 5;
index++;
}
}
protected override void OnFormClosing(FormClosingEventArgs e)
{
// Don't allow closing if there are active loading processes
if (_loadingProcesses.Count > 0)
{
e.Cancel = true;
return;
}
base.OnFormClosing(e);
}
protected override void Dispose(bool disposing)
{
if (disposing)
{
// Cancel all ongoing operations and dispose resources
foreach (var components in _loadingProcesses.Values)
{
components.CancellationTokenSource?.Dispose();
}
_loadingProcesses.Clear();
}
base.Dispose(disposing);
}
}
}

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>