Ejemplo n.º 1
0
        public virtual Type SelectTypes(Window parent, IEnumerable <Type> implementations, Func <Type, bool> filterType)
        {
            if (implementations == null || implementations.Count() == 0)
            {
                throw new ArgumentException("implementations");
            }

            var filtered = implementations.Where(filterType).ToList();

            var only = filtered.Only();

            if (only != null)
            {
                return(only);
            }

            if (SelectorWindow.ShowDialog(filtered, out Type sel,
                                          elementIcon: t => Navigator.Manager.GetEntityIcon(t, true),
                                          elementText: t => t.NiceName(),
                                          title: SelectorMessage.TypeSelector.NiceToString(),
                                          message: SelectorMessage.PleaseSelectAType.NiceToString(),
                                          owner: parent))
            {
                return(sel);
            }
            return(null);
        }
Ejemplo n.º 2
0
        public static bool ShowDialog <T>(IEnumerable <T> elements, out T selectedElement,
                                          Func <T, ImageSource> elementIcon = null,
                                          Func <T, string> elementText      = null,
                                          string title                    = null,
                                          string message                  = null,
                                          bool autoSelectOnlyElement      = true,
                                          Window owner                    = null,
                                          Func <T, string> elementTooltip = null)
        {
            if (title == null)
            {
                title = SelectorMessage.SelectAnElement.NiceToString();
            }

            if (message == null)
            {
                message = SelectorMessage.PleaseSelectAnElement.NiceToString();
            }

            if (elements.Count() == 1 && autoSelectOnlyElement)
            {
                selectedElement = elements.SingleEx();
                return(true);
            }

            if (elementIcon == null)
            {
                elementIcon = o => null;
            }

            if (elementText == null)
            {
                elementText = o => o.ToString();
            }

            if (elementTooltip == null)
            {
                elementTooltip = o => null;
            }

            SelectorWindow w = new SelectorWindow()
            {
                WindowStartupLocation = owner == null ? WindowStartupLocation.CenterScreen : WindowStartupLocation.CenterOwner,
                Owner    = owner,
                Title    = title,
                Message  = message,
                Elements = elements.Select(e => new ElementInfo()
                {
                    Element     = e,
                    Image       = elementIcon(e),
                    Text        = elementText(e),
                    ToolTipText = elementTooltip(e)
                }).ToArray()
            };
            bool res = w.ShowDialog() ?? false;

            if (res)
            {
                selectedElement = (T)w.SelectedElement;
            }
            else
            {
                selectedElement = default(T);
            }
            return(res);
        }