public static MenuItem Construct(IContextualOperationContext coc)
        {
            MenuItem miResult = new MenuItem
            {
                Header = OperationClient.GetText(coc.Type, coc.OperationInfo.OperationSymbol),
                Icon   = OperationClient.GetImage(coc.Type, coc.OperationInfo.OperationSymbol).ToSmallImage(),
                Tag    = coc,
            };

            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.HasClick)
                {
                    coc.OperationSettings.OnClick(coc);
                }
                else
                {
                    if (coc.ConfirmMessage())
                    {
                        Entity result = (Entity) new ConstructorContext(coc.SearchControl, coc.OperationInfo).SurroundConstructUntyped(coc.OperationInfo.ReturnType, ctx =>
                                                                                                                                       Server.Return((IOperationServer s) => s.ConstructFromMany(coc.SearchControl.SelectedItems.ToList(), coc.Type, coc.OperationInfo.OperationSymbol, ctx.Args)));

                        if (result != null)
                        {
                            Navigator.Navigate(result);
                        }
                        else
                        {
                            MessageBox.Show(Window.GetWindow(coc.SearchControl), OperationMessage.TheOperation0DidNotReturnAnEntity.NiceToString().FormatWith(coc.OperationInfo.OperationSymbol.NiceToString()));
                        }
                    }
                }
            };

            return(miResult);
        }
示例#2
0
        protected internal virtual Entity Construct(ConstructorContext ctx)
        {
            var dic = (from oi in OperationInfos(ctx.Type)
                       where oi.OperationType == OperationType.Constructor
                       let os = GetSettings <ConstructorOperationSettingsBase>(ctx.Type, oi.OperationSymbol)
                                let coc = newConstructorOperationContext.GetInvoker(ctx.Type)(oi, ctx, os)
                                          where os != null && os.HasIsVisible ? os.OnIsVisible(coc) : true
                                          select coc).ToDictionary(a => a.OperationInfo.OperationSymbol);

            if (dic.Count == 0)
            {
                return(null);
            }

            OperationSymbol selected = null;

            if (dic.Count == 1)
            {
                selected = dic.Keys.SingleEx();
            }
            else
            {
                if (!SelectorWindow.ShowDialog(dic.Keys.ToArray(), out selected,
                                               elementIcon: k => OperationClient.GetImage(ctx.Type, k),
                                               elementText: k => OperationClient.GetText(ctx.Type, k),
                                               title: SelectorMessage.ConstructorSelector.NiceToString(),
                                               message: SelectorMessage.PleaseSelectAConstructor.NiceToString(),
                                               owner: Window.GetWindow(ctx.Element)))
                {
                    return(null);
                }
            }

            var selCoc = dic[selected];

            if (selCoc.Settings != null && selCoc.Settings.HasConstructor)
            {
                return(selCoc.Settings.OnConstructor(selCoc));
            }
            else
            {
                return(Server.Return((IOperationServer s) => s.Construct(ctx.Type, selected, ctx.Args)));
            }
        }