2019-04-24 18:46:37 +00:00
|
|
|
using bzit.bomg.Models;
|
|
|
|
using RyzStudio.Windows.Forms;
|
|
|
|
using RyzStudio.Windows.ThemedForms;
|
|
|
|
using System;
|
|
|
|
using System.Collections.Generic;
|
|
|
|
using System.ComponentModel;
|
|
|
|
using System.Windows.Forms;
|
|
|
|
using Form = System.Windows.Forms.Form;
|
|
|
|
using Resources = bzit.bomg.Properties.Resources;
|
|
|
|
|
|
|
|
namespace bzit.bomg
|
|
|
|
{
|
|
|
|
public partial class OptionForm : Form
|
|
|
|
{
|
|
|
|
protected BackgroundWorker threadWorker = null;
|
|
|
|
|
|
|
|
protected BookmarkItemModel itemModel = null;
|
|
|
|
protected MainForm parentForm = null;
|
|
|
|
|
|
|
|
public OptionForm(MainForm mainForm) : base()
|
|
|
|
{
|
|
|
|
InitializeComponent();
|
|
|
|
|
|
|
|
parentForm = mainForm;
|
|
|
|
|
|
|
|
this.StartPosition = FormStartPosition.WindowsDefaultLocation;
|
|
|
|
|
|
|
|
if (threadWorker == null)
|
|
|
|
{
|
|
|
|
threadWorker = new BackgroundWorker();
|
|
|
|
threadWorker.WorkerReportsProgress = threadWorker.WorkerSupportsCancellation = true;
|
|
|
|
threadWorker.DoWork += threadWorker1_DoWork;
|
|
|
|
threadWorker.RunWorkerCompleted += threadWorker1_RunWorkerCompleted;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
protected void threadWorker1_DoWork(object sender, DoWorkEventArgs e)
|
|
|
|
{
|
|
|
|
if (threadWorker.CancellationPending)
|
|
|
|
{
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
List<TreeNode> nodeList = parentForm.treeView1.GetBookmarkNodeList();
|
|
|
|
|
2020-08-23 13:42:33 +00:00
|
|
|
ThreadControl.SetValue(progressBar1, 0, nodeList.Count);
|
2019-04-24 18:46:37 +00:00
|
|
|
|
|
|
|
for (int i=0; i<nodeList.Count; i++)
|
|
|
|
{
|
|
|
|
if (threadWorker.CancellationPending)
|
|
|
|
{
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2020-08-23 13:42:33 +00:00
|
|
|
ThreadControl.SetValue(progressBar1, (i + 1));
|
2019-04-24 18:46:37 +00:00
|
|
|
|
|
|
|
BookmarkItemViewModel viewModel = (BookmarkItemViewModel)nodeList[i].Tag;
|
|
|
|
BookmarkItemModel model = viewModel.ToModel();
|
|
|
|
bool rv = model.UpdateFavicon();
|
|
|
|
if (rv)
|
|
|
|
{
|
|
|
|
if (parentForm.treeView1.InvokeRequired)
|
|
|
|
{
|
|
|
|
parentForm.treeView1.Invoke(new MethodInvoker(() => {
|
|
|
|
parentForm.treeView1.UpdateItem(nodeList[i], model.ToViewModel());
|
|
|
|
}));
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
parentForm.treeView1.UpdateItem(nodeList[i], model.ToViewModel());
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
protected void threadWorker1_RunWorkerCompleted(object sender, RunWorkerCompletedEventArgs e)
|
|
|
|
{
|
|
|
|
this.IsBusy = false;
|
|
|
|
|
2020-08-23 13:42:33 +00:00
|
|
|
ThreadControl.SetText(button2, "&Update");
|
2019-04-24 18:46:37 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
protected override void OnClosing(CancelEventArgs e)
|
|
|
|
{
|
|
|
|
base.OnClosing(e);
|
|
|
|
|
|
|
|
if (this.IsBusy)
|
|
|
|
{
|
|
|
|
e.Cancel = true;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
protected bool IsBusy
|
|
|
|
{
|
|
|
|
get => threadWorker.IsBusy;
|
|
|
|
set
|
|
|
|
{
|
|
|
|
pictureBox1.Image = (value) ? Resources.aniZomq2x32 : null;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
private void button1_Click(object sender, EventArgs e)
|
|
|
|
{
|
|
|
|
if (this.IsBusy)
|
|
|
|
{
|
2020-08-23 13:42:33 +00:00
|
|
|
ThreadControl.SetText(button2, "&Cancelling...");
|
2019-04-24 18:46:37 +00:00
|
|
|
|
|
|
|
threadWorker.CancelAsync();
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
this.IsBusy = true;
|
|
|
|
|
2020-08-23 13:42:33 +00:00
|
|
|
ThreadControl.SetText(button2, "&Updating...");
|
2019-04-24 18:46:37 +00:00
|
|
|
|
|
|
|
threadWorker.RunWorkerAsync();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
private void button2_Click(object sender, EventArgs e)
|
|
|
|
{
|
|
|
|
if (this.IsBusy)
|
|
|
|
{
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
this.Close();
|
|
|
|
}
|
|
|
|
|
|
|
|
}
|
|
|
|
}
|