|
|
|
|
|
using System;
|
|
|
|
|
|
using System.Collections.Generic;
|
|
|
|
|
|
using System.IO;
|
|
|
|
|
|
using System.Linq;
|
|
|
|
|
|
using System.Text;
|
|
|
|
|
|
using System.Threading.Tasks;
|
|
|
|
|
|
using System.Windows.Forms;
|
|
|
|
|
|
using System.Xml;
|
|
|
|
|
|
using System.Xml.Serialization;
|
|
|
|
|
|
|
|
|
|
|
|
namespace PcgDrawR
|
|
|
|
|
|
{
|
|
|
|
|
|
/// <summary>
|
|
|
|
|
|
/// 自定义菜单
|
|
|
|
|
|
/// </summary>
|
|
|
|
|
|
public class CustomMenu
|
|
|
|
|
|
{
|
|
|
|
|
|
/// <summary>
|
|
|
|
|
|
/// Gets or sets the group name.
|
|
|
|
|
|
/// </summary>
|
|
|
|
|
|
public string GroupName { get; set; }
|
|
|
|
|
|
/// <summary>
|
|
|
|
|
|
/// Gets or sets the menu items.
|
|
|
|
|
|
/// </summary>
|
|
|
|
|
|
public List<CustomMenuItem> MenuItems { get; set; }
|
|
|
|
|
|
private string strFile = "CustomMenu.xml";
|
|
|
|
|
|
public CustomMenu()
|
|
|
|
|
|
{
|
|
|
|
|
|
strFile = Path.Combine(Application.StartupPath, "CustomMenu.xml");
|
|
|
|
|
|
|
|
|
|
|
|
//GroupName = "钻井辅助分析";
|
|
|
|
|
|
MenuItems = new List<CustomMenuItem>();
|
|
|
|
|
|
//MenuItems.Add(new CustomMenuItem("TestDrawerInteract.exe", "TestDrawerInteract"));
|
|
|
|
|
|
//MenuItems.Add(new CustomMenuItem("TestDrawerInteract2.exe", "TestDrawerInteract2"));
|
|
|
|
|
|
}
|
|
|
|
|
|
/// <summary>
|
|
|
|
|
|
/// 加载菜单项
|
|
|
|
|
|
/// </summary>
|
|
|
|
|
|
/// <returns>是否成功</returns>
|
|
|
|
|
|
public bool LoadItems()
|
|
|
|
|
|
{
|
|
|
|
|
|
if (!File.Exists(strFile))
|
|
|
|
|
|
{
|
|
|
|
|
|
return false;
|
|
|
|
|
|
}
|
|
|
|
|
|
using (StreamReader sr = new StreamReader(strFile, Encoding.Default))
|
|
|
|
|
|
{
|
|
|
|
|
|
try
|
|
|
|
|
|
{
|
|
|
|
|
|
XmlSerializer xmlSerializer = new XmlSerializer(typeof(CustomMenu));
|
|
|
|
|
|
CustomMenu customMenu = xmlSerializer.Deserialize(sr) as CustomMenu;
|
|
|
|
|
|
this.GroupName = customMenu.GroupName;
|
|
|
|
|
|
this.MenuItems = customMenu.MenuItems;
|
|
|
|
|
|
}
|
|
|
|
|
|
catch
|
|
|
|
|
|
{
|
|
|
|
|
|
return false;
|
|
|
|
|
|
}
|
|
|
|
|
|
}
|
|
|
|
|
|
return true;
|
|
|
|
|
|
}
|
|
|
|
|
|
/// <summary>
|
|
|
|
|
|
/// 保存自定义菜单
|
|
|
|
|
|
/// </summary>
|
|
|
|
|
|
/// <returns>是否成功</returns>
|
|
|
|
|
|
public bool SaveItems()
|
|
|
|
|
|
{
|
|
|
|
|
|
XmlWriterSettings settings = new XmlWriterSettings();
|
|
|
|
|
|
settings.Indent = true;
|
|
|
|
|
|
settings.IndentChars = " ";
|
|
|
|
|
|
settings.NewLineChars = "\r\n";
|
|
|
|
|
|
settings.Encoding = Encoding.Default;
|
|
|
|
|
|
using (StreamWriter sw = new StreamWriter(strFile, false, Encoding.Default))
|
|
|
|
|
|
using (XmlWriter writer = XmlWriter.Create(sw, settings))
|
|
|
|
|
|
{
|
|
|
|
|
|
try
|
|
|
|
|
|
{
|
|
|
|
|
|
XmlSerializer xmlSerializer = new XmlSerializer(typeof(CustomMenu));
|
|
|
|
|
|
xmlSerializer.Serialize(writer, this);
|
|
|
|
|
|
}
|
|
|
|
|
|
catch
|
|
|
|
|
|
{
|
|
|
|
|
|
return false;
|
|
|
|
|
|
}
|
|
|
|
|
|
}
|
|
|
|
|
|
return true;
|
|
|
|
|
|
}
|
|
|
|
|
|
}
|
|
|
|
|
|
public class CustomMenuItem
|
|
|
|
|
|
{
|
|
|
|
|
|
/// <summary>
|
|
|
|
|
|
/// Gets or sets the caption.
|
|
|
|
|
|
/// </summary>
|
|
|
|
|
|
[XmlAttribute]
|
|
|
|
|
|
public string Caption { get; set; }
|
|
|
|
|
|
/// <summary>
|
|
|
|
|
|
/// Gets or sets the program file.
|
|
|
|
|
|
/// </summary>
|
|
|
|
|
|
[XmlAttribute]
|
|
|
|
|
|
public string ProgramFile { get; set; }
|
|
|
|
|
|
/// <summary>
|
|
|
|
|
|
/// Gets or sets the class name.
|
|
|
|
|
|
/// </summary>
|
|
|
|
|
|
[XmlAttribute]
|
|
|
|
|
|
public string ClassName { get; set; }
|
|
|
|
|
|
/// <summary>
|
|
|
|
|
|
/// Gets or sets a value indicating whether popup is item.
|
|
|
|
|
|
/// </summary>
|
|
|
|
|
|
[XmlAttribute]
|
|
|
|
|
|
public bool IsPopupItem { get; set; } = false;
|
|
|
|
|
|
/// <summary>
|
|
|
|
|
|
/// Gets or sets the svg image.
|
|
|
|
|
|
/// </summary>
|
|
|
|
|
|
[XmlAttribute]
|
|
|
|
|
|
public string SvgImage { get; set; }
|
|
|
|
|
|
/// <summary>
|
|
|
|
|
|
/// Gets or sets the image text styles.
|
|
|
|
|
|
/// </summary>
|
|
|
|
|
|
public int ImageTextStyles { get; set; }
|
|
|
|
|
|
public CustomMenuItem()
|
|
|
|
|
|
{
|
|
|
|
|
|
ImageTextStyles = 0;
|
|
|
|
|
|
}
|
|
|
|
|
|
public CustomMenuItem(string caption, string programFile, string className, string svgImage)
|
|
|
|
|
|
: this()
|
|
|
|
|
|
{
|
|
|
|
|
|
this.Caption = caption;
|
|
|
|
|
|
this.ProgramFile = programFile;
|
|
|
|
|
|
this.ClassName = className;
|
|
|
|
|
|
this.SvgImage = svgImage;
|
|
|
|
|
|
}
|
|
|
|
|
|
}
|
|
|
|
|
|
}
|