public static MenuItem Construct(ContextualOperationContext coc) { MenuItem miResult = new MenuItem() { Header = coc.OperationSettings.Try(f => f.Text) ?? coc.OperationInfo.OperationSymbol.NiceToString(), Icon = coc.OperationSettings.Try(f => f.Icon.ToSmallImage()), }; if (coc.OperationSettings != null && coc.OperationSettings.Order != 0) Common.SetOrder(miResult, coc.OperationSettings.Order); if (coc.CanExecute != null) { miResult.ToolTip = coc.CanExecute; miResult.IsEnabled = false; ToolTipService.SetShowOnDisabled(miResult, true); AutomationProperties.SetHelpText(miResult, coc.CanExecute); } miResult.Click += (object sender, RoutedEventArgs e) => { coc.SearchControl.SetDirtySelectedItems(); if (coc.OperationSettings != null && coc.OperationSettings.Click != null) coc.OperationSettings.Click(coc); else { var lite = coc.SearchControl.SelectedItems.Single(); switch (coc.OperationInfo.OperationType) { case OperationType.Execute: Server.Return((IOperationServer os) => os.ExecuteOperationLite(lite, coc.OperationInfo.OperationSymbol)); break; case OperationType.Delete: Server.Execute((IOperationServer os) => os.Delete(lite, coc.OperationInfo.OperationSymbol)); break; case OperationType.ConstructorFrom: { var result = Server.Return((IOperationServer os) => os.ConstructFromLite(lite, coc.OperationInfo.OperationSymbol)); if (Navigator.IsNavigable(result, true)) Navigator.Navigate(result); break; } case OperationType.Constructor: case OperationType.ConstructorFromMany: throw new InvalidOperationException("Unexpected operation type"); } } }; return miResult; }
public static MenuItem Construct(ContextualOperationContext coc) { MenuItem miResult = new MenuItem { Header = OperationClient.GetText(coc.OperationInfo.OperationSymbol), Icon = OperationClient.GetImage(coc.OperationInfo.OperationSymbol).ToSmallImage(), }; if (coc.OperationSettings != null && coc.OperationSettings.Order != 0) Common.SetOrder(miResult, coc.OperationSettings.Order); if (coc.CanExecute != null) { miResult.ToolTip = coc.CanExecute; miResult.IsEnabled = false; ToolTipService.SetShowOnDisabled(miResult, true); AutomationProperties.SetHelpText(miResult, coc.CanExecute); } miResult.Click += (object sender, RoutedEventArgs e) => { Type entityType = coc.SearchControl.EntityType; coc.SearchControl.SetDirtySelectedItems(); if (coc.OperationSettings != null && coc.OperationSettings.Click != null) coc.OperationSettings.Click(coc); else { IIdentifiable result = Server.Return((IOperationServer s) => s.ConstructFromMany(coc.SearchControl.SelectedItems.ToList(), entityType, coc.OperationInfo.OperationSymbol)); if (result != null) Navigator.Navigate(result); else MessageBox.Show(Window.GetWindow(coc.SearchControl), OperationMessage.TheOperation0DidNotReturnAnEntity.NiceToString().Formato(coc.OperationInfo.OperationSymbol.NiceToString())); } }; return miResult; }