/// <summary> /// Use this function to add a new item into the 'AllItems' list. /// </summary> /// <param name="item"></param> public void AddItem(GlobalItem item) { if (item == null) { return; } //if (!(sideItem is PathEventItem) && !(sideItem is SideStartItem)) if (item.asMetadata) { if (routeItems.IndexOf(item) < 0) { routeItems.Add(item); } } if (AllItems.IndexOf(item) < 0) { AllItems.Add(item); } toSave = true; if (item.GetType() == typeof(StationItem)) { foreach (StationAreaItem SAItem in ((StationItem)item).stationArea) { AllItems.Add(SAItem); } } }
public int GetDropDownId() { if (Name == "") { return(0); } return(AllItems.IndexOf(AllItems.First(x => x.Text == Department.ToString()))); }
/// <summary> /// Replaces ALL the elements that match in KEY and VALUE for the new one /// </summary> public void Replace(CfgNodeValue <TK, TV> oldKeyVal, CfgNodeValue <TK, TV> newKeyVal) { lock (_lock) { var index = AllItems.IndexOf(oldKeyVal); if (index >= 0) { AllItems[index] = newKeyVal; if (SingleItems.ContainsKey(oldKeyVal.Key)) { if (oldKeyVal.Key.Equals(newKeyVal.Key)) { SingleItems[oldKeyVal.Key] = newKeyVal; } else { SingleItems.Remove(oldKeyVal.Key); SingleItems.Add(newKeyVal.Key, newKeyVal); } } else { if (RepeatedItems.ContainsKey(oldKeyVal.Key)) { if (oldKeyVal.Key.Equals(newKeyVal.Key)) { for (var i = 0; i < RepeatedItems[oldKeyVal.Key].Count; i++) { if (RepeatedItems[oldKeyVal.Key][i].Equals(oldKeyVal)) { RepeatedItems[oldKeyVal.Key][i] = newKeyVal; } } } else { Remove(oldKeyVal); Add(newKeyVal); } } } } } }
/// <summary> /// Adds (inserts before) a child KmlItem to this nodes lists of children. /// If item to insert before is null or not contained, it will be added at the end. /// This is the basic add method, derived classes can override but should /// always call base.Add(beforeItem, newItem) within. /// Public Add, AddRange, InsertBefore and InsertAfter all use this protected /// method to access the lists. /// <see cref="KML.KmlNode.Add(KML.KmlItem)"/> /// </summary> /// <param name="beforeItem">The KmlItem where the new item should be inserted before</param> /// <param name="newItem">The KmlItem to add</param> protected virtual void Add(KmlItem beforeItem, KmlItem newItem) { // ensure that item.Parent is this node if (newItem.Parent != this) { RemapParent(newItem, this); } // Not add always to end of AllItems, add well ordered: attribs first, then nodes. // Like Add(attrib), Add(Node), Add(attrib) should result in attrib, attrib, node if (newItem is KmlAttrib && !(beforeItem is KmlAttrib) && Children.Count > 0) { Syntax.Warning(newItem, "KML attribute should not come after nodes, will be fixed when saved"); beforeItem = Children[0]; } if (beforeItem != null && AllItems.Contains(beforeItem)) { AllItems.Insert(AllItems.IndexOf(beforeItem), newItem); } else { AllItems.Add(newItem); } if (newItem is KmlNode) { if (beforeItem is KmlNode && Children.Contains((KmlNode)beforeItem)) { Children.Insert(Children.IndexOf((KmlNode)beforeItem), (KmlNode)newItem); } else { Children.Add((KmlNode)newItem); } InvokeChildrenChanged(); } else if (newItem is KmlAttrib) { KmlAttrib attrib = (KmlAttrib)newItem; if (attrib.Name.ToLower() == "name") { if (Name.Length == 0) { Name = attrib.Value; // Get notified when Name changes attrib.AttribValueChanged += Name_Changed; attrib.CanBeDeleted = false; // And notify that the name changed InvokeToStringChanged(); } } if (beforeItem is KmlAttrib && Attribs.Contains((KmlAttrib)beforeItem)) { Attribs.Insert(Attribs.IndexOf((KmlAttrib)beforeItem), attrib); } else { Attribs.Add(attrib); } InvokeAttribChanged(); } else { if (beforeItem != null && Unknown.Contains(newItem)) { Unknown.Insert(Unknown.IndexOf(beforeItem), newItem); } else { Unknown.Add(newItem); } Syntax.Warning(this, "Unknown line in persistence file: " + newItem.ToString()); } }
/// <summary> /// Adds a child KmlItem to this nodes lists of children, depending of its /// derived class KmlNode, KmlPart, KmlAttrib or further derived from these. /// When an KmlAttrib "Name", "Type" or "Root" are found, their value /// will be used for the corresponding property of this node. /// </summary> /// <param name="beforeItem">The KmlItem where the new item should be inserted before</param> /// <param name="newItem">The KmlItem to add</param> protected override void Add(KmlItem beforeItem, KmlItem newItem) { if (newItem is KmlAttrib) { KmlAttrib attrib = (KmlAttrib)newItem; if (attrib.Name.ToLower() == "type" && Type.Length == 0) { Type = attrib.Value; // Get notified when Type changes attrib.AttribValueChanged += Type_Changed; attrib.CanBeDeleted = false; } else if (attrib.Name.ToLower() == "sit" && Situation.Length == 0) { Situation = attrib.Value; // Get notified when Type changes attrib.AttribValueChanged += Situation_Changed; attrib.CanBeDeleted = false; } else if (attrib.Name.ToLower() == "root" && RootPart == null) { SetRootPart(attrib.Value); // Get notified when Type changes attrib.AttribValueChanged += Root_Changed; attrib.CanBeDeleted = false; } } else if (newItem is KmlPart) { KmlPart part = (KmlPart)newItem; if (beforeItem != null) { KmlPart beforePart = null; int allIndex = AllItems.IndexOf(beforeItem); for (int i = allIndex; i < AllItems.Count; i++) { if (AllItems[i] is KmlPart && Parts.Contains((KmlPart)AllItems[i])) { beforePart = (KmlPart)AllItems[i]; break; } } if (beforePart != null) { beforePart.InsertionPreparation(); Parts.Insert(Parts.IndexOf(beforePart), part); beforePart.InsertionFinalization(); } else { Parts.Add(part); } } else { Parts.Add(part); } if (Parts.Count == rootPartIndex + 1) { RootPart = Parts[rootPartIndex]; } if (part.Flag != "" && !Flags.Any(x => x.ToLower() == part.Flag.ToLower())) { Flags.Add(part.Flag); } if (part.HasResources) { foreach (string resType in part.ResourceTypes) { ResourceTypes.Add(resType); } } KmlAttrib flag = part.GetAttrib("flag"); if (flag != null) { flag.AttribValueChanged += Flag_Changed; } } base.Add(beforeItem, newItem); }