Пример #1
0
        /// <summary>
        /// Adds a field to the parent <see cref="ObjectFieldCollection"/>.
        /// </summary>
        /// <param name="field">The field to add.</param>
        private void AddNewEntry(ObjectField field)
        {
            object newValue = GetNewValue(field);

            ObjectFieldDictionary parentDictionary = field as ObjectFieldDictionary;

            if (parentDictionary != null)
            {
                // Find a new key value
                string key;
                for (int i = 1; ; ++i)
                {
                    key = "Key" + i;
                    if (!parentDictionary.Items.ContainsKey(key))
                    {
                        break;
                    }
                }

                ObjectField newField = ModelCreator.CreateObjectField("[" + key + "]", newValue, parentDictionary);
                newField.NameTag = key;
                parentDictionary.Add(newField);
                return;
            }

            ObjectFieldList parentList = field as ObjectFieldList;

            if (parentList != null)
            {
                ObjectField newField = ModelCreator.CreateObjectField("[" + (parentList.Items.Count + 1) + "]", newValue, parentList);
                parentList.Add(newField);
            }
        }
Пример #2
0
 /// <summary>
 /// Gets called when an item is dropped over the treeview.
 /// </summary>
 /// <param name="sender">The sender of the event.</param>
 /// <param name="e">More information about the event.</param>
 private void trvTree_DragDrop(object sender, DragEventArgs e)
 {
     if (e.Data.GetDataPresent(typeof(TreeNodeAdv[])) && trvTree.DropPosition.Node != null)
     {
         TreeNodeAdv[] nodes  = e.Data.GetData(typeof(TreeNodeAdv[])) as TreeNodeAdv[];
         TreeNodeAdv   parent = trvTree.DropPosition.Node;
         if (nodes != null && nodes.Length == 1 && parent != null)
         {
             ObjectField draggedField = nodes[0].Tag as ObjectField;
             ObjectField destField    = parent.Tag as ObjectField;
             if (draggedField != null && destField != null)
             {
                 bool ownNode = trvTree.FindNodeByTag(draggedField) != null;
                 if (ownNode)
                 {
                     ObjectFieldList parentList = destField.Parent as ObjectFieldList;
                     if (parentList != null)
                     {
                         int index = parentList.Items.IndexOf(destField);
                         index = trvTree.DropPosition.Position == NodePosition.After ? index + 1 : index;
                         bool expanded = nodes[0].IsExpanded;
                         parentList.Move(draggedField, index);
                         trvTree.FindNodeByTag(draggedField).IsExpanded = expanded;
                     }
                 }
                 else
                 {
                     ObjectFieldDictionary parentDestDict = destField.Parent as ObjectFieldDictionary;
                     ObjectFieldList       parentDestList = destField.Parent as ObjectFieldList;
                     ObjectField           clonedField    = draggedField.Clone() as ObjectField;
                     if (clonedField != null)
                     {
                         clonedField.Parent = destField.Parent;
                         //TODO: The cloned field still wraps the uncloned value. Cloning this is not easy since
                         //      we can't use Clone() on it since it could not be implemented.
                         if (parentDestDict != null)
                         {
                             parentDestDict.Add(clonedField);
                         }
                         else if (parentDestList != null)
                         {
                             int index = parentDestList.Items.IndexOf(destField);
                             index += trvTree.DropPosition.Position == NodePosition.After ? 1 : 0;
                             parentDestList.Insert(index, clonedField);
                         }
                     }
                 }
             }
         }
     }
 }