Example #1
0
        private ICommand LoadFromCommandInfo(RibbonCommandInfo cmdInfo)
        {
            if (cmdInfo == null)
            {
                return(null);
            }

            string curPage      = cmdInfo.Page;
            string curPageGroup = cmdInfo.PageGroup;

            // BarItem
            ICommand cmd = null;

            try
            {
                cmd = ResourceFactory.CreateCommand(cmdInfo.CommandClass);
                if (cmd != null)
                {
                    LoadFromCommand(cmd, curPage, curPageGroup, cmdInfo.Caption, cmdInfo.Icon, cmdInfo.Type, cmdInfo.ID, cmdInfo.Parent == null ? null : cmdInfo.Parent.ID);
                }
            }
            catch (Exception exp)
            {
                SendMessage(string.Format("创建{0}实例时出错,信息:{1};将跳过此命令。", cmdInfo.CommandClass.ClassName, exp.ToString(), exp.ToString()));
            }

            return(cmd);
        }
Example #2
0
        public void Load(ref List <ICommand> cmdList)
        {
            if (Ribbon == null || CommandInfoList == null)
            {
                return;
            }

            if (cmdList == null)
            {
                cmdList = new List <ICommand>();
            }

            Init();
            int count = CommandInfoList.Count;

            for (int i = 0; i < count; i++)
            {
                RibbonCommandInfo cmdInfo = CommandInfoList[i];
                if (cmdInfo == null)
                {
                    continue;
                }

                ICommand cmd = LoadFromCommandInfo(cmdInfo);
                if (cmd == null)
                {
                    continue;
                }

                cmdList.Add(cmd);
            }
        }
Example #3
0
        private void SaveCommandNode(TreeListNode nodeCommand, TreeListNode nodePage, TreeListNode nodeGroup, int pageOrder, int groupOrder, int cmdOrder)
        {
            SendMessage(string.Format("正在保存第{0}个命令...", ++m_SaveIndex));
            RibbonCommandInfo rcInfo = null;

            if (nodeCommand.Tag is RibbonCommandInfo)
            {
                rcInfo = nodeCommand.Tag as RibbonCommandInfo;
            }
            else
            {
                rcInfo = new RibbonCommandInfo();
            }

            rcInfo.Page         = nodePage.GetValue(tlColCaption) as string;
            rcInfo.PageGroup    = nodeGroup.GetValue(tlColCaption) as string;
            rcInfo.Caption      = nodeCommand.GetValue(tlColCaption) as string;
            rcInfo.CommandClass = nodeCommand.GetValue(tlColContent) as ClassInfo;
            object objIcon = nodeCommand.GetValue(tlColIcon);

            rcInfo.Icon = objIcon is byte[]?Image.FromStream(new System.IO.MemoryStream(objIcon as byte[])):objIcon as Image;

            rcInfo.Parent = nodeCommand.ParentNode.Tag as RibbonCommandInfo;// nodeCommand.ParentNode.Tag is RibbonCommandInfo ? nodeCommand.ParentNode.Tag as RibbonCommandInfo : null;
            if (rcInfo.Parent != null)
            {
                rcInfo.Order = rcInfo.Parent.Order + cmdOrder.ToString("00");
            }
            else
            {
                rcInfo.Order = pageOrder.ToString("00") + groupOrder.ToString("00") + cmdOrder.ToString("00");
            }
            int typeIndex = m_TypeNames.IndexOf(nodeCommand.GetValue(tlColCommandType) as string);

            rcInfo.Type = (enumCommandType)(typeIndex < 0?0:typeIndex);

            //if (nodeCommand.Tag is RibbonCommandInfo)
            //{
            //    m_HibernateHelper.UpdateObject(rcInfo);

            //}
            //else
            //{
            //    m_HibernateHelper.SaveObject(rcInfo);
            //    nodeCommand.Tag = rcInfo;
            //}
            m_HibernateHelper.SaveObject(rcInfo);
            nodeCommand.Tag = rcInfo;
            //m_HibernateHelper.RefreshObject(rcInfo);
            for (int i = 0; i < nodeCommand.Nodes.Count; i++)
            {
                SaveCommandNode(nodeCommand.Nodes[i], nodePage, nodeGroup, pageOrder, groupOrder, i + 1);
            }
            //foreach (TreeListNode nodeSub in nodeCommand.Nodes)
            //{
            //    SaveCommandNode(nodeSub, nodePage, nodeGroup, pageOrder, groupOrder, cmdOrder);
            //}
        }
Example #4
0
        private void InitRibbon()
        {
            IList <RibbonCommandInfo> listCommand = m_HibernateHelper.GetObjectsByCondition <RibbonCommandInfo>("from RibbonCommandInfo rcInfo order by Order asc");//from RibbonCommandInfo rcInfo order by Page,PageGroup asc");
            int count = listCommand.Count;

            //m_CommandList = new List<RibbonCommandInfo>();
            //for (int i = 0; i < count; i++)
            //{
            //    m_CommandList.Add(listCommand[i] as RibbonCommandInfo);
            //}
            m_CommandList = listCommand as List <RibbonCommandInfo>;

            // 工具栏预览
            this.applicationMenu1.ItemLinks.Clear();
            this.ribbonControl1.Items.Clear();
            this.ribbonControl1.Pages.Clear();
            this.ribbonControl1.StatusBar.ItemLinks.Clear();
            this.ribbonControl1.PageHeaderItemLinks.Clear();
            this.ribbonControl1.Toolbar.ItemLinks.Clear();
            ribbonControl1.Pages.Clear();
            RibbonEngine ribbonEngine = new RibbonEngine();

            ribbonEngine.CommandInfoList   = m_CommandList;
            ribbonEngine.Ribbon            = this.ribbonControl1;
            ribbonEngine.MainMenu          = applicationMenu1;
            ribbonEngine.CommandInfoFinder = delegate(string resourceID)
            {
                return(m_CommandList.Find(delegate(RibbonCommandInfo cmdInfo) { return cmdInfo.ID == resourceID; }));
            };
            List <ICommand> cmdList = new List <ICommand>();

            ribbonEngine.Load(ref cmdList);


            // 树
            tlRibbon.Nodes.Clear();
            string strPage  = null;
            string strGroup = null;
            Dictionary <string, TreeListNode> dicNode = new Dictionary <string, TreeListNode>();
            TreeListNode nodePage   = null;
            TreeListNode nodeGroup  = null;
            TreeListNode nodeParent = null;
            int          pageOrder  = 1;
            int          groupOrder = 1;
            int          cmdOrder   = 1;

            for (int i = 0; i < count; i++)
            {
                RibbonCommandInfo cmdInfo = m_CommandList[i];
                //if (cmdInfo.Type != enumCommandType.Normal)
                //    continue;
                if (cmdInfo.Parent != null)
                {
                    // 必须排好序才能这么来
                    nodeParent = dicNode[cmdInfo.Parent.ID];
                }
                else
                {
                    if (strPage != cmdInfo.Page)
                    {
                        strPage   = cmdInfo.Page;
                        nodePage  = tlRibbon.AppendNode(new object[] { strPage, null, null, pageOrder++ }, null);
                        pageOrder = 1;
                    }

                    if (strGroup != cmdInfo.PageGroup)
                    {
                        strGroup  = cmdInfo.PageGroup;
                        nodeGroup = tlRibbon.AppendNode(new object[] { strGroup, null, null, groupOrder++ }, nodePage);
                        cmdOrder  = 1;
                    }
                    nodeParent = nodeGroup;
                }

                TreeListNode nodeCommand = tlRibbon.AppendNode(new object[] { cmdInfo.Caption, cmdInfo.Icon, cmdInfo.CommandClass, cmdOrder++, m_TypeNames[(int)cmdInfo.Type] }, nodeParent);
                nodeCommand.Tag = cmdInfo;

                dicNode.Add(cmdInfo.ID, nodeCommand);
            }
        }