public static ToolBarButton CreateGroupContainer(EntityOperationGroup group) { ToolBarButton groupButton = new ToolBarButton { Content = group.Text(), ContextMenu = new ContextMenu(), Background = group.Background, }; Common.SetOrder(groupButton, group.Order); AutomationProperties.SetItemStatus(groupButton, "Group"); if (group.AutomationName.HasText()) { AutomationProperties.SetName(groupButton, group.AutomationName); } groupButton.ContextMenu = new ContextMenu { PlacementTarget = groupButton, Placement = PlacementMode.Bottom, }; ContextMenuService.SetIsEnabled(groupButton, false); groupButton.Click += (object sender, RoutedEventArgs e) => { ToolBarButton tbb = (ToolBarButton)sender; tbb.ContextMenu.IsEnabled = true; tbb.ContextMenu.IsOpen = true; }; return(groupButton); }
internal static MenuItem NewMenuItem(EntityOperationContext eoc, EntityOperationGroup group) { var man = OperationClient.Manager; MenuItem menuItem = new MenuItem { Header = eoc.OperationSettings.Try(os => os.Text) ?? (group == null || group.SimplifyName == null ? eoc.OperationInfo.OperationSymbol.NiceToString() : group.SimplifyName(eoc.OperationInfo.OperationSymbol.NiceToString())), Icon = man.GetImage(eoc.OperationInfo.OperationSymbol, eoc.OperationSettings).ToSmallImage(), Tag = eoc.OperationInfo, Background = man.GetBackground(eoc.OperationInfo, eoc.OperationSettings) }; if (eoc.OperationSettings != null && eoc.OperationSettings.Order != 0) Common.SetOrder(menuItem, eoc.OperationSettings.Order); AutomationProperties.SetName(menuItem, eoc.OperationInfo.OperationSymbol.Key); eoc.SenderButton = menuItem; if (eoc.CanExecute != null) { menuItem.ToolTip = eoc.CanExecute; menuItem.IsEnabled = false; ToolTipService.SetShowOnDisabled(menuItem, true); AutomationProperties.SetHelpText(menuItem, eoc.CanExecute); } else { menuItem.Click += (_, __) => OperationExecute(eoc); } return menuItem; }
public static void Start() { if (Navigator.Manager.NotDefined(MethodInfo.GetCurrentMethod())) { Navigator.AddSettings(new List<EntitySettings>() { new EntitySettings<ScheduledTaskEntity> { View = e => new ScheduledTask(), Icon = Image("clock.png") }, new EntitySettings<SimpleTaskSymbol> { View = e => new SimpleTask(), Icon = Image("simpleTask.png") }, new EntitySettings<ScheduledTaskLogEntity> { View = e => new ScheduledTaskLog(), Icon = Image("scheduledTaskLog.png") }, new EntitySettings<ScheduleRuleMonthsEntity> { View = e => new ScheduleRuleMonths() }, new EntitySettings<ScheduleRuleWeekDaysEntity> { View = e => new ScheduleRuleWeekDays() }, new EntitySettings<ScheduleRuleMinutelyEntity> { View = e => new ScheduleRuleMinutely() }, new EntitySettings<HolidayCalendarEntity> { View = e => new HolidayCalendar() }, }); Server.SetSymbolIds<SimpleTaskSymbol>(); var executeGroup = new EntityOperationGroup { Background = Brushes.Gold, AutomationName = "execute", Text = () => TaskMessage.Execute.NiceToString() + "...", }; OperationClient.AddSetting(new EntityOperationSettings<ITaskEntity>(TaskOperation.ExecuteSync) { Icon = Image("execute.png"), Group = executeGroup }); OperationClient.AddSetting(new EntityOperationSettings<ITaskEntity>(TaskOperation.ExecuteAsync) { Icon = Image("execute.png"), Group = executeGroup }); } }
internal static MenuItem NewMenuItem(IEntityOperationContext eoc, EntityOperationGroup group) { var man = OperationClient.Manager; MenuItem menuItem = new MenuItem { Header = eoc.OperationSettings?.Text ?? (group == null || group.SimplifyName == null ? eoc.OperationInfo.OperationSymbol.NiceToString() : group.SimplifyName(eoc.OperationInfo.OperationSymbol.NiceToString())), Icon = man.GetImage(eoc.OperationInfo.OperationSymbol, eoc.OperationSettings).ToSmallImage(), Tag = eoc.OperationInfo, Background = man.GetBackground(eoc.OperationInfo, eoc.OperationSettings) }; if (eoc.OperationSettings != null && eoc.OperationSettings.Order != 0) { Common.SetOrder(menuItem, eoc.OperationSettings.Order); } AutomationProperties.SetName(menuItem, eoc.OperationInfo.OperationSymbol.Key); eoc.SenderButton = menuItem; if (eoc.CanExecute != null) { menuItem.ToolTip = eoc.CanExecute; menuItem.IsEnabled = false; ToolTipService.SetShowOnDisabled(menuItem, true); AutomationProperties.SetHelpText(menuItem, eoc.CanExecute); } else { menuItem.Click += (_, __) => OperationExecute(eoc); } return(menuItem); }
protected internal virtual List <FrameworkElement> ButtonBar_GetButtonBarElement(object entity, EntityButtonContext ctx) { Entity ident = entity as Entity; if (ident == null) { return(null); } Type type = ident.GetType(); var operations = (from oi in OperationInfos(type) where oi.IsEntityOperation && (oi.AllowsNew.Value || !ident.IsNew) let os = GetSettings <EntityOperationSettingsBase>(type, oi.OperationSymbol) let eoc = newEntityOperationContext.GetInvoker(os?.OverridenType ?? type)(ident, oi, ctx, os) where (os != null && os.HasIsVisible) ? os.OnIsVisible(eoc) : ctx.ShowOperations select eoc).ToList(); if (operations.Any(eoc => eoc.OperationInfo.HasCanExecute == true)) { Dictionary <OperationSymbol, string> canExecutes = Server.Return((IOperationServer os) => os.GetCanExecuteAll(ident)); foreach (var eoc in operations) { var ce = canExecutes.TryGetC(eoc.OperationInfo.OperationSymbol); if (ce != null && ce.HasText()) { eoc.CanExecute = ce; } } } List <FrameworkElement> buttons = new List <FrameworkElement>(); Dictionary <EntityOperationGroup, ToolBarButton> groups = new Dictionary <EntityOperationGroup, ToolBarButton>(); Dictionary <EntityOperationGroup, List <FrameworkElement> > groupButtons = new Dictionary <EntityOperationGroup, List <FrameworkElement> >(); foreach (var eoc in operations) { if (eoc.OperationInfo.OperationType == OperationType.ConstructorFrom && (eoc.OperationSettings == null || !eoc.OperationSettings.AvoidMoveToSearchControl)) { if (EntityOperationToolBarButton.MoveToSearchControls(eoc)) { continue; } } EntityOperationGroup group = GetDefaultGroup(eoc); if (group != null) { var list = groupButtons.GetOrCreate(group, () => { var tbb = EntityOperationToolBarButton.CreateGroupContainer(group); groups.Add(group, tbb); buttons.Add(tbb); return(new List <FrameworkElement>()); }); list.Add(EntityOperationToolBarButton.NewMenuItem(eoc, group)); } else { buttons.Add(EntityOperationToolBarButton.NewToolbarButton(eoc)); } } foreach (var gr in groups) { var cm = gr.Value.ContextMenu; foreach (var b in groupButtons.GetOrThrow(gr.Key).OrderBy(Common.GetOrder)) { cm.Items.Add(b); } } return(buttons.ToList()); }
public static ToolBarButton CreateGroupContainer(EntityOperationGroup group) { ToolBarButton groupButton = new ToolBarButton { Content = group.Description(), ContextMenu = new ContextMenu(), Background = group.Background, }; Common.SetOrder(groupButton, group.Order); AutomationProperties.SetItemStatus(groupButton, "Group"); if (group.AutomationName.HasText()) AutomationProperties.SetName(groupButton, group.AutomationName); groupButton.ContextMenu = new ContextMenu { PlacementTarget = groupButton, Placement = PlacementMode.Bottom, }; ContextMenuService.SetIsEnabled(groupButton, false); groupButton.Click += (object sender, RoutedEventArgs e) => { ToolBarButton tbb = (ToolBarButton)sender; tbb.ContextMenu.IsEnabled = true; tbb.ContextMenu.IsOpen = true; }; return groupButton; }