Example #1
0
        public override void ConstructFromXml(XmlNode node, XmlDocument document)
        {
            base.ConstructFromXml(node, document);
            children.Clear();

            //One offs
            isSealed   = node.GetAttribute("sealed", "false").Equals("true", System.StringComparison.InvariantCultureIgnoreCase);
            isStatic   = node.GetAttribute("static", "false").Equals("true", System.StringComparison.InvariantCultureIgnoreCase);
            isPartial  = node.GetAttribute("partial", "false").Equals("true", System.StringComparison.InvariantCultureIgnoreCase);
            isAbstract = node.GetAttribute("abstract", "false").Equals("true", System.StringComparison.InvariantCultureIgnoreCase);
            @base      = node.GetAttribute("base");

            //Children
            foreach (XmlNode child in node.ChildNodes)
            {
                XmlBase xmlObj = XmlTemplate.CreateXmlObjectFromNode(child, document);

                if (xmlObj is XmlInterfaceContract)
                {
                    interfaces.Add(xmlObj as XmlInterfaceContract);
                }
                else if (xmlObj != null)
                {
                    children.Add(xmlObj);
                }
            }
        }
Example #2
0
 /// Saves any persistent settings for the provided template
 public void SavePersistentSettings(XmlTemplate template)
 {
     EditorPrefs.SetInt(GetPersistentSettingKey(PERSISTENT_SETTING_LINE_ENDINGS), (int)lineEndings);
     EditorPrefs.SetInt(GetPersistentSettingKey(PERSISTENT_SETTING_TAB_MODE), (int)tabMode);
     EditorPrefs.SetString(GetPersistentSettingKey(PERSISTENT_SETTING_BUILD_OPTIONS, template), buildOptions != null ? JsonUtility.ToJson(new BuildOptionCollection(buildOptions), false) : null);
     EditorPrefs.SetString(GetPersistentSettingKey(PERSISTENT_SETTING_OPTIONAL_USINGS, template), optionalUsings != null ? JsonUtility.ToJson(new OptionalUsingCollection(optionalUsings), false) : null);
 }
Example #3
0
        public static IEnumerable <BuildOption> ConstructBuildOptionsForTemplate(XmlTemplate template)
        {
            foreach (XmlBuildOption xmlBuildOption in template.buildOptions)
            {
                switch (xmlBuildOption.type.ToLower())
                {
                case "string":
                case "text":
                    yield return(new BuildOption(xmlBuildOption));

                    break;

                case "int":
                    yield return(new IntBuildOption(xmlBuildOption));

                    break;

                case "float":
                case "double":
                    yield return(new FloatBuildOption(xmlBuildOption));

                    break;

                case "bool":
                case "boolean":
                    yield return(new BoolBuildOption(xmlBuildOption));

                    break;
                }
            }
        }
Example #4
0
        /// Recovers any persistent settings from the provided template
        public void RestorePeristentSettingsForTemplate(XmlTemplate template)
        {
            //Build options
            string buildOptionsString = EditorPrefs.GetString(GetPersistentSettingKey(PERSISTENT_SETTING_BUILD_OPTIONS, template));

            if (!string.IsNullOrEmpty(buildOptionsString))
            {
                try
                {
                    BuildOptionCollection collection = JsonUtility.FromJson <BuildOptionCollection>(buildOptionsString);
                    MergeInPersistentBuildOptions(collection);
                }
                catch {}
            }

            //Optional Usings
            string optionalUsingsString = EditorPrefs.GetString(GetPersistentSettingKey(PERSISTENT_SETTING_OPTIONAL_USINGS, template));

            if (!string.IsNullOrEmpty(optionalUsingsString))
            {
                try
                {
                    OptionalUsingCollection collection = JsonUtility.FromJson <OptionalUsingCollection>(optionalUsingsString);
                    MergeInPersistentOptionalUsings(collection);
                }
                catch {}
            }
        }
Example #5
0
        /// Saves any persistent settings for the provided template
        public void SavePersistentSettings(XmlTemplate template)
        {
            EditorPrefs.SetInt(GetPersistentSettingKey(PERSISTENT_SETTING_LINE_ENDINGS), (int)lineEndings);
            EditorPrefs.SetInt(GetPersistentSettingKey(PERSISTENT_SETTING_TAB_MODE), (int)tabMode);
            EditorPrefs.SetInt(GetPersistentSettingKey(PERSISTENT_SETTING_OVERLAPPING_USING_NAMESPACES), includeOverlappingUsingNamespace ? 1 : 0);
            EditorPrefs.SetInt(GetPersistentSettingKey(PERSISTENT_SETTING_OPEN_FILE_ON_CREATE), openFileOnCreate ? 1 : 0);

            EditorPrefs.SetString(GetPersistentSettingKey(PERSISTENT_SETTING_BUILD_OPTIONS, template), buildOptions != null ? JsonUtility.ToJson(new BuildOptionCollection(buildOptions), false) : null);
            EditorPrefs.SetString(GetPersistentSettingKey(PERSISTENT_SETTING_OPTIONAL_USINGS, template), optionalUsings != null ? JsonUtility.ToJson(new OptionalUsingCollection(optionalUsings), false) : null);
        }
Example #6
0
        public TemplateSettings(XmlTemplate template) : this()
        {
            buildOptions   = new List <BuildOption>();
            optionalUsings = new List <OptionalUsing>();

            if (template != null)
            {
                buildOptions.AddRange(ConstructBuildOptionsForTemplate(template));
                optionalUsings.AddRange(ConstructOptionalUsingsForTemplate(template));
            }
        }
Example #7
0
        public static IEnumerable <XmlTemplate> FindAllTemplatesInProject()
        {
            const string TEMPLATE_EXTENSION = ".xtemplate";
            var          files = Directory.GetFiles(Application.dataPath + "/", "*" + TEMPLATE_EXTENSION, SearchOption.AllDirectories);

            foreach (string filePath in files)
            {
                if (Path.GetExtension(filePath) == TEMPLATE_EXTENSION)
                {
                    yield return(XmlTemplate.FromFile(filePath));
                }
            }
        }
Example #8
0
 public static IEnumerable <OptionalUsing> ConstructOptionalUsingsForTemplate(XmlTemplate template)
 {
     foreach (XmlUsingNamespace xmlUsing in template.usings)
     {
         if (xmlUsing.isOptional)
         {
             yield return(new OptionalUsing()
             {
                 id = xmlUsing.id,
                 isEnabled = xmlUsing.isOnByDefault,
                 isCustom = false,
             });
         }
     }
 }
Example #9
0
        /// Constructs the object from an Xml node and document
        public override void ConstructFromXml(XmlNode node, XmlDocument document)
        {
            base.ConstructFromXml(node, document);

            //Children
            foreach (XmlNode child in node.ChildNodes)
            {
                XmlBase xmlBase = XmlTemplate.CreateXmlObjectFromNode(child, document);

                if (xmlBase != null)
                {
                    children.Add(xmlBase);
                }
            }
        }
Example #10
0
        public static XmlTemplate FromFile(string path)
        {
            XmlTemplate result = null;

            if (File.Exists(path))
            {
                XmlDocument document = new XmlDocument();
                document.Load(path);

                XmlNode templateNode = document.GetFirstChild("template");
                result = new XmlTemplate();
                result.ConstructFromXml(templateNode, document);
            }

            return(result);
        }
Example #11
0
        public static string BuildCodeFromTemplate(XmlTemplate template, TemplateSettings settings)
        {
            //Create the code
            StringBuilder codeBuilder = new StringBuilder(_4KiB);

            template.ToCSharp(codeBuilder, 0, settings);

            //Transform the code
            string code = NormalizeLineEndings(codeBuilder.ToString(), settings.lineEndings);

            code = NormalizeTabs(codeBuilder.ToString(), settings.tabMode);
            code = settings.ApplyReplacementsToText(code);

            //Return the result
            return(code);
        }
        /// Constructs the object from an Xml node and document
        public override void ConstructFromXml(XmlNode node, XmlDocument document)
        {
            base.ConstructFromXml(node, document);
            buildOptionsToCheck = node.GetAttribute("options", string.Empty).Split(DELIMITERS, System.StringSplitOptions.RemoveEmptyEntries);
            isAND = node.GetAttribute("operator", "and").Equals("and", System.StringComparison.InvariantCultureIgnoreCase);

            //Children
            foreach (XmlNode child in node.ChildNodes)
            {
                XmlBase xmlBase = XmlTemplate.CreateXmlObjectFromNode(child, document);

                if (xmlBase != null)
                {
                    children.Add(xmlBase);
                }
            }
        }
Example #13
0
 protected virtual void BodyToCSharp(StringBuilder stringBuilder, int indentationLevel, TemplateSettings templateSettings)
 {
     if (children.Count == 1 && children[0] is XmlCodeblock && !(children[0] as XmlCodeblock).body.Contains("\n"))
     {
         stringBuilder.Append(" { ");
         XmlTemplate.ChildrenToCSharp(stringBuilder, 0, templateSettings, children);
         stringBuilder.Append(" }");
     }
     else
     {
         stringBuilder.Append("\n");
         stringBuilder.AppendIndentations(indentationLevel);
         stringBuilder.Append("{\n");
         XmlTemplate.ChildrenToCSharp(stringBuilder, indentationLevel + 1, templateSettings, children);
         stringBuilder.Append("\n");
         stringBuilder.AppendIndentations(indentationLevel);
         stringBuilder.Append("}");
     }
 }
        public void SelectTemplate(XmlTemplate template, bool wipeGlobalSettings = false, bool wipeTemplateSettings = false)
        {
            this.template         = template;
            this.codePreview      = null;
            this.templateSettings = new TemplateSettings(template);
            this.templateSettings.enableSyntaxHighlighting = true;
            lastSelectedTemplateID = template.id;

            if (!wipeGlobalSettings)
            {
                this.templateSettings.RestorePeristentSettings();
            }

            if (!wipeTemplateSettings)
            {
                this.templateSettings.RestorePeristentSettingsForTemplate(template);
            }

            EditorGUIUtility.editingTextField = false;
        }
        private void DrawTemplatePicker()
        {
            EditorGUILayout.BeginHorizontal();
            {
                EditorGUILayout.PrefixLabel("Template");

                if (EditorGUILayout.DropdownButton(new GUIContent(template != null ? template.id : "<select template>"), FocusType.Keyboard))
                {
                    int         lastPriority = int.MinValue;
                    GenericMenu menu         = new GenericMenu();

                    foreach (var template in templates)
                    {
                        XmlTemplate _template = template;

                        //Check if the template is malformed
                        if (_template.isMalformed)
                        {
                            menu.AddDisabledItem(new GUIContent(template.id));
                        }
                        else
                        {
                            //Add a separator
                            if (lastPriority != int.MinValue && _template.priority / 100 != lastPriority / 100)
                            {
                                string path = Path.GetDirectoryName(_template.id + ".t");

                                menu.AddSeparator(string.IsNullOrEmpty(path) ? string.Empty : path + "/");
                            }

                            menu.AddItem(new GUIContent(template.id), false, () => SelectTemplate(_template));
                            lastPriority = _template.priority;
                        }
                    }

                    menu.ShowAsContext();
                }
            }
            EditorGUILayout.EndHorizontal();
        }
        public bool SelectTemplate(string templateID)
        {
            bool didFind = false;

            if (templates != null)
            {
                //Iterate over each template and find the one with the matching ID
                for (int i = 0; i < templates.Count; ++i)
                {
                    XmlTemplate template = templates[i];

                    if (template.id.Equals(templateID, System.StringComparison.InvariantCultureIgnoreCase))
                    {
                        SelectTemplate(template);
                        didFind = true;
                        break;
                    }
                }
            }

            //Return the result
            return(didFind);
        }
Example #17
0
        /// Converts the XML object into C# and adds it to the string builder
        public override void ToCSharp(StringBuilder stringBuilder, int indentationLevel, TemplateSettings settings)
        {
            //Signature
            stringBuilder.AppendIndentations(indentationLevel);
            TemplateBuilder.BeginColorBlock(stringBuilder, settings, TemplateSettings.ACCESSIBILITY_KEYWORD_COLOR);
            stringBuilder.Append(accessibility);
            TemplateBuilder.EndColorBlock(stringBuilder, settings, TemplateSettings.ACCESSIBILITY_KEYWORD_COLOR);
            stringBuilder.AppendSpace();
            TemplateBuilder.BeginColorBlock(stringBuilder, settings, TemplateSettings.SYSTEM_KEYWORD_COLOR);
            stringBuilder.Append(kind);
            stringBuilder.AppendSpace();
            stringBuilder.AppendIf("static ", isStatic);
            stringBuilder.AppendIf("partial", isPartial);
            stringBuilder.AppendIf("abstract ", isAbstract);
            stringBuilder.AppendIf("sealed ", isSealed);
            TemplateBuilder.EndColorBlock(stringBuilder, settings, TemplateSettings.SYSTEM_KEYWORD_COLOR);

            TemplateBuilder.BeginColorBlock(stringBuilder, settings, TemplateSettings.TYPE_COLOR);
            stringBuilder.Append(id);
            TemplateBuilder.EndColorBlock(stringBuilder, settings, TemplateSettings.TYPE_COLOR);

            BuildBaseType(stringBuilder, settings);
            stringBuilder.Append("\n");

            //Body start
            stringBuilder.AppendIndentations(indentationLevel);
            stringBuilder.Append("{\n");

            //Body
            XmlTemplate.ChildrenToCSharp(stringBuilder, indentationLevel + 1, settings, children);

            //Body end
            stringBuilder.Append("\n");
            stringBuilder.AppendIndentations(indentationLevel);
            stringBuilder.Append("}");
        }
Example #18
0
 /// Converts the XML object into C# and adds it to the string builder
 public override void ToCSharp(StringBuilder stringBuilder, int indentationLevel, TemplateSettings templateSettings)
 {
     XmlTemplate.ChildrenToCSharp(stringBuilder, indentationLevel, templateSettings, children);
 }
Example #19
0
 public static string GetPersistentSettingKey(string settingID, XmlTemplate template)
 {
     return(string.Format("com.fright.templatebuilder.{0}.{1}.{2}", Application.productName, template.id, settingID));
 }