예제 #1
0
        /// <summary>
        /// Converts a EditorMarkUpFlags value into a string representation of the values that are set.
        /// </summary>
        /// <param name="flags">Flags to convert into a string.</param>
        /// <returns>String representation of the flag values set.</returns>
        private static string MarkUpFlagsToString(EditorMarkUpFlags flags)
        {
            string flagsStr = string.Empty;

            // Get a list of the enum values and names.
            string[] enumNames  = Enum.GetNames(typeof(EditorMarkUpFlags));
            Array    enumValues = Enum.GetValues(typeof(EditorMarkUpFlags));

            // Loop through all of the options in the markup flags enum and check for each one.
            for (int i = 1; i < enumNames.Length; i++)
            {
                // Check if the flags specified contain the current flag value.
                if ((flags & (EditorMarkUpFlags)enumValues.GetValue(i)) != EditorMarkUpFlags.None)
                {
                    // Add the flag value to the string.
                    if (flagsStr == string.Empty)
                    {
                        flagsStr += string.Format("EditorMarkUpFlags.{0}", enumNames[i]);
                    }
                    else
                    {
                        flagsStr += string.Format(" | EditorMarkUpFlags.{0}", enumNames[i]);
                    }
                }
            }

            // Return the string representation of the flag values.
            return(flagsStr);
        }
예제 #2
0
 /// <summary>
 /// Initializes a new EditorMarkUpAttribute instance using the values provided.
 /// </summary>
 /// <param name="flags">Display flags for the field.</param>
 /// <param name="displayName">UI display name for the field.</param>
 /// <param name="unitsSpecifier">Units specifier for the field.</param>
 /// <param name="tooltipText">Tooltip text for the field.</param>
 public EditorMarkUpAttribute(EditorMarkUpFlags flags = EditorMarkUpFlags.None, string displayName = "", string unitsSpecifier = "", string tooltipText = "")
 {
     // Initialize fields.
     this.Flags          = flags;
     this.DisplayName    = displayName;
     this.UnitsSpecifier = unitsSpecifier;
     this.ToolTipText    = tooltipText;
 }
예제 #3
0
        /// <summary>
        /// Determines the editor markup flags that are present for in field name.
        /// </summary>
        /// <param name="fieldName">Field name to check.</param>
        /// <returns>The EditorMarkUpFlags value for the markup flags present in the field name.</returns>
        public static EditorMarkUpFlags MarkupFlagsFromFieldName(string fieldName)
        {
            EditorMarkUpFlags flags = EditorMarkUpFlags.None;

            // Check the field name for the read-only character.
            flags |= (fieldName.Contains(FieldNameReadOnlyCharacter) == true ? EditorMarkUpFlags.ReadOnly : EditorMarkUpFlags.None);

            // Check the field name for the advanced view character.
            flags |= (fieldName.Contains(FieldNameAdvancedCharacter) == true ? EditorMarkUpFlags.Advanced : EditorMarkUpFlags.None);

            // Check the field name for the block naming character.
            flags |= (fieldName.Contains(FieldNameBlockNameCharacter) == true ? EditorMarkUpFlags.BlockName : EditorMarkUpFlags.None);

            // Return the markup flags.
            return(flags);
        }
예제 #4
0
        /// <summary>
        /// Creates a EditorMarkupAttribute CodeDOM declaration.
        /// </summary>
        /// <param name="flags">Markup flags.</param>
        /// <param name="displayName">Editor display name.</param>
        /// <param name="unitsSpecifier">Units specifier.</param>
        /// <param name="tooltipText">Tooltip text.</param>
        /// <returns>A CodeDOM attribute declaration.</returns>
        public static CodeAttributeDeclaration CreateAttributeDeclaration(EditorMarkUpFlags flags = EditorMarkUpFlags.None, string displayName = "", string unitsSpecifier = "", string tooltipText = "")
        {
            // Create the attribute declaration and initialize it with no parameters.
            CodeAttributeDeclaration attribute = new CodeAttributeDeclaration(typeof(EditorMarkUpAttribute).Name);

            // Check if the display flags are set.
            if (flags != EditorMarkUpFlags.None)
            {
                // Add an argument for the display flags.
                attribute.Arguments.Add(new CodeAttributeArgument(new CodeSnippetExpression(string.Format("flags: {0}", MarkUpFlagsToString(flags)))));
            }

            // Check if the display name is present.
            if (displayName != string.Empty)
            {
                // Add an argument for the display name.
                attribute.Arguments.Add(new CodeAttributeArgument(new CodeSnippetExpression(string.Format("displayName: {0}", displayName))));
            }

            // Check if the units specifier is present.
            if (unitsSpecifier != string.Empty)
            {
                // Add an argument for the units specifier.
                attribute.Arguments.Add(new CodeAttributeArgument(new CodeSnippetExpression(string.Format("unitsSpecifier: {0}", unitsSpecifier))));
            }

            // Check if the tooltip text is present.
            if (tooltipText != string.Empty)
            {
                // Add an argument for the tooltip text.
                attribute.Arguments.Add(new CodeAttributeArgument(new CodeSnippetExpression(string.Format("tooltipText: {0}", tooltipText))));
            }

            // Return the new attribute declaration.
            return(attribute);
        }
예제 #5
0
        /// <summary>
        /// Creates a new code safe field name that is unique in the current scope and adds it to the fields list for this scope.
        /// </summary>
        /// <param name="fieldType">Type of field.</param>
        /// <param name="fieldName">Name of the field</param>
        /// <param name="displayName">The UI mark up display name for the field.</param>
        /// <param name="units">String to receive the units specifier is one is present</param>
        /// <param name="tooltip">String to receive the tooltip text if it is present</param>
        /// <param name="markupFlags">The UI markup flags for this field.</param>
        /// <returns>The new code safe field name for the field</returns>
        public string CreateCodeSafeFieldName(field_type fieldType, string fieldName, out string displayName, out string units, out string tooltip, out EditorMarkUpFlags markupFlags)
        {
            string newFieldName = "";

            // Satisfy the compiler.
            displayName = string.Empty;
            units       = string.Empty;
            tooltip     = string.Empty;
            markupFlags = EditorMarkUpFlags.None;

            // Check if the field is a padding field.
            if (fieldType == field_type._field_pad || fieldType == field_type._field_skip || fieldType == field_type._field_useless_pad)
            {
                // Create a new padding field name.
                return(AddPaddingField());
            }
            else if (fieldType == field_type._field_explanation)
            {
                // Create a new explanation field name.
                return(AddExplanationField());
            }

            // Check if the name is invalid.
            if (MutationCodeFormatter.IsValidFieldName(fieldName) == false)
            {
                // Create a new no-name field name.
                return(AddNoNameField());
            }

            // Convert the field name to a code safe representation.
            MutationCodeFormatter.ProcessFieldName(fieldName, out newFieldName, out displayName, out units, out tooltip, out markupFlags);
            if (newFieldName == "")
            {
                // Create a new no-name field name.
                return(AddNoNameField());
            }

            // Make sure the new field name is unique in the code scope.
            if (this.Fields.Contains(newFieldName) == true)
            {
                string tempFieldName = "";

                // Loop and append an integer until the field name becomes unique.
                int uniqueInt = 1;
                do
                {
                    // Append an integer to the field name to try and make it unique.
                    tempFieldName = String.Format("{0}{1}", newFieldName, uniqueInt++);
                }while (this.Fields.Contains(tempFieldName) == true);

                // Save the new field name.
                newFieldName = tempFieldName;
            }

            // Add the new field name to the fields list.
            this.Fields.Add(newFieldName);

            // Return the new field name.
            return(newFieldName);
        }
예제 #6
0
        /// <summary>
        /// Processes a Guerilla UI field name back into a code safe field name with UI markup.
        /// </summary>
        /// <param name="fieldText">The Guerilla field name to process.</param>
        /// <param name="fieldName">The code safe field name.</param>
        /// <param name="displayName">The UI mark up display name for the field.</param>
        /// <param name="units">The units associated with the field (UI markup data).</param>
        /// <param name="tooltip">The tooltip associated with the field (UI markup data).</param>
        /// <param name="markupFlags">The UI markup flags for this field.</param>
        public static void ProcessFieldName(string fieldText, out string fieldName, out string displayName, out string units, out string tooltip, out EditorMarkUpFlags markupFlags)
        {
            // Satisfy the compiler.
            fieldName   = string.Empty;
            displayName = string.Empty;
            units       = string.Empty;
            tooltip     = string.Empty;
            markupFlags = EditorMarkUpFlags.None;

            // Split the string using the markup delimiters.
            string[] pieces = fieldText.Split(new char[] { FieldNameUnitsCharacter, FieldNameToolTipCharacter });

            // Create our indcies for splicing.
            int lastIndex    = fieldText.Length;
            int unitsIndex   = fieldText.IndexOf(FieldNameUnitsCharacter);
            int toolTipIndex = fieldText.IndexOf(FieldNameToolTipCharacter);

            // Check if the tooltip string exists.
            if (toolTipIndex != -1)
            {
                // Determine which piece the tooltip string is.
                tooltip = CreateCodeSafeStringLiteral(toolTipIndex > unitsIndex ? pieces[pieces.Length - 1] : pieces[pieces.Length - 2]);

                // Set the last index so we can continue parsing.
                if (toolTipIndex < lastIndex)
                {
                    lastIndex = toolTipIndex;
                }
            }

            // Check if the units string exists.
            if (unitsIndex != -1)
            {
                // Determine which piece the units string is.
                units = CreateCodeSafeStringLiteral(unitsIndex > toolTipIndex ? pieces[pieces.Length - 1] : pieces[pieces.Length - 2]);

                // Set the last index so we can continue parsing.
                if (unitsIndex < lastIndex)
                {
                    lastIndex = unitsIndex;
                }
            }

            // Split out the field name and sanitize it.
            displayName = CreateCodeSafeStringLiteral(RemoveMarkupFromFieldName(pieces[0]));
            fieldName   = CreateCodeSafeFieldName(pieces[0]);

            // Determine the markup flags based on the display name.
            markupFlags = MarkupFlagsFromFieldName(pieces[0]);

            // If the name ends with a safe character just remove it.
            if (fieldName.EndsWith("_") == true)
            {
                fieldName = fieldName.Remove(fieldName.Length - 1);
            }
        }