static object CreateToolbarItemFromDescriptor(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 ToolBarSeparator(codon, caller, descriptor.Conditions); case "CheckBox": return new ToolBarCheckBox(codon, caller, descriptor.Conditions); case "Item": return new ToolBarCommand(codon, caller, createCommand, descriptor.Conditions); case "Label": return new ToolBarLabel(codon, caller, descriptor.Conditions); case "DropDownButton": return new ToolBarDropDownButton(codon, caller, MenuService.ConvertSubItems(descriptor.SubItems), descriptor.Conditions); case "SplitButton": return new ToolBarSplitButton(codon, caller, MenuService.ConvertSubItems(descriptor.SubItems), descriptor.Conditions); case "Custom": case "Builder": return codon.AddIn.CreateObject(codon.Properties["class"]); default: throw new System.NotSupportedException("unsupported menu item type : " + type); } }
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); } }
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); } }
static object CreateToolBarItemFromDescriptor(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("CheckBox"); //return new ToolBarCheckBox(codon, caller); case "Item": return(new ToolBarButton(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("DropDownButton"); //return new ToolBarDropDownButton(codon, caller, MenuService.CreateMenuItems(descriptor.SubItems)); case "SplitButton": return(new ToolBarSplitButton(codon, caller, MenuService.CreateMenuItems(null, descriptor.SubItems))); case "Builder": return(codon.AddIn.CreateObject(codon.Properties["class"])); default: throw new System.NotSupportedException("unsupported menu item type : " + type); } }
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); } }
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); } }
private 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"; 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, 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": var resultType = codon.AddIn.FindType(codon.Properties["class"]); if (null != resultType) { object result = null; var c1 = resultType.GetConstructor(new Type[] { typeof(Codon), typeof(object), typeof(IReadOnlyCollection <ICondition>) }); result = c1?.Invoke(new object[] { codon, caller, descriptor.Conditions }); if (null == result) { result = Activator.CreateInstance(resultType); } if (result is ComboBox cb) { cb.SetResourceReference(FrameworkElement.StyleProperty, ToolBar.ComboBoxStyleKey); } if (result is ICustomToolBarItem ctbi) { ctbi.Initialize(inputBindingOwner, codon, caller); } return(result); } else { throw new System.NotSupportedException("Unsupported: Custom item must contain a class name"); } default: throw new System.NotSupportedException("unsupported menu item type : " + type); } }