2019-04-18 20:04:58 +00:00
|
|
|
using bzit.bomg.Models;
|
|
|
|
using RyzStudio.Windows.Forms;
|
2017-07-30 11:59:34 +00:00
|
|
|
using System;
|
|
|
|
using System.ComponentModel;
|
2020-08-24 23:30:40 +00:00
|
|
|
using System.Threading.Tasks;
|
2017-07-30 11:59:34 +00:00
|
|
|
using System.Windows.Forms;
|
2019-04-18 20:04:58 +00:00
|
|
|
using Form = System.Windows.Forms.Form;
|
|
|
|
using Resources = bzit.bomg.Properties.Resources;
|
2017-07-30 11:59:34 +00:00
|
|
|
|
|
|
|
namespace bzit.bomg
|
|
|
|
{
|
|
|
|
public partial class BookmarkEditForm : Form
|
|
|
|
{
|
2020-08-24 23:30:40 +00:00
|
|
|
protected bool isBusy = false;
|
2019-04-18 20:04:58 +00:00
|
|
|
protected BookmarkItemModel itemModel = null;
|
|
|
|
protected BookmarkTreeView treeView = null;
|
|
|
|
|
|
|
|
public BookmarkEditForm(BookmarkTreeView treeview) : base()
|
2017-07-30 11:59:34 +00:00
|
|
|
{
|
|
|
|
InitializeComponent();
|
|
|
|
|
2019-04-18 20:04:58 +00:00
|
|
|
treeView = treeview;
|
|
|
|
|
2017-07-30 11:59:34 +00:00
|
|
|
this.StartPosition = FormStartPosition.WindowsDefaultLocation;
|
|
|
|
}
|
|
|
|
|
|
|
|
protected override void OnShown(EventArgs e)
|
|
|
|
{
|
|
|
|
base.OnShown(e);
|
|
|
|
|
2019-04-18 20:04:58 +00:00
|
|
|
if (treeView.SNode.GetNodeType() == BookmarkTreeView.NodeType.Page)
|
2017-07-30 11:59:34 +00:00
|
|
|
{
|
2019-04-18 20:04:58 +00:00
|
|
|
BookmarkItemViewModel bookmarkItem = (BookmarkItemViewModel)treeView.SelectedNode.Tag;
|
|
|
|
if (bookmarkItem != null)
|
2017-07-30 11:59:34 +00:00
|
|
|
{
|
2019-04-18 20:04:58 +00:00
|
|
|
if (itemModel == null)
|
2017-07-30 11:59:34 +00:00
|
|
|
{
|
2019-04-18 20:04:58 +00:00
|
|
|
itemModel = new BookmarkItemModel();
|
2017-07-30 11:59:34 +00:00
|
|
|
}
|
2019-04-18 20:04:58 +00:00
|
|
|
|
|
|
|
updateViewModel(bookmarkItem);
|
2017-07-30 11:59:34 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
protected override void OnClosing(CancelEventArgs e)
|
|
|
|
{
|
|
|
|
base.OnClosing(e);
|
|
|
|
|
2019-04-18 20:04:58 +00:00
|
|
|
if (this.IsBusy)
|
2017-07-30 11:59:34 +00:00
|
|
|
{
|
|
|
|
e.Cancel = true;
|
2019-04-16 20:57:31 +00:00
|
|
|
}
|
2017-07-30 11:59:34 +00:00
|
|
|
}
|
|
|
|
|
2019-04-18 20:04:58 +00:00
|
|
|
protected bool IsBusy
|
2017-07-30 11:59:34 +00:00
|
|
|
{
|
2020-08-24 23:30:40 +00:00
|
|
|
get => isBusy;
|
2017-07-30 11:59:34 +00:00
|
|
|
set
|
|
|
|
{
|
2020-08-24 23:30:40 +00:00
|
|
|
isBusy = value;
|
2019-04-18 20:04:58 +00:00
|
|
|
textBox1.Enabled = textBox2.Enabled = memoBox1.Enabled = !value;
|
2017-07-30 11:59:34 +00:00
|
|
|
|
2020-08-29 08:56:25 +00:00
|
|
|
ThreadControl.SetImage(pictureBox1, (value) ? Resources.aniZomq2x32 : null);
|
2017-07-30 11:59:34 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2019-04-18 20:04:58 +00:00
|
|
|
protected void updateViewModel(BookmarkItemViewModel viewModel)
|
2017-07-30 11:59:34 +00:00
|
|
|
{
|
2019-04-18 20:04:58 +00:00
|
|
|
itemModel.SiteName = viewModel.SiteName?.Trim();
|
|
|
|
itemModel.SiteAddress = viewModel.SiteAddress?.Trim();
|
|
|
|
itemModel.SiteDescription = viewModel.SiteDescription?.Trim();
|
|
|
|
itemModel.FaviconAddress = viewModel.FaviconAddress?.Trim();
|
|
|
|
|
|
|
|
textBox1.Text = itemModel.SiteName;
|
|
|
|
textBox2.Text = itemModel.SiteAddress;
|
|
|
|
memoBox1.Text = itemModel.SiteDescription;
|
|
|
|
pictureBox2.Image = treeView.ImageList.Images[treeView.SelectedNode.ImageIndex];
|
2017-07-30 11:59:34 +00:00
|
|
|
}
|
|
|
|
|
2020-08-24 23:30:40 +00:00
|
|
|
private async void button1_Click(object sender, EventArgs e)
|
2017-07-30 11:59:34 +00:00
|
|
|
{
|
2019-04-18 20:04:58 +00:00
|
|
|
if (this.IsBusy)
|
2017-07-30 11:59:34 +00:00
|
|
|
{
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2019-04-18 20:04:58 +00:00
|
|
|
if (string.IsNullOrWhiteSpace(textBox2.Text))
|
2017-07-30 11:59:34 +00:00
|
|
|
{
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2019-04-18 20:04:58 +00:00
|
|
|
this.IsBusy = true;
|
2017-07-30 11:59:34 +00:00
|
|
|
|
2020-08-24 23:30:40 +00:00
|
|
|
await Task.Run(() =>
|
|
|
|
{
|
|
|
|
if (itemModel == null) itemModel = new BookmarkItemModel();
|
|
|
|
|
|
|
|
itemModel.SiteAddress = textBox2.Text;
|
|
|
|
|
|
|
|
bool rv = itemModel.Update();
|
|
|
|
if (rv)
|
|
|
|
{
|
|
|
|
ThreadControl.SetText(textBox1, itemModel.SiteName);
|
|
|
|
ThreadControl.SetText(textBox2, itemModel.SiteAddress);
|
|
|
|
ThreadControl.SetText(memoBox1, itemModel.SiteDescription);
|
|
|
|
ThreadControl.SetImage(pictureBox2, itemModel.RetrieveFavicon());
|
|
|
|
}
|
|
|
|
});
|
|
|
|
|
|
|
|
this.IsBusy = false;
|
2017-07-30 11:59:34 +00:00
|
|
|
}
|
|
|
|
|
2019-04-18 20:04:58 +00:00
|
|
|
private void button2_Click(object sender, EventArgs e)
|
2017-07-30 11:59:34 +00:00
|
|
|
{
|
2020-08-24 23:30:40 +00:00
|
|
|
if (this.IsBusy) return;
|
|
|
|
if (string.IsNullOrWhiteSpace(textBox1.Text)) return;
|
|
|
|
if (string.IsNullOrWhiteSpace(textBox2.Text)) return;
|
2019-04-20 16:05:55 +00:00
|
|
|
|
2020-08-24 23:30:40 +00:00
|
|
|
if (itemModel == null) itemModel = new BookmarkItemModel();
|
2017-07-30 11:59:34 +00:00
|
|
|
|
2019-04-18 20:04:58 +00:00
|
|
|
itemModel.SiteName = textBox1.Text?.Trim();
|
|
|
|
itemModel.SiteAddress = textBox2.Text?.Trim();
|
|
|
|
itemModel.SiteDescription = memoBox1.Text?.Trim();
|
2017-07-30 11:59:34 +00:00
|
|
|
|
2019-04-23 20:57:35 +00:00
|
|
|
treeView?.SNode.AddOrUpdateItem(itemModel.ToViewModel());
|
2017-07-30 11:59:34 +00:00
|
|
|
|
|
|
|
this.Close();
|
|
|
|
}
|
2020-08-24 23:30:40 +00:00
|
|
|
|
2017-07-30 11:59:34 +00:00
|
|
|
}
|
|
|
|
}
|