Пример #1
0
        private void LoadShortCutMenu()
        {
            if (!Directory.Exists(_strConfigFilePath))
            {
                Directory.CreateDirectory(_strConfigFilePath);
            }
            string strShortCutFilePath = Path.Combine(_strConfigFilePath, WorkHelperStaticString.ShortCutMenuFileName);

            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");
                _ShortCutMenuList = new ShortCutList();
                _ShortCutMenuList.AddShortCutItem += AddShortCutMenuItem;//新增快捷菜单事件

                foreach (XmlNode xnModel in xmlList)
                {
                    if (xnModel.NodeType == XmlNodeType.Comment)
                    {
                        continue;
                    }
                    string strGuid = xnModel.GetAttributeValue("Guid");
                    if (_MenuDic.ContainsKey(strGuid))
                    {
                        ShortCutItem scItem = new ShortCutItem(_MenuDic[strGuid]);
                        scItem.ShortCutItemClick  += ShortCutMenuItem_Click;       //点击快捷菜单事件
                        scItem.ShortCutItemCancel += CancelShortCutMenuItem_Click; //取消快捷菜单事件
                        _ShortCutMenuList.AddItem(scItem);
                    }
                }
                //
                _ShortCutMenuList.Dock = DockStyle.Fill;
                pnlDestop.Controls.Add(_ShortCutMenuList);
            }
        }
Пример #2
0
        private void SaveShortCutMenuConfig(DMenu dMenu, bool IsAdd)
        {
            string      strShortCutFilePath = Path.Combine(_strConfigFilePath, WorkHelperStaticString.ShortCutMenuFileName);
            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 (_ShortCutMenuList.ItemList.ContainsKey(dMenu.Guid))
                    {
                        _ShortCutMenuList.MenuListPanl.Controls.Remove(_ShortCutMenuList.ItemList[dMenu.Guid]);
                        _ShortCutMenuList.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 (!_ShortCutMenuList.ItemList.ContainsKey(dMenu.Guid))
                    {
                        ShortCutItem scItem = new ShortCutItem(dMenu);
                        scItem.ShortCutItemClick  += ShortCutMenuItem_Click;       //点击快捷菜单事件
                        scItem.ShortCutItemCancel += CancelShortCutMenuItem_Click; //取消快捷菜单事件
                        _ShortCutMenuList.AddItem(scItem);
                    }
                }
            }
            xmlMenu.Save(strShortCutFilePath);
        }
Пример #3
0
 public void AddItem(ShortCutItem sci)
 {
     this.flpMenuList.Controls.Add(sci);
     _ItemList.Add(sci.Menu.Guid, sci);
 }