Example #1
0
        ///////////////////////////////////////////////////////////////////////////
        // 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();
        }
Example #2
0
        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);
        }