Пример #1
0
        private Component DelayInitTab(Component component,
                                       object data,
                                       object buildContext)
        {
            RibbonBuildContext rbc = (RibbonBuildContext)buildContext;
            Tab tab = (Tab)component;

            rbc.InitializedTab = (Tab)component;
            // If the data node does not have children, then it means that this tab
            // was shallowly fetched from the server.  In this case we need to run
            // a query to get the whole node with all of its controls from the server.
            JSObject[] children = DataNodeWrapper.GetNodeChildren(data);
            if (children.Length == 0)
            {
                // TODO: implement this so that the asynchronous part works
                // Find out if we even need to fetch the tabs asynchronously
                // or if we can get away with just initializing them asynchronously
                DataQuery query = new DataQuery();
                query.TabQuery  = true;
                query.Id        = rbc.InitializedTab.Id;
                query.QueryType = DataQueryType.RibbonTab;
                query.Handler   = new DataReturnedEventHandler(this.OnReturnTab);
                query.Data      = rbc;
                DataSource.RunQuery(query);
                return(null);
            }

            FillTab(tab, data, rbc);
            tab.OnDelayedInitFinished(true);
            // TODO(josefl): this should later be an idle task registration instead of a hard call
            Ribbon.Refresh();

            return(tab);
        }
Пример #2
0
        private void HandleRow(Row row, JSObject data, DeclarativeTemplateBuildContext bc)
        {
            JSObject[] children = DataNodeWrapper.GetNodeChildren(data);
            for (int i = 0; i < children.Length; i++)
            {
                string    name = DataNodeWrapper.GetNodeName(children[i]);
                Component comp = null;

                if (name == DataNodeWrapper.CONTROL)
                {
                    comp = CreateControlComponentFromData(children[i], bc);
                }
                else if (name == DataNodeWrapper.OVERFLOWAREA)
                {
                    HandleOverflow(children[i], bc, row, i);
                }
                else
                {
                    comp = CreateStripFromData(children[i], bc, row, i);
                }

                if (!CUIUtility.IsNullOrUndefined(comp))
                {
                    row.AddChild(comp);
                }
            }
        }
Пример #3
0
        public override Group CreateGroup(SPRibbon ribbon,
                                          string id,
                                          GroupProperties properties,
                                          string title,
                                          string description,
                                          string command,
                                          Dictionary <string, List <Control> > controls,
                                          Dictionary <string, string> pars)
        {
            DeclarativeTemplateBuildContext bc = new DeclarativeTemplateBuildContext();

            bc.Ribbon     = ribbon;
            bc.Controls   = controls;
            bc.Parameters = pars;

            Group group = ribbon.CreateGroup(id, properties, title, description, command);

            // Loop through the Layouts for this group and create them.
            JSObject[] children = DataNodeWrapper.GetNodeChildren(_data);
            for (int i = 0; i < children.Length; i++)
            {
                Layout layout = CreateLayoutFromData(children[i], group, bc);
                if (!CUIUtility.IsNullOrUndefined(layout))
                {
                    group.AddChild(layout);
                }
            }
            return(group);
        }
Пример #4
0
        private Strip CreateStripFromData(object data,
                                          DeclarativeTemplateBuildContext bc,
                                          Component parent,
                                          int rowComponentNumber)
        {
            JSObject[] children = DataNodeWrapper.GetNodeChildren(data);
            Strip      strip    = bc.Ribbon.CreateStrip(parent.Id + "-" + rowComponentNumber);

            for (int i = 0; i < children.Length; i++)
            {
                string name = DataNodeWrapper.GetNodeName(children[i]);
                if (name == DataNodeWrapper.CONTROL)
                {
                    ControlComponent comp = CreateControlComponentFromData(children[i], bc);
                    if (!CUIUtility.IsNullOrUndefined(comp))
                    {
                        strip.AddChild(comp);
                    }
                }
                else
                {
                    HandleOverflow(children[i], bc, strip, i);
                }
            }

            // If there are no children in the strip then there is no reason to add it
            // If we ever support dynamically adding and removing components out of the ribbon
            // then this will need to be revisitited.
            if (strip.Children.Count == 0)
            {
                return(null);
            }

            return(strip);
        }
Пример #5
0
        private ColorPicker BuildColorPicker(object data, BuildContext bc)
        {
            ColorPickerProperties properties = DataNodeWrapper.GetNodeAttributes(data).To <ColorPickerProperties>();

            JSObject[] colorNodes = DataNodeWrapper.GetNodeChildren(
                DataNodeWrapper.GetFirstChildNodeWithName(data,
                                                          DataNodeWrapper.Colors));
            int numColors = colorNodes.Length;

            ColorStyle[] colors = new ColorStyle[numColors];
            for (int i = 0; i < numColors; i++)
            {
                ColorStyle color = new ColorStyle();
                JSObject   dict  = DataNodeWrapper.GetNodeAttributes(colorNodes[i]);
                string     title = DataNodeWrapper.GetAttribute(dict, DataNodeWrapper.TITLE);
                color.Title = string.IsNullOrEmpty(title) ?
                              DataNodeWrapper.GetAttribute(dict, DataNodeWrapper.ALT) : title;
                color.Color        = DataNodeWrapper.GetAttribute(dict, DataNodeWrapper.COLOR);
                color.DisplayColor = DataNodeWrapper.GetAttribute(dict, DataNodeWrapper.DISPLAYCOLOR);
                color.Style        = DataNodeWrapper.GetAttribute(dict, DataNodeWrapper.STYLE);
                colors[i]          = color;
            }


            ColorPicker cp = new ColorPicker(Root,
                                             properties.Id,
                                             properties,
                                             colors);

            return(cp);
        }
Пример #6
0
        private QAT BuildQATInternal(object data, QATBuildContext qbc)
        {
            if (CUIUtility.IsNullOrUndefined(data))
            {
                throw new ArgumentNullException("No QAT element was present in the data");
            }

            QAT = new QAT(DataNodeWrapper.GetAttribute(data, "Id"),
                          DataNodeWrapper.GetNodeAttributes(data).To <QATProperties>());

            // Handle the controls in the QAT
            // The XML structure looks like <QAT><Controls><Control></Control><Control></Control>...
            JSObject controlsParent = DataNodeWrapper.GetFirstChildNodeWithName(data, DataNodeWrapper.CONTROLS);

            JSObject[] controls = DataNodeWrapper.GetNodeChildren(controlsParent);
            for (int j = 0; j < controls.Length; j++)
            {
                if (!IsNodeTrimmed(controls[j]))
                {
                    Control control = BuildControl(controls[j], qbc);
                    QAT.AddChild(control.CreateComponentForDisplayMode("Small"));
                }
            }

            return(QAT);
        }
Пример #7
0
        public void LoadTemplates(object data)
        {
            JSObject templatesNode = DataNodeWrapper.GetFirstChildNodeWithName(data, DataNodeWrapper.RIBBONTEMPLATES);

            JSObject[] children = DataNodeWrapper.GetNodeChildren(templatesNode);
            for (int i = 0; i < children.Length; i++)
            {
                LoadGroupTemplate(children[i]);
            }
        }
Пример #8
0
        private SPRibbon BuildRibbon(object data, RibbonBuildContext rbc)
        {
            JSObject ribbonElement = DataNodeWrapper.GetFirstChildNodeWithName(data,
                                                                               DataNodeWrapper.RIBBON);

            if (CUIUtility.IsNullOrUndefined(ribbonElement))
            {
                throw new ArgumentNullException("No ribbon element was present in the data");
            }

            Ribbon = new SPRibbon(DataNodeWrapper.GetAttribute(ribbonElement, "Id"),
                                  DataNodeWrapper.GetNodeAttributes(ribbonElement).To <RibbonProperties>());

            //REVIEW(josefl) Should this be configurable?
            Ribbon.UseDataCookie = true;

            // Handle the Tabs
            // The XML structure that we are looking at is <Ribbon><Tabs><Tab/><Tab/>...
            JSObject[] tabChildren = DataNodeWrapper.GetNodeChildren(
                DataNodeWrapper.GetFirstChildNodeWithName(ribbonElement, DataNodeWrapper.TABS));

            AddTabsToRibbon(tabChildren, "", rbc);

            // Handle the Contextual Tab Groups
            // The XML structure that we are looking at is <Ribbon><ContextualTabs><ContextualGroup>...
            object contextualTabs = DataNodeWrapper.GetFirstChildNodeWithName(ribbonElement, DataNodeWrapper.CONTEXTUALTABS);

            if (!CUIUtility.IsNullOrUndefined(contextualTabs))
            {
                JSObject[] cgChildren = DataNodeWrapper.GetNodeChildren(contextualTabs);
                bool       shownContextualGroupsSpecified =
                    !CUIUtility.IsNullOrUndefined(RibbonBuildOptions.ShownContextualGroups);
                for (int j = 0; j < cgChildren.Length; j++)
                {
                    if (shownContextualGroupsSpecified)
                    {
                        // Show the contextual group if it has been explicitly requested/ made available
                        string cgId = DataNodeWrapper.GetAttribute(cgChildren[j], DataNodeWrapper.ID);
                        if (!string.IsNullOrEmpty(cgId))
                        {
                            if (!RibbonBuildOptions.ShownContextualGroups.ContainsKey(cgId) ||
                                CUIUtility.IsNullOrUndefined(RibbonBuildOptions.ShownContextualGroups[cgId]))
                            {
                                continue;
                            }
                        }
                    }
                    AddContextualGroup(cgChildren[j], rbc);
                }
            }

            return(Ribbon);
        }
Пример #9
0
        private MenuSection BuildMenuSection(JSObject data, BuildContext bc)
        {
            string displayMode = DataNodeWrapper.GetAttribute(data, DataNodeWrapper.DISPLAYMODE);

            if (CUIUtility.IsNullOrUndefined(displayMode))
            {
                displayMode = "Menu";
            }

            string      id          = DataNodeWrapper.GetAttribute(data, DataNodeWrapper.ID);
            string      title       = DataNodeWrapper.GetAttribute(data, DataNodeWrapper.TITLE);
            string      description = DataNodeWrapper.GetAttribute(data, DataNodeWrapper.DESCRIPTION);
            bool        scrollable  = Utility.IsTrue(DataNodeWrapper.GetAttribute(data, DataNodeWrapper.SCROLLABLE));
            string      maxheight   = DataNodeWrapper.GetAttribute(data, DataNodeWrapper.MAXHEIGHT);
            MenuSection ms          = Root.CreateMenuSection(id,
                                                             title,
                                                             description,
                                                             scrollable,
                                                             maxheight,
                                                             displayMode);

            JSObject[] menuSectionChildren = DataNodeWrapper.GetNodeChildren(data);
            JSObject   msChild             = menuSectionChildren[0];
            string     msChildName         = DataNodeWrapper.GetNodeName(msChild);

            if (msChildName == DataNodeWrapper.CONTROLS)
            {
                // Get the <MenuSection><Controls> node's children
                JSObject[] individualControls = DataNodeWrapper.GetNodeChildren(msChild);
                int        l = individualControls.Length;

                JSObject child = null;
                for (int i = 0; i < l; i++)
                {
                    child = individualControls[i];
                    if (IsNodeTrimmed(child))
                    {
                        continue;
                    }
                    Control control = BuildControl(child, bc);
                    ms.AddChild(control.CreateComponentForDisplayMode(displayMode));
                }
            }
            else if (msChildName == DataNodeWrapper.GALLERY)
            {
                Gallery gallery = BuildGallery(msChild, bc, true);
                ms.AddChild(gallery);
            }

            return(ms);
        }
Пример #10
0
        private Tab BuildTab(object data,
                             RibbonBuildContext rbc,
                             string contextualGroupId)
        {
            Tab    tab;
            string id          = DataNodeWrapper.GetAttribute(data, DataNodeWrapper.ID);
            string title       = DataNodeWrapper.GetAttribute(data, DataNodeWrapper.TITLE);
            string description = DataNodeWrapper.GetAttribute(data, DataNodeWrapper.DESCRIPTION);
            string command     = DataNodeWrapper.GetAttribute(data, DataNodeWrapper.COMMAND);
            string cssclass    = DataNodeWrapper.GetAttribute(data, DataNodeWrapper.CSSCLASS);

            if (string.IsNullOrEmpty(contextualGroupId))
            {
                tab = Ribbon.CreateTab(id,
                                       title,
                                       description,
                                       command,
                                       cssclass);
            }
            else
            {
                tab = Ribbon.CreateContextualTab(id,
                                                 title,
                                                 description,
                                                 command,
                                                 contextualGroupId,
                                                 cssclass);
                // Make sure that the tabs that are in the initially shown contextual groups are visible
                if (!CUIUtility.IsNullOrUndefined(RibbonBuildOptions.InitiallyVisibleContextualGroups) &&
                    RibbonBuildOptions.InitiallyVisibleContextualGroups.ContainsKey(contextualGroupId) &&
                    RibbonBuildOptions.InitiallyVisibleContextualGroups[contextualGroupId])
                {
                    tab.VisibleInternal = true;
                }
            }

            // If the Tab is being inited in a shallow way, then we set the callback so that
            // the builder will be called if the Tab is selected.
            // We set up the Tab to be delay initialized and give it its own copy of the build context
            JSObject[] children = DataNodeWrapper.GetNodeChildren(data);
            if (children.Length == 0)
            {
                tab.SetDelayedInitData(new DelayedInitHandler(DelayInitTab), data, rbc.Clone());
            }
            else
            {
                FillTab(tab, data, rbc);
            }

            return(tab);
        }
Пример #11
0
        private ComboBox BuildComboBox(object data, BuildContext bc)
        {
            ComboBoxProperties properties =
                DataNodeWrapper.GetNodeAttributes(data).To <ComboBoxProperties>();

            JSObject[] children = DataNodeWrapper.GetNodeChildren(data);

            Menu menu = null;

            MenuLauncherControlProperties launcherProperties =
                DataNodeWrapper.GetNodeAttributes(data).To <MenuLauncherControlProperties>();

            Dictionary <string, string> menuItems = null;

            if (!Utility.IsTrue(launcherProperties.PopulateDynamically))
            {
                // Since PopulateDynamically is not true, we pass in "false" for LazyInit
                menu = BuildMenu(children[0], bc, false);

                // Parse XML subtree to build MenuItem list for auto-complete
                menuItems = new Dictionary <string, string>();
                JSObject[] sections = DataNodeWrapper.GetNodeChildren(children[0]);
                int        l        = sections.Length;
                for (int i = 0; i < l; i++)
                {
                    // Get children of the MenuSection node
                    JSObject[] sectionChildren = DataNodeWrapper.GetNodeChildren(sections[i]);
                    // Get children of the Controls node within the MenuSection
                    // There should only be 1 Controls node within the MenuSection subtree
                    JSObject[] items = DataNodeWrapper.GetNodeChildren(sectionChildren[0]);
                    int        m     = items.Length;
                    for (int j = 0; j < m; j++)
                    {
                        string labeltext  = DataNodeWrapper.GetAttribute(items[j], DataNodeWrapper.LABELTEXT);
                        string menuitemid = DataNodeWrapper.GetAttribute(items[j], DataNodeWrapper.MENUITEMID);
                        menuItems[labeltext] = menuitemid;
                    }
                }
            }

            ComboBox fscb = new ComboBox(Root,
                                         properties.Id,
                                         properties,
                                         menu);

            fscb.MenuItems = menuItems;
            return(fscb);
        }
Пример #12
0
        public static JSObject GetFirstChildNodeWithName(object data, string name)
        {
            JSObject[] children = DataNodeWrapper.GetNodeChildren(data);

            int l = children.Length;

            for (int i = 0; i < l; i++)
            {
                JSObject child = children[i];
                string   nm    = DataNodeWrapper.GetNodeName(child);
                if (nm == name)
                {
                    return(child);
                }
            }
            return(null);
        }
Пример #13
0
        private SplitButton BuildSplitButton(object data, BuildContext bc)
        {
            SplitButtonProperties properties =
                DataNodeWrapper.GetNodeAttributes(data).To <SplitButtonProperties>();

            JSObject[] children = DataNodeWrapper.GetNodeChildren(data);
            Menu       menu     = null;

            if (!Utility.IsTrue(properties.PopulateDynamically))
            {
                menu = BuildMenu(children[0], bc, true);
            }

            SplitButton fseo =
                new SplitButton(Root,
                                properties.Id,
                                properties,
                                menu);

            return(fseo);
        }
Пример #14
0
        private Gallery BuildGallery(object data, BuildContext bc, bool isInMenu)
        {
            JSObject          attrs      = DataNodeWrapper.GetNodeAttributes(data);
            GalleryProperties properties = DataNodeWrapper.GetNodeAttributes(data).To <GalleryProperties>();
            Gallery           gallery    = Root.CreateGallery(properties.Id,
                                                              DataNodeWrapper.GetAttribute(attrs, DataNodeWrapper.TITLE),
                                                              DataNodeWrapper.GetAttribute(attrs, DataNodeWrapper.DESCRIPTION),
                                                              properties);

            string displayMode = isInMenu ? "Menu" : "Default";

            JSObject[] children = DataNodeWrapper.GetNodeChildren(data);
            int        l        = children.Length;

            for (int i = 0; i < l; i++)
            {
                JSObject child = children[i];
                if (IsNodeTrimmed(child))
                {
                    continue;
                }

                // NOTE: currently, galleries can only host GalleryButton controls.
                // In the future, the gallery could support other control types, so those should be added here.
                Control control;
                switch (DataNodeWrapper.GetNodeName(child))
                {
                case DataNodeWrapper.GalleryButton:
                    control = BuildGalleryButton(child, bc, properties.ElementDimensions);
                    break;

                default:
                    control = BuildControl(child, bc);
                    break;
                }
                gallery.AddChild(control.CreateComponentForDisplayMode(displayMode));
            }

            return(gallery);
        }
Пример #15
0
        /// <summary>
        /// Constructs a toolbar from its JSON data.
        /// </summary>
        private Toolbar BuildToolbarFromData(object data, ToolbarBuildContext context)
        {
            JSObject toolbarElement = DataNodeWrapper.GetFirstChildNodeWithName(data, DataNodeWrapper.TOOLBAR);

            if (CUIUtility.IsNullOrUndefined(toolbarElement))
            {
                throw new ArgumentNullException("No toolbar element was present in the data");
            }

            bool hasJewel = !CUIUtility.IsNullOrUndefined(DataNodeWrapper.GetFirstChildNodeWithName(data, DataNodeWrapper.JEWEL));

            Toolbar = new Toolbar(
                DataNodeWrapper.GetAttribute(toolbarElement, DataNodeWrapper.ID),
                DataNodeWrapper.GetNodeAttributes(toolbarElement).To <ToolbarProperties>(),
                this,
                hasJewel);

            Toolbar.ClientID      = Options.ClientID;
            Toolbar.UseDataCookie = true;

            Toolbar.RefreshInternal(); // We need to refresh before we can attach the jewel.

            if (hasJewel)
            {
                Toolbar.AttachAndBuildJewelFromData(data);
            }

            // Build the ButtonDocks (the Docks will build their subcontrols).
            JSObject docks = DataNodeWrapper.GetFirstChildNodeWithName(toolbarElement, DataNodeWrapper.BUTTONDOCKS);

            JSObject[] dockChildren = DataNodeWrapper.GetNodeChildren(docks);

            for (int i = 0; i < dockChildren.Length; i++)
            {
                ButtonDock dock = BuildButtonDock(dockChildren[i], context);
                Toolbar.AddChild(dock);
            }

            return(Toolbar);
        }
Пример #16
0
        internal void FillLayout(object data,
                                 Layout layout,
                                 DeclarativeTemplateBuildContext bc)
        {
            JSObject[] children       = DataNodeWrapper.GetNodeChildren(data);
            int        sectionCounter = 0;

            for (int i = 0; i < children.Length; i++)
            {
                string name = DataNodeWrapper.GetNodeName(children[i]);
                if (name == DataNodeWrapper.SECTION)
                {
                    Section section = CreateSectionFromData(children[i], bc, layout, sectionCounter++);
                    layout.AddChild(section);
                }
                else
                {
                    // This must be an <OverflowSection>
                    sectionCounter = HandleOverflow(children[i], bc, layout, sectionCounter);
                }
            }
        }
Пример #17
0
        /// <summary>
        /// Build up a ButtonDock based on the JSON object provided.
        /// </summary>
        private ButtonDock BuildButtonDock(object data, ToolbarBuildContext buildContext)
        {
            ButtonDock dock = Toolbar.CreateButtonDock(data, buildContext);

            JSObject controlsNode = DataNodeWrapper.GetFirstChildNodeWithName(data, DataNodeWrapper.CONTROLS);

            JSObject[] controls = DataNodeWrapper.GetNodeChildren(controlsNode);

            for (int i = 0; i < controls.Length; i++)
            {
                // Don't build trimmed controls
                if (IsNodeTrimmed(controls[i]))
                {
                    continue;
                }

                Component currentDisplayComponent = BuildToolbarControlComponent(controls[i], buildContext);
                dock.AddChild(currentDisplayComponent);
            }

            return(dock);
        }
Пример #18
0
        private Unit[] BuildUnits(object data)
        {
            JSObject[] children = DataNodeWrapper.GetNodeChildren(data);
            int        l        = children.Length;

            Unit[] units = new Unit[l];
            for (int i = 0; i < l; i++)
            {
                JSObject childData     = children[i];
                string   name          = DataNodeWrapper.GetAttribute(childData, DataNodeWrapper.NAME_CAPS);
                string   minValue      = DataNodeWrapper.GetAttribute(childData, DataNodeWrapper.MINIMUMVALUE);
                string   maxValue      = DataNodeWrapper.GetAttribute(childData, DataNodeWrapper.MAXIMUMVALUE);
                string   decimalDigits = DataNodeWrapper.GetAttribute(childData, DataNodeWrapper.DECIMALDIGITS);
                string   interval      = DataNodeWrapper.GetAttribute(childData, DataNodeWrapper.INTERVAL);
                units[i] = Spinner.CreateUnit(name,
                                              BuildUnitAbbreviations(DataNodeWrapper.GetNodeChildren(childData)),
                                              Double.Parse(minValue),
                                              Double.Parse(maxValue),
                                              Int32.Parse(decimalDigits),
                                              Double.Parse(interval));
            }
            return(units);
        }
Пример #19
0
        private void FillMenu(Menu menu, JSObject data, BuildContext bc)
        {
            JSObject[] children = DataNodeWrapper.GetNodeChildren(data);
            int        l        = children.Length;

            for (int i = 0; i < l; i++)
            {
                JSObject child = children[i];
                string   name  = DataNodeWrapper.GetNodeName(child);
                if (name != DataNodeWrapper.MENUSECTION)
                {
                    throw new InvalidOperationException("Tags with the name: " + name + " cannot be children of Menu tags.");
                }

                // Skip over menu sections that have been trimmed
                if (IsNodeTrimmed(child))
                {
                    continue;
                }

                MenuSection ms = BuildMenuSection(child, bc);
                menu.AddChild(ms);
            }
        }
Пример #20
0
        private FlyoutAnchor BuildFlyoutAnchor(object data, BuildContext bc)
        {
            FlyoutAnchorProperties properties =
                DataNodeWrapper.GetNodeAttributes(data).To <FlyoutAnchorProperties>();

            JSObject[] children = DataNodeWrapper.GetNodeChildren(data);

            Menu menu = null;

            MenuLauncherControlProperties launcherProperties =
                DataNodeWrapper.GetNodeAttributes(data).To <MenuLauncherControlProperties>();

            if (!Utility.IsTrue(launcherProperties.PopulateDynamically))
            {
                menu = BuildMenu(children[0], bc, true);
            }

            FlyoutAnchor fsfa = new FlyoutAnchor(Root,
                                                 properties.Id,
                                                 properties,
                                                 menu);

            return(fsfa);
        }
Пример #21
0
        private MRUSplitButton BuildMRUSplitButton(object data, BuildContext bc)
        {
            DropDownProperties properties =
                DataNodeWrapper.GetNodeAttributes(data).To <DropDownProperties>();

            JSObject[] children = DataNodeWrapper.GetNodeChildren(data);

            Menu menu = null;

            MenuLauncherControlProperties launcherProperties =
                DataNodeWrapper.GetNodeAttributes(data).To <MenuLauncherControlProperties>();

            if (!Utility.IsTrue(launcherProperties.PopulateDynamically))
            {
                menu = BuildMenu(children[0], bc, false);
            }

            MRUSplitButton fssb = new MRUSplitButton(Root,
                                                     properties.Id,
                                                     properties,
                                                     menu);

            return(fssb);
        }
Пример #22
0
        private JewelMenuLauncher BuildJewelMenuLauncher(object data, JewelBuildContext jbc)
        {
            JewelMenuLauncherProperties properties =
                DataNodeWrapper.GetNodeAttributes(data).To <JewelMenuLauncherProperties>();

            JSObject[] children = DataNodeWrapper.GetNodeChildren(data);

            Menu menu = null;

            MenuLauncherControlProperties launcherProperties =
                DataNodeWrapper.GetNodeAttributes(data).To <MenuLauncherControlProperties>();

            if (!Utility.IsTrue(launcherProperties.PopulateDynamically))
            {
                menu = BuildMenu(children[0], jbc, false);
            }

            JewelMenuLauncher jml = new JewelMenuLauncher(Jewel,
                                                          properties.Id,
                                                          properties,
                                                          menu);

            return(jml);
        }
Пример #23
0
        private void FillTab(Tab tab, object data, RibbonBuildContext rbc)
        {
            JSObject groupsNode = DataNodeWrapper.GetFirstChildNodeWithName(data, DataNodeWrapper.GROUPS);

            JSObject[] groupChildren = DataNodeWrapper.GetNodeChildren(groupsNode);
            Dictionary <string, string> emptyTrimmedGroupIds = new Dictionary <string, string>();

            for (int i = 0; i < groupChildren.Length; i++)
            {
                if (IsNodeTrimmed(groupChildren[i]))
                {
                    continue;
                }

                Group group = BuildGroup(groupChildren[i], rbc);
                // If the build option TrimEmptyGroups is null, and the Group is empty
                // then null is returned by BuildGroup()
                if (!CUIUtility.IsNullOrUndefined(group))
                {
                    tab.AddChild(group);
                }
                else
                {
                    // If the group has an Id, then we store it so that we can ignore any scaling
                    // information that relates it it.  If it does not have an id, then any scaling info
                    // will not work anyways and it is an invalid node.  Groups must have ids.
                    string id = DataNodeWrapper.GetAttribute(groupChildren[i], DataNodeWrapper.ID);
                    if (!string.IsNullOrEmpty(id))
                    {
                        emptyTrimmedGroupIds[id] = id;
                    }
                }
            }

            JSObject scaling = DataNodeWrapper.GetFirstChildNodeWithName(data,
                                                                         DataNodeWrapper.SCALING);

            JSObject[] children             = DataNodeWrapper.GetNodeChildren(scaling);
            string     _scaleWarningMessage = "";
            bool       _scaleWarning        = false;

            for (int i = 0; i < children.Length; i++)
            {
                string name    = DataNodeWrapper.GetNodeName(children[i]);
                string groupId = DataNodeWrapper.GetAttribute(children[i], DataNodeWrapper.GROUPID);

                if (name == DataNodeWrapper.MAXSIZE)
                {
                    // Don't include the scale step if the group that it refers to has been trimmed
                    if (IsIdTrimmed(groupId) || (emptyTrimmedGroupIds.ContainsKey(groupId) &&
                                                 !CUIUtility.IsNullOrUndefined(emptyTrimmedGroupIds[groupId])))
                    {
                        continue;
                    }

                    tab.Scaling.SetGroupMaxSize(groupId,
                                                DataNodeWrapper.GetAttribute(children[i], DataNodeWrapper.SIZE));
                }
                else if (name == DataNodeWrapper.SCALE)
                {
                    // Don't include the scale step if the group that it refers to has been trimmed
                    if (IsIdTrimmed(groupId) || (emptyTrimmedGroupIds.ContainsKey(groupId) &&
                                                 !CUIUtility.IsNullOrUndefined(emptyTrimmedGroupIds[groupId])))
                    {
                        continue;
                    }

                    tab.Scaling.AddScalingStep(new ScalingStep(groupId,
                                                               DataNodeWrapper.GetAttribute(children[i], DataNodeWrapper.SIZE),
                                                               DataNodeWrapper.GetAttribute(children[i], DataNodeWrapper.POPUPSIZE),
                                                               _scaleWarningMessage,
                                                               _scaleWarning));
                    _scaleWarningMessage = "";
                    _scaleWarning        = false;
                }
                else if (name == DataNodeWrapper.LOWSCALEWARNING)
                {
                    _scaleWarningMessage = DataNodeWrapper.GetAttribute(children[i], DataNodeWrapper.MESSAGE);
                    _scaleWarning        = true;
                }
                else
                {
                    throw new InvalidOperationException("Was expecting a node with name MaxSize or Scale.");
                }
            }

            // Start at the largest scale
            tab.ScaleMax();
        }
Пример #24
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);
        }
Пример #25
0
        private void OnReturnTab(DataQueryResult res)
        {
            RibbonBuildContext rbc = (RibbonBuildContext)res.ContextData;

            if (res.Success)
            {
                JSObject ribbonNode =
                    DataNodeWrapper.GetFirstChildNodeWithName(res.QueryData,
                                                              DataNodeWrapper.RIBBON);
                JSObject tabsNode =
                    DataNodeWrapper.GetFirstChildNodeWithName(ribbonNode,
                                                              DataNodeWrapper.TABS);

                JSObject[] tabs     = null;
                JSObject[] children = DataNodeWrapper.GetNodeChildren(tabsNode);
                if (children.Length == 0)
                {
                    JSObject ctxtabsNode =
                        DataNodeWrapper.GetFirstChildNodeWithName(ribbonNode,
                                                                  DataNodeWrapper.CONTEXTUALTABS);
                    JSObject[] contextualGroups = DataNodeWrapper.GetNodeChildren(ctxtabsNode);
                    for (int i = 0; i < contextualGroups.Length; i++)
                    {
                        JSObject contextualGroup = contextualGroups[i];
                        tabs = DataNodeWrapper.GetNodeChildren(contextualGroup);
                        if (tabs.Length > 0)
                        {
                            break;
                        }
                    }
                }
                else
                {
                    tabs = DataNodeWrapper.GetNodeChildren(tabsNode);
                }

                JSObject templatesNode = DataNodeWrapper.GetFirstChildNodeWithName(res.QueryData,
                                                                                   DataNodeWrapper.TEMPLATES);

                // Apply any extensions to the template data.
                templatesNode = (JSObject)ApplyDataExtensions(templatesNode);

                TemplateManager.Instance.LoadTemplates(templatesNode);

                // Apply any extensions to the tab data.
                // In this case we do not want to apply the extensions to the whole hierarchy
                // including <CommandUI>, <Ribbon> etc because this query is really only for
                // a specific tab.
                object tabData = ApplyDataExtensions(tabs[0]);

                FillTab(rbc.InitializedTab, tabData, rbc);
                // This may need to be parametrized so that tabs can be inited
                // without automatically getting selected when the initing is done.
                rbc.InitializedTab.Ribbon.MakeTabSelectedInternal(rbc.InitializedTab);
                rbc.InitializedTab.OnDelayedInitFinished(true);
            }
            // TODO: how to handle failures

#if PERF_METRICS
            PMetrics.PerfMark(PMarker.perfCUIRibbonTabSwitchWarmPercvdEnd);
#endif
        }
Пример #26
0
        private Section CreateSectionFromData(object data, DeclarativeTemplateBuildContext bc, Layout layout, int sectionNumber)
        {
            SectionType type;
            string      strType      = DataNodeWrapper.GetAttribute(data, DataNodeWrapper.TYPE);
            string      strAlignment = DataNodeWrapper.GetAttribute(data, DataNodeWrapper.ALIGNMENT);

            switch (strType)
            {
            case DataNodeWrapper.ONEROW:
                type = SectionType.OneRow;
                break;

            case DataNodeWrapper.TWOROW:
                type = SectionType.TwoRow;
                break;

            case DataNodeWrapper.THREEROW:
                type = SectionType.ThreeRow;
                break;

            case DataNodeWrapper.DIVIDER:
                type = SectionType.Divider;
                break;

            default:
                throw new ArgumentOutOfRangeException("Invalid Section attribute \"Type\" found in XML: " + strType);
            }

            SectionAlignment alignment = SectionAlignment.Top;

            if (strAlignment == "Middle")
            {
                alignment = SectionAlignment.Middle;
            }

            Section section = bc.Ribbon.CreateSection(layout.Id + "-" + sectionNumber, type, alignment);

            if (type != SectionType.Divider)
            {
                HandleRow(section.GetRow(1),
                          DataNodeWrapper.GetNodeChildren(data)[0],
                          bc);

                if (section.Type == SectionType.TwoRow ||
                    section.Type == SectionType.ThreeRow)
                {
                    HandleRow(section.GetRow(2),
                              DataNodeWrapper.GetNodeChildren(data)[1],
                              bc);
                }

                if (section.Type == SectionType.ThreeRow)
                {
                    HandleRow(section.GetRow(3),
                              DataNodeWrapper.GetNodeChildren(data)[2],
                              bc);
                }
            }

            return(section);
        }
Пример #27
0
        private Group BuildGroup(object data, RibbonBuildContext rbc)
        {
            string templateName = DataNodeWrapper.GetAttribute(data, DataNodeWrapper.TEMPLATE);

            Template template = TemplateManager.Instance.GetTemplate(templateName);

            if (CUIUtility.IsNullOrUndefined(template))
            {
                throw new ArgumentOutOfRangeException("A template with name: " + templateName + " could not be loaded.");
            }

            JSObject controlsData = null;

            JSObject[] dataChildren = DataNodeWrapper.GetNodeChildren(data);
            for (int i = 0; i < dataChildren.Length; i++)
            {
                if (DataNodeWrapper.GetNodeName(dataChildren[i]) == DataNodeWrapper.CONTROLS)
                {
                    controlsData = dataChildren[i];
                    break;
                }
            }

            if (CUIUtility.IsNullOrUndefined(controlsData))
            {
                throw new InvalidOperationException("No Controls node found in this Group tag.");
            }
            JSObject[] children = DataNodeWrapper.GetNodeChildren(controlsData);

            bool groupIsEmpty = true;
            Dictionary <string, List <Control> > controls = new Dictionary <string, List <Control> >();

            int len = children.Length;

            for (int i = 0; i < len; i++)
            {
                // Don't build controls that have been trimmed
                if (IsNodeTrimmed(children[i]))
                {
                    continue;
                }

                // The group has one or more controls in it
                groupIsEmpty = false;
                Control control = BuildControl(children[i], rbc);

                if (!controls.ContainsKey(control.TemplateAlias) ||
                    CUIUtility.IsNullOrUndefined(controls[control.TemplateAlias]))
                {
                    controls[control.TemplateAlias] = new List <Control>();
                }

                controls[control.TemplateAlias].Add(control);
            }

            if (RibbonBuildOptions.TrimEmptyGroups && groupIsEmpty)
            {
                return(null);
            }

            string id          = DataNodeWrapper.GetAttribute(data, DataNodeWrapper.ID);
            string title       = DataNodeWrapper.GetAttribute(data, DataNodeWrapper.TITLE);
            string description = DataNodeWrapper.GetAttribute(data, DataNodeWrapper.DESCRIPTION);
            string command     = DataNodeWrapper.GetAttribute(data, DataNodeWrapper.COMMAND);
            Group  group       = template.CreateGroup(Ribbon,
                                                      id,
                                                      DataNodeWrapper.GetNodeAttributes(data).To <GroupProperties>(),
                                                      title,
                                                      description,
                                                      command,
                                                      controls,
                                                      null);

            return(group);
        }
Пример #28
0
        /// <summary>
        /// As much as we'd like to fail gracefully in every corner case for this,
        /// we have to maintain a "garbage in garbage out policy" because this
        /// recursive set of routines is very performance sensitive since it
        /// will run on every single node in the CUI data.
        /// </summary>
        /// <param name="data"></param>
        /// <param name="extensions"></param>
        /// <returns></returns>
        protected static JSObject ApplyDataNodeExtensions(object data, Dictionary <string, List <JSObject> > extensions)
        {
            // If a data node does not have any attributes, then it cannot be extended
            if (CUIUtility.IsNullOrUndefined(DataNodeWrapper.GetNodeAttributes(data)))
            {
                return((JSObject)data);
            }

            string id = DataNodeWrapper.GetAttribute(data, "Id");

            List <JSObject> replacementData = extensions.ContainsKey(id) ? extensions[id] : null;

            // Has this data node been overridden?
            if (!CUIUtility.IsNullOrUndefined(replacementData))
            {
                JSObject winner          = null;
                int      winningSequence = Int32.MaxValue;

                // We now go through and find the correct replacement depending on sequence number.
                // We can only pick one replacement if there are multiple replacements.
                int l = replacementData.Count;
                for (int i = 0; i < l; i++)
                {
                    JSObject replacementNode = replacementData[i];

                    // If there is an entry in the array but it is null, then
                    // we remove this node from the final data by returning null.
                    // Because this means that it was basically overriden with "nothing".
                    // aka "removed".
                    if (replacementNode == null)
                    {
                        return(null);
                    }

                    string sequence = DataNodeWrapper.GetAttribute(replacementNode,
                                                                   DataNodeWrapper.SEQUENCE);

                    // If this extension does not have a sequence, then it has lowest precedence.
                    // This means that it will only be the winner if there is no previous winner.
                    if (string.IsNullOrEmpty(sequence))
                    {
                        if (CUIUtility.IsNullOrUndefined(winner))
                        {
                            winner = replacementNode;
                        }
                        continue;
                    }

                    // If this extension node has a lower sequence value than anything previously seen
                    // then it becomes the new winner.  "Lowest Sequence Wins".
                    int seq = Int32.Parse(sequence);
                    if (seq < winningSequence)
                    {
                        winner          = replacementNode;
                        winningSequence = seq;
                    }
                }

                // Set the actual data node that we will be returning to the
                // node the winner that was determined by examining all the possible extensions.
                if (!CUIUtility.IsNullOrUndefined(winner))
                {
                    data = winner;
                }
            }

            JSObject[] children = DataNodeWrapper.GetNodeChildren(data);

            // If there is not a children node, then we create one so that we can add extensions
            if (CUIUtility.IsNullOrUndefined(children))
            {
                children    = new JSObject[1];
                children[0] = new JSObject();
                ((JSObject)data).SetField <JSObject[]>("children", children);
            }

            // Now we make a temporary list where we will put the data nodes and the
            // extension nodes and then sort them according to sequence before saving
            // them back into the children array in the data node.
            List <JSObject> combinedNodes = new List <JSObject>();
            int             m             = children.Length;

            for (int i = 0; i < m; i++)
            {
                combinedNodes.Add(children[i]);
            }

            // Have any children been added to this node through this extension mechanism?
            string          extKey = id + "._children";
            List <JSObject> childrenReplacementData = extensions.ContainsKey(extKey) ? extensions[extKey] : null;

            // Add the extension nodes if there are any
            if (!CUIUtility.IsNullOrUndefined(childrenReplacementData))
            {
                int n = childrenReplacementData.Count;
                for (int i = 0; i < n; i++)
                {
                    combinedNodes.Add(childrenReplacementData[i]);
                }

                // Now do a sort over the combined list to get the final order
                combinedNodes.Sort(new CompareDataNodeOrder());
            }

            // Now that we have the maximal set of child nodes from the data and the customizations,
            // we need to allow for extensibility on each one before we finally add them to the main
            // parent node.
            int ln = combinedNodes.Count;

            JSObject[] finalChildNodes = new JSObject[ln];
            for (int i = 0; i < ln; i++)
            {
                // Recurse on this child node to get its customizations
                JSObject dataNode = ApplyDataNodeExtensions(combinedNodes[i], extensions);
                if (!CUIUtility.IsNullOrUndefined(dataNode))
                {
                    finalChildNodes[i] = dataNode;
                }
            }

            // Now insert this combined, sorted and extended list of children into the data node
            ((JSObject)data).SetField <JSObject[]>("children", finalChildNodes);
            return((JSObject)data);
        }