示例#1
0
        static object CreateMenuItemFromDescriptor(MenuCreateContext context, MenuItemDescriptor descriptor)
        {
            Codon  codon         = descriptor.Codon;
            string type          = codon.Properties.Contains("type") ? codon.Properties["type"] : "Command";
            bool   createCommand = codon.Properties["loadclasslazy"] == "false";

            switch (type)
            {
            case "Separator":
                return(new ConditionalSeparator(codon, descriptor.Caller, false));

            case "CheckBox":
                return("CheckBox");

            //return new MenuCheckBox(codon, descriptor.Caller);
            case "Item":
            case "Command":
                return(new MenuCommand(context.InputBindingOwner, codon, descriptor.Caller, createCommand, context.ActivationMethod));

            case "Menu":
                var item = new CoreMenuItem(codon, descriptor.Caller)
                {
                    ItemsSource = new object[1],
                    SetEnabled  = true
                };
                var subItems = CreateUnexpandedMenuItems(context, descriptor.SubItems);
                item.SubmenuOpened += (sender, args) => {
                    item.ItemsSource = ExpandMenuBuilders(subItems, true);
                    args.Handled     = true;
                };
                if (context.ImmediatelyExpandMenuBuildersForShortcuts)
                {
                    ExpandMenuBuilders(subItems, false);
                }
                return(item);

            case "Builder":
                IMenuItemBuilder builder = codon.AddIn.CreateObject(codon.Properties["class"]) as IMenuItemBuilder;
                if (builder == null)
                {
                    throw new NotSupportedException("Menu item builder " + codon.Properties["class"] + " does not implement IMenuItemBuilder");
                }
                return(new MenuItemBuilderPlaceholder(builder, descriptor.Codon, descriptor.Caller));

            default:
                throw new NotSupportedException("unsupported menu item type : " + type);
            }
        }
示例#2
0
		static object CreateMenuItemFromDescriptor(MenuCreateContext context, MenuItemDescriptor descriptor)
		{
			Codon codon = descriptor.Codon;
			string type = codon.Properties.Contains("type") ? codon.Properties["type"] : "Command";
			
			switch (type) {
				case "Separator":
					return new ConditionalSeparator(codon, descriptor.Parameter, false, descriptor.Conditions);
				case "CheckBox":
					return new MenuCheckBox(context.InputBindingOwner, codon, descriptor.Parameter, descriptor.Conditions);
				case "Item":
				case "Command":
					return new MenuCommand(context.InputBindingOwner, codon, descriptor.Parameter, context.ActivationMethod, descriptor.Conditions);
				case "Menu":
					var item = new CoreMenuItem(codon, descriptor.Parameter, descriptor.Conditions) {
						ItemsSource = new object[1],
						SetEnabled = true
					};
					var subItems = CreateUnexpandedMenuItems(context, descriptor.SubItems);
					item.SubmenuOpened += (sender, args) => {
						item.ItemsSource = ExpandMenuBuilders(subItems, true);
						args.Handled = true;
					};
					if (context.ImmediatelyExpandMenuBuildersForShortcuts)
						ExpandMenuBuilders(subItems, false);
					return item;
				case "Builder":
					IMenuItemBuilder builder = codon.AddIn.CreateObject(codon.Properties["class"]) as IMenuItemBuilder;
					if (builder == null)
						throw new NotSupportedException("Menu item builder " + codon.Properties["class"] + " does not implement IMenuItemBuilder");
					return new MenuItemBuilderPlaceholder(builder, descriptor.Codon, descriptor.Parameter);
				default:
					throw new NotSupportedException("unsupported menu item type : " + type);
			}
		}