Example #1
0
    void DrawOption(int i)
    {
        OptionEntry o = stats[i];

        BeginHorizontal("box");
        OptionEntry temp = new OptionEntry(o);

        if (Button("-", Width(20)))
        {
            removeAt = i;
        }
        if (Button("/\\", Width(20)))
        {
            moveUp = i;
        }
        if (Button("\\/", Width(20)))
        {
            moveDown = i;
        }


        o.name  = TextField(o.name, Width(200));
        o.value = EditorGUILayout.FloatField(o.value, Width(200));

        changed = changed || (!o.Equals(temp));
        EndHorizontal();
    }
 private void DisplayOptions()
 {
     displayedSettings = new List <OptionEntry>();
     PropertyInfo[] properties = Type.GetType(sectionTypeName, true, false).GetProperties();
     foreach (PropertyInfo pif in properties)
     {
         OptionEntry opt = Instantiate(prefab, content.transform);
         opt.Property = pif;
         displayedSettings.Add(opt);
     }
 }
Example #3
0
        public new bool Equals(System.Object other)
        {
            if (other == null)
            {
                return(false);
            }
            if (other.GetType() != GetType())
            {
                return(false);
            }
            OptionEntry o = other as OptionEntry;

            return(o.name == name && o.value == value);
        }
        public ShapeOptions(BinaryReader _reader, uint size, uint typeCode, uint version, uint instance)
            : base(_reader, size, typeCode, version, instance)
        {
            long pos = this.Reader.BaseStream.Position;

            //instance is the count of properties stored in this record
            this.Options = new OptionEntry[instance];

            //parse the flags and the simple values
            for (int i = 0; i < instance; i++)
            {
                OptionEntry entry = new OptionEntry();
                UInt16      flag  = this.Reader.ReadUInt16();
                entry.pid      = (PropertyId)Utils.BitmaskToInt(flag, 0x3FFF);
                entry.fBid     = Utils.BitmaskToBool(flag, 0x4000);
                entry.fComplex = Utils.BitmaskToBool(flag, 0x8000);
                entry.op       = this.Reader.ReadUInt32();

                this.Options[i] = entry;
            }

            //parse the complex values
            //these values are stored directly at the end
            //of the OptionEntry arry, sorted by pid
            for (int i = 0; i < instance; i++)
            {
                if (this.Options[i].fComplex)
                {
                    if (this.Options[i].pid == PropertyId.pVertices)
                    {
                        this.Options[i].opComplex = this.Reader.ReadBytes((int)this.Options[i].op + 6);
                    }
                    else
                    {
                        this.Options[i].opComplex = this.Reader.ReadBytes((int)this.Options[i].op);
                    }
                }
                if (this.OptionsByID.ContainsKey(this.Options[i].pid))
                {
                    OptionsByID[this.Options[i].pid] = this.Options[i];
                }
                else
                {
                    OptionsByID.Add(this.Options[i].pid, this.Options[i]);
                }
            }

            this.Reader.BaseStream.Seek(pos + size, SeekOrigin.Begin);
        }
        private IEnumerable <OptionEntry> GetCommandLineArgsFromString(string argsContent)
        {
            (string argNameGroup, string argContainsQoutesGroup)argNameGroupsData  = ("ArgNameGroup", "ArgNameGroupContainsQoutes");
            (string argNameGroup, string argContainsQoutesGroup)argValueGroupsData = ("ArgValueGroup", "ArgValueGroupContainsQoutes");
            const string baseArgPatternFormat = "((?<{0}>\"(?<{1}>.*?[^\\\\])\")|(?<{1}>[\\w\\,]*))";
            var          finalPatten          = $"(?>-\\s*{string.Format( baseArgPatternFormat, argNameGroupsData.argContainsQoutesGroup,argNameGroupsData.argNameGroup )}((\\s*[\\=]\\s*)|(\\s*))" +
                                                $"{string.Format( baseArgPatternFormat, argValueGroupsData.argContainsQoutesGroup,argValueGroupsData.argNameGroup )})";

            var parsedArgs = Regex.Matches(argsContent, finalPatten, RegexOptions.Multiline);

            foreach (Match parsedArg in parsedArgs)
            {
                var argName = parsedArg.Groups[argNameGroupsData.argNameGroup].Value;

                var availableOption = _optionsList.FirstOrDefault(option => option.Name == argName);

                if (availableOption == null)
                {
                    continue;
                }

                var argValue  = parsedArg.Groups[argValueGroupsData.argNameGroup].Value;
                var argValues = argValue.Contains(CommandValueSplitSymbol) ? argValue.Split(new[] { CommandValueSplitSymbol }, StringSplitOptions.None) : new[] { argValue };

                var optionEntry = new OptionEntry
                {
                    Name          = argName,
                    IsQuoteForced = !string.IsNullOrEmpty(parsedArg.Groups[argValueGroupsData.argContainsQoutesGroup].Value)
                };

                for (var i = 0; i < argValues.Length; ++i)
                {
                    optionEntry.Parameters.Add(new EntryParameter()
                    {
                        Name  = availableOption.Parameters[i].Name,
                        Value = argValues[i]
                    });
                }

                yield return(optionEntry);
            }
        }
Example #6
0
        public IOptionsProvider AddOption(IOptionsProvider provider, string name, string value, uint?priority = default(uint?))
        {
            if (name == null)
            {
                throw new ArgumentException("name");
            }

            IOptionsProvider res  = null;
            OptionEntry      curr = null;

            if (store.TryGetValue(name, out curr))
            {
                curr.Update(provider, value, priority);
            }
            else
            {
                store.Add(name, new OptionEntry(provider, value, priority));
            }
            return(res);
        }
Example #7
0
        public void CommandLineParserTests()
        {
            IList <string> vapi_directories = null;
            bool           foo = false;

            OptionEntry[] options = new OptionEntry[] {
                new OptionEntry <IList <string> >(
                    "vapidir", 0, 0, OptionArg.FILENAME_ARRAY,
                    "Look for package bindings in DIRECTORY", "DIRECTORY...",
                    (value) => { vapi_directories = value; }
                    ),
                new OptionEntry <bool>(
                    "foo", 0, 0, OptionArg.NONE,
                    "Unit Test", "",
                    (value) => { foo = value; }
                    )
            };

            var opt_context = new OptionContext("- Vala Interpreter");

            opt_context.help_enabled = true;
            opt_context.add_main_entries(options, null);

            string[] args =
            {
                "--vapidir",     "foo",
                "--vapidir",     "bar",
                "--vapidir=baz",
                "--foo"
            };

            opt_context.parse(args);

            Assert.IsTrue(vapi_directories != null && vapi_directories.Count == 3);
            Assert.AreEqual(vapi_directories[0], "foo");
            Assert.AreEqual(vapi_directories[1], "bar");
            Assert.AreEqual(vapi_directories[2], "baz");
            Assert.IsTrue(foo);
        }
Example #8
0
		protected void SetValue(OptionEntry entry, object value)
		{
			entry.Value = Convert.ChangeType(value, entry.ValueType);
		}
Example #9
0
		protected virtual void OnOptionEditChar(OptionEntry entry, char value)
		{
			new InputDialogGump(User, Refresh())
			{
				Limit = 1,
				Title = entry.Label,
				Html = entry.Info,
				InputText = value.ToString(),
				Callback = (b, v) =>
				{
					SetValue(entry, v);

					Refresh(true);
				}
			}.Send();
		}
Example #10
0
		protected virtual void OnOptionEditObject(OptionEntry entry, object value)
		{
			new InputDialogGump(User, Refresh())
			{
				Title = entry.Label,
				Html = entry.Info,
				InputText = value.ToString(),
				Callback = (b, v) =>
				{
					if (v.TryParse(out value))
					{
						SetValue(entry, value);
					}

					Refresh(true);
				}
			}.Send();
		}
Example #11
0
		protected virtual void OnOptionEditBool(OptionEntry entry, bool value)
		{
			entry.Value = !value;

			Refresh(true);
		}
Example #12
0
		protected virtual void OnOptionEditString(OptionEntry entry, string value)
		{
			new InputDialogGump(User, Refresh())
			{
				Title = entry.Label,
				Html = entry.Info,
				InputText = value,
				Callback = (b, v) =>
				{
					SetValue(entry, v);

					Refresh(true);
				}
			}.Send();
		}
Example #13
0
		protected virtual void OnOptionInfo(OptionEntry entry)
		{
			new NoticeDialogGump(User, Refresh())
			{
				Title = entry.Label,
				Html = entry.Info
			}.Send();
		}
Example #14
0
		protected virtual void OnOptionEdit(OptionEntry entry)
		{
			var val = entry.Value;

			if (val is bool)
			{
				OnOptionEditBool(entry, (bool)val);
			}
			else if (val is sbyte || val is short || val is int || val is long)
			{
				OnOptionEditNumber(entry, (long)val);
			}
			else if (val is byte || val is ushort || val is uint || val is ulong)
			{
				OnOptionEditNumber(entry, (ulong)val);
			}
			else if (val is float || val is decimal || val is double)
			{
				OnOptionEditNumber(entry, (double)val);
			}
			else if (val is string)
			{
				OnOptionEditString(entry, (string)val);
			}
			else if (val is char)
			{
				OnOptionEditChar(entry, (char)val);
			}
			else
			{
				OnOptionEditObject(entry, val);
			}
		}
	void DrawOption(int i) {
		OptionEntry o = stats[i];
		BeginHorizontal("box");
			OptionEntry temp = new OptionEntry(o);
			
			if (Button("-", Width(20))) { removeAt = i; }
			if (Button("/\\", Width(20))) { moveUp = i; }
			if (Button("\\/", Width(20))) { moveDown = i; }
			
			
			o.name = TextField(o.name, Width(200));
			o.value = EditorGUILayout.FloatField(o.value, Width(200));
			
			changed = changed || (!o.Equals(temp));
		EndHorizontal();
	}
		public OptionEntry(OptionEntry o) { name = o.name; value = o.value; }
Example #17
0
		protected string GetValueString(OptionEntry e)
		{
			var val = e.Value;

			if (val == null)
			{
				return "(~null~)";
			}

			if (val is bool)
			{
				return (bool)val ? "True" : "False";
			}

			if (val is sbyte || val is short || val is int || val is long)
			{
				return ((long)val).ToString("#,0");
			}

			if (val is byte || val is ushort || val is uint || val is ulong)
			{
				return ((ulong)val).ToString("#,0");
			}

			if (val is float || val is decimal || val is double)
			{
				return ((double)val).ToString("#,0.00");
			}

			return val.ToString();
		}
Example #18
0
        /// <summary>
        /// Do Parsing
        /// </summary>
        /// <param name="commandLineArgs">Target args</param>
        /// <returns>Parsing result</returns>
        public ParseResult Parse(string[] commandLineArgs)
        {
            ParseResult parsingResult = new ParseResult();

            //note: parsing automata will be faster, but just compare all by length order because this may not be performance critical routine
            List <string> orderedStartCharacters = new List <string>(flagStarters);

            orderedStartCharacters.Sort((x, y) => y.Length.CompareTo(x.Length));

            List <string> orderedValueDelimiters = new List <string>(valueDelimiters);

            orderedValueDelimiters.Sort((x, y) => y.Length.CompareTo(x.Length));

            List <string> orderedArgumentOptions = m_argumentedOptions.ToList();

            orderedArgumentOptions.Sort((x, y) => y.Length.CompareTo(x.Length));

            OptionEntry currentCapturing = null;

            int readingPointer = 0;

            while (readingPointer < commandLineArgs.Length)
            {
                string specialParsingString = null;
                foreach (string currentStartCheck in orderedStartCharacters)
                {
                    if (commandLineArgs[readingPointer].StartsWith(currentStartCheck))
                    {
                        specialParsingString = commandLineArgs[readingPointer].Substring(currentStartCheck.Length);
                        break;
                    }
                }

                if (specialParsingString == null)
                {
                    if (currentCapturing != null)
                    {
                        currentCapturing.valueString = commandLineArgs[readingPointer];
                        parsingResult.options.Add(currentCapturing);
                        currentCapturing = null;
                    }
                    else
                    {
                        parsingResult.normalArgs.Add(commandLineArgs[readingPointer]);
                    }
                }
                else
                {
                    // Invalidate capture after special arguments
                    if (currentCapturing != null)
                    {
                        parsingResult.options.Add(currentCapturing);
                        currentCapturing = null;
                    }

                    if (string.IsNullOrWhiteSpace(specialParsingString))
                    {
                        // Not a valid option. considered as normal parameter
                        parsingResult.normalArgs.Add(commandLineArgs[readingPointer]);
                    }
                    else
                    {
                        string valueCandidateString = null;
                        string capturedOption       = null;
                        foreach (string currentOptionCheck in orderedArgumentOptions)
                        {
                            if (specialParsingString.StartsWith(currentOptionCheck))
                            {
                                valueCandidateString = specialParsingString.Substring(currentOptionCheck.Length);
                                capturedOption       = currentOptionCheck;
                                break;
                            }
                        }

                        if (capturedOption == null)
                        {
                            // Non-argumented options
                            parsingResult.options.Add(new OptionEntry()
                            {
                                optionString = specialParsingString
                            });
                        }
                        else
                        {
                            // Options with an argument
                            currentCapturing = new OptionEntry()
                            {
                                optionString = capturedOption
                            };
                            if (valueCandidateString.Length > 0)
                            {
                                string assignedOptionValue = null;
                                foreach (string currentDelimiter in orderedValueDelimiters)
                                {
                                    if (valueCandidateString.StartsWith(currentDelimiter))
                                    {
                                        assignedOptionValue = valueCandidateString.Substring(currentDelimiter.Length);
                                        break;
                                    }
                                }

                                if (assignedOptionValue == null)
                                {
                                    currentCapturing.valueString = valueCandidateString;
                                }
                                else
                                {
                                    currentCapturing.valueString = assignedOptionValue;
                                }
                                parsingResult.options.Add(currentCapturing);
                                currentCapturing = null;
                            }
                        }
                    }
                }

                ++readingPointer;
            }
            if (currentCapturing != null)
            {
                parsingResult.options.Add(currentCapturing);
            }

            return(parsingResult);
        }
Example #19
0
 public OptionEntry(OptionEntry o)
 {
     name = o.name; value = o.value;
 }
Example #20
0
        public void parse_args(string[] args)
        {
            OptionEntry[] options = new OptionEntry[] {
                new OptionEntry <string>(
                    "path", 0, 0, OptionArg.STRING,
                    "Use the gcc/toolchain binaries located in DIRECTORY", "DIRECTORY",
                    (value) => { path = value; }
                    ),
                new OptionEntry <IList <string> >(
                    "vapidir", 0, 0, OptionArg.FILENAME_ARRAY,
                    "Look for package bindings in DIRECTORY", "DIRECTORY...",
                    (value) => { vapi_directories = value; }
                    ),
                new OptionEntry <IList <string> >(
                    "girdir", 0, 0, OptionArg.FILENAME_ARRAY,
                    "Look for .gir files in DIRECTORY", "DIRECTORY...",
                    (value) => { gir_directories = value; }
                    ),
                new OptionEntry <IList <string> >(
                    "metadatadir", 0, 0, OptionArg.FILENAME_ARRAY,
                    "Look for GIR .metadata files in DIRECTORY", "DIRECTORY...",
                    (value) => { metadata_directories = value; }
                    ),
                new OptionEntry <IList <string> >(
                    "pkg", 0, 0, OptionArg.STRING_ARRAY,
                    "Include binding for PACKAGE", "PACKAGE...",
                    (value) => { packages = value; }
                    ),
                new OptionEntry <string>(
                    "vapi", 0, 0, OptionArg.FILENAME,
                    "Output VAPI file name", "FILE",
                    (value) => { vapi_filename = value; }
                    ),
                new OptionEntry <string>(
                    "library", 0, 0, OptionArg.STRING,
                    "Library name", "NAME",
                    (value) => { library = value; }
                    ),
                new OptionEntry <string>(
                    "shared-library", 0, 0, OptionArg.STRING,
                    "Shared library name used in generated gir", "NAME",
                    (value) => { shared_library = value; }
                    ),
                new OptionEntry <string>(
                    "gir", 0, 0, OptionArg.STRING,
                    "GObject-Introspection repository file name", "NAME-VERSION.gir",
                    (value) => { gir = value; }
                    ),
                new OptionEntry <string>(
                    "basedir", 'b', 0, OptionArg.FILENAME,
                    "Base source directory", "DIRECTORY",
                    (value) => { basedir = value; }
                    ),
                new OptionEntry <string>(
                    "directory", 'd', 0, OptionArg.FILENAME,
                    "Change output directory from current working directory", "DIRECTORY",
                    (value) => { directory = value; }
                    ),
                new OptionEntry <bool>(
                    "version", 0, 0, OptionArg.NONE,
                    "Display version number", null,
                    (value) => { version = value; }
                    ),
                new OptionEntry <bool>(
                    "api-version", 0, 0, OptionArg.NONE,
                    "Display API version number", null,
                    (value) => { api_version = value; }
                    ),
                new OptionEntry <bool>(
                    "ccode", 'C', 0, OptionArg.NONE,
                    "Output C code", null,
                    (value) => { ccode_only = value; }
                    ),
                new OptionEntry <bool>(
                    "dry-run", 'n', 0, OptionArg.NONE,
                    "Dry Run", null,
                    (value) => { dry_run = value; }
                    ),
                new OptionEntry <string>(
                    "header", 'H', 0, OptionArg.FILENAME,
                    "Output C header file", "FILE",
                    (value) => { header_filename = value; }
                    ),
                new OptionEntry <bool>(
                    "use-header", 0, 0, OptionArg.NONE,
                    "Use C header file", null,
                    (value) => { use_header = value; }
                    ),
                new OptionEntry <string>(
                    "includedir", 0, 0, OptionArg.FILENAME,
                    "Directory used to include the C header file", "DIRECTORY",
                    (value) => { includedir = value; }
                    ),
                new OptionEntry <string>(
                    "internal-header", 'h', 0, OptionArg.FILENAME,
                    "Output internal C header file", "FILE",
                    (value) => { internal_header_filename = value; }
                    ),
                new OptionEntry <string>(
                    "internal-vapi", 0, 0, OptionArg.FILENAME,
                    "Output vapi with internal api", "FILE",
                    (value) => { internal_vapi_filename = value; }
                    ),
                new OptionEntry <string>(
                    "fast-vapi", 0, 0, OptionArg.STRING,
                    "Output vapi without performing symbol resolution", null,
                    (value) => { fast_vapi_filename = value; }
                    ),
                new OptionEntry <IList <string> >(
                    "use-fast-vapi", 0, 0, OptionArg.STRING_ARRAY,
                    "Use --fast-vapi output during this compile", null,
                    (value) => { fast_vapis = value; }
                    ),
                new OptionEntry <bool>(
                    "vapi-comments", 0, 0, OptionArg.NONE,
                    "Include comments in generated vapi", null,
                    (value) => { vapi_comments = value; }
                    ),
                new OptionEntry <string>(
                    "deps", 0, 0, OptionArg.STRING,
                    "Write make-style dependency information to this file", null,
                    (value) => { dependencies = value; }
                    ),
                new OptionEntry <string>(
                    "symbols", 0, 0, OptionArg.FILENAME,
                    "Output symbols file", "FILE",
                    (value) => { symbols_filename = value; }
                    ),
                new OptionEntry <bool>(
                    "compile", 'c', 0, OptionArg.NONE,
                    "Compile but do not link", null,
                    (value) => { compile_only = value; }
                    ),
                new OptionEntry <string>(
                    "output", 'o', 0, OptionArg.FILENAME,
                    "Place output in file FILE", "FILE",
                    (value) => { output = value; }
                    ),
                new OptionEntry <bool>(
                    "debug", 'g', 0, OptionArg.NONE,
                    "Produce debug information", null,
                    (value) => { debug = value; }
                    ),
                new OptionEntry <bool>(
                    "valac-debug", 0, 0, OptionArg.NONE,
                    "Start the debugger", null,
                    (value) => { valac_debug = value; }
                    ),
                new OptionEntry <bool>(
                    "thread", 0, 0, OptionArg.NONE,
                    "Enable multithreading support (DEPRECATED AND IGNORED)", null,
                    (value) => { thread = value; }
                    ),
                new OptionEntry <bool>(
                    "enable-mem-profiler", 0, 0, OptionArg.NONE,
                    "Enable GLib memory profiler", null,
                    (value) => { mem_profiler = value; }
                    ),
                new OptionEntry <IList <string> >(
                    "define", 'D', 0, OptionArg.STRING_ARRAY,
                    "Define SYMBOL", "SYMBOL...",
                    (value) => { defines = value; }
                    ),
                new OptionEntry <string>(
                    "main", 0, 0, OptionArg.STRING,
                    "Use SYMBOL as entry point", "SYMBOL...",
                    (value) => { entry_point = value; }
                    ),
                new OptionEntry <bool>(
                    "nostdpkg", 0, 0, OptionArg.NONE,
                    "Do not include standard packages", null,
                    (value) => { nostdpkg = value; }
                    ),
                new OptionEntry <bool>(
                    "disable-assert", 0, 0, OptionArg.NONE,
                    "Disable assertions", null,
                    (value) => { disable_assert = value; }
                    ),
                new OptionEntry <bool>(
                    "enable-checking", 0, 0, OptionArg.NONE,
                    "Enable additional run-time checks", null,
                    (value) => { enable_checking = value; }
                    ),
                new OptionEntry <bool>(
                    "enable-deprecated", 0, 0, OptionArg.NONE,
                    "Enable deprecated features", null,
                    (value) => { deprecated = value; }
                    ),
                new OptionEntry <bool>(
                    "hide-internal", 0, 0, OptionArg.NONE,
                    "Hide symbols marked as internal", null,
                    (value) => { hide_internal = value; }
                    ),
                new OptionEntry <bool>(
                    "enable-experimental", 0, 0, OptionArg.NONE,
                    "Enable experimental features", null,
                    (value) => { experimental = value; }
                    ),
                new OptionEntry <bool>(
                    "disable-warnings", 0, 0, OptionArg.NONE,
                    "Disable warnings", null,
                    (value) => { disable_warnings = value; }
                    ),
                new OptionEntry <bool>(
                    "fatal-warnings", 0, 0, OptionArg.NONE,
                    "Treat warnings as fatal", null,
                    (value) => { fatal_warnings = value; }
                    ),
                new OptionEntry <bool>(
                    "disable-since-check", 0, 0, OptionArg.NONE,
                    "Do not check whether used symbols exist in local packages", null,
                    (value) => { disable_since_check = value; }
                    ),
                new OptionEntry <bool>(
                    "enable-experimental-non-null", 0, 0, OptionArg.NONE,
                    "Enable experimental enhancements for non-null types", null,
                    (value) => { experimental_non_null = value; }
                    ),
                new OptionEntry <bool>(
                    "enable-gobject-tracing", 0, 0, OptionArg.NONE,
                    "Enable GObject creation tracing", null,
                    (value) => { gobject_tracing = value; }
                    ),
                new OptionEntry <string>(
                    "cc", 0, 0, OptionArg.STRING,
                    "Use COMMAND as C compiler command", "COMMAND",
                    (value) => { cc_command = value; }
                    ),
                new OptionEntry <IList <string> >(
                    "Xcc", 'X', 0, OptionArg.STRING_ARRAY,
                    "Pass OPTION to the C compiler", "OPTION...",
                    (value) => { cc_options = value; }
                    ),
                new OptionEntry <string>(
                    "pkg-config", 0, 0, OptionArg.STRING,
                    "Use COMMAND as pkg-config command", "COMMAND",
                    (value) => { pkg_config_command = value; }
                    ),
                new OptionEntry <string>(
                    "dump-tree", 0, 0, OptionArg.FILENAME,
                    "Write code tree to FILE", "FILE",
                    (value) => { dump_tree = value; }
                    ),
                new OptionEntry <bool>(
                    "save-temps", 0, 0, OptionArg.NONE,
                    "Keep temporary files", null,
                    (value) => { save_temps = value; }
                    ),
                new OptionEntry <string>(
                    "profile", 0, 0, OptionArg.STRING,
                    "Use the given profile instead of the default", "PROFILE",
                    (value) => { profile = value; }
                    ),
                new OptionEntry <bool>(
                    "quiet", 'q', 0, OptionArg.NONE,
                    "Do not print messages to the console", null,
                    (value) => { quiet_mode = value; }
                    ),
                new OptionEntry <bool>(
                    "verbose", 'v', 0, OptionArg.NONE,
                    "Print additional messages to the console", null,
                    (value) => { verbose_mode = value; }
                    ),
                new OptionEntry <bool>(
                    "no-color", 0, 0, OptionArg.NONE,
                    "Disable colored output, alias for --color=never", null,
                    (value) => { disable_colored_output = value; }
                    ),
                new OptionEntry <OptionArgFunc>(
                    "color", 0, OptionFlags.OPTIONAL_ARG, OptionArg.CALLBACK,
                    "Enable color output, options are 'always', 'never', or 'auto'", "WHEN",
                    (value) => { }
                    )
                {
                    arg_data = new OptionArgFunc(option_parse_color)
                },
                new OptionEntry <string>(
                    "target-glib", 0, 0, OptionArg.STRING,
                    "Target version of glib for code generation", "MAJOR.MINOR",
                    (value) => { target_glib = value; }
                    ),
                new OptionEntry <IList <string> >(
                    "gresources", 0, 0, OptionArg.FILENAME_ARRAY,
                    "XML of gresources", "FILE...",
                    (value) => { gresources = value; }
                    ),
                new OptionEntry <IList <string> >(
                    "gresourcesdir", 0, 0, OptionArg.FILENAME_ARRAY,
                    "Look for resources in DIRECTORY", "DIRECTORY...",
                    (value) => { gresources_directories = value; }
                    ),
                new OptionEntry <bool>(
                    "enable-version-header", 0, 0, OptionArg.NONE,
                    "Write vala build version in generated files", null,
                    (value) => { enable_version_header = value; }
                    ),
                new OptionEntry <bool>(
                    "disable-version-header", 0, 0, OptionArg.NONE,
                    "Do not write vala build version in generated files", null,
                    (value) => { disable_version_header = value; }
                    ),
                new OptionEntry <IList <string> >(
                    "", 0, 0, OptionArg.FILENAME_ARRAY,
                    null, "FILE...",
                    (value) => { sources = value; }
                    )
            };

            var opt_context = new OptionContext("- Vala Interpreter");

            opt_context.help_enabled = true;
            opt_context.add_main_entries(options, null);
            opt_context.parse(args);
        }
Example #21
0
        public ShapeOptions(BinaryReader _reader, uint size, uint typeCode, uint version, uint instance)
            : base(_reader, size, typeCode, version, instance)
        {
            long pos = this.Reader.BaseStream.Position;

            //instance is the count of properties stored in this record
            this.Options = new OptionEntry[instance];

            //parse the flags and the simple values
            for (int i = 0; i < instance; i++)
            {
                var    entry = new OptionEntry();
                ushort flag  = this.Reader.ReadUInt16();
                entry.pid      = (PropertyId)Utils.BitmaskToInt(flag, 0x3FFF);
                entry.fBid     = Utils.BitmaskToBool(flag, 0x4000);
                entry.fComplex = Utils.BitmaskToBool(flag, 0x8000);
                entry.op       = this.Reader.ReadUInt32();

                this.Options[i] = entry;
            }

            //parse the complex values
            //these values are stored directly at the end
            //of the OptionEntry arry, sorted by pid
            long tempPos;

            for (int i = 0; i < instance; i++)
            {
                if (this.Options[i].fComplex)
                {
                    tempPos = this.Reader.BaseStream.Position;
                    if (this.Options[i].op > 0)
                    {
                        this.Options[i].opComplex = this.Reader.ReadBytes((int)this.Options[i].op);
                    }

                    if (this.Options[i].pid == PropertyId.pVertices)
                    {
                        ushort nElemsVert      = System.BitConverter.ToUInt16(this.Options[i].opComplex, 0);
                        ushort nElemsAllocVert = System.BitConverter.ToUInt16(this.Options[i].opComplex, 2);
                        ushort cbElemVert      = System.BitConverter.ToUInt16(this.Options[i].opComplex, 4);
                        if (cbElemVert == 0xfff0)
                        {
                            cbElemVert = 4;
                        }
                        if (nElemsVert * cbElemVert == this.Options[i].op)
                        {
                            this.Reader.BaseStream.Seek(tempPos, SeekOrigin.Begin);
                            this.Options[i].opComplex = this.Reader.ReadBytes((int)this.Options[i].op + 6);
                        }

                        //    this.Options[i].opComplex = this.Reader.ReadBytes((int)this.Options[i].op + 6);
                    }
                    //else
                    //{
                    //    this.Options[i].opComplex = this.Reader.ReadBytes((int)this.Options[i].op);
                    //}
                }

                if (this.OptionsByID.ContainsKey(this.Options[i].pid))
                {
                    this.OptionsByID[this.Options[i].pid] = this.Options[i];
                }
                else
                {
                    this.OptionsByID.Add(this.Options[i].pid, this.Options[i]);
                }
            }

            this.Reader.BaseStream.Seek(pos + size, SeekOrigin.Begin);
        }
        /// <summary>
        /// 追加
        /// </summary>
        public void Add(string type, string name, string value, string min = "", string max = "", List <string> var = null)
        {
            type = type.ToLowerInvariant();
            if (value == "<empty>")
            {
                value = "";
            }

            panel1.Height += RowHeight;

            OptionEntry entry = new OptionEntry()
            {
                Name = name
            };

            Label label = new Label();

            label.Text = name;
            panel1.Controls.Add(label);
            label.Location = new Point(0, panel1.Height - RowHeight + (RowHeight - label.Height) / 2);

            Control valueControl;

            switch (type)
            {
            case "check":     //
            {
                CheckBox checkBox = new CheckBox();
                checkBox.Text = name;
                bool @checked;
                if (bool.TryParse(name, out @checked))
                {
                    checkBox.Checked = @checked;
                }

                valueControl   = checkBox;
                entry.GetValue = () => checkBox.Checked ? "true" : "false";
            }
            break;

            case "spin":     //
            {
                NumericUpDown spin = new NumericUpDown();
                spin.ThousandsSeparator = true;
                {
                    long spinMin;
                    if (long.TryParse(min, out spinMin))
                    {
                        spin.Minimum = spinMin;
                    }
                    else
                    {
                        spin.Minimum = 0;
                    }
                }
                {
                    long spinMax;
                    if (long.TryParse(max, out spinMax))
                    {
                        spin.Maximum = Math.Max(spin.Minimum, spinMax);
                    }
                    else
                    {
                        spin.Maximum = long.MaxValue;
                    }
                }
                {
                    long spinValue;
                    if (long.TryParse(value, out spinValue))
                    {
                        spin.Value = spinValue;
                    }
                    else
                    {
                        spin.Value = spin.Minimum;
                    }
                }

                valueControl   = spin;
                entry.GetValue = () => ((long)spin.Value).ToString();
            }
            break;

            case "combo":     //
            {
                ComboBox comboBox = new ComboBox();
                comboBox.DropDownStyle = ComboBoxStyle.DropDownList;
                if (var != null)
                {
                    comboBox.Items.AddRange(var.ToArray());
                }
                comboBox.SelectedIndex = comboBox.Items.IndexOf(value);

                valueControl   = comboBox;
                entry.GetValue = () => (string)comboBox.SelectedItem;
            }
            break;

            case "button":                    // 未対応
                valueControl   = new Label(); // dummy
                entry.GetValue = null;
                break;

            case "string":
            case "filename":     //
            {
                TextBox textBox = new TextBox();
                textBox.Text = value;

                valueControl   = textBox;
                entry.GetValue = () => textBox.Text;
            }
            break;

            case "readonly":     // 勝手に拡張
            {
                TextBox textBox = new TextBox();
                textBox.Text     = value;
                textBox.ReadOnly = true;

                valueControl   = textBox;
                entry.GetValue = () => textBox.Text;
            }
            break;

            default:
                goto case "string";
            }

            int x = panel1.Width / 2;

            valueControl.Width = x;
            panel1.Controls.Add(valueControl);
            valueControl.Location = new Point(x, panel1.Height - RowHeight + (RowHeight - valueControl.Height) / 2);

            options.Add(entry);
        }
        private void DrawAvailableOptions()
        {
            using (new GUILayout.VerticalScope(GUILayout.MaxWidth(position.width / 2)))
            {
                using (new GUILayout.HorizontalScope(  ))
                {
                    GUILayout.Label("Available options:", _optionsLabel);
                    GUILayout.FlexibleSpace();

                    _searchMask = EditorGUILayout.TextField(_searchMask, GUILayout.Width(150));
                    if (GUILayout.Button("X", EditorStyles.miniButton, GUILayout.MaxWidth(16), GUILayout.MaxHeight(16)))
                    {
                        _searchMask = null;
                    }
                }

                if (_collectException == null)
                {
                    using (var scroll = new GUILayout.ScrollViewScope(_availableOptionsScrollPosition))
                    {
                        _availableOptionsScrollPosition = scroll.scrollPosition;
                        using (new GUILayout.VerticalScope())
                        {
                            var visibleOptions = string.IsNullOrEmpty(_searchMask) ? _optionsList : _optionsList.Where(o => o.Name.ToLowerInvariant().Contains(_searchMask.ToLowerInvariant()));

                            foreach (var option in visibleOptions)
                            {
                                using (new GUILayout.HorizontalScope())
                                {
                                    GUILayout.Label(new GUIContent($"-{option.Name}", $"{ string.Join(", ",option.Parameters.Select( pair => pair.ToString() )) }"));
                                    GUILayout.FlexibleSpace();
                                    if (GUILayout.Button(new GUIContent("+", $"Add -{name}"), EditorStyles.miniButton, GUILayout.MaxWidth(16), GUILayout.MaxHeight(16)))
                                    {
                                        var optionEntry = new OptionEntry()
                                        {
                                            Name = option.Name
                                        };

                                        foreach (var pair in option.Parameters)
                                        {
                                            optionEntry.Parameters.Add(new EntryParameter()
                                            {
                                                Name  = pair.Name,
                                                Value = pair.DefaultValue
                                            });
                                        }

                                        _selectedOptions.Add(optionEntry);
                                    }
                                }
                            }
                        }
                    }
                }
                else
                {
                    GUILayout.Label("Error while parsing options:");
                    GUILayout.Label(_collectException.ToString(), EditorStyles.wordWrappedLabel);
                }
            }
        }