private void SetStuff() { CommandTarget tgt1 = new CommandTarget(mPrefix + "1", "1", "foopy1" as Object, false); mTargets.Add(tgt1.GetHashCode(), tgt1); CommandTarget tgt2 = new CommandTarget(mPrefix + "2", "2", "foopy2" as Object, false); mTargets.Add(tgt2.GetHashCode(), tgt2); CommandTarget tgt3 = new CommandTarget(mPrefix + "3", "3", "foopy3" as Object, false); mTargets.Add(tgt3.GetHashCode(), tgt3); CommandTarget tgt4 = new CommandTarget(mPrefix + "4", "4", "foopy4" as Object, false); mTargets.Add(tgt4.GetHashCode(), tgt4); }
public void RemoveOdd() { IEnumerator targets = mTargets.Values.GetEnumerator(); while (targets.MoveNext()) { IEnumerator observers = mObservers.Values.GetEnumerator(); while (observers.MoveNext()) { IDataStoreObserver idso = observers.Current as IDataStoreObserver; CommandTarget current = targets.Current as CommandTarget; if (Int32.Parse(current.AccessKey) % 2 != 0) { mTargets.Remove(current.Data.GetHashCode()); idso.OnNodeRemoved(targets.Current as CommandTarget); } } } }
public void SetBookmarkAttribute(String aBookmarkID, String aAttribute, String aValue) { XmlElement elt = GetElementById(aBookmarkID); CommandTarget oldTarget = new CommandTarget(); switch (aAttribute) { case "label": oldTarget.Label = elt.GetAttribute(aAttribute); break; case "icon": oldTarget.IconURL = elt.GetAttribute(aAttribute); break; case "container": oldTarget.IsContainer = elt.GetAttribute(aAttribute) == "true"; break; case "open": oldTarget.IsOpen = elt.GetAttribute(aAttribute) == "true"; break; } oldTarget.Data = aBookmarkID; elt.SetAttribute(aAttribute, aValue); // Enumerate the attributes presentation cares about and set the attribute on the // target if it is being changed. // XXX could optimize this. CommandTarget newTarget = new CommandTarget(); switch (aAttribute) { case "label": newTarget.Label = aValue; break; case "icon": newTarget.IconURL = aValue; break; case "container": newTarget.IsContainer = aValue == "true"; break; case "open": newTarget.IsOpen = aValue == "true"; break; } newTarget.Data = aBookmarkID; IEnumerator observers = mObservers.GetEnumerator(); while (observers.MoveNext()) { IDataStoreObserver idso = observers.Current as IDataStoreObserver; idso.OnNodeChanged(oldTarget, newTarget); } }
/////////////////////////////////////////////////////////////////////////// // IDataStore implementation public void GetElements(String aContainerID, out IEnumerator aElements) { XmlElement container = GetElementById(aContainerID); if (container == null) container = mBookmarksDocument.DocumentElement.FirstChild as XmlElement; int itemCount = container.ChildNodes.Count; Queue items = new Queue(); for (int i = 0; i < itemCount; ++i) { XmlElement currElt = container.ChildNodes[i] as XmlElement; // If the bookmark does not have an ID, generate one and set it. if (!currElt.HasAttribute("id") || currElt.GetAttribute("id") == "") currElt.SetAttribute("id", Bookmarks.GenerateID()); CommandTarget target = new CommandTarget(); target.Label = currElt.GetAttribute("label"); target.AccessKey = currElt.GetAttribute("accesskey"); target.Data = currElt.GetAttribute("id"); target.IsContainer = currElt.HasChildNodes; target.IconURL = currElt.GetAttribute("icon"); target.IsOpen = currElt.GetAttribute("open") == "true"; items.Enqueue(target); } aElements = items.GetEnumerator(); }
public String CreateBookmark(String aLabel, String aParentID, int aPosition) { XmlElement parentElt = GetElementById(aParentID); XmlElement childElt = mBookmarksDocument.CreateElement("item"); childElt.SetAttribute("label", aLabel); String bookmarkID = Bookmarks.GenerateID(); childElt.SetAttribute("id", bookmarkID); if (aPosition != -1) parentElt.InsertBefore(childElt, parentElt.ChildNodes[aPosition]); else parentElt.AppendChild(childElt); CommandTarget target = new CommandTarget(aLabel, "", bookmarkID, false); CommandTarget parentTarget = new CommandTarget("", "", aParentID, true); IEnumerator observers = mObservers.GetEnumerator(); while (observers.MoveNext()) { IDataStoreObserver idso = observers.Current as IDataStoreObserver; idso.OnNodeAdded(target, parentTarget, -1); } return bookmarkID; }
public void AddItems() { CommandTarget tgt5 = new CommandTarget(mPrefix + "5", "5", "foopy5" as Object, false); mTargets.Add(tgt5.GetHashCode(), tgt5); CommandTarget tgt6 = new CommandTarget(mPrefix + "6", "6", "foopy6" as Object, false); mTargets.Add(tgt6.GetHashCode(), tgt6); }
public virtual bool ShouldBuild(CommandTarget aTarget) { return true; }
/// <summary> /// Client overrides to provide special Icons for the particular treeview. /// </summary> /// <param name="aCommandTarget"></param> /// <returns></returns> public virtual int GetIconIndex(CommandTarget aCommandTarget) { return -1; }
public override bool ShouldBuild(CommandTarget aTarget) { Bookmarks bmks = ServiceManager.Bookmarks; if (mFilterAttributes != null) { IEnumerator criteria = mFilterAttributes.GetEnumerator(); while (criteria.MoveNext()) { String[] singleCriteria = criteria.Current as String[]; if (bmks.GetBookmarkAttribute(aTarget.Data as String, singleCriteria[0]) != singleCriteria[1]) return false; } } return true; }
public override int GetIconIndex(CommandTarget aTarget) { int index = 2; if (aTarget.IsContainer) { index = 0; if (aTarget.IsOpen) index = 1; } int fileIndex = GetIconIndex(aTarget.IconURL); if (fileIndex != -1) index = fileIndex; return index; }