bookmark-manager-r4/EditBookmarkForm.cs
2024-07-17 01:56:17 +01:00

447 lines
17 KiB
C#

using System;
using System.Drawing;
using System.Windows.Forms;
using BookmarkManager.Services;
using bzit.bomg.Models;
using RyzStudio.Windows.Forms;
using RyzStudio.Windows.ThemedForms;
using RyzStudio.Windows.ThemedForms.ButtonTextBox;
namespace FizzyLauncher
{
public class EditBookmarkForm : TDialog
{
private System.Windows.Forms.Label label1;
private ThButton button1;
private RyzStudio.Windows.Forms.THorizontalSeparator tHorizontalSeparator1;
private ThClearableTextBox textBox1;
private Label label2;
private Label label3;
private ThToolbarMemoBox memoBox1;
private Label label4;
private ThHiButtonTextBox textBox2;
private PictureBox pictureBox1;
private PictureBox pictureBox2;
private ToolTip toolTip1;
private System.ComponentModel.IContainer components;
private ThClearableTextBox textBox3;
private ThUserControl thUserControl1;
private Label label5;
private readonly WebProvider _webProvider;
private BookmarkModel result = null;
private bool _isBusy = false;
public EditBookmarkForm(BookmarkModel model = null)
{
InitializeComponent();
this.StartPosition = FormStartPosition.WindowsDefaultLocation;
this.OkButton = button1;
_webProvider = new WebProvider();
result = model;
if (result != null)
{
Text = "Edit Bookmark";
textBox1.Text = model.Title?.Trim() ?? string.Empty;
textBox2.Text = model.Address?.Trim() ?? string.Empty;
textBox3.Text = model.Description?.Trim() ?? string.Empty;
pictureBox1.Image = model.Icon;
memoBox1.Text = model.Notes?.Trim() ?? string.Empty;
}
else
{
Text = "Add Bookmark";
}
}
private void InitializeComponent()
{
components = new System.ComponentModel.Container();
label1 = new Label();
button1 = new ThButton();
tHorizontalSeparator1 = new THorizontalSeparator();
textBox1 = new ThClearableTextBox();
label2 = new Label();
label3 = new Label();
memoBox1 = new ThToolbarMemoBox();
label4 = new Label();
textBox2 = new ThHiButtonTextBox();
pictureBox1 = new PictureBox();
toolTip1 = new ToolTip(components);
pictureBox2 = new PictureBox();
textBox3 = new ThClearableTextBox();
thUserControl1 = new ThUserControl();
label5 = new Label();
((System.ComponentModel.ISupportInitialize)pictureBox1).BeginInit();
((System.ComponentModel.ISupportInitialize)pictureBox2).BeginInit();
SuspendLayout();
//
// label1
//
label1.AutoSize = true;
label1.BackColor = Color.Transparent;
label1.ForeColor = SystemColors.ControlText;
label1.Location = new Point(10, 21);
label1.Margin = new Padding(0);
label1.Name = "label1";
label1.Padding = new Padding(0, 8, 0, 0);
label1.Size = new Size(29, 23);
label1.TabIndex = 153;
label1.Text = "Title";
label1.TextAlign = ContentAlignment.MiddleLeft;
//
// button1
//
button1.AcceptButton = null;
button1.ActiveImage = null;
button1.Anchor = AnchorStyles.Bottom | AnchorStyles.Right;
button1.BackColor = Color.Transparent;
button1.EnableMenuOnClick = false;
button1.EnableReactiveVisual = true;
button1.HoverImage = null;
button1.IdleImage = null;
button1.LabelText = "&Save";
button1.Location = new Point(241, 469);
button1.Margin = new Padding(10, 10, 10, 0);
button1.Name = "button1";
button1.Padding = new Padding(4, 4, 3, 3);
button1.Size = new Size(128, 32);
button1.TabIndex = 4;
button1.TabStop = false;
//
// tHorizontalSeparator1
//
tHorizontalSeparator1.Anchor = AnchorStyles.Bottom | AnchorStyles.Left | AnchorStyles.Right;
tHorizontalSeparator1.AutoScrollMargin = new Size(0, 0);
tHorizontalSeparator1.AutoScrollMinSize = new Size(0, 0);
tHorizontalSeparator1.BackColor = Color.Transparent;
tHorizontalSeparator1.Location = new Point(10, 437);
tHorizontalSeparator1.Margin = new Padding(0, 10, 0, 0);
tHorizontalSeparator1.MaximumSize = new Size(4920, 2);
tHorizontalSeparator1.MinimumSize = new Size(0, 22);
tHorizontalSeparator1.Name = "tHorizontalSeparator1";
tHorizontalSeparator1.Size = new Size(364, 22);
tHorizontalSeparator1.TabIndex = 188;
tHorizontalSeparator1.TabStop = false;
//
// textBox1
//
textBox1.AcceptButton = null;
textBox1.Anchor = AnchorStyles.Top | AnchorStyles.Left | AnchorStyles.Right;
textBox1.BackColor = Color.Transparent;
textBox1.ClearedValue = "";
textBox1.EnableReactiveVisual = true;
textBox1.Font = new Font("Segoe UI", 9F);
textBox1.Icon = "O";
textBox1.IconSize = 13F;
textBox1.Location = new Point(109, 20);
textBox1.Margin = new Padding(10, 10, 10, 0);
textBox1.Name = "textBox1";
textBox1.Padding = new Padding(4, 4, 3, 3);
textBox1.Size = new Size(260, 32);
textBox1.TabIndex = 0;
textBox1.TabStop = false;
textBox1.UseSystemPasswordChar = false;
//
// label2
//
label2.AutoSize = true;
label2.BackColor = Color.Transparent;
label2.ForeColor = SystemColors.ControlText;
label2.Location = new Point(10, 61);
label2.Margin = new Padding(0);
label2.Name = "label2";
label2.Padding = new Padding(0, 8, 0, 0);
label2.Size = new Size(49, 23);
label2.TabIndex = 193;
label2.Text = "Address";
label2.TextAlign = ContentAlignment.MiddleLeft;
//
// label3
//
label3.AutoSize = true;
label3.BackColor = Color.Transparent;
label3.ForeColor = SystemColors.ControlText;
label3.Location = new Point(10, 104);
label3.Margin = new Padding(0);
label3.Name = "label3";
label3.Padding = new Padding(0, 8, 0, 0);
label3.Size = new Size(67, 23);
label3.TabIndex = 195;
label3.Text = "Description";
label3.TextAlign = ContentAlignment.MiddleLeft;
//
// memoBox1
//
memoBox1.AcceptButton = null;
memoBox1.AllowDrop = true;
memoBox1.Anchor = AnchorStyles.Top | AnchorStyles.Bottom | AnchorStyles.Left | AnchorStyles.Right;
memoBox1.BackColor = Color.Transparent;
memoBox1.ClearedValue = "";
memoBox1.EnableReactiveVisual = true;
memoBox1.Font = new Font("Segoe UI", 9F);
memoBox1.Location = new Point(110, 196);
memoBox1.Margin = new Padding(10, 10, 10, 0);
memoBox1.Name = "memoBox1";
memoBox1.Padding = new Padding(4, 4, 3, 3);
memoBox1.ReadOnly = false;
memoBox1.ScrollBars = ScrollBars.Vertical;
memoBox1.Size = new Size(259, 232);
memoBox1.TabIndex = 3;
memoBox1.TabStop = false;
memoBox1.WordWrap = false;
//
// label4
//
label4.AutoSize = true;
label4.BackColor = Color.Transparent;
label4.ForeColor = SystemColors.ControlText;
label4.Location = new Point(10, 196);
label4.Margin = new Padding(0);
label4.Name = "label4";
label4.Padding = new Padding(0, 8, 0, 0);
label4.Size = new Size(38, 23);
label4.TabIndex = 198;
label4.Text = "Notes";
label4.TextAlign = ContentAlignment.MiddleLeft;
//
// textBox2
//
textBox2.AcceptButton = null;
textBox2.Anchor = AnchorStyles.Top | AnchorStyles.Left | AnchorStyles.Right;
textBox2.BackColor = Color.Transparent;
textBox2.EnableReactiveVisual = true;
textBox2.Font = new Font("Segoe UI", 9F);
textBox2.Icon = "M";
textBox2.IconSize = 13F;
textBox2.Location = new Point(110, 62);
textBox2.Margin = new Padding(10, 10, 10, 0);
textBox2.Name = "textBox2";
textBox2.Padding = new Padding(4, 4, 3, 3);
textBox2.Size = new Size(259, 32);
textBox2.TabIndex = 1;
textBox2.TabStop = false;
textBox2.UseSystemPasswordChar = false;
textBox2.OnButtonClick += textBox2_OnButtonClick;
//
// pictureBox1
//
pictureBox1.BackColor = Color.White;
pictureBox1.ErrorImage = null;
pictureBox1.InitialImage = null;
pictureBox1.Location = new Point(113, 150);
pictureBox1.Name = "pictureBox1";
pictureBox1.Size = new Size(32, 32);
pictureBox1.SizeMode = PictureBoxSizeMode.CenterImage;
pictureBox1.TabIndex = 201;
pictureBox1.TabStop = false;
pictureBox1.MouseDoubleClick += pictureBox1_MouseDoubleClick;
//
// pictureBox2
//
pictureBox2.Anchor = AnchorStyles.Bottom | AnchorStyles.Right;
pictureBox2.BackColor = Color.Transparent;
pictureBox2.ErrorImage = null;
pictureBox2.InitialImage = null;
pictureBox2.Location = new Point(196, 469);
pictureBox2.Name = "pictureBox2";
pictureBox2.Size = new Size(32, 32);
pictureBox2.SizeMode = PictureBoxSizeMode.CenterImage;
pictureBox2.TabIndex = 202;
pictureBox2.TabStop = false;
//
// textBox3
//
textBox3.AcceptButton = null;
textBox3.Anchor = AnchorStyles.Top | AnchorStyles.Left | AnchorStyles.Right;
textBox3.BackColor = Color.Transparent;
textBox3.ClearedValue = "";
textBox3.EnableReactiveVisual = true;
textBox3.Font = new Font("Segoe UI", 9F);
textBox3.Icon = "O";
textBox3.IconSize = 13F;
textBox3.Location = new Point(109, 104);
textBox3.Margin = new Padding(10, 10, 10, 0);
textBox3.Name = "textBox3";
textBox3.Padding = new Padding(4, 4, 3, 3);
textBox3.Size = new Size(260, 32);
textBox3.TabIndex = 203;
textBox3.TabStop = false;
textBox3.UseSystemPasswordChar = false;
//
// thUserControl1
//
thUserControl1.AcceptButton = null;
thUserControl1.BackColor = Color.Transparent;
thUserControl1.EnableReactiveVisual = true;
thUserControl1.Location = new Point(109, 146);
thUserControl1.Name = "thUserControl1";
thUserControl1.Padding = new Padding(4, 4, 3, 3);
thUserControl1.Size = new Size(40, 40);
thUserControl1.TabIndex = 204;
//
// label5
//
label5.AutoSize = true;
label5.BackColor = Color.Transparent;
label5.ForeColor = SystemColors.ControlText;
label5.Location = new Point(10, 146);
label5.Margin = new Padding(0);
label5.Name = "label5";
label5.Padding = new Padding(0, 8, 0, 0);
label5.Size = new Size(30, 23);
label5.TabIndex = 195;
label5.Text = "Icon";
label5.TextAlign = ContentAlignment.MiddleLeft;
//
// EditBookmarkForm
//
AutoScaleDimensions = new SizeF(7F, 15F);
AutoScaleMode = AutoScaleMode.Font;
ClientSize = new Size(384, 521);
Controls.Add(textBox3);
Controls.Add(pictureBox2);
Controls.Add(pictureBox1);
Controls.Add(textBox2);
Controls.Add(memoBox1);
Controls.Add(label4);
Controls.Add(label5);
Controls.Add(label3);
Controls.Add(label2);
Controls.Add(textBox1);
Controls.Add(tHorizontalSeparator1);
Controls.Add(button1);
Controls.Add(label1);
Controls.Add(thUserControl1);
KeyPreview = true;
MinimumSize = new Size(400, 560);
Name = "EditBookmarkForm";
Text = "Edit Bookmark";
((System.ComponentModel.ISupportInitialize)pictureBox1).EndInit();
((System.ComponentModel.ISupportInitialize)pictureBox2).EndInit();
ResumeLayout(false);
PerformLayout();
}
protected override void OnShown(EventArgs e)
{
base.OnShown(e);
textBox2.Focus();
}
public BookmarkModel Result
{
get
{
if (result == null)
{
result = new BookmarkModel();
}
result.Title = textBox1.Text?.Trim() ?? string.Empty;
result.Address = textBox2.Text?.Trim() ?? string.Empty;
result.Description = textBox3.Text?.Trim() ?? string.Empty;
result.Icon = pictureBox1.Image;
result.Notes = memoBox1.Text?.Trim() ?? string.Empty;
return result;
}
}
protected bool IsBusy
{
get => _isBusy;
set
{
_isBusy = value;
UIControl.SetEnable(textBox1, !this.IsBusy);
UIControl.SetEnable(textBox2, !this.IsBusy);
UIControl.SetEnable(textBox3, !this.IsBusy);
UIControl.SetValue(pictureBox2, (this.IsBusy ? RyzStudio.Windows.ThemedForms.Resource2.loading_block : null));
UIControl.SetEnable(memoBox1, !this.IsBusy);
UIControl.SetEnable(button1, !this.IsBusy);
}
}
private async void textBox2_OnButtonClick(object sender, EventArgs e)
{
if (string.IsNullOrWhiteSpace(textBox2.Text))
{
return;
}
if (this.IsBusy)
{
return;
}
this.IsBusy = true;
if (!textBox2.Text.StartsWith("http://", StringComparison.CurrentCultureIgnoreCase) && !textBox2.Text.StartsWith("https://", StringComparison.CurrentCultureIgnoreCase))
{
textBox2.Text = "http://" + textBox2.Text;
}
var document = await _webProvider.RetrieveHtmlDocument(textBox2.Text);
if (document == null)
{
this.IsBusy = false;
return;
}
textBox1.Text = _webProvider.ParseTitle(document);
textBox3.Text = _webProvider.ParseMetaDescription(document);
pictureBox1.Image = await _webProvider.RetrieveImage(document);
this.IsBusy = false;
textBox2.Focus();
}
private async void pictureBox1_MouseDoubleClick(object sender, MouseEventArgs e)
{
if (e.Button == MouseButtons.Left)
{
if (string.IsNullOrWhiteSpace(textBox2.Text))
{
return;
}
if (this.IsBusy)
{
return;
}
this.IsBusy = true;
if (!textBox2.Text.StartsWith("http://", StringComparison.CurrentCultureIgnoreCase) && !textBox2.Text.StartsWith("https://", StringComparison.CurrentCultureIgnoreCase))
{
textBox2.Text = "http://" + textBox2.Text;
}
var document = await _webProvider.RetrieveHtmlDocument(textBox2.Text);
if (document == null)
{
this.IsBusy = false;
return;
}
pictureBox1.Image = await _webProvider.RetrieveImage(document);
this.IsBusy = false;
}
}
}
}