private void InitializeRibbonGroups(IEnumerable <RibbonEntry> ribbonEnties, Ribbon ribbonContainer)
        {
            foreach (RibbonEntry item in ribbonEnties)
            {
                string targetTabHeaderKey = item.RibbonTabName;
                if (String.IsNullOrEmpty(targetTabHeaderKey))
                {
                    targetTabHeaderKey = "HomeRibbonTabHeader";
                }

                RibbonTab ribbonTab = null;
                foreach (RibbonTab tab in ribbonContainer.Items)
                {
                    string currentTabHeaderKey = RibbonExtension.GetRibbonTabHeader(tab);
                    if (!String.IsNullOrEmpty(currentTabHeaderKey) && currentTabHeaderKey.Equals(targetTabHeaderKey, StringComparison.OrdinalIgnoreCase))
                    {
                        ribbonTab = tab;
                        break;
                    }
                }
                if (ribbonTab == null)
                {
                    ribbonTab = new RibbonTab();

                    string targetTabHeader = GisEditor.LanguageManager.GetStringResource(targetTabHeaderKey);
                    if (string.IsNullOrEmpty(targetTabHeader))
                    {
                        ribbonTab.Header = targetTabHeaderKey;
                    }
                    else
                    {
                        ribbonTab.SetResourceReference(RibbonTab.HeaderProperty, targetTabHeaderKey);
                    }

                    ribbonContainer.Items.Add(ribbonTab);
                }

                RibbonExtension.SetRibbonTabHeader(ribbonTab, targetTabHeaderKey);
                RibbonExtension.SetRibbonTabIndex(ribbonTab, item.RibbonTabIndex);
                if (!ribbonTab.Items.Contains(item.RibbonGroup))
                {
                    ribbonTab.Items.Add(item.RibbonGroup);
                }
            }
        }
        private RibbonTab GetRibbonTabContaining(RibbonEntry ribbonEntry, Ribbon ribbonContainer)
        {
            RibbonTab ribbonTab    = null;
            string    tabHeaderKey = ribbonEntry.RibbonTabName;

            if (String.IsNullOrEmpty(tabHeaderKey))
            {
                tabHeaderKey = "HomeRibbonTabHeader";
            }

            if (!String.IsNullOrEmpty(tabHeaderKey))
            {
                ribbonTab = ribbonContainer.Items.OfType <RibbonTab>().FirstOrDefault(t =>
                {
                    string tmpTabHeaderKey = RibbonExtension.GetRibbonTabHeader(t);
                    return(!String.IsNullOrEmpty(tmpTabHeaderKey) && tmpTabHeaderKey.Equals(tabHeaderKey, StringComparison.Ordinal));
                });
            }

            return(ribbonTab);
        }
        private void ReorderRibbonGroups(Ribbon ribbonContainer)
        {
            var enabledPlugins = GetActiveUIPlugins().ToArray();

            for (int i = enabledPlugins.Length - 1; i >= 0; i--)
            {
                UIPlugin currentPlugin = enabledPlugins[i];
                foreach (var ribbonEntry in currentPlugin.RibbonEntries.OrderBy(r => r.RibbonGroupIndex).Reverse())
                {
                    RibbonTab containingRibbonTab = GetRibbonTabContaining(ribbonEntry, ribbonContainer);
                    containingRibbonTab.Items.Remove(ribbonEntry.RibbonGroup);

                    int    insertIndex        = 0;
                    string ribbonTabHeaderKey = RibbonExtension.GetRibbonTabHeader(containingRibbonTab);
                    if ("HomeRibbonTabHeader".Equals(ribbonTabHeaderKey, StringComparison.Ordinal))
                    {
                        insertIndex = 1;
                    }
                    containingRibbonTab.Items.Insert(insertIndex, ribbonEntry.RibbonGroup);
                }
            }
        }