public MenuCheckBox(UIElement inputBindingOwner, Codon codon, object caller, IReadOnlyCollection <ICondition> conditions) : base(codon, caller, conditions) { Command = CommandWrapper.CreateCommand(codon, conditions); CommandParameter = caller; cmd = CommandWrapper.Unwrap(Command) as ICheckableMenuCommand; if (cmd != null) { isCheckedChangedHandler = cmd_IsCheckedChanged; cmd.IsCheckedChanged += isCheckedChangedHandler; IsChecked = cmd.IsChecked(caller); } if (!string.IsNullOrEmpty(codon.Properties["shortcut"])) { KeyGesture kg = MenuService.ParseShortcut(codon.Properties["shortcut"]); MenuCommand.AddGestureToInputBindingOwner(inputBindingOwner, kg, Command, null); InputGestureText = MenuService.GetDisplayStringForShortcut(kg); } }
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); } }
/// <summary> /// Updates the status of the tool bar items /// </summary> /// <param name="toolBarItems">The tool bar items.</param> /// <remarks>The workbench calls <see cref="IStatusUpdate.UpdateStatus"/> for all tool bars when /// <see cref="CommandManager.RequerySuggested"/> fires.</remarks> public static void UpdateStatus(IEnumerable toolBarItems) { MenuService.UpdateStatus(toolBarItems); }