コード例 #1
0
        private static List <IOption> SetupOptionsView()
        {
            var expectedOptionBool = new OptionBool
            {
                Name  = "bool",
                Value = false
            };
            var expectedOptionInt = new OptionInt
            {
                Name  = "int",
                Value = 10
            };
            var expectedOptionAutocompletebox = new OptionAutocomplete
            {
                Name  = "auto",
                Value = "new text"
            };
            var expectedOptions = new List <IOption>
            {
                expectedOptionBool,
                expectedOptionInt,
                expectedOptionAutocompletebox
            };

            return(expectedOptions);
        }
コード例 #2
0
ファイル: UIOptions.cs プロジェクト: daviddw/oss-public
        public UiOptions(IHelper aHelper)
        {
            iWindowWidth     = new OptionDouble("windowwidth", "WindowWidth", "", 1024);
            iWindowHeight    = new OptionDouble("windowheight", "WindowHeight", "", 600);
            iWindowLocationX = new OptionDouble("windowx", "WindowLocationX", "", -1);
            iWindowLocationY = new OptionDouble("windowy", "WindowLocationY", "", -1);

            iBrowserSplitterLocationLeft  = new OptionInt("browsersplitterleft", "BrowserSplitterLocationLeft", "", 652);
            iBrowserSplitterLocationRight = new OptionInt("browsersplitterright", "BrowserSplitterLocationRight", "", 404);
            iFullscreen    = new OptionBool("fullscreen", "Fullscreen", "", false);
            iMiniMode      = new OptionBool("minimode", "MiniMode", "", false);
            iContainerView = new OptionUint("containerview", "ContainerView", "", 0);
            iContainerViewSizeThumbsView = new OptionDouble("containerviewsizethumbs", "ContainerViewSizeThumbs", "", 150);
            iContainerViewSizeListView   = new OptionDouble("containerviewsizelist", "ContainerViewSizeList", "", 100);

            iOptionDialogSettings = new OptionDialogSettings();

            aHelper.AddOption(iWindowWidth);
            aHelper.AddOption(iWindowHeight);
            aHelper.AddOption(iWindowLocationX);
            aHelper.AddOption(iWindowLocationY);
            aHelper.AddOption(iBrowserSplitterLocationLeft);
            aHelper.AddOption(iBrowserSplitterLocationRight);
            aHelper.AddOption(iFullscreen);
            aHelper.AddOption(iMiniMode);
            aHelper.AddOption(iContainerView);
            aHelper.AddOption(iContainerViewSizeThumbsView);
            aHelper.AddOption(iContainerViewSizeListView);
            aHelper.AddOption(iOptionDialogSettings);
        }
コード例 #3
0
ファイル: UiOptions.cs プロジェクト: daviddw/oss-public
        public UiOptions(IHelper aHelper)
        {
            iWindowWidth       = new OptionInt("windowwidth", "WindowWidth", "", 1024);
            iWindowHeight      = new OptionInt("windowheight", "WindowHeight", "", 600);
            iWindowLocationX   = new OptionInt("windowx", "WindowLocationX", "", -1);
            iWindowLocationY   = new OptionInt("windowy", "WindowLocationY", "", -1);
            iSplitterLocation  = new OptionInt("splitterx", "SplitterLocation", "", 502);
            iFullscreen        = new OptionBool("fullscreen", "Fullscreen", "", false);
            iMiniMode          = new OptionBool("minimode", "MiniMode", "", false);
            iMiniModeWidth     = new OptionInt("minimodewidth", "MiniModeWidth", "", Screen.PrimaryScreen.WorkingArea.Width / 2);
            iMiniModeLocationX = new OptionInt("minimodex", "MiniModeLocationX", "", Screen.PrimaryScreen.WorkingArea.Width / 2);
            iMiniModeLocationY = new OptionInt("minimodey", "MiniModeLocationY", "", Screen.PrimaryScreen.WorkingArea.Height - 100);
            iAlbumView         = new OptionUint("albumview", "AlbumView", "", 0);
            iContainerView     = new OptionUint("containerview", "ContainerView", "", 0);
            iContainerViewSize = new OptionUint("containerviewsize", "ContainerViewSize", "", 0);

            aHelper.AddOption(iWindowWidth);
            aHelper.AddOption(iWindowHeight);
            aHelper.AddOption(iWindowLocationX);
            aHelper.AddOption(iWindowLocationY);
            aHelper.AddOption(iSplitterLocation);
            aHelper.AddOption(iFullscreen);
            aHelper.AddOption(iMiniMode);
            aHelper.AddOption(iMiniModeWidth);
            aHelper.AddOption(iMiniModeLocationX);
            aHelper.AddOption(iMiniModeLocationY);
            aHelper.AddOption(iAlbumView);
            aHelper.AddOption(iContainerView);
            aHelper.AddOption(iContainerViewSize);
        }
コード例 #4
0
        public void OptionInt_Clone()
        {
            var optionInt = new OptionInt
            {
                Name  = "MaxAllowed",
                Value = 10
            };

            var cloneOptionBool = optionInt.Clone() as OptionInt;

            Assert.AreEqual(optionInt.Name, cloneOptionBool.Name);
            Assert.AreEqual(optionInt.Value, cloneOptionBool.Value);
        }
コード例 #5
0
        public void OptionInt_Default()
        {
            var optionInt = new OptionInt();

            Assert.IsNull(optionInt.Name);
            optionInt.Name = "MaxAllowed";
            Assert.AreEqual("MaxAllowed", optionInt.Name);

            Assert.AreEqual(0, optionInt.Value);
            optionInt.Value = 10;
            Assert.AreEqual(10, optionInt.Value);

            Assert.AreEqual(0, optionInt.Default);
        }
コード例 #6
0
        public void OptionInt_CompareTo()
        {
            var optionInt = new OptionInt
            {
                Name  = "MaxAllowed",
                Value = 10
            };

            var expectedValue = optionInt.CompareTo(null);

            Assert.AreEqual(-1, expectedValue);

            expectedValue = optionInt.CompareTo(new object { });
            Assert.AreEqual(-1, expectedValue);

            expectedValue = optionInt.CompareTo(optionInt);
            Assert.AreEqual(0, expectedValue);
        }
コード例 #7
0
        public ApplicationOptions(IHelper aHelper)
        {
            iLeftSplitterLocation = new OptionInt("leftsplitter", "Left Splitter Location", "Graphical location in pixels of left splitter", 300);
            aHelper.AddOption(iLeftSplitterLocation);

            iRightSplitterLocation = new OptionInt("rightsplitter", "Right Splitter Location", "Graphical location in pixels of right splitter", 300);
            aHelper.AddOption(iRightSplitterLocation);

            iWindowWidth = new OptionInt("width", "Window Width", "Width of application window in pixels", 900);
            aHelper.AddOption(iWindowWidth);

            iWindowHeight = new OptionInt("height", "Window Height", "Height of application window in pixels", 600);
            aHelper.AddOption(iWindowHeight);

            iWindowMaximised = new OptionBool("maximised", "Window Maximised", "Flag to determine if the application window is maximised", false);
            aHelper.AddOption(iWindowMaximised);

            iWindowMinimised = new OptionBool("minimised", "Window Minimised", "Flag to determine if the application window is minimised", false);
            aHelper.AddOption(iWindowMinimised);

            iPrintPagesPerSheetIndex = new OptionInt("printpagespersheet", "Print Pages Per Sheet Index", "Index value of pages per sheet selection for printing a catalog (last selected by user)", 0);
            aHelper.AddOption(iPrintPagesPerSheetIndex);

            iPrintPageLayout = new OptionEnum("printpagelayout", "Print Page Layout", "Page layout selection for printing a catalog (last selected by user)");
            iPrintPageLayout.AddDefault(kPotraitTrackDetails);
            iPrintPageLayout.Add(kLandscapeTrackDetails);
            iPrintPageLayout.Add(kPotrait);
            iPrintPageLayout.Add(kLandscape);
            aHelper.AddOption(iPrintPageLayout);

            iPrintOrderBooklet = new OptionBool("printorderbooklet", "Print Order Booklet", "Booklet order selection for printing a catalog (last selected by user)", false);
            aHelper.AddOption(iPrintOrderBooklet);

            iPrintDocumentType = new OptionEnum("printdoctype", "Print Document Type", "Document type selection for printing a catalog (last selected by user)");
            iPrintDocumentType.AddDefault(kPdf);
            iPrintDocumentType.Add(kRtf);
            aHelper.AddOption(iPrintDocumentType);

            iPrintSections = new OptionListString("printsections", "Print Sections", "User selected sections to print when creating a catalog", new List <string>()
            {
                kToc
            });
            aHelper.AddOption(iPrintSections);
        }
コード例 #8
0
        private static IOption PropertyToOption(object instance, PropertyInfo prop, IOptionConvertParameter topLevelInstance)
        {
            var helptextAttr = prop.GetCustomAttributes().Where(o => o is HelpTextAttribute).Cast <HelpTextAttribute>().FirstOrDefault();
            var tooltipAttr  = prop.GetCustomAttributes().Where(o => o is TooltipAttribute).Cast <TooltipAttribute>().FirstOrDefault();

            if (prop.PropertyType.IsAssignableFrom(typeof(string)))
            {
                var attr   = prop.GetCustomAttributes().Where(o => o is DataProviderAttribute).Cast <DataProviderAttribute>().FirstOrDefault();
                var result = new OptionAutocomplete()
                {
                    Name  = prop.Name,
                    Value = (string)prop.GetValue(instance)
                };
                if (attr != null)
                {
                    result.Suggestions = ((IOptionDataList)attr.Get()).Options;
                }
                if (helptextAttr != null)
                {
                    result.HelpText = helptextAttr.Get();
                }
                if (tooltipAttr != null)
                {
                    result.Tooltip = tooltipAttr.Get();
                }
                result.PropertyChanged += (o, e) => { prop.SetValue(instance, ((OptionAutocomplete)o).Value); topLevelInstance?.Notify(); };

                return(result);
            }
            else if (prop.PropertyType.IsAssignableFrom(typeof(int)))
            {
                var optionInt = new OptionInt
                {
                    Name  = prop.Name,
                    Value = (int)prop.GetValue(instance)
                };
                if (helptextAttr != null)
                {
                    optionInt.HelpText = helptextAttr.Get();
                }
                if (tooltipAttr != null)
                {
                    optionInt.Tooltip = tooltipAttr.Get();
                }

                optionInt.PropertyChanged += (o, e) => { prop.SetValue(instance, ((OptionInt)o).Value); topLevelInstance?.Notify(); };
                return(optionInt);
            }
            else if (prop.PropertyType.IsAssignableFrom(typeof(IWorkflow)))
            {
                var workflow       = (IWorkflow)prop.GetValue(instance);
                var optionWorkflow = new OptionWorkflow
                {
                    Name     = prop.Name,
                    Workflow = new WorkflowWithInputs {
                        Name = workflow.Name, Value = workflow.Value, Inputs = workflow.Inputs
                    },
                };
                if (helptextAttr != null)
                {
                    optionWorkflow.HelpText = helptextAttr.Get();
                }
                if (tooltipAttr != null)
                {
                    optionWorkflow.Tooltip = tooltipAttr.Get();
                }
                optionWorkflow.PropertyChanged += (o, e) =>
                {
                    if (e.PropertyName == nameof(OptionWorkflow.Workflow))
                    {
                        prop.SetValue(instance, ((OptionWorkflow)o).Workflow);
                    }
                    topLevelInstance?.Notify();
                };
                return(optionWorkflow);
            }
            else if (prop.PropertyType.IsAssignableFrom(typeof(bool)))
            {
                var optionBool = new OptionBool
                {
                    Name  = prop.Name,
                    Value = (bool)prop.GetValue(instance),
                };
                if (helptextAttr != null)
                {
                    optionBool.HelpText = helptextAttr.Get();
                }
                if (tooltipAttr != null)
                {
                    optionBool.Tooltip = tooltipAttr.Get();
                }
                optionBool.PropertyChanged += (o, e) => { prop.SetValue(instance, ((OptionBool)o).Value); topLevelInstance?.Notify(); };

                return(optionBool);
            }
            else if (prop.PropertyType.IsEnum)
            {
                var values = new List <KeyValuePair <string, int> >();
                foreach (var option in Enum.GetValues(prop.PropertyType))
                {
                    var key = Enum.GetName(prop.PropertyType, option);
                    values.Add(new KeyValuePair <string, int>(key, (int)option));
                }

                var result = new OptionEnum
                {
                    Values = values,
                    Name   = prop.Name,
                    Value  = (int)prop.GetValue(instance),
                };
                if (helptextAttr != null)
                {
                    result.HelpText = helptextAttr.Get();
                }
                if (tooltipAttr != null)
                {
                    result.Tooltip = tooltipAttr.Get();
                }
                result.PropertyChanged += (o, e) => { prop.SetValue(instance, ((OptionEnum)o).Value); topLevelInstance?.Notify(); };

                return(result);
            }
            else
            {
                var attrs            = prop.GetCustomAttributes();
                var optionTypeUXAttr = attrs.Where(o => o is OptionUXAttribute).Cast <OptionUXAttribute>().FirstOrDefault();
                var fieldValueAttr   = attrs.Where(o => o is DataValueAttribute).Cast <DataValueAttribute>().FirstOrDefault();
                var dataProviderAttr = attrs.Where(o => o is MultiDataProviderAttribute).Cast <MultiDataProviderAttribute>().FirstOrDefault();

                if (fieldValueAttr == null)
                {
                    throw new Exception("FieldValueAttribute required");
                }
                var fieldValueName = fieldValueAttr.Get();

                var propertyValue = prop.GetValue(instance);
                var types         = prop.PropertyType.GetProperties();
                var fieldNameProp = types.First(type => type.Name == fieldValueName);
                if (fieldNameProp == null)
                {
                    throw new Exception("property does not exist");
                }
                if (!fieldNameProp.PropertyType.IsEnum)
                {
                    throw new Exception("currently only enums supported");
                }
                if (propertyValue is null)
                {
                    throw NullException;
                }

                IOptionMultiData returnVal;
                var enumValue = fieldNameProp.GetValue(propertyValue);

                Orientation?orientation = null;
                if (optionTypeUXAttr?.Get() == typeof(OptionRadioButtons))
                {
                    var orientationAttr = attrs.Where(o => o is OrientationAttribute).Cast <OrientationAttribute>().FirstOrDefault();
                    if (orientationAttr != null)
                    {
                        orientation = orientationAttr.Get();
                    }
                    returnVal = new OptionRadioButtons
                    {
                        Name  = prop.Name,
                        Value = Enum.GetName(fieldNameProp.PropertyType, enumValue),
                    };
                }
                else
                { // optionTypeUXAttr is OptionCombobox
                    returnVal = new OptionCombobox
                    {
                        Name  = prop.Name,
                        Value = Enum.GetName(fieldNameProp.PropertyType, enumValue),
                    };
                }
                if (helptextAttr != null)
                {
                    returnVal.HelpText = helptextAttr.Get();
                }
                if (tooltipAttr != null)
                {
                    returnVal.Tooltip = tooltipAttr.Get();
                }

                var optionCount = 0;
                if (dataProviderAttr != null)
                {
                    var optionTypes = dataProviderAttr.Get();
                    foreach (var optionType in optionTypes)
                    {
                        object value = propertyValue != null && propertyValue.GetType() == optionType.GetType() ? propertyValue : optionType;

                        var type = optionType.GetType();
                        returnVal.Options[type.Name] = OptionConvertor.Convert(value, topLevelInstance).Where(o => o.Name != fieldValueName);
                    }
                    optionCount = optionTypes.Length;
                }
                if (returnVal is OptionRadioButtons optionRadioButton)
                {
                    var calcOrientation = optionCount == 2 ? Orientation.Horizontal : Orientation.Vertical;
                    optionRadioButton.Orientation = orientation ?? calcOrientation;

                    returnVal.PropertyChanged += (o, e) => { prop.SetValue(instance, ExtractValueFromOptionMultiData(instance, prop, (OptionRadioButtons)o)); topLevelInstance?.Notify(); };
                }
                else
                {
                    returnVal.PropertyChanged += (o, e) => { prop.SetValue(instance, ExtractValueFromOptionMultiData(instance, prop, (OptionCombobox)o)); topLevelInstance?.Notify(); };
                }
                return(returnVal);
            }
            throw UnhandledException;
        }