bukkubuddy-bookmark-manager/Forms/ClearIconsForm.cs
2026-05-22 01:16:08 +01:00

161 lines
4.8 KiB
C#

using System;
using System.Drawing;
using System.Threading.Tasks;
using System.Windows.Forms;
using BukkuBuddy.DTOs.SaveFile;
using RyzStudio.Windows.Forms;
using static System.Windows.Forms.VisualStyles.VisualStyleElement;
namespace BukkuBuddy.Forms
{
public class ClearIconsForm : Form
{
private TProgressBar progressBar1;
private RyzStudio.Windows.ThemedForms.ThUserControl userControl1;
private Label label1;
private Label label2;
private readonly BookmarkTreeView _treeView = null;
public ClearIconsForm(BookmarkTreeView treeView)
{
InitializeComponent();
UISetup.Dialog(this, true);
this.Text = "Deleting Icons";
_treeView = treeView;
}
private void InitializeComponent()
{
progressBar1 = new TProgressBar();
userControl1 = new RyzStudio.Windows.ThemedForms.ThUserControl();
label1 = new Label();
label2 = new Label();
userControl1.SuspendLayout();
SuspendLayout();
//
// progressBar1
//
progressBar1.BarColour = Color.FromArgb(25, 104, 218);
progressBar1.Dock = DockStyle.Fill;
progressBar1.EnableMovable = false;
progressBar1.Location = new Point(3, 3);
progressBar1.Maximum = 100;
progressBar1.Minimum = 0;
progressBar1.Name = "progressBar1";
progressBar1.OnProgressChanged = null;
progressBar1.ShowText = true;
progressBar1.Size = new Size(418, 18);
progressBar1.TabIndex = 156;
progressBar1.Value = 25;
//
// userControl1
//
userControl1.Anchor = AnchorStyles.Top | AnchorStyles.Left | AnchorStyles.Right;
userControl1.BackColor = Color.Transparent;
userControl1.Controls.Add(progressBar1);
userControl1.EnableMovable = false;
userControl1.Location = new Point(10, 64);
userControl1.Name = "userControl1";
userControl1.Size = new Size(424, 24);
userControl1.TabIndex = 157;
//
// label1
//
label1.Anchor = AnchorStyles.Top | AnchorStyles.Left | AnchorStyles.Right;
label1.AutoEllipsis = true;
label1.Location = new Point(10, 20);
label1.Name = "label1";
label1.Size = new Size(424, 15);
label1.TabIndex = 159;
//
// label2
//
label2.Anchor = AnchorStyles.Top | AnchorStyles.Left | AnchorStyles.Right;
label2.AutoEllipsis = true;
label2.Location = new Point(10, 40);
label2.Name = "label2";
label2.Size = new Size(424, 15);
label2.TabIndex = 160;
//
// ClearIconsForm
//
BackColor = Color.White;
ClientSize = new Size(444, 117);
Controls.Add(label2);
Controls.Add(label1);
Controls.Add(userControl1);
Name = "ClearIconsForm";
Text = "Clear Icons";
userControl1.ResumeLayout(false);
ResumeLayout(false);
}
protected async override void OnShown(EventArgs e)
{
base.OnShown(e);
await Task.Run(async () =>
{
this.Clear();
var model = _treeView.ToNodeList<App6Options.Item>();
// Update progress bars
progressBar1.Maximum = model.Count;
progressBar1.Value = 0;
UIControl.SetText(label1, "Deleting...");
UIControl.SetText(label2, "");
foreach (var item in model)
{
UIControl.SetText(label2, "... " + item.Value.Title);
progressBar1.Value++;
if (item.Value.Icon == null)
{
continue;
}
var newModel = item.Value;
newModel.Icon = null;
_treeView.UpdateNode(item.Key, newModel);
}
_treeView.Clear(false, true);
UIControl.SetText(label1, "");
UIControl.SetText(label2, "Done");
});
this.DialogResult = DialogResult.OK;
}
protected override void OnFormClosing(FormClosingEventArgs e)
{
base.OnFormClosing(e);
if (this.DialogResult != DialogResult.OK)
{
e.Cancel = true;
}
}
public void Clear()
{
UIControl.SetText(label1, "Ready");
UIControl.SetText(label2, "");
progressBar1.Value = progressBar1.Maximum = 0;
}
}
}