| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703 | using System;using System.Collections.Generic;using System.ComponentModel;using System.Drawing;using System.Data;using System.Linq;using System.Text;using System.Threading.Tasks;using System.Windows.Forms;using PaintDotNet.Base.SettingModel;using PaintDotNet.Base.CommTool;using System.IO;namespace PaintDotNet.Instrument.CustomInterface{    internal class FastTools : UserControl    {        /// <summary>        /// 右侧树形菜单        /// </summary>        private ToolStripItemCollection collectionRight;        /// <summary>        /// 工作空间        /// </summary>        private AppWorkspace appWorkspace;        /// <summary>        /// 快捷菜单的数据        /// </summary>        private ShortcutbarModel shortcutbar_Model = Startup.instance.shortcutbarModel;        private string txtPath = Application.StartupPath + "\\Config\\" + Startup.instance.SettingPrefix + "\\ModuleConfig.txt";        private string[] menuIdArr;        #region 控件        private GroupBox groupBoxLeft;        private ListView listViewLeft;        private ListViewItem listViewLeftDown = null;        private ImageList imageListLeft;        private GroupBox groupBoxRight;        private TreeView treeViewRight;        private Button buttonAdd;        private Button buttonRemove;        private Button buttonUp;        private Button buttonDown;        private IContainer components;        #endregion        public FastTools(AppWorkspace appWorkspace)        {            this.appWorkspace = appWorkspace;            InitializeComponent();            InitializeLanguageText();            InitVisibleMenuId();            InitializeLeftTreeData();            InitializeRightTreeData();            InitializeTreeEvent();        }        /// <summary>        /// 获取txt文件中已保存的菜单可用id        /// </summary>        private void InitVisibleMenuId()        {            if (System.IO.File.Exists(txtPath))            {                string str = System.IO.File.ReadAllText(txtPath);                if (str.IndexOf(',') != -1)                {                    menuIdArr = str.Split(',');                }                else                {                    if (!string.IsNullOrEmpty(str))                    {                        menuIdArr = new string[] { str };                    }                }            }        }        /// <summary>        /// 初始化treeview的事件        /// </summary>        private void InitializeTreeEvent()        {            this.treeViewRight.HideSelection = false;            this.treeViewRight.DrawMode = TreeViewDrawMode.OwnerDrawText;            this.treeViewRight.DrawNode += new DrawTreeNodeEventHandler(this.treeViewRight_DrawNode);            this.treeViewRight.Invalidated += new InvalidateEventHandler(this.treeViewRight_Invalidated);            this.treeViewRight.MouseDown += new System.Windows.Forms.MouseEventHandler(this.treeViewRight_MouseDown);        }        /// <summary>        /// 右侧功能列表鼠标按下事件        /// </summary>        /// <param name="sender"></param>        /// <param name="e"></param>        private void treeViewRight_MouseDown(object sender, MouseEventArgs e)        {            if ((sender as TreeView) != null && e.Clicks == 2 && this.buttonAdd.Enabled)            {//自定义软件界面,双击可添加                 if (this.treeViewRight.GetNodeAt(e.X, e.Y) == null)                    return;            }            else                return;            //自定义软件界面,双击可添加             TreeNode downNode = this.treeViewRight.GetNodeAt(e.X, e.Y);            //if ((sender as TreeView) != null)            //{            //    this.treeViewRight.SelectedNode = this.treeViewRight.GetNodeAt(e.X, e.Y);            //    this.treeViewRight.Refresh();            //}            if (/*this.treeViewRight.SelectedNode != null && */downNode.Nodes.Count == 0)            {                ToolStripItem[] items = this.appWorkspace.ToolBar.MainMenu.Items.Find(downNode.Name, true);                if (items != null && items.Length > 0)                {                    if (((PdnMenuItem)(items[0])).Image != null)                        this.listViewLeft.SmallImageList.Images.Add(downNode.Name, ((PdnMenuItem)(items[0])).Image);                    else                        this.listViewLeft.SmallImageList.Images.Add(downNode.Name, new Bitmap(16, 16));                }                else                {                    this.listViewLeft.SmallImageList.Images.Add(downNode.Name, new Bitmap(16, 16));                }                ListViewItem item = new ListViewItem();                item.Text = downNode.Text;                item.Tag = downNode.Tag;                item.Name = downNode.Name;                item.ImageIndex = this.listViewLeft.SmallImageList.Images.Count - 1;                this.listViewLeft.Items.Add(item);            }        }        /// <summary>        /// treeView1的重绘事件        /// </summary>        /// <param name="sender"></param>        /// <param name="e"></param>        private void treeViewRight_Invalidated(object sender, InvalidateEventArgs e)        {                    }        /// <summary>        /// 自定义绘制        /// 参考https://www.cnblogs.com/JiYF/p/6693503.html        /// </summary>        /// <param name="sender"></param>        /// <param name="e"></param>        private void treeViewRight_DrawNode(object sender, DrawTreeNodeEventArgs e)        {            /**用默认颜色            e.DrawDefault = true;            return;            **/            //以下是自定义颜色            if ((e.State & TreeNodeStates.Selected) != 0)            {                //演示为蓝(绿)底白字                  e.Graphics.FillRectangle(SystemBrushes.Highlight/*Brushes.Green*/, e.Node.Bounds);                Font nodeFont = e.Node.NodeFont;                if (nodeFont == null) nodeFont = ((TreeView)sender).Font;                e.Graphics.DrawString(e.Node.Text, nodeFont, Brushes.White, Rectangle.Inflate(e.Bounds, 2, 0));            }            else            {                e.DrawDefault = true;            }            if ((e.State & TreeNodeStates.Focused) != 0)            {                using (Pen focusPen = new Pen(Color.Black))                {                    focusPen.DashStyle = System.Drawing.Drawing2D.DashStyle.Dot;                    Rectangle focusBounds = e.Node.Bounds;                    focusBounds.Size = new Size(focusBounds.Width - 1,                    focusBounds.Height - 1);                    e.Graphics.DrawRectangle(focusPen, focusBounds);                }            }        }        /// <summary>        /// 初始化左侧listview菜单        /// </summary>        private void InitializeLeftTreeData()        {            this.listViewLeft.View = View.Details;            ColumnHeader header = new ColumnHeader();            header.Text = PdnResources.GetString("Menu.tool.Generateshortcut.functionlist.text");            header.Width = 240;            this.listViewLeft.Columns.Add(header);            this.listViewLeft.Items.Clear();            if (shortcutbar_Model!=null) {                if (shortcutbar_Model.Menus != null)                {                    for (int i=0; i< shortcutbar_Model.Menus.Count; i++)                    {                        ToolStripItem[] items = this.appWorkspace.ToolBar.MainMenu.Items.Find(shortcutbar_Model.Menus[i].Description, true);                        ListViewItem item = new ListViewItem();                        if (items != null && items.Length > 0)                        {                            if (((PdnMenuItem)(items[0])).Image != null)                                this.listViewLeft.SmallImageList.Images.Add(shortcutbar_Model.Menus[i].Description, ((PdnMenuItem)(items[0])).Image);                            else                                this.listViewLeft.SmallImageList.Images.Add(shortcutbar_Model.Menus[i].Description, new Bitmap(16, 16));                            item.Text = ((PdnMenuItem)(items[0])).Text;                        }                        else                        {                            this.listViewLeft.SmallImageList.Images.Add(shortcutbar_Model.Menus[i].Description, new Bitmap(16, 16));                            item.Text = shortcutbar_Model.Menus[i].Name;// getShowName(Startup.instance.configModel.Language);                        }                        item.Tag = shortcutbar_Model.Menus[i].Id;                        item.Name = shortcutbar_Model.Menus[i].Description;                        item.ImageIndex = i;                        this.listViewLeft.Items.Add(item);                    }                }            }        }        /// <summary>        /// 初始化右侧树形菜单数据        /// </summary>        private void InitializeRightTreeData()        {            this.collectionRight = this.appWorkspace.ToolBar.MainMenu.Items;            TreeNode anime = new TreeNode(PdnResources.GetString("Menu.menu.Text"));            this.RecursiveData(collectionRight, anime);            anime.Expand();            this.treeViewRight.Nodes.Add(anime);        }        /// <summary>        /// 递归进行数据组织        /// </summary>        private void RecursiveData(ToolStripItemCollection collection, TreeNode anime)        {                       for (int i = 0; i < collection.Count; i++)            {                TreeNode node = new TreeNode(/*collection[i].Text*/);                if (collection[i] is PdnMenuItem)                {                    PdnMenuItem item = (PdnMenuItem)collection[i];                    if (!item.CanShowInSenseShield)                        continue;                    node.Tag = item.MenuId;                    if (menuIdArr != null && menuIdArr.Length > 0)                    {                        if (Array.IndexOf(menuIdArr, item.MenuId.ToString()) != -1)                        {                            node.Name = collection[i].Name;                            node.Text = collection[i].Text;                            node.Tag = ((PdnMenuItem)collection[i]).MenuId;                            node.Checked = true;                        }                        else                        {                            node.Checked = false;                        }                    }                    if (node.Checked)                    {                        anime.Nodes.Add(node);                    }                    if (collection[i].Name.Equals("OpenRecent") || collection[i].Name.Equals("CameraSelection"))                        continue;                    RecursiveData(((PdnMenuItem)collection[i]).DropDownItems, node);                }            }        }        #region 组件设计器生成的代码        private void InitializeLanguageText()        {            this.buttonDown.Text = PdnResources.GetString("Menu.LabelAction.MoveDownAction.Text");            this.buttonUp.Text = PdnResources.GetString("Menu.LabelAction.MoveUpAction.Text");            this.buttonRemove.Text = PdnResources.GetString("Menu.Moveout.text")+" >";            this.buttonAdd.Text = "< "+ PdnResources.GetString("Menu.Addto.text");            this.groupBoxRight.Text = PdnResources.GetString("Menu.Availablefunctions.text");            this.groupBoxLeft.Text = PdnResources.GetString("Menu.tool.Generateshortcut.Shortcutbarcontent.text");        }        /// <summary>         /// 设计器支持所需的方法 - 不要修改        /// 使用代码编辑器修改此方法的内容。        /// </summary>        private void InitializeComponent()        {            this.components = new System.ComponentModel.Container();            this.groupBoxLeft = new System.Windows.Forms.GroupBox();            this.listViewLeft = new System.Windows.Forms.ListView();            this.imageListLeft = new System.Windows.Forms.ImageList(this.components);            this.groupBoxRight = new System.Windows.Forms.GroupBox();            this.treeViewRight = new System.Windows.Forms.TreeView();            this.buttonAdd = new System.Windows.Forms.Button();            this.buttonRemove = new System.Windows.Forms.Button();            this.buttonUp = new System.Windows.Forms.Button();            this.buttonDown = new System.Windows.Forms.Button();            this.groupBoxLeft.SuspendLayout();            this.groupBoxRight.SuspendLayout();            this.SuspendLayout();            //             // groupBoxLeft            //             this.groupBoxLeft.Controls.Add(this.listViewLeft);            this.groupBoxLeft.Location = new System.Drawing.Point(0, 0);            this.groupBoxLeft.Name = "groupBoxLeft";            this.groupBoxLeft.Size = new System.Drawing.Size(256, 398);            this.groupBoxLeft.TabIndex = 0;            this.groupBoxLeft.TabStop = false;            this.groupBoxLeft.Text = "快捷栏内容";            //             // listViewLeft            //             this.listViewLeft.HideSelection = false;            this.listViewLeft.Location = new System.Drawing.Point(7, 20);            this.listViewLeft.MultiSelect = false;            this.listViewLeft.Name = "listViewLeft";            this.listViewLeft.Size = new System.Drawing.Size(243, 372);            this.listViewLeft.SmallImageList = this.imageListLeft;            this.listViewLeft.TabIndex = 0;            this.listViewLeft.UseCompatibleStateImageBehavior = false;            this.listViewLeft.MouseDown += ListViewLeft_MouseDown;            this.listViewLeft.DrawItem += new System.Windows.Forms.DrawListViewItemEventHandler(this.listViewLeft_DrawItem);            this.listViewLeft.Invalidated += new InvalidateEventHandler(this.treeViewLeft_InvalidateEvent);            //             // imageListLeft            //             this.imageListLeft.ColorDepth = System.Windows.Forms.ColorDepth.Depth8Bit;            this.imageListLeft.ImageSize = new System.Drawing.Size(16, 16);            this.imageListLeft.TransparentColor = System.Drawing.Color.Transparent;            //             // groupBoxRight            //             this.groupBoxRight.Controls.Add(this.treeViewRight);            this.groupBoxRight.Location = new System.Drawing.Point(367, 0);            this.groupBoxRight.Name = "groupBoxRight";            this.groupBoxRight.Size = new System.Drawing.Size(256, 398);            this.groupBoxRight.TabIndex = 1;            this.groupBoxRight.TabStop = false;            this.groupBoxRight.Text = "可用功能";                        //             // treeViewRight            //             this.treeViewRight.Location = new System.Drawing.Point(7, 20);            this.treeViewRight.Name = "treeViewRight";            this.treeViewRight.Size = new System.Drawing.Size(243, 372);            this.treeViewRight.TabIndex = 0;            //             // buttonAdd            //             this.buttonAdd.Location = new System.Drawing.Point(277, 20);            this.buttonAdd.Name = "buttonAdd";            this.buttonAdd.Size = new System.Drawing.Size(75, 23);            this.buttonAdd.TabIndex = 3;            this.buttonAdd.Text = "< 添加";                        this.buttonAdd.UseVisualStyleBackColor = true;            this.buttonAdd.Click += new System.EventHandler(this.buttonAddClick);            //             // buttonRemove            //             this.buttonRemove.Location = new System.Drawing.Point(277, 49);            this.buttonRemove.Name = "buttonRemove";            this.buttonRemove.Size = new System.Drawing.Size(75, 23);            this.buttonRemove.TabIndex = 4;            this.buttonRemove.Text = "移出 >";                        this.buttonRemove.UseVisualStyleBackColor = true;            this.buttonRemove.Click += new System.EventHandler(this.buttonRemoveClick);            //             // buttonUp            //             this.buttonUp.Location = new System.Drawing.Point(277, 78);            this.buttonUp.Name = "buttonUp";            this.buttonUp.Size = new System.Drawing.Size(75, 23);            this.buttonUp.TabIndex = 5;            this.buttonUp.Text = "向上移动";                        this.buttonUp.UseVisualStyleBackColor = true;            this.buttonUp.Click += new System.EventHandler(this.buttonUpClick);            //             // buttonDown            //             this.buttonDown.Location = new System.Drawing.Point(277, 107);            this.buttonDown.Name = "buttonDown";            this.buttonDown.Size = new System.Drawing.Size(75, 23);            this.buttonDown.TabIndex = 6;            this.buttonDown.Text = "向下移动";                        this.buttonDown.UseVisualStyleBackColor = true;            this.buttonDown.Click += new System.EventHandler(this.buttonDownClick);            //             // FastTools            //             this.AutoScaleDimensions = new System.Drawing.SizeF(6F, 12F);            this.AutoScaleMode = System.Windows.Forms.AutoScaleMode.Font;            this.Controls.Add(this.buttonDown);            this.Controls.Add(this.buttonUp);            this.Controls.Add(this.buttonRemove);            this.Controls.Add(this.buttonAdd);            this.Controls.Add(this.groupBoxRight);            this.Controls.Add(this.groupBoxLeft);            this.Name = "FastTools";            this.Size = new System.Drawing.Size(623, 398);            this.groupBoxLeft.ResumeLayout(false);            this.groupBoxRight.ResumeLayout(false);            this.ResumeLayout(false);        }        private void ListViewLeft_MouseDown(object sender, MouseEventArgs e)        {            if ((sender as ListView) != null)            {                listViewLeftDown = this.listViewLeft.GetItemAt(e.X, e.Y);                this.listViewLeft.Refresh();            }            //this.listViewLeft.Refresh();        }        #endregion        /// <summary>        /// 添加        /// </summary>        /// <param name="sender"></param>        /// <param name="e"></param>        private void buttonAddClick(object sender, EventArgs e)        {            if (this.treeViewRight.SelectedNode!=null && this.treeViewRight.SelectedNode.Nodes.Count==0)            {                ToolStripItem[] items = this.appWorkspace.ToolBar.MainMenu.Items.Find(this.treeViewRight.SelectedNode.Name, true);                if (items != null && items.Length > 0)                {                    if (((PdnMenuItem)(items[0])).Image != null)                        this.listViewLeft.SmallImageList.Images.Add(this.treeViewRight.SelectedNode.Name, ((PdnMenuItem)(items[0])).Image);                    else                        this.listViewLeft.SmallImageList.Images.Add(this.treeViewRight.SelectedNode.Name, new Bitmap(16, 16));                }                else                {                    this.listViewLeft.SmallImageList.Images.Add(this.treeViewRight.SelectedNode.Name, new Bitmap(16, 16));                }                ListViewItem item = new ListViewItem();                item.Text = this.treeViewRight.SelectedNode.Text;                item.Tag = this.treeViewRight.SelectedNode.Tag;                item.Name = this.treeViewRight.SelectedNode.Name;                item.ImageIndex = this.listViewLeft.SmallImageList.Images.Count-1;                this.listViewLeft.Items.Add(item);            }        }        /// <summary>        /// 移出        /// </summary>        /// <param name="sender"></param>        /// <param name="e"></param>        private void buttonRemoveClick(object sender, EventArgs e)        {            if (this.listViewLeft.SelectedItems.Count > 0)            {                foreach(ListViewItem item in this.listViewLeft.SelectedItems)                    this.listViewLeft.Items.Remove(item);            }        }        /// <summary>        /// 向上移动        /// </summary>        /// <param name="sender"></param>        /// <param name="e"></param>        private void buttonUpClick(object sender, EventArgs e)        {            if (this.listViewLeft.SelectedItems.Count == 1)            {                int index = this.listViewLeft.Items.IndexOf(this.listViewLeft.SelectedItems[0]);                if (index > 0)                {                    ListViewItem prenode = (ListViewItem)this.listViewLeft.Items[index-1].Clone();                    prenode.Name = this.listViewLeft.Items[index - 1].Name;                    this.listViewLeft.Items.Insert(index + 1, prenode);                    this.listViewLeft.Items.Remove(this.listViewLeft.Items[index - 1]);                    this.listViewLeft.Refresh();                }            }          }        /// <summary>        /// 向下移动        /// </summary>        /// <param name="sender"></param>        /// <param name="e"></param>        private void buttonDownClick(object sender, EventArgs e)        {            if (this.listViewLeft.SelectedItems.Count == 1)            {                int index = this.listViewLeft.Items.IndexOf(this.listViewLeft.SelectedItems[0]);                if (index < this.listViewLeft.Items.Count-1)                {                    ListViewItem nextnode = (ListViewItem)this.listViewLeft.Items[index + 1].Clone();                    nextnode.Name = this.listViewLeft.Items[index + 1].Name;                    this.listViewLeft.Items.Insert(index, nextnode);                    this.listViewLeft.Items.Remove(this.listViewLeft.Items[index + 2]);                    this.listViewLeft.Refresh();                }            }        }        private void listViewLeft_DrawItem(object sender, DrawListViewItemEventArgs e)        {            e.DrawDefault = true;            return;        }        /// <summary>        /// treeViewLeft的重绘事件        /// </summary>        /// <param name="sender"></param>        /// <param name="e"></param>        private void treeViewLeft_InvalidateEvent(object sender, InvalidateEventArgs e)        {            //1009###17142            if (listViewLeftDown == null)            {                //this.buttonUp.Enabled = false;                //this.buttonDown.Enabled = false;                if (this.listViewLeft.SelectedItems.Count == 1)                {                    int index = this.listViewLeft.Items.IndexOf(this.listViewLeft.SelectedItems[0]);                    if (index > 0)                        this.buttonUp.Enabled = true;                    else                        this.buttonUp.Enabled = false;                }                else                    this.buttonUp.Enabled = false;                if (this.listViewLeft.SelectedItems.Count == 1)                {                    int index = this.listViewLeft.Items.IndexOf(this.listViewLeft.SelectedItems[0]);                    if (index < this.listViewLeft.Items.Count - 1)                        this.buttonDown.Enabled = true;                    else                        this.buttonDown.Enabled = false;                }                else                    this.buttonDown.Enabled = false;            }            else            {                int index = this.listViewLeft.Items.IndexOf(listViewLeftDown);                if (index > 0)                    this.buttonUp.Enabled = true;                else                    this.buttonUp.Enabled = false;                index = this.listViewLeft.Items.IndexOf(listViewLeftDown);                if (index < this.listViewLeft.Items.Count - 1)                    this.buttonDown.Enabled = true;                else                    this.buttonDown.Enabled = false;                listViewLeftDown = null;            }        }        /// <summary>        /// 保存数据到xml        /// </summary>        public void SaveToolbar()        {            shortcutbar_Model.Menus.Clear();            for (int i = 0; i < this.listViewLeft.Items.Count; i++)            {                ShortcutbarModel.Item flow = new ShortcutbarModel.Item();                flow.Id = (int)(this.listViewLeft.Items[i].Tag);                flow.Name = this.listViewLeft.Items[i].Text;                //################                flow.Description = this.listViewLeft.Items[i].Name;                shortcutbar_Model.Menus.Add(flow);            }            string userInfoXml = XmlSerializeHelper.XmlSerialize<ShortcutbarModel>(shortcutbar_Model);            string filePath = Application.StartupPath + "\\Config\\" + Startup.instance.SettingPrefix + "\\Shortcutbar.xml";            if (FileOperationHelper.WriteStringToFile(userInfoXml, filePath, FileMode.Create))            {                //更新全局数据                Startup.instance.shortcutbarModel = shortcutbar_Model;                //this.appWorkspace.mainToolBarForm.setCilentSize();                //this.appWorkspace.mainToolBarForm.ToolsControl.Refresh();                this.appWorkspace.toolsPanel.RefreshTools();            }            else            {                MessageBox.Show(PdnResources.GetString("Menu.Shortcuttoolbarsavefailed.text"));            }        }        /// <summary>        /// 导出配置        /// </summary>        /// <returns></returns>        public void ExportToolbarXml()        {            using (SaveFileDialog saveFileDialog = new SaveFileDialog())            {                saveFileDialog.InitialDirectory = Environment.GetFolderPath(Environment.SpecialFolder.Desktop);                saveFileDialog.Filter = "Xml(*.xml)|*.xml";                saveFileDialog.DefaultExt = "xml";                saveFileDialog.FilterIndex = 1;                saveFileDialog.CheckFileExists = false;                saveFileDialog.AddExtension = true;                saveFileDialog.FileName = "Shortcutbar";                if (saveFileDialog.ShowDialog() == DialogResult.OK)                {                    string filePath = saveFileDialog.FileName;                    string toolbarXml = XmlSerializeHelper.XmlSerialize<ShortcutbarModel>(Startup.instance.shortcutbarModel);                    if (FileOperationHelper.WriteStringToFile(toolbarXml, filePath, FileMode.Create))                        MessageBox.Show(PdnResources.GetString("Menu.lbarconfigurationfilewassavedsuccessfu.text"));                    else                        MessageBox.Show(PdnResources.GetString("Menu.Theshortcuttoolbarsave.text"));                }            }        }        /// <summary>        /// 导入配置        /// </summary>        /// <returns></returns>        public void ImportToolbarXml()        {            using (var openFileDialog = new OpenFileDialog { Filter = "*.xml|*.xml" })            {                if (openFileDialog.ShowDialog() == DialogResult.OK)                {                    using (Stream shortbarStream = System.IO.File.OpenRead(openFileDialog.FileName))                    {                        StreamReader sr = new StreamReader(shortbarStream);                        string xmlNotes =  sr.ReadToEnd();                        ShortcutbarModel toolbarXml = XmlSerializeHelper.DESerializer<ShortcutbarModel>(xmlNotes);                        if (toolbarXml.Menus.Count > 0)                        {                            try                            {                                this.listViewLeft.Items.Clear();                                this.listViewLeft.SmallImageList = new ImageList();                                this.listViewLeft.BeginUpdate();                                for (int i = 0; i < toolbarXml.Menus.Count; i++)                                {                                    ToolStripItem[] items = this.appWorkspace.ToolBar.MainMenu.Items.Find(toolbarXml.Menus[i].Description, true);                                    ListViewItem listItem = new ListViewItem();                                    if (items != null && items.Length > 0)                                    {                                        if (((PdnMenuItem)(items[0])).Image != null)                                            this.listViewLeft.SmallImageList.Images.Add(((PdnMenuItem)(items[0])).Text, ((PdnMenuItem)(items[0])).Image);                                        else                                            this.listViewLeft.SmallImageList.Images.Add(((PdnMenuItem)(items[0])).Text, new Bitmap(16, 16));                                        listItem.Text = ((PdnMenuItem)(items[0])).Text;                                    }                                    else                                    {                                        this.listViewLeft.SmallImageList.Images.Add(toolbarXml.Menus[i].Name/*getShowName(Startup.instance.configModel.Language)*/, new Bitmap(16, 16));                                        listItem.Text = toolbarXml.Menus[i].Name;// getShowName(Startup.instance.configModel.Language);                                    }                                    listItem.Tag = toolbarXml.Menus[i].Id;                                    listItem.Name = toolbarXml.Menus[i].Description;                                    listItem.ImageIndex = i;                                    this.listViewLeft.Items.Add(listItem);                                }                                this.listViewLeft.EndUpdate();                                MessageBox.Show(PdnResources.GetString("Menu.Shortcuttoolbasuccessfully.text"));                            }                            catch(Exception)                            {                                this.listViewLeft.Items.Clear();                                this.listViewLeft.SmallImageList = new ImageList();                                MessageBox.Show(PdnResources.GetString("Menu.Theshortcutconfigurationfileimportailed.text"));                            }                        }                        else                        {                            MessageBox.Show(PdnResources.GetString("Menu.onfiguratiofilesavedconfiguratio.text"));                        }                    }                }            }        }    }}
 |