Beispiel #1
0
 public void RemoveValue()
 {
     Assert.AreEqual(_element.Count, 0);
     _element["key1"] = new PListBoolean();
     _element["key2"] = new PListBoolean();
     Assert.AreEqual(_element.Count, 2);
     _element.Remove("key1");
     Assert.AreEqual(_element.Count, 1);
     Assert.IsTrue(_element.ContainsKey("key2"));
     Assert.IsFalse(_element.ContainsKey("key1"));
 }
Beispiel #2
0
        protected void UpdateDictionaryKey(PListDictionary dict, string oldKey, string newKey)
        {
            if (oldKey == newKey)
            {
                return;
            }

            if (string.IsNullOrEmpty(newKey))
            {
                return;
            }

            if (dict.ContainsKey(newKey))
            {
                return;
            }

            var element = dict[oldKey];

            dict.Remove(oldKey);
            dict.Add(newKey, element);
        }
Beispiel #3
0
        protected override void DrawDictionaryCommon(PListDictionary dic)
        {
            _indentLevel++;
            string        entryToRemove    = "";
            string        keyToUpdate      = "";
            string        newKeyValue      = "";
            string        valueToUpdateKey = "";
            IPListElement valueToUpdate    = null;
            Color         original         = GUI.color;

            foreach (var kvp in dic)
            {
                Style.IndentedHorizontalLine(Styling.ROW_COLOR, _indentLevel * INDENT_AMOUNT);
                EditorGUILayout.BeginHorizontal();
                GUILayout.Space(_indentLevel * INDENT_AMOUNT);
                bool open = DrawFoldout(kvp.Value);

                try
                {
                    //draw the key
                    EditorGUI.BeginChangeCheck();
                    string key = EditorGUILayout.TextField(kvp.Key, GUILayout.MinWidth(KEY_WIDTH), GUILayout.MaxWidth(KEY_WIDTH));

                    if (EditorGUI.EndChangeCheck())
                    {
                        keyToUpdate = kvp.Key;
                        newKeyValue = key;
                        IsDirty     = true;
                    }

                    //draw type selector
                    IPListElement value = TypeSelector(kvp.Value);

                    if (value != kvp.Value)
                    {
                        valueToUpdateKey = key;
                        valueToUpdate    = value;
                        IsDirty          = true;
                    }
                }
                catch
                {
                    Debug.LogError("EgoXproject: Failed to update key: " + kvp.Key);
                }

                //draw the value
                DrawElement(kvp.Value);

                if (RemoveElement(kvp.Key))
                {
                    entryToRemove = kvp.Key;
                    IsDirty       = true;
                }

                EditorGUILayout.EndHorizontal();

                if (!open)
                {
                    continue;
                }

                //if element is a dictionary or an array, draw its entries
                if (kvp.Value is PListDictionary)
                {
                    DrawDictionaryCommon(kvp.Value as PListDictionary);
                }
                else if (kvp.Value is PListArray)
                {
                    DrawArrayContent(kvp.Value as PListArray);
                }
            }

            GUI.color = original;

            //perform dictionary maintenance
            if (!string.IsNullOrEmpty(keyToUpdate))
            {
                UpdateDictionaryKey(dic, keyToUpdate, newKeyValue);
            }

            if (!string.IsNullOrEmpty(valueToUpdateKey))
            {
                RemoveFoldoutEntry(dic [valueToUpdateKey]);
                dic [valueToUpdateKey] = valueToUpdate;
            }

            if (!string.IsNullOrEmpty(entryToRemove))
            {
                RemoveFoldoutEntry(dic [entryToRemove]);
                dic.Remove(entryToRemove);
            }

            if (AddElement())
            {
                string newKeyName = "New Key";
                int    count      = 1;

                while (dic.ContainsKey(newKeyName))
                {
                    newKeyName = "New Key " + count;
                    count++;
                }

                dic.Add(newKeyName, new PListString());
                IsDirty = true;
            }

            _indentLevel--;
        }