Ejemplo n.º 1
0
        // This method refreshes the property grid.
        public void RefreshGrid(string configuration, string platform)
        {
            // If we don't have a project yet, don't run this method.
            if (project == null)
            {
                return;
            }

            bag.Properties.Clear();

            Configuration = configuration;
            Platform      = platform;

            // Setup the new configuration.  If it doesn't exist, add it.
            pOptions = ProjectOptions.GetNewConfiguration(Configuration, Platform).Options;

            /*=== Setup the property bag. ===*/

            FieldInfo[] oFields;
            Type        oType = typeof(Options);

            oFields = oType.GetFields(BindingFlags.Public | BindingFlags.Instance);

            // Loop through all the fields in the 'Options' class.
            for (int i = 0; i < oFields.Length; i++)
            {
                // If the current field is not an option, ignore it.
                if (!oFields[i].FieldType.IsSubclassOf(typeof(OptionBase)))
                {
                    continue;
                }

                List <Attribute> attrs = AttributeUtility.GetAllAttributes(oFields[i], false);
                OptionInfo       info  = new OptionInfo(attrs);

                // Ignore options that shouldn't show up in the project options dialog.
                if (!info.IsProject)
                {
                    continue;
                }

                OptionBase   gOption = (OptionBase)oFields[i].GetValue(gOptions);
                OptionBase   pOption = (OptionBase)oFields[i].GetValue(pOptions);
                PropertySpec ps      = new PropertySpec(info.Name, pOption.GetOptionType());

                ps.Category          = info.Category;
                ps.Description       = info.Description;
                ps.EditorTypeName    = info.EditorType;
                ps.ConverterTypeName = info.ProjectTypeConverter;
                ps.DefaultValue      = gOption;

                bag.Properties.Add(ps);
            }

            // Set the selected object to be the bag.
            this.SelectedObject = bag;
        }
Ejemplo n.º 2
0
        /*=== utility ===*/

        // This method refreshes the property grid.
        public void RefreshGrid()
        {
            bag.Properties.Clear();

            /*=== Setup the property bag. ===*/

            FieldInfo[] oFields;
            Type        oType = typeof(Options);

            oFields = oType.GetFields(BindingFlags.Public | BindingFlags.Instance);

            // Loop through all the fields in the 'Options' class.
            for (int i = 0; i < oFields.Length; i++)
            {
                // If the current field is not an option, ignore it.
                if (!oFields[i].FieldType.IsSubclassOf(typeof(OptionBase)))
                {
                    continue;
                }

                List <Attribute> attrs = AttributeUtility.GetAllAttributes(oFields[i], false);
                OptionInfo       info  = new OptionInfo(attrs);

                // Ignore options that shouldn't show up in the global options dialog.
                if (!info.IsGlobal)
                {
                    continue;
                }

                OptionBase   aOption = (OptionBase)oFields[i].GetValue(aOptions);
                OptionBase   gOption = (OptionBase)oFields[i].GetValue(gOptions);
                PropertySpec ps      = new PropertySpec(info.Name, gOption.GetOptionType());

                ps.Category          = info.Category;
                ps.Description       = info.Description;
                ps.EditorTypeName    = info.EditorType;
                ps.ConverterTypeName = info.GlobalTypeConverter;
                ps.DefaultValue      = aOption;

                bag.Properties.Add(ps);
            }

            // Set the selected object to be the bag.
            this.SelectedObject = bag;
        }
Ejemplo n.º 3
0
        // This method returns the command line argument string.
        public static CommandLineInfo GetCommandLineInfo(Project p)
        {
            /*=== Read the options. ===*/

            Options gOptions = GetGlobalOptions().GetGlobalConfiguration().Options;
            Options pOptions = GetProjectOptions(p).GetActiveConfiguration().Options;

            /*=== Use reflection to build the command line string. ===*/

            string cmd = "";

            FieldInfo[] oFields;
            Type        oType = typeof(Options);

            char[] trimchars = { '"' };

            // Get the fields for type 'Options'.
            oFields = oType.GetFields(BindingFlags.Public | BindingFlags.Instance);

            /*=== Loop through the data members in the 'Options' object. ===*/

            for (int i = 0; i < oFields.Length; i++)
            {
                /*=== If the current field is not an option, ignore it. ===*/

                if (!oFields[i].FieldType.IsSubclassOf(typeof(OptionBase)))
                {
                    continue;
                }

                /*=== Parse this option's attributes. ===*/

                List <Attribute> attrs = AttributeUtility.GetAllAttributes(oFields[i], false);
                OptionInfo       info  = new OptionInfo(attrs);

                // If a commandline syntax isn't specified, ignore this option.
                if (info.CommandLine == "")
                {
                    continue;
                }

                string tag = info.CommandLine;

                // Handle string list options.
                if (oFields[i].FieldType == typeof(StringListOption))
                {
                    StringListOption gOption = (StringListOption)oFields[i].GetValue(gOptions);
                    StringListOption pOption = (StringListOption)oFields[i].GetValue(pOptions);
                    int gsize = gOption.StringList.Count;
                    int psize = pOption.StringList.Count;

                    if (gsize > 0)
                    {
                        cmd += " " + tag + " ";
                        cmd += '"' + gOption.StringList[0].Trim(trimchars) + '"';

                        for (int j = 1; j < gsize; j++)
                        {
                            cmd += "," + '"' + gOption.StringList[j].Trim(trimchars) + '"';
                        }
                    }

                    if (psize > 0)
                    {
                        int j = 0;

                        if (gsize < 1)
                        {
                            cmd += " " + tag + " ";
                            cmd += '"' + pOption.StringList[0].Trim(trimchars) + '"';
                            j    = 1;
                        }

                        for (; j < psize; j++)
                        {
                            cmd += "," + '"' + pOption.StringList[j].Trim(trimchars) + '"';
                        }
                    }
                }
                // Handle string options.
                else if (oFields[i].FieldType == typeof(StringOption))
                {
                    StringOption gOption = (StringOption)oFields[i].GetValue(gOptions);
                    StringOption pOption = (StringOption)oFields[i].GetValue(pOptions);

                    if (pOption.Value != "")
                    {
                        cmd += " " + tag + " " + '"' + pOption.Value.Trim(trimchars) + '"';
                    }
                    else if (gOption.Value != "")
                    {
                        cmd += " " + tag + " " + '"' + gOption.Value.Trim(trimchars) + '"';
                    }
                }
                // Handle boolean options.
                else if (oFields[i].FieldType == typeof(BoolOption))
                {
                    BoolOption gOption = (BoolOption)oFields[i].GetValue(gOptions);
                    BoolOption pOption = (BoolOption)oFields[i].GetValue(pOptions);
                    bool       on      = pOption.UseDefault ? gOption.Value : pOption.Value;

                    if (on)
                    {
                        cmd += " " + tag;
                    }
                }
                // Handle int options.
                else if (oFields[i].FieldType == typeof(IntOption))
                {
                    IntOption gOption = (IntOption)oFields[i].GetValue(gOptions);
                    IntOption pOption = (IntOption)oFields[i].GetValue(pOptions);
                    int       val     = pOption.UseDefault ? gOption.Value : pOption.Value;

                    cmd += " " + tag + " " + val;
                }
            }

            /*=== Setup the command line info data structure. ===*/

            CommandLineInfo cmdinfo = new CommandLineInfo();

            /*=== set the license path ===*/

            if (pOptions.LicensePath.Value != "")
            {
                cmd += " -license " + '"' + pOptions.LicensePath.Value.Trim(trimchars) + '"';
            }
            else if (gOptions.LicensePath.Value != "")
            {
                cmd += " -license " + '"' + gOptions.LicensePath.Value.Trim(trimchars) + '"';
            }
            else
            {
                cmd += " -license " + '"' + opLicenseUtility.FullLicenseFileName + '"';
            }

            cmdinfo.Arguments = cmd;

            /*=== set the executable path ===*/

            if (pOptions.ExecutablePath.Value != "")
            {
                cmdinfo.ExecutablePath = pOptions.ExecutablePath.Value.Trim(trimchars);
            }
            else if (gOptions.ExecutablePath.Value != "")
            {
                cmdinfo.ExecutablePath = gOptions.ExecutablePath.Value.Trim(trimchars);
            }
            else
            {
                cmdinfo.ExecutablePath = Path.GetFullPath(Paths.GetFullAppPath() + "..\\Release\\opCpp.exe");
            }

            return(cmdinfo);
        }