static async void Manager_TaskNormalWindow(NormalWindow normal, ModifiableEntity entity) { ButtonBar bar = normal.Child<ButtonBar>(); var wrapPanel = (WrapPanel)bar.Content; bar.Content = null; HelpButton helpButton = new HelpButton { MainControl = normal, Margin = new Thickness(4), IsEnabled = false, }.Set(DockPanel.DockProperty, Dock.Right); bar.Content = new DockPanel { Children = { helpButton, wrapPanel } }; helpButton.IsActive = await Server.ReturnAsync((IHelpServer s) => s.HasEntityHelpService(entity.GetType())); helpButton.Checked += async (sender, args) => { var entityHelp = await Server.ReturnAsync((IHelpServer s) => s.GetEntityHelpService(entity.GetType())); SetHelpInfo(normal.Child<EntityTitle>(), entityHelp.Info); var properties = (from control in normal.Children<Control>(p => p.IsSet(Common.PropertyRouteProperty), HelpButton.WhereFlags) let propertyRoute = Common.GetPropertyRoute(control).SimplifyToPropertyOrRoot() where propertyRoute.PropertyRouteType != PropertyRouteType.Root select new { control, propertyRoute }).ToList(); var external = properties.Extract(t => t.propertyRoute.RootType != entity.GetType()); foreach (var t in properties) { SetHelpInfo(t.control, entityHelp.Properties.GetOrThrow(t.propertyRoute)); } var buttonBar = normal.Child<ButtonBar>(); var operations = (from control in buttonBar.Children<ToolBarButton>(p => p.Tag is OperationInfo, HelpButton.WhereFlags) select new { control, operation = ((OperationInfo)control.Tag).OperationSymbol }).ToList(); foreach (var t in operations) { SetHelpInfo(t.control, entityHelp.Operations.GetOrThrow(t.operation)); } var menuInfos = (from c in buttonBar.Children<ToolBarButton>(p => p.ContextMenu != null, HelpButton.WhereFlags) from mi in c.ContextMenu.Children<MenuItem>(p => p.Tag is OperationInfo, HelpButton.WhereFlags) select new { mi, operation = ((OperationInfo)mi.Tag).OperationSymbol }).ToList(); foreach (var t in menuInfos) { SetHelpInfo(t.mi, entityHelp.Operations.GetOrThrow(t.operation)); //ConstructFrom OperationInfo } if (external.Any()) { var externalRoutes = external.Select(a => a.propertyRoute).Distinct().ToList(); var dictionary = await Server.ReturnAsync((IHelpServer s) => s.GetPropertyRoutesService(externalRoutes)); foreach (var t in external) { SetHelpInfo(t.control, dictionary.GetOrThrow(t.propertyRoute)); } } }; helpButton.IsEnabled = true; }
static async void Manager_TaskNormalWindow(NormalWindow normal, ModifiableEntity entity) { ButtonBar bar = normal.Child <ButtonBar>(); var wrapPanel = (WrapPanel)bar.Content; bar.Content = null; HelpButton helpButton = new HelpButton { MainControl = normal, Margin = new Thickness(4), IsEnabled = false, }.Set(DockPanel.DockProperty, Dock.Right); bar.Content = new DockPanel { Children = { helpButton, wrapPanel } }; helpButton.IsActive = await Server.ReturnAsync((IHelpServer s) => s.HasEntityHelpService(entity.GetType())); helpButton.Checked += async(sender, args) => { var entityHelp = await Server.ReturnAsync((IHelpServer s) => s.GetEntityHelpService(entity.GetType())); SetHelpInfo(normal.Child <EntityTitle>(), entityHelp.Info); var properties = (from control in normal.Children <Control>(p => p.IsSet(Common.PropertyRouteProperty), HelpButton.WhereFlags) let propertyRoute = Common.GetPropertyRoute(control).SimplifyToPropertyOrRoot() where propertyRoute.PropertyRouteType != PropertyRouteType.Root select new { control, propertyRoute }).ToList(); var external = properties.Extract(t => t.propertyRoute.RootType != entity.GetType()); foreach (var t in properties) { SetHelpInfo(t.control, entityHelp.Properties.GetOrThrow(t.propertyRoute)); } var buttonBar = normal.Child <ButtonBar>(); var operations = (from control in buttonBar.Children <ToolBarButton>(p => p.Tag is OperationInfo, HelpButton.WhereFlags) select new { control, operation = ((OperationInfo)control.Tag).OperationSymbol }).ToList(); foreach (var t in operations) { SetHelpInfo(t.control, entityHelp.Operations.GetOrThrow(t.operation)); } var menuInfos = (from c in buttonBar.Children <ToolBarButton>(p => p.ContextMenu != null, HelpButton.WhereFlags) from mi in c.ContextMenu.Children <MenuItem>(p => p.Tag is OperationInfo, HelpButton.WhereFlags) select new { mi, operation = ((OperationInfo)mi.Tag).OperationSymbol }).ToList(); foreach (var t in menuInfos) { SetHelpInfo(t.mi, entityHelp.Operations.GetOrThrow(t.operation)); //ConstructFrom OperationInfo } if (external.Any()) { var externalRoutes = external.Select(a => a.propertyRoute).Distinct().ToList(); var dictionary = await Server.ReturnAsync((IHelpServer s) => s.GetPropertyRoutesService(externalRoutes)); foreach (var t in external) { SetHelpInfo(t.control, dictionary.GetOrThrow(t.propertyRoute)); } } }; helpButton.IsEnabled = true; }