static object CreateToolBarItemFromDescriptor(UIElement inputBindingOwner, ToolbarItemDescriptor descriptor)
        {
            Codon  codon  = descriptor.Codon;
            object caller = descriptor.Caller;
            string type   = codon.Properties.Contains("type") ? codon.Properties["type"] : "Item";

            bool createCommand = codon.Properties["loadclasslazy"] == "false";

            switch (type)
            {
            case "Separator":
                return(new ConditionalSeparator(codon, caller, true));

            case "CheckBox":
                return(new ToolBarCheckBox(codon, caller));

            case "Item":
                return(new ToolBarButton(inputBindingOwner, codon, caller, createCommand));

            case "ComboBox":
                return(new ToolBarComboBox(codon, caller));

            case "TextBox":
                return("TextBox");

            //return new ToolBarTextBox(codon, caller);
            case "Label":
                return("Label");

            //return new ToolBarLabel(codon, caller);
            case "DropDownButton":
                return(new ToolBarDropDownButton(
                           codon, caller, MenuService.CreateUnexpandedMenuItems(
                               new MenuService.MenuCreateContext {
                    ActivationMethod = "ToolbarDropDownMenu"
                },
                               descriptor.SubItems)));

            case "SplitButton":
                return(new ToolBarSplitButton(
                           codon, caller, MenuService.CreateUnexpandedMenuItems(
                               new MenuService.MenuCreateContext {
                    ActivationMethod = "ToolbarDropDownMenu"
                },
                               descriptor.SubItems)));

            case "Builder":
                object result = codon.AddIn.CreateObject(codon.Properties["class"]);
                if (result is IToolBarItemBuilder)
                {
                    ((IToolBarItemBuilder)result).Initialize(inputBindingOwner, codon, caller);
                }
                return(result);

            default:
                throw new System.NotSupportedException("unsupported menu item type : " + type);
            }
        }
Exemple #2
0
        static object CreateToolBarItemFromDescriptor(UIElement inputBindingOwner, ToolbarItemDescriptor descriptor)
        {
            Codon  codon  = descriptor.Codon;
            object caller = descriptor.Parameter;
            string type   = codon.Properties.Contains("type") ? codon.Properties["type"] : "Item";

            bool createCommand = codon.Properties["loadclasslazy"] == "false";

            switch (type)
            {
            case "Separator":
                return(new ConditionalSeparator(codon, caller, true, descriptor.Conditions));

            case "CheckBox":
                return(new ToolBarCheckBox(codon, caller, descriptor.Conditions));

            case "Item":
                return(new ToolBarButton(inputBindingOwner, codon, caller, createCommand, descriptor.Conditions));

            case "DropDownButton":
                return(new ToolBarDropDownButton(
                           codon, caller, MenuService.CreateUnexpandedMenuItems(
                               new MenuService.MenuCreateContext {
                    ActivationMethod = "ToolbarDropDownMenu"
                },
                               descriptor.SubItems), descriptor.Conditions));

            case "SplitButton":
                return(new ToolBarSplitButton(
                           codon, caller, MenuService.CreateUnexpandedMenuItems(
                               new MenuService.MenuCreateContext {
                    ActivationMethod = "ToolbarDropDownMenu"
                },
                               descriptor.SubItems), descriptor.Conditions));

            case "Builder":
                return(codon.AddIn.CreateObject(codon.Properties["class"]));

            case "Custom":
                object result = codon.AddIn.CreateObject(codon.Properties["class"]);
                if (result is ComboBox)
                {
                    ((ComboBox)result).SetResourceReference(FrameworkElement.StyleProperty, ToolBar.ComboBoxStyleKey);
                }
                if (result is ICustomToolBarItem)
                {
                    ((ICustomToolBarItem)result).Initialize(inputBindingOwner, codon, caller);
                }
                return(result);

            default:
                throw new System.NotSupportedException("unsupported menu item type : " + type);
            }
        }