Example #1
0
        public BookmarksTreeView(String aRoot)
        {
            mBuilder           = new BaseTreeBuilder(this, null);
            mBuilder.Root      = aRoot;
            mBuilder.DataStore = DataStoreRegistry.GetDataStore("Bookmarks");
            mBuilder.DataStore.AddObserver(mBuilder);

            // Use bright green as transparent colour
            mIconTransparentColor = ColorTranslator.FromOle(0x00FF00);

            ImageList = new ImageList();
            // Built in Bookmark icons
            ImageList.Images.Add(Image.FromFile(@"resources\bookmark-folder-closed.png"), mIconTransparentColor);
            ImageList.Images.Add(Image.FromFile(@"resources\bookmark-folder-open.png"), mIconTransparentColor);
            ImageList.Images.Add(Image.FromFile(@"resources\bookmark.png"), mIconTransparentColor);

            // Don't draw lines to root
            ShowRootLines = false;
            ShowPlusMinus = true;

            AfterLabelEdit += new NodeLabelEditEventHandler(OnAfterLabelEdit);
            AfterExpand    += new TreeViewEventHandler(OnAfterExpand);
            AfterCollapse  += new TreeViewEventHandler(OnAfterCollapse);
        }
        protected void Recurse(XmlTextReader reader, Menu root)
        {
            String inner = reader.ReadInnerXml();

            NameTable           nt      = new NameTable();
            XmlNamespaceManager nsmgr   = new XmlNamespaceManager(nt);
            XmlParserContext    ctxt    = new XmlParserContext(null, nsmgr, null, XmlSpace.None);
            XmlTextReader       reader2 = new XmlTextReader(inner, XmlNodeType.Element, ctxt);

            while (reader2.Read())
            {
                if (reader2.NodeType == XmlNodeType.Element)
                {
                    switch (reader2.LocalName)
                    {
                    case "menu":
                        // Menuitem. Find the name, accesskey, command and id strings
                        String[] values = new String[3] {
                            "", "", ""
                        };
                        String[] names = new String[3] {
                            "label", "accesskey", "command"
                        };
                        for (int i = 0; i < names.Length; ++i)
                        {
                            if (reader2.MoveToAttribute(names[i]) &&
                                reader2.ReadAttributeValue())
                            {
                                values[i] = reader2.Value; // XXX need to handle entities
                            }
                            reader2.MoveToElement();
                        }

                        // Handle Accesskey
                        values[0] = ManticoreMenuItem.GenerateAccessKeyString(values[0], values[1]);

                        // Create menu item and attach an event handler
                        // BLUESKY - should we support data stored in the XML file as an attribute?
                        mCurrentMenuItem = new ManticoreMenuItem(values[0],
                                                                 new EventHandler(OnCommandInternal),
                                                                 values[2], "");
                        if (values[2] != "")
                        {
                            mItems.Add(values[2], mCurrentMenuItem);
                        }
                        root.MenuItems.Add(mCurrentMenuItem);
                        Recurse(reader2, mCurrentMenuItem);
                        break;

                    case "menuseparator":
                        mCurrentMenuItem = new MenuItem("-");
                        root.MenuItems.Add(mCurrentMenuItem);
                        break;

                    case "menubuilder":
                        String id = "";
                        if (reader2.MoveToAttribute("id") &&
                            reader2.ReadAttributeValue())
                        {
                            id = reader2.Value;
                        }
                        reader2.MoveToElement();
                        String datastore = "";
                        if (reader2.MoveToAttribute("datastore") &&
                            reader2.ReadAttributeValue())
                        {
                            datastore = reader2.Value;
                        }

                        BaseMenuBuilder builder = new BaseMenuBuilder(mMainMenu, root as MenuItem, mCurrentMenuItem, null);
                        builder.Root      = id;
                        builder.DataStore = DataStoreRegistry.GetDataStore(datastore);
                        builder.DataStore.AddObserver(builder);
                        builder.OnCommand += new EventHandler(OnCommandInternal);
                        mBuilders.Add(builder.GetHashCode(), builder);
                        break;
                    }
                }
            }
        }