Esempio n. 1
0
        public static ILayoutCellEditor GetCellEditor(ILayoutCell cell)
        {
            var type = cell?.DataType;

            if (type == null)
            {
                return(null);
            }
            type = TypeHelper.CheckNullable(type);
            ILayoutCellEditor editor = null;

            if (CellEditorFabric.TryGetValue(type, out var generator))
            {
                editor = generator(cell);
            }
            if (editor == null)
            {
                foreach (var entry in CellEditorFabric)
                {
                    if (TypeHelper.IsBaseType(type, entry.Key))
                    {
                        editor = entry.Value(cell);
                    }
                }
            }

            //if (type.IsEnum)
            //{
            //    editor = new CellEditorEnum();
            //}
            if (editor == null)
            {
                if (TypeHelper.IsList(type))
                {
                    editor = new CellEditorFields()
                    {
                        Header = type.Name
                    };
                }
                else if (GuiService.IsCompound(type))
                {
                    editor = new CellEditorFields()
                    {
                        Header = type.Name
                    };
                }
                else
                {
                    editor = new CellEditorText()
                    {
                        Format         = cell.Format,
                        MultiLine      = false,
                        DropDownWindow = false
                    };
                }
            }
            editor.DataType = type;
            return(editor);
        }
Esempio n. 2
0
        static GuiEnvironment()
        {
            Instance.Themes.GenerateDefault();

            CellEditorFabric[typeof(string)] = cell =>
            {
                ILayoutCellEditor editor = null;
                if (cell.Name == nameof(object.ToString))
                {
                    editor = new CellEditorHeader();
                }
                else if (cell.Format == "Path")
                {
                    editor = new CellEditorPath();
                }
                else if (cell.Password)
                {
                    editor = new CellEditorPassword();
                }
                else
                {
                    editor = new CellEditorText {
                        MultiLine = true
                    };
                }
                return(editor);
            };
            CellEditorFabric[typeof(System.Security.SecureString)] = cell =>
            {
                return(new CellEditorPassword());
            };
            CellEditorFabric[typeof(byte[])] = cell =>
            {
                var    editor   = new CellEditorFile();
                string property = cell.Name;
                int    index    = property.LastIndexOf(".", StringComparison.Ordinal);
                if (index >= 0)
                {
                    property = property.Substring(index);
                }
                editor.PropertyFileName = property + "Name";
                return(editor);
            };
            CellEditorFabric[typeof(bool)] = CellEditorFabric[typeof(bool?)] = cell =>
            {
                return(new CellEditorCheck
                {
                    ValueTrue = true,
                    ValueFalse = false,
                    ValueNull = null,
                    TreeState = false
                });
            };
            CellEditorFabric[typeof(DateTime)] = cell =>
            {
                return(new CellEditorDate()
                {
                    Format = cell.Format
                });
            };
            CellEditorFabric[typeof(DateInterval)] = cell =>
            {
                return(new CellEditorDate()
                {
                    Format = cell.Format, TwoDate = true
                });
            };
            CellEditorFabric[typeof(Xwt.CheckBoxState)] = cell =>
            {
                return(new CellEditorCheck
                {
                    ValueTrue = Xwt.CheckBoxState.On,
                    ValueFalse = Xwt.CheckBoxState.Off,
                    ValueNull = Xwt.CheckBoxState.Mixed,
                    TreeState = true
                });
            };
            CellEditorFabric[typeof(CheckedState)] = cell =>
            {
                return(new CellEditorCheck
                {
                    ValueTrue = CheckedState.Checked,
                    ValueFalse = CheckedState.Unchecked,
                    ValueNull = CheckedState.Indeterminate,
                    TreeState = true
                });
            };
            CellEditorFabric[typeof(System.Net.IPAddress)] = cell =>
            {
                return(new CellEditorNetTree());
            };
            CellEditorFabric[typeof(System.Globalization.CultureInfo)] = cell =>
            {
                return(new CellEditorList {
                    DataSource = Locale.Instance.Cultures
                });
            };
            CellEditorFabric[typeof(System.Text.EncodingInfo)] = cell =>
            {
                return(new CellEditorList {
                    DataSource = System.Text.Encoding.GetEncodings()
                });
            };
            CellEditorFabric[typeof(Xwt.Drawing.Image)] = cell =>
            {
                return(new CellEditorImage());
            };
            CellEditorFabric[typeof(Xwt.Drawing.Color)] = cell =>
            {
                return(new CellEditorColor());
            };
            CellEditorFabric[typeof(Xwt.Drawing.Font)] = cell =>
            {
                return(new CellEditorFont());
            };
            CellEditorFabric[typeof(Enum)] = cell =>
            {
                return(new CellEditorEnum());
            };
            CellEditorFabric[typeof(CellStyle)] = cell =>
            {
                return(new CellEditorListEditor()
                {
                    DataSource = GuiEnvironment.Theme
                });
            };

            LocaleImage.ImageCache += (item) =>
            {
                using (var stream = new MemoryStream(item.Data))
                    return(Xwt.Drawing.Image.FromStream(stream));
            };

            AppDomain.CurrentDomain.AssemblyLoad += OnAssemblyLoad;

            foreach (var assembly in AppDomain.CurrentDomain.GetAssemblies())
            {
                OnAssemblyLoad(null, new AssemblyLoadEventArgs(assembly));
            }
        }