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; } } } }
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; } } } }