重构
This commit is contained in:
@@ -13,7 +13,7 @@ namespace SpineViewer
|
|||||||
public partial class ProgressDialog : Form
|
public partial class ProgressDialog : Form
|
||||||
{
|
{
|
||||||
[Category("自定义"), Description("BackgroundWorker 的 DoWork 事件")]
|
[Category("自定义"), Description("BackgroundWorker 的 DoWork 事件")]
|
||||||
public event DoWorkEventHandler? Dowork
|
public event DoWorkEventHandler? DoWork
|
||||||
{
|
{
|
||||||
add { backgroundWorker.DoWork += value; }
|
add { backgroundWorker.DoWork += value; }
|
||||||
remove { backgroundWorker.DoWork -= value; }
|
remove { backgroundWorker.DoWork -= value; }
|
||||||
|
|||||||
@@ -1,21 +0,0 @@
|
|||||||
using System;
|
|
||||||
using System.Collections.Generic;
|
|
||||||
using System.Linq;
|
|
||||||
using System.Text;
|
|
||||||
using System.Threading.Tasks;
|
|
||||||
|
|
||||||
namespace SpineViewer.Spine
|
|
||||||
{
|
|
||||||
/// <summary>
|
|
||||||
/// 骨骼预览器
|
|
||||||
/// </summary>
|
|
||||||
class Previewer
|
|
||||||
{
|
|
||||||
private readonly Panel panel;
|
|
||||||
|
|
||||||
public Previewer(Panel panel)
|
|
||||||
{
|
|
||||||
this.panel = panel;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
@@ -25,50 +25,6 @@ namespace SpineViewer.Spine
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
public class PointFTypeConverter : ExpandableObjectConverter
|
|
||||||
{
|
|
||||||
public override bool CanConvertTo(ITypeDescriptorContext? context, [NotNullWhen(true)] Type? destinationType)
|
|
||||||
{
|
|
||||||
return destinationType == typeof(string) || base.CanConvertTo(context, destinationType);
|
|
||||||
}
|
|
||||||
|
|
||||||
public override object? ConvertTo(ITypeDescriptorContext? context, CultureInfo? culture, object? value, Type destinationType)
|
|
||||||
{
|
|
||||||
if (destinationType == typeof(string) && value is PointF point)
|
|
||||||
{
|
|
||||||
return $"{point.X}, {point.Y}";
|
|
||||||
}
|
|
||||||
return base.ConvertTo(context, culture, value, destinationType);
|
|
||||||
}
|
|
||||||
|
|
||||||
public override bool CanConvertFrom(ITypeDescriptorContext? context, Type sourceType)
|
|
||||||
{
|
|
||||||
return sourceType == typeof(string) || base.CanConvertFrom(context, sourceType);
|
|
||||||
}
|
|
||||||
|
|
||||||
public override object? ConvertFrom(ITypeDescriptorContext? context, CultureInfo? culture, object value)
|
|
||||||
{
|
|
||||||
if (value is string str)
|
|
||||||
{
|
|
||||||
var parts = str.Split(',');
|
|
||||||
if (parts.Length == 2 &&
|
|
||||||
float.TryParse(parts[0], out var x) &&
|
|
||||||
float.TryParse(parts[1], out var y))
|
|
||||||
{
|
|
||||||
return new PointF(x, y);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
return base.ConvertFrom(context, culture, value);
|
|
||||||
}
|
|
||||||
|
|
||||||
public override PropertyDescriptorCollection GetProperties(ITypeDescriptorContext? context, object value, Attribute[]? attributes)
|
|
||||||
{
|
|
||||||
return TypeDescriptor.GetProperties(typeof(PointF), attributes);
|
|
||||||
}
|
|
||||||
|
|
||||||
public override bool GetPropertiesSupported(ITypeDescriptorContext? context) => true;
|
|
||||||
}
|
|
||||||
|
|
||||||
public class AnimationTypeConverter : StringConverter
|
public class AnimationTypeConverter : StringConverter
|
||||||
{
|
{
|
||||||
public override bool GetStandardValuesSupported(ITypeDescriptorContext? context)
|
public override bool GetStandardValuesSupported(ITypeDescriptorContext? context)
|
||||||
|
|||||||
30
SpineViewer/src/SpineListView.Designer.cs
generated
30
SpineViewer/src/SpineListView.Designer.cs
generated
@@ -34,11 +34,11 @@
|
|||||||
columnHeader_Version = new ColumnHeader();
|
columnHeader_Version = new ColumnHeader();
|
||||||
contextMenuStrip = new ContextMenuStrip(components);
|
contextMenuStrip = new ContextMenuStrip(components);
|
||||||
toolStripMenuItem_Add = new ToolStripMenuItem();
|
toolStripMenuItem_Add = new ToolStripMenuItem();
|
||||||
|
toolStripMenuItem_BatchAdd = new ToolStripMenuItem();
|
||||||
toolStripMenuItem_Insert = new ToolStripMenuItem();
|
toolStripMenuItem_Insert = new ToolStripMenuItem();
|
||||||
toolStripMenuItem_Remove = new ToolStripMenuItem();
|
toolStripMenuItem_Remove = new ToolStripMenuItem();
|
||||||
toolStripSeparator1 = new ToolStripSeparator();
|
toolStripSeparator1 = new ToolStripSeparator();
|
||||||
toolStripMenuItem_RemoveAll = new ToolStripMenuItem();
|
toolStripMenuItem_RemoveAll = new ToolStripMenuItem();
|
||||||
toolStripMenuItem_BatchAdd = new ToolStripMenuItem();
|
|
||||||
contextMenuStrip.SuspendLayout();
|
contextMenuStrip.SuspendLayout();
|
||||||
SuspendLayout();
|
SuspendLayout();
|
||||||
//
|
//
|
||||||
@@ -78,21 +78,28 @@
|
|||||||
contextMenuStrip.ImageScalingSize = new Size(24, 24);
|
contextMenuStrip.ImageScalingSize = new Size(24, 24);
|
||||||
contextMenuStrip.Items.AddRange(new ToolStripItem[] { toolStripMenuItem_Add, toolStripMenuItem_BatchAdd, toolStripMenuItem_Insert, toolStripMenuItem_Remove, toolStripSeparator1, toolStripMenuItem_RemoveAll });
|
contextMenuStrip.Items.AddRange(new ToolStripItem[] { toolStripMenuItem_Add, toolStripMenuItem_BatchAdd, toolStripMenuItem_Insert, toolStripMenuItem_Remove, toolStripSeparator1, toolStripMenuItem_RemoveAll });
|
||||||
contextMenuStrip.Name = "contextMenuStrip";
|
contextMenuStrip.Name = "contextMenuStrip";
|
||||||
contextMenuStrip.Size = new Size(241, 193);
|
contextMenuStrip.Size = new Size(188, 160);
|
||||||
contextMenuStrip.Opening += contextMenuStrip_Opening;
|
contextMenuStrip.Opening += contextMenuStrip_Opening;
|
||||||
//
|
//
|
||||||
// toolStripMenuItem_Add
|
// toolStripMenuItem_Add
|
||||||
//
|
//
|
||||||
toolStripMenuItem_Add.Name = "toolStripMenuItem_Add";
|
toolStripMenuItem_Add.Name = "toolStripMenuItem_Add";
|
||||||
toolStripMenuItem_Add.Size = new Size(240, 30);
|
toolStripMenuItem_Add.Size = new Size(187, 30);
|
||||||
toolStripMenuItem_Add.Text = "添加(&A)...";
|
toolStripMenuItem_Add.Text = "添加(&A)...";
|
||||||
toolStripMenuItem_Add.Click += toolStripMenuItem_Add_Click;
|
toolStripMenuItem_Add.Click += toolStripMenuItem_Add_Click;
|
||||||
//
|
//
|
||||||
|
// toolStripMenuItem_BatchAdd
|
||||||
|
//
|
||||||
|
toolStripMenuItem_BatchAdd.Name = "toolStripMenuItem_BatchAdd";
|
||||||
|
toolStripMenuItem_BatchAdd.Size = new Size(187, 30);
|
||||||
|
toolStripMenuItem_BatchAdd.Text = "批量添加(&B)...";
|
||||||
|
toolStripMenuItem_BatchAdd.Click += toolStripMenuItem_BatchAdd_Click;
|
||||||
|
//
|
||||||
// toolStripMenuItem_Insert
|
// toolStripMenuItem_Insert
|
||||||
//
|
//
|
||||||
toolStripMenuItem_Insert.Enabled = false;
|
toolStripMenuItem_Insert.Enabled = false;
|
||||||
toolStripMenuItem_Insert.Name = "toolStripMenuItem_Insert";
|
toolStripMenuItem_Insert.Name = "toolStripMenuItem_Insert";
|
||||||
toolStripMenuItem_Insert.Size = new Size(240, 30);
|
toolStripMenuItem_Insert.Size = new Size(187, 30);
|
||||||
toolStripMenuItem_Insert.Text = "插入(&I)...";
|
toolStripMenuItem_Insert.Text = "插入(&I)...";
|
||||||
toolStripMenuItem_Insert.Click += toolStripMenuItem_Insert_Click;
|
toolStripMenuItem_Insert.Click += toolStripMenuItem_Insert_Click;
|
||||||
//
|
//
|
||||||
@@ -100,30 +107,23 @@
|
|||||||
//
|
//
|
||||||
toolStripMenuItem_Remove.Enabled = false;
|
toolStripMenuItem_Remove.Enabled = false;
|
||||||
toolStripMenuItem_Remove.Name = "toolStripMenuItem_Remove";
|
toolStripMenuItem_Remove.Name = "toolStripMenuItem_Remove";
|
||||||
toolStripMenuItem_Remove.Size = new Size(240, 30);
|
toolStripMenuItem_Remove.Size = new Size(187, 30);
|
||||||
toolStripMenuItem_Remove.Text = "移除(&R)";
|
toolStripMenuItem_Remove.Text = "移除(&R)";
|
||||||
toolStripMenuItem_Remove.Click += toolStripMenuItem_Remove_Click;
|
toolStripMenuItem_Remove.Click += toolStripMenuItem_Remove_Click;
|
||||||
//
|
//
|
||||||
// toolStripSeparator1
|
// toolStripSeparator1
|
||||||
//
|
//
|
||||||
toolStripSeparator1.Name = "toolStripSeparator1";
|
toolStripSeparator1.Name = "toolStripSeparator1";
|
||||||
toolStripSeparator1.Size = new Size(237, 6);
|
toolStripSeparator1.Size = new Size(184, 6);
|
||||||
//
|
//
|
||||||
// toolStripMenuItem_RemoveAll
|
// toolStripMenuItem_RemoveAll
|
||||||
//
|
//
|
||||||
toolStripMenuItem_RemoveAll.Enabled = false;
|
toolStripMenuItem_RemoveAll.Enabled = false;
|
||||||
toolStripMenuItem_RemoveAll.Name = "toolStripMenuItem_RemoveAll";
|
toolStripMenuItem_RemoveAll.Name = "toolStripMenuItem_RemoveAll";
|
||||||
toolStripMenuItem_RemoveAll.Size = new Size(240, 30);
|
toolStripMenuItem_RemoveAll.Size = new Size(187, 30);
|
||||||
toolStripMenuItem_RemoveAll.Text = "移除全部(&X)";
|
toolStripMenuItem_RemoveAll.Text = "移除全部(&X)";
|
||||||
toolStripMenuItem_RemoveAll.Click += toolStripMenuItem_RemoveAll_Click;
|
toolStripMenuItem_RemoveAll.Click += toolStripMenuItem_RemoveAll_Click;
|
||||||
//
|
//
|
||||||
// toolStripMenuItem_BatchAdd
|
|
||||||
//
|
|
||||||
toolStripMenuItem_BatchAdd.Name = "toolStripMenuItem_BatchAdd";
|
|
||||||
toolStripMenuItem_BatchAdd.Size = new Size(240, 30);
|
|
||||||
toolStripMenuItem_BatchAdd.Text = "批量添加(&B)...";
|
|
||||||
toolStripMenuItem_BatchAdd.Click += toolStripMenuItem_BatchAdd_Click;
|
|
||||||
//
|
|
||||||
// SpineListView
|
// SpineListView
|
||||||
//
|
//
|
||||||
AutoScaleDimensions = new SizeF(11F, 24F);
|
AutoScaleDimensions = new SizeF(11F, 24F);
|
||||||
@@ -136,7 +136,6 @@
|
|||||||
}
|
}
|
||||||
|
|
||||||
#endregion
|
#endregion
|
||||||
private ListView listView;
|
|
||||||
private ColumnHeader columnHeader_Name;
|
private ColumnHeader columnHeader_Name;
|
||||||
private ColumnHeader columnHeader_Version;
|
private ColumnHeader columnHeader_Version;
|
||||||
private ContextMenuStrip contextMenuStrip;
|
private ContextMenuStrip contextMenuStrip;
|
||||||
@@ -146,5 +145,6 @@
|
|||||||
private ToolStripMenuItem toolStripMenuItem_RemoveAll;
|
private ToolStripMenuItem toolStripMenuItem_RemoveAll;
|
||||||
private ToolStripSeparator toolStripSeparator1;
|
private ToolStripSeparator toolStripSeparator1;
|
||||||
private ToolStripMenuItem toolStripMenuItem_BatchAdd;
|
private ToolStripMenuItem toolStripMenuItem_BatchAdd;
|
||||||
|
private ListView listView;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -76,7 +76,7 @@ namespace SpineViewer
|
|||||||
return;
|
return;
|
||||||
|
|
||||||
var progressDialog = new ProgressDialog();
|
var progressDialog = new ProgressDialog();
|
||||||
progressDialog.Dowork += BatchAdd_Work;
|
progressDialog.DoWork += BatchAdd_Work;
|
||||||
progressDialog.RunWorkerAsync(new { openDialog.SkelPaths, openDialog.Version });
|
progressDialog.RunWorkerAsync(new { openDialog.SkelPaths, openDialog.Version });
|
||||||
progressDialog.ShowDialog();
|
progressDialog.ShowDialog();
|
||||||
}
|
}
|
||||||
@@ -103,13 +103,18 @@ namespace SpineViewer
|
|||||||
try
|
try
|
||||||
{
|
{
|
||||||
var spine = Spine.Spine.New(version, skelPath);
|
var spine = Spine.Spine.New(version, skelPath);
|
||||||
spines.Add(spine);
|
// 对 spines 和 Items 的操作都要转到窗口线程操作
|
||||||
if (listView.InvokeRequired)
|
if (listView.InvokeRequired)
|
||||||
{
|
{
|
||||||
listView.Invoke(() => listView.Items.Add(new ListViewItem([spine.Name, spine.Version.String()], -1) { ToolTipText = spine.SkelPath }));
|
listView.Invoke(() =>
|
||||||
|
{
|
||||||
|
spines.Add(spine);
|
||||||
|
listView.Items.Add(new ListViewItem([spine.Name, spine.Version.String()], -1) { ToolTipText = spine.SkelPath });
|
||||||
|
});
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
|
spines.Add(spine);
|
||||||
listView.Items.Add(new ListViewItem([spine.Name, spine.Version.String()], -1) { ToolTipText = spine.SkelPath });
|
listView.Items.Add(new ListViewItem([spine.Name, spine.Version.String()], -1) { ToolTipText = spine.SkelPath });
|
||||||
}
|
}
|
||||||
success++;
|
success++;
|
||||||
|
|||||||
99
SpineViewer/src/TypeConverter.cs
Normal file
99
SpineViewer/src/TypeConverter.cs
Normal file
@@ -0,0 +1,99 @@
|
|||||||
|
using System;
|
||||||
|
using System.Collections.Generic;
|
||||||
|
using System.ComponentModel;
|
||||||
|
using System.Diagnostics.CodeAnalysis;
|
||||||
|
using System.Globalization;
|
||||||
|
using System.Linq;
|
||||||
|
using System.Text;
|
||||||
|
using System.Threading.Tasks;
|
||||||
|
|
||||||
|
namespace SpineViewer
|
||||||
|
{
|
||||||
|
public class PointFTypeConverter : ExpandableObjectConverter
|
||||||
|
{
|
||||||
|
public override bool CanConvertTo(ITypeDescriptorContext? context, [NotNullWhen(true)] Type? destinationType)
|
||||||
|
{
|
||||||
|
return destinationType == typeof(string) || base.CanConvertTo(context, destinationType);
|
||||||
|
}
|
||||||
|
|
||||||
|
public override object? ConvertTo(ITypeDescriptorContext? context, CultureInfo? culture, object? value, Type destinationType)
|
||||||
|
{
|
||||||
|
if (destinationType == typeof(string) && value is PointF point)
|
||||||
|
{
|
||||||
|
return $"{point.X}, {point.Y}";
|
||||||
|
}
|
||||||
|
return base.ConvertTo(context, culture, value, destinationType);
|
||||||
|
}
|
||||||
|
|
||||||
|
public override bool CanConvertFrom(ITypeDescriptorContext? context, Type sourceType)
|
||||||
|
{
|
||||||
|
return sourceType == typeof(string) || base.CanConvertFrom(context, sourceType);
|
||||||
|
}
|
||||||
|
|
||||||
|
public override object? ConvertFrom(ITypeDescriptorContext? context, CultureInfo? culture, object value)
|
||||||
|
{
|
||||||
|
if (value is string str)
|
||||||
|
{
|
||||||
|
var parts = str.Split(',');
|
||||||
|
if (parts.Length == 2 &&
|
||||||
|
float.TryParse(parts[0], out var x) &&
|
||||||
|
float.TryParse(parts[1], out var y))
|
||||||
|
{
|
||||||
|
return new PointF(x, y);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return base.ConvertFrom(context, culture, value);
|
||||||
|
}
|
||||||
|
|
||||||
|
public override PropertyDescriptorCollection GetProperties(ITypeDescriptorContext? context, object value, Attribute[]? attributes)
|
||||||
|
{
|
||||||
|
return TypeDescriptor.GetProperties(typeof(PointF), attributes);
|
||||||
|
}
|
||||||
|
|
||||||
|
public override bool GetPropertiesSupported(ITypeDescriptorContext? context) => true;
|
||||||
|
}
|
||||||
|
|
||||||
|
public class SizeTypeConverter : ExpandableObjectConverter
|
||||||
|
{
|
||||||
|
public override bool CanConvertTo(ITypeDescriptorContext? context, [NotNullWhen(true)] Type? destinationType)
|
||||||
|
{
|
||||||
|
return destinationType == typeof(string) || base.CanConvertTo(context, destinationType);
|
||||||
|
}
|
||||||
|
|
||||||
|
public override object? ConvertTo(ITypeDescriptorContext? context, CultureInfo? culture, object? value, Type destinationType)
|
||||||
|
{
|
||||||
|
if (destinationType == typeof(string) && value is Size size)
|
||||||
|
{
|
||||||
|
return $"{size.Width}, {size.Height}";
|
||||||
|
}
|
||||||
|
return base.ConvertTo(context, culture, value, destinationType);
|
||||||
|
}
|
||||||
|
|
||||||
|
public override bool CanConvertFrom(ITypeDescriptorContext? context, Type sourceType)
|
||||||
|
{
|
||||||
|
return sourceType == typeof(string) || base.CanConvertFrom(context, sourceType);
|
||||||
|
}
|
||||||
|
|
||||||
|
public override object? ConvertFrom(ITypeDescriptorContext? context, CultureInfo? culture, object value)
|
||||||
|
{
|
||||||
|
if (value is string str)
|
||||||
|
{
|
||||||
|
var parts = str.Split(',');
|
||||||
|
if (parts.Length == 2 &&
|
||||||
|
int.TryParse(parts[0], out var width) &&
|
||||||
|
int.TryParse(parts[1], out var height))
|
||||||
|
{
|
||||||
|
return new Size(width, height);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return base.ConvertFrom(context, culture, value);
|
||||||
|
}
|
||||||
|
|
||||||
|
public override PropertyDescriptorCollection GetProperties(ITypeDescriptorContext? context, object value, Attribute[]? attributes)
|
||||||
|
{
|
||||||
|
return TypeDescriptor.GetProperties(typeof(Size), attributes);
|
||||||
|
}
|
||||||
|
|
||||||
|
public override bool GetPropertiesSupported(ITypeDescriptorContext? context) => true;
|
||||||
|
}
|
||||||
|
}
|
||||||
Reference in New Issue
Block a user