Esempio n. 1
0
        private void AddContextualGroup(JSObject data, RibbonBuildContext rbc)
        {
            ContextualColor color             = ContextualColor.None;
            string          contextualGroupId = DataNodeWrapper.GetAttribute(data, DataNodeWrapper.ID);

            // If the contextual tab group has been normalized, then we build the tabs as regular tabs
            bool normalized = !CUIUtility.IsNullOrUndefined(RibbonBuildOptions.NormalizedContextualGroups) &&
                              RibbonBuildOptions.NormalizedContextualGroups.ContainsKey(contextualGroupId) &&
                              RibbonBuildOptions.NormalizedContextualGroups[contextualGroupId];

            // If the contextual group has been normalized, it means that all of its tabs should
            // behave like regular tabs on this page so we do not need to create the contextual
            // group object in this case.
            if (!normalized)
            {
                switch (DataNodeWrapper.GetAttribute(data, DataNodeWrapper.COLOR))
                {
                case DataNodeWrapper.DARKBLUE:
                    color = ContextualColor.DarkBlue;
                    break;

                case DataNodeWrapper.LIGHTBLUE:
                    color = ContextualColor.LightBlue;
                    break;

                case DataNodeWrapper.MAGENTA:
                    color = ContextualColor.Magenta;
                    break;

                case DataNodeWrapper.GREEN:
                    color = ContextualColor.Green;
                    break;

                case DataNodeWrapper.ORANGE:
                    color = ContextualColor.Orange;
                    break;

                case DataNodeWrapper.PURPLE:
                    color = ContextualColor.Purple;
                    break;

                case DataNodeWrapper.TEAL:
                    color = ContextualColor.Teal;
                    break;

                case DataNodeWrapper.YELLOW:
                    color = ContextualColor.Yellow;
                    break;

                default:
                    color = ContextualColor.None;
                    break;
                }

                Ribbon.AddContextualGroup(contextualGroupId,
                                          DataNodeWrapper.GetAttribute(data, DataNodeWrapper.TITLE),
                                          color,
                                          DataNodeWrapper.GetAttribute(data, DataNodeWrapper.COMMAND));
            }

            JSObject[] tabChildren = DataNodeWrapper.GetNodeChildren(data);
            if (!normalized)
            {
                // This array will usually have one or two entries and at the very most three
                // So we are not using an iterator or caching tabChildren.Length etc.
                for (int i = 0; i < tabChildren.Length; i++)
                {
                    // If the initially visible tabId is in a contextual group, then we make that contextual
                    // group initially visible.
                    string tabId = DataNodeWrapper.GetAttribute(tabChildren[i], DataNodeWrapper.ID);
                    if (tabId == rbc.InitialTabId)
                    {
                        if (CUIUtility.IsNullOrUndefined(RibbonBuildOptions.InitiallyVisibleContextualGroups))
                        {
                            RibbonBuildOptions.InitiallyVisibleContextualGroups = new Dictionary <string, bool>();
                        }
                        RibbonBuildOptions.InitiallyVisibleContextualGroups[contextualGroupId] = true;
                        break;
                    }
                }
            }

            AddTabsToRibbon(tabChildren, normalized ? "" : contextualGroupId, rbc);
        }