private void AddAttrib(KmlNode toItem, KmlAttrib beforeItem) { KmlNode node = toItem; string input; string preset = ""; bool loop = true; while (loop && DlgInput.Show("Enter the name for the new attribute:", "NEW attribute", Icons.Add, preset, out input)) { string attrib = input; if (attrib.Length > 0 && attrib.IndexOf('=') < 0) { attrib = attrib + "="; } KmlItem item = KmlItem.CreateItem(attrib); if (item is KmlAttrib && beforeItem != null) { node.InsertBefore(beforeItem, (KmlAttrib)item); loop = false; // View will be refreshed in AttribChanged event } else if (item is KmlAttrib) { node.Add((KmlAttrib)item); loop = false; // View will be refreshed in AttribChanged event } else { DlgMessage.Show("Attribute name is not allowed to be empty or contain following characters: {}", "NEW attribute", Icons.Warning); preset = input; // Input will pop up again while loop == true } } }
private void AddChildNode(KmlNode toItem, KmlNode beforeItem) { KmlNode node = toItem; string input; string preset = ""; bool loop = true; while (loop && DlgInput.Show("Enter the tag for the new node:", "NEW node", Icons.Add, preset, out input)) { KmlItem item = KmlItem.CreateItem(input); if (item is KmlNode && beforeItem != null) { node.InsertBefore(beforeItem, (KmlNode)item); loop = false; // View will be refreshed in ChildrenChanged event } else if (item is KmlNode) { node.Add((KmlNode)item); loop = false; // View will be refreshed in ChildrenChanged event } else { DlgMessage.Show("Tag is not allowed to be empty or contain following characters: ={}", "NEW node", Icons.Warning); preset = input; // Input will pop up again while loop == true } } }
/// <summary> /// Search all child nodes of this node for a certain tag and name, /// create one if not found. Does not search recursive. /// </summary> /// <param name="tag">The tag of the KmlNode to search for</param> /// <param name="name">The name of the KmlNode to search for</param> /// <returns>The found or created KmlNode</returns> public KmlNode GetOrCreateChildNode(string tag, string name) { KmlNode node = GetChildNode(tag, name); if (node == null) { node = KmlItem.CreateItem(tag) as KmlNode; if (name != null && name.Length > 0) { // Add name attribute node.Add(KmlItem.CreateItem("name=" + name)); } Add(node); } return(node); }
/// <summary> /// Search all KmlAttribs of this node, create one if not found. /// Does not search recursive. Default value will only be used on creation. /// </summary> /// <param name="name">The name of the KmlAttribs to search for</param> /// <param name="defaultValue">The default value for a created attribute</param> /// <returns>The found or created KmlAttrib</returns> public KmlAttrib GetOrCreateAttrib(string name, string defaultValue) { KmlAttrib attrib = GetAttrib(name); if (attrib == null) { string line = name + "="; if (defaultValue != null && defaultValue.Length > 0) { line += defaultValue; } attrib = KmlItem.CreateItem(line) as KmlAttrib; Add(attrib); } return(attrib); }
private void AttribInsertBefore_Click(object sender, RoutedEventArgs e) { // TODO GuiTreeAttrib.AttribInsertBefore_Click(): Almost same code as private GuiTreeNode.AddAttrib() KmlAttrib beforeItem = ((sender as MenuItem).DataContext as KmlAttrib); KmlNode node = beforeItem.Parent; if (node != null) { string input; string preset = ""; bool loop = true; while (loop && DlgInput.Show("Enter the name for the new attribute:", "NEW attribute", Icons.Add, preset, out input)) { string attrib = input; if (attrib.Length > 0 && attrib.IndexOf('=') < 0) { attrib = attrib + "="; } KmlItem item = KmlItem.CreateItem(attrib); if (item is KmlAttrib && beforeItem != null) { node.InsertBefore(beforeItem, (KmlAttrib)item); loop = false; // View will be refreshed in AttribChanged event } else if (item is KmlAttrib) { node.Add((KmlAttrib)item); loop = false; // View will be refreshed in AttribChanged event } else { DlgMessage.Show("Attribute name is not allowed to be empty or contain following characters: {}", "NEW attribute", Icons.Warning); preset = input; // Input will pop up again while loop == true } } } else { DlgMessage.Show("Can not insert, attribute has no parent", "NEW attribute", Icons.Warning); } }