public static void DrawArrayValues(InfoPlistKey plistKey) { plistKey.IsListOpen = EditorGUILayout.Foldout(plistKey.IsListOpen, "Array Values (" + plistKey.ChildrenIds.Count + ")"); if (plistKey.IsListOpen) { EditorGUI.indentLevel++; { foreach (var uniqueKey in plistKey.ChildrenIds) { var v = XCodeProjectSettings.Instance.GetVariableById(uniqueKey); DrawPlistVariable(v, uniqueKey, plistKey.ChildrenIds); if (!plistKey.ChildrenIds.Contains(uniqueKey)) { return; } } EditorGUILayout.BeginHorizontal(); EditorGUILayout.Space(); if (GUILayout.Button("Add Value", GUILayout.Width(100))) { var newVar = new InfoPlistKey(); plistKey.AddChild(newVar); } EditorGUILayout.EndHorizontal(); EditorGUILayout.Space(); } EditorGUI.indentLevel--; } }
//-------------------------------------- // Variables //-------------------------------------- /// <summary> /// Method for adding new variable into <c>VariableDictionary</c> list. /// </summary> /// <param name="uniqueIdKey"> Unique id key</param> /// <param name="var"> Info plist key value</param> public void AddVariableToDictionary(string uniqueIdKey, InfoPlistKey var) { var newVar = new PlistKeyId(); newVar.uniqueIdKey = uniqueIdKey; newVar.VariableValue = var; VariableDictionary.Add(newVar); }
//-------------------------------------- // Info.plist //-------------------------------------- /// <summary> /// Method will add or replace new <see cref="InfoPlistKey"/> to the Info.plist keys /// </summary> /// <param name="key">Info.plist key name</param> public static void SetInfoPlistKey(InfoPlistKey key) { var infoPlistKey = GetInfoPlistKey(key.Name); if (infoPlistKey != null) { XCodeProjectSettings.Instance.PlistVariables.Remove(infoPlistKey); } XCodeProjectSettings.Instance.PlistVariables.Add(key); }
public override void OnGUI() { IMGUILayout.Header("PLIST VALUES"); foreach (var plistKey in XCodeProjectSettings.Instance.PlistVariables) { EditorGUILayout.BeginVertical(GUI.skin.box); DrawPlistVariable(plistKey, plistKey, XCodeProjectSettings.Instance.PlistVariables); EditorGUILayout.EndVertical(); if (!XCodeProjectSettings.Instance.PlistVariables.Contains(plistKey)) { return; } } EditorGUILayout.Space(); EditorGUILayout.BeginVertical(GUI.skin.box); EditorGUILayout.BeginHorizontal(); EditorGUILayout.PrefixLabel("New Variable Name"); s_NewPlistValueName = EditorGUILayout.TextField(s_NewPlistValueName); EditorGUILayout.EndHorizontal(); EditorGUILayout.BeginHorizontal(); EditorGUILayout.Space(); if (GUILayout.Button("Add", GUILayout.Width(100))) { if (s_NewPlistValueName.Length > 0) { var v = new InfoPlistKey(); v.Name = s_NewPlistValueName; XCodeProject.SetInfoPlistKey(v); } s_NewPlistValueName = string.Empty; } EditorGUILayout.EndHorizontal(); EditorGUILayout.Space(); EditorGUILayout.EndVertical(); }
/// <summary> /// Adds child key /// </summary> /// <param name="childKey"></param> public void AddChild(InfoPlistKey childKey) { if (Type.Equals(InfoPlistKeyType.Dictionary)) { foreach (var childId in ChildrenIds) { var var = XCodeProjectSettings.Instance.GetVariableById(childId); if (var.Name.Equals(childKey.Name)) { XCodeProjectSettings.Instance.RemoveVariable(var, ChildrenIds); break; } } } var keyId = IdFactory.RandomString; XCodeProjectSettings.Instance.AddVariableToDictionary(keyId, childKey); ChildrenIds.Add(keyId); }
static PlistElementDict CreatePlistDict(InfoPlistKey variable, PlistElementDict dict = null) { if (dict == null) { dict = new PlistElementDict(); } foreach (var variableUniqueIdKey in variable.ChildrenIds) { var v = XCodeProjectSettings.Instance.GetVariableById(variableUniqueIdKey); switch (v.Type) { case InfoPlistKeyType.String: dict.SetString(v.Name, v.StringValue); break; case InfoPlistKeyType.Boolean: dict.SetBoolean(v.Name, v.BooleanValue); break; case InfoPlistKeyType.Integer: dict.SetInteger(v.Name, v.IntegerValue); break; case InfoPlistKeyType.Array: var array = dict.CreateArray(v.Name); CreatePlistArray(v, array); break; case InfoPlistKeyType.Dictionary: var d = dict.CreateDict(v.Name); CreatePlistDict(v, d); break; } } return(dict); }
/// <summary> /// Method that removes info plist key from <c>VariableDictionary</c> list. /// </summary> /// <param name="v"> Info plist key value.</param> /// <param name="listWithThisVariable"> </param> public void RemoveVariable(InfoPlistKey v, IList listWithThisVariable) { if (Instance.PlistVariables.Contains(v)) { Instance.PlistVariables.Remove(v); } else { foreach (var vid in VariableDictionary) { if (vid.VariableValue.Equals(v)) { VariableDictionary.Remove(vid); var id = vid.uniqueIdKey; if (listWithThisVariable.Contains(id)) { listWithThisVariable.Remove(vid.uniqueIdKey); } break; } } } //remove junk var keysInUse = new List <PlistKeyId>(VariableDictionary); foreach (var id in VariableDictionary) { var isInUse = IsInUse(id.uniqueIdKey, PlistVariables); if (!isInUse) { keysInUse.Remove(id); } } VariableDictionary = keysInUse; }
public static void DrawDictionaryValues(InfoPlistKey plistKey) { plistKey.IsListOpen = EditorGUILayout.Foldout(plistKey.IsListOpen, "Dictionary Values"); if (plistKey.IsListOpen) { EditorGUI.indentLevel++; { foreach (var uniqueKey in plistKey.ChildrenIds) { var v = XCodeProjectSettings.Instance.GetVariableById(uniqueKey); DrawPlistVariable(v, uniqueKey, plistKey.ChildrenIds); if (!plistKey.ChildrenIds.Contains(uniqueKey)) { return; } } EditorGUILayout.BeginHorizontal(); EditorGUILayout.PrefixLabel("New Key"); s_NewValueName = EditorGUILayout.TextField(s_NewValueName); if (GUILayout.Button("Add", GUILayout.Width(50))) { if (s_NewValueName.Length > 0) { var v = new InfoPlistKey(); v.Name = s_NewValueName; plistKey.AddChild(v); } } EditorGUILayout.EndHorizontal(); } EditorGUI.indentLevel--; } }
static void RegisterAppLanguages() { //We have nothing to register, no point to add en empty CFBundleLocalizations key. if (XCodeProjectSettings.Instance.Languages.Count == 0) { return; } var cfBundleLocalizations = new InfoPlistKey(); cfBundleLocalizations.Name = XCodeProjectSettings.CfLocalizationsPlistKey; cfBundleLocalizations.Type = InfoPlistKeyType.Array; foreach (var lang in XCodeProjectSettings.Instance.Languages) { var langItem = new InfoPlistKey(); langItem.Type = InfoPlistKeyType.String; langItem.StringValue = lang.Name; cfBundleLocalizations.AddChild(langItem); } XCodeProject.SetInfoPlistKey(cfBundleLocalizations); }
static PlistElementArray CreatePlistArray(InfoPlistKey variable, PlistElementArray array = null) { if (array == null) { array = new PlistElementArray(); } foreach (var variableUniqueIdKey in variable.ChildrenIds) { var v = XCodeProjectSettings.Instance.GetVariableById(variableUniqueIdKey); switch (v.Type) { case InfoPlistKeyType.String: array.AddString(v.StringValue); break; case InfoPlistKeyType.Boolean: array.AddBoolean(v.BooleanValue); break; case InfoPlistKeyType.Integer: array.AddInteger(v.IntegerValue); break; case InfoPlistKeyType.Array: CreatePlistArray(v, array.AddArray()); break; case InfoPlistKeyType.Dictionary: CreatePlistDict(v, array.AddDict()); break; } } return(array); }
/// <summary> /// Removes Info.plist key /// </summary> /// <param name="key">Info.plist key</param> public static void RemoveInfoPlistKey(InfoPlistKey key) { RemoveInfoPlistKey(key.Name); }
public static void DrawPlistVariable(InfoPlistKey plistKey, object valuePointer, IList valueOrigin) { EditorGUILayout.BeginHorizontal(); if (plistKey.Name.Length > 0) { plistKey.IsOpen = EditorGUILayout.Foldout(plistKey.IsOpen, plistKey.Name + " (" + plistKey.Type.ToString() + ")"); } else { plistKey.IsOpen = EditorGUILayout.Foldout(plistKey.IsOpen, plistKey.Type.ToString()); } var itemWasRemoved = SortingButtons(valuePointer, valueOrigin); if (itemWasRemoved) { XCodeProjectSettings.Instance.RemoveVariable(plistKey, valueOrigin); return; } EditorGUILayout.EndHorizontal(); if (plistKey.IsOpen) { EditorGUI.indentLevel++; { EditorGUILayout.BeginHorizontal(); EditorGUILayout.LabelField("Type"); if (plistKey.ChildrenIds.Count > 0) { GUI.enabled = false; plistKey.Type = (InfoPlistKeyType)EditorGUILayout.EnumPopup(plistKey.Type); } else { plistKey.Type = (InfoPlistKeyType)EditorGUILayout.EnumPopup(plistKey.Type); } EditorGUILayout.EndHorizontal(); if (plistKey.Type == InfoPlistKeyType.Array) { DrawArrayValues(plistKey); } else if (plistKey.Type == InfoPlistKeyType.Dictionary) { DrawDictionaryValues(plistKey); } else if (plistKey.Type == InfoPlistKeyType.Boolean) { plistKey.BooleanValue = IMGUILayout.ToggleFiled("Value", plistKey.BooleanValue, IMGUIToggleStyle.ToggleType.YesNo); } else { EditorGUILayout.BeginHorizontal(); EditorGUILayout.LabelField("Value"); switch (plistKey.Type) { case InfoPlistKeyType.Integer: plistKey.IntegerValue = EditorGUILayout.IntField(plistKey.IntegerValue); break; case InfoPlistKeyType.String: plistKey.StringValue = EditorGUILayout.TextField(plistKey.StringValue); break; } EditorGUILayout.EndHorizontal(); } } EditorGUI.indentLevel--; } }
public void RemoveChild(InfoPlistKey childKey) { XCodeProjectSettings.Instance.RemoveVariable(childKey, ChildrenIds); }