Example #1
0
        static object CreateMenuItemFromDescriptor(NavItemDescriptor descriptor)
        {
            Codon  codon     = descriptor.Codon;
            string builderid = string.Empty;

            if (codon.Properties.Contains("builderid"))
            {
                builderid = codon.Properties["builderid"];
            }
            else
            {
                throw new Exception(string.Format("BuiderID not found:codonid ={0},condonname = {1}", codon.Id, codon.Name));
            }
            if (builderid == string.Empty)
            {
                throw new Exception(string.Format("BuiderID is empty:codonid ={0},condonname = {1}", codon.Id, codon.Name));
            }

            IPartBuilder builder = RibbonBuilderManager.GetBuider(builderid);
            object       obj     = builder.Build(codon, descriptor.Caller, codon.Conditions);

            if (obj is ModuleNavBarItem)
            {
                ModuleNavBarItem item = obj as ModuleNavBarItem;
                item.ModuleName = codon.Id;
            }
            return(obj);
        }
Example #2
0
        private void LoadCustomCommand(Codon codon, MenuItemDescriptor descriptor)
        {
            string commandId      = codon.Id;
            string builderid      = string.Empty;
            string checkForViewId = string.Empty;
            string controllerId   = string.Empty;

            //builder
            if (string.IsNullOrEmpty(codon.Properties["builderid"]))
            {
                throw new Exception(string.Format("BuiderID not found:codonid ={0},condonname = {1}", codon.Id, codon.Name));
            }
            else
            {
                builderid = codon.Properties["builderid"];
            }

            if (!string.IsNullOrEmpty(codon.Properties["controllerId"]))
            {
                controllerId = codon.Properties["controllerId"];
            }
            //checkForViewId
            if (!string.IsNullOrEmpty(codon.Properties["checkForViewId"]))
            {
                checkForViewId = codon.Properties["checkForViewId"];
            }


            //build item
            IPartBuilder buider = RibbonBuilderManager.GetBuider(builderid);
            object       item   = buider.Build(codon, this._controllerFinder.FindController(string.Empty), codon.Conditions);

            if (!(item is BarItem))
            {
                throw new Exception(string.Format("Builded Custom Command object is not BarItem:id ={0},name = {1}", codon.Id, codon.Name));
            }
            if (string.IsNullOrEmpty(codon.Properties["class"]))
            {
                throw new Exception(string.Format("Action Command Class not defined in Custom Command:id ={0},name = {1}", codon.Id, codon.Name));
            }
            //build action command
            ICommand command = (ICommand)codon.AddIn.CreateObject(codon.Properties["class"]);

            BarItem       barItem = item as BarItem;
            CommandDrawer drawer  = new CommandDrawer();

            drawer.SetItemGlyph(codon, barItem);
            this._barManager.Items.Add(barItem);
            this.AddCustomCommand(commandId, checkForViewId, barItem, command, descriptor.Conditions, controllerId);
        }
Example #3
0
        static object CreateMenuItemFromDescriptor(MenuItemDescriptor descriptor, string addinTreePath, ICommandRegister register)
        {
            Codon codon = descriptor.Codon;

            string cmdPath   = addinTreePath + "/" + codon.Id;
            string builderid = string.Empty;

            if (codon.Properties.Contains("builderid"))
            {
                builderid = codon.Properties["builderid"];
            }
            else if (codon.Properties.Contains("cmdId"))
            {
                string cmdId = codon.Properties["cmdId"];
                return(register.GetBarItem(cmdId));
            }
            else
            {
                throw new Exception(string.Format("BuiderID not found:codonid ={0},condonname = {1}", codon.Id, codon.Name));
            }
            if (builderid == string.Empty)
            {
                throw new Exception(string.Format("BuiderID is empty:codonid ={0},condonname = {1}", codon.Id, codon.Name));
            }

            IPartBuilder builder = RibbonBuilderManager.GetBuider(builderid);
            object       obj     = builder.Build(codon, descriptor.Caller, descriptor.Conditions);;

            try
            {
                if (obj is BarButtonItemEx)
                {
                    BarItem cmdBar = obj as BarItem;

                    string formats = "<MenuItem id ={0} checkForViewId =\"\" source =\"Ribbon\" cmdPath =\"{1}\"/>";
                    System.Diagnostics.Debug.WriteLine(string.Format(formats, codon.Id, cmdPath));
                    if (register != null)
                    {
                        //ICommand command = (ICommand)codon.AddIn.CreateObject(codon.Properties["class"]);
                        //command.Owner = register.owner;
                        ICommand command = cmdBar.Tag as ICommand;
                        if (command != null)
                        {
                            if (string.IsNullOrEmpty(codon.Properties["groupName"]))
                            {
                                bool registerSuc = register.RegisterCommand(cmdBar, cmdPath, command, descriptor.Conditions);
                            }
                            else
                            {
                                string groupName   = codon.Properties["groupName"];
                                bool   registerSuc = register.RegisterCommand(cmdBar, codon.Id, cmdPath, command, groupName);
                            }
                        }
                        //Debug.WriteLine("Register =" + registerSuc.ToString());
                    }
                }
            }
            catch (Exception ex)
            {
                throw ex;
            }
            return(obj);
        }