private void LoadShortCutMenu() { if (!Directory.Exists(_strConfigFilePath)) { Directory.CreateDirectory(_strConfigFilePath); } string strShortCutFilePath = System.IO.Path.Combine(_strConfigFilePath, WorkHelperStaticString.ShortCutMenuFileName_WPF); if (!File.Exists(strShortCutFilePath)) { XmlDocument xmlShortCut = new XmlDocument(); XmlElement xmRoot = xmlShortCut.CreateElement("xml"); xmlShortCut.AppendChild(xmRoot); xmlShortCut.Save(strShortCutFilePath); } else { XmlDocument xmlMenu = new XmlDocument(); xmlMenu.Load(strShortCutFilePath); XmlNodeList xmlList = xmlMenu.SelectNodes("xml/Menu"); _UC_Desktop.AddShortCutItem += AddShortCutMenuItem;//新增快捷菜单事件 foreach (XmlNode xnModel in xmlList) { if (xnModel.NodeType == XmlNodeType.Comment) { continue; } string strGuid = xnModel.GetAttributeValue("Guid"); if (_MenuDic.ContainsKey(strGuid)) { var scItem = new UC_ShortCutItem(_MenuDic[strGuid]); scItem.ShortCutItemClick += ShortCutMenuItem_Click; //点击快捷菜单事件 scItem.ShortCutItemCancel += CancelShortCutMenuItem_Click; //取消快捷菜单事件 _UC_Desktop.AddItem(scItem); } } // //_ShortCutMenuList.Dock = DockStyle.Fill; //pnlDestop.Controls.Add(_ShortCutMenuList); } }
private void SaveShortCutMenuConfig(DMenu dMenu, bool IsAdd) { string strShortCutFilePath = System.IO.Path.Combine(_strConfigFilePath, WorkHelperStaticString.ShortCutMenuFileName_WPF); XmlDocument xmlMenu = new XmlDocument(); xmlMenu.Load(strShortCutFilePath); XmlNodeList xmlList = xmlMenu.SelectNodes("xml/Menu"); XmlNode xnRemove = xmlMenu.SelectSingleNode("xml/Menu[@Guid='" + dMenu.Guid + "']"); if (xnRemove != null) { if (!IsAdd) { xnRemove.ParentNode.RemoveChild(xnRemove); //从快捷菜单中移除 if (_UC_Desktop.ItemList.ContainsKey(dMenu.Guid)) { _UC_Desktop.MenuListPanl.Children.Remove(_UC_Desktop.ItemList[dMenu.Guid]); _UC_Desktop.ItemList.Remove(dMenu.Guid); } } } else { if (IsAdd) { XmlElement xnNew = xmlMenu.CreateElement("Menu"); xnNew.SetAttribute("Guid", dMenu.Guid); xnNew.SetAttribute("Name", dMenu.Name); xmlMenu.DocumentElement.AppendChild(xnNew); if (!_UC_Desktop.ItemList.ContainsKey(dMenu.Guid)) { var scItem = new UC_ShortCutItem(dMenu); scItem.ShortCutItemClick += ShortCutMenuItem_Click; //点击快捷菜单事件 scItem.ShortCutItemCancel += CancelShortCutMenuItem_Click; //取消快捷菜单事件 _UC_Desktop.AddItem(scItem); } } } xmlMenu.Save(strShortCutFilePath); }
public void AddItem(UC_ShortCutItem sci) { this.flpMenuList.Children.Add(sci); _ItemList.Add(sci.Menu.Guid, sci); }