Esempio n. 1
0
        private static void AddExtensibleMenuItems(ICommandBar contextMenu, SceneViewModel viewModel, Type selectionType)
        {
            if (!(selectionType != (Type)null))
            {
                return;
            }
            bool anythingAdded    = false;
            bool lastWasSeperator = true;

            viewModel.ExtensibilityManager.UpdateSelection();
            foreach (ContextMenuProvider contextMenuProvider in viewModel.ExtensibilityManager.FeatureManager.CreateFeatureProviders(typeof(ContextMenuProvider), selectionType))
            {
                contextMenuProvider.Update(viewModel.ExtensibilityManager.EditingContext);
                foreach (Microsoft.Windows.Design.Interaction.MenuBase menuItem in (Collection <Microsoft.Windows.Design.Interaction.MenuBase>)contextMenuProvider.Items)
                {
                    ContextMenuHelper.BuildExtensibleMenuItem(contextMenu, menuItem, ref lastWasSeperator, ref anythingAdded);
                }
            }
            if (!anythingAdded || lastWasSeperator)
            {
                return;
            }
            contextMenu.Items.AddSeparator();
        }
Esempio n. 2
0
        private static void BuildExtensibleMenuItem(ICommandBar parentMenu, Microsoft.Windows.Design.Interaction.MenuBase menuItem, ref bool lastWasSeperator, ref bool anythingAdded)
        {
            MenuAction menuAction = menuItem as MenuAction;
            MenuGroup  menuGroup  = menuItem as MenuGroup;

            if (menuAction != null)
            {
                if (!menuAction.Visible)
                {
                    return;
                }
                ICommandBarButton commandBarButton = parentMenu.Items.AddButton("ExtensibilityCommand");
                commandBarButton.Text = menuAction.DisplayName;
                MenuItem menuItem1 = (MenuItem)commandBarButton;
                menuItem1.Command     = menuAction.Command;
                menuItem1.IsEnabled   = menuAction.Enabled;
                menuItem1.IsCheckable = menuAction.Checkable;
                menuItem1.IsChecked   = menuAction.Checked;
                lastWasSeperator      = false;
                anythingAdded         = true;
            }
            else
            {
                if (menuGroup == null)
                {
                    return;
                }
                ICommandBar parentMenu1;
                if (menuGroup.HasDropDown)
                {
                    parentMenu1      = (ICommandBar)parentMenu.Items.AddMenu("ExtensibilityMenu", menuGroup.DisplayName);
                    anythingAdded    = true;
                    lastWasSeperator = false;
                }
                else
                {
                    parentMenu1 = parentMenu;
                    if (anythingAdded && !lastWasSeperator)
                    {
                        parentMenu.Items.AddSeparator();
                        lastWasSeperator = true;
                    }
                }
                foreach (Microsoft.Windows.Design.Interaction.MenuBase menuItem1 in (Collection <Microsoft.Windows.Design.Interaction.MenuBase>)menuGroup.Items)
                {
                    ContextMenuHelper.BuildExtensibleMenuItem(parentMenu1, menuItem1, ref lastWasSeperator, ref anythingAdded);
                }
                if (menuGroup.HasDropDown)
                {
                    return;
                }
                if (!lastWasSeperator && anythingAdded)
                {
                    parentMenu.Items.AddSeparator();
                    lastWasSeperator = true;
                }
                else
                {
                    lastWasSeperator = false;
                }
            }
        }