Esempio n. 1
0
        public void SetContextMenu(Control mapControl)
        {
            if (string.IsNullOrEmpty(_oldToolName))
            {
                _ribbonManager.SetPopupContextMenu(mapControl, null);
                return;
            }
            BarItem item = _ribbonManager.Items[_oldToolName];

            if (item == null)
            {
                _ribbonManager.SetPopupContextMenu(mapControl, null);
                return;
            }
            YutaiTool tool = item.Tag as YutaiTool;

            if (!(tool is IToolContextMenu))
            {
                _ribbonManager.SetPopupContextMenu(mapControl, null);
                return;
            }

            PopupMenu mPCurrentPopupMenu = this.m_pCurrentPopupMenu;

            mPCurrentPopupMenu.ClearLinks();
            string[] keys = ((IToolContextMenu)tool).ContextMenuKeys;
            if (keys == null)
            {
                return;
            }
            item = null;
            bool nextGroup = false;

            for (int i = 0; i < keys.Length; i++)
            {
                if (keys[i].Equals('-'))
                {
                    nextGroup = true;
                    continue;
                }
                item = _ribbonManager.Items[keys[i]];

                if (item == null)
                {
                    continue;
                }
                BarItemLink link = mPCurrentPopupMenu.AddItem(item);
                if (nextGroup)
                {
                    link.BeginGroup = true;
                    nextGroup       = false;
                }
            }
            if (mPCurrentPopupMenu.ItemLinks.Count <= 0)
            {
                _ribbonManager.SetPopupContextMenu(mapControl, this.m_pSystemPopupMenu);
            }
            else
            {
                _ribbonManager.SetPopupContextMenu(mapControl, mPCurrentPopupMenu);
            }
        }