// helper that renders a menu item at the correct indentation level.

        void RecursiveRender(HtmlTextWriter output, MenuCompositeItem item, int depth)
        {
            if (depth > 0) // skip root node
            {
                if (depth == 1)
                {
                    output.Write("<li>");  // main menu
                }
                else
                {
                    output.Write(@"<li class=""indented"">");  // sub menu
                }
                output.Write(@"<a href=""" + item.Link + @""">");

                if (item.Item == SelectedItem)  // selected item
                {
                    output.Write(@"<span class=""selected"">" + item.Item + "</span>");
                }
                else
                {
                    output.Write(item.Item);  // unselected item.
                }
                output.Write("</a>");
            }

            // recursively iterate over its children

            for (int i = 0; i < item.Children.Count; i++)
            {
                RecursiveRender(output, item.Children[i], depth + 1);
            }
        }
Exemple #2
0
        // helper that renders a menu item at the correct indentation level.  
      
        void RecursiveRender(HtmlTextWriter output, MenuCompositeItem item, int depth)
        {
            if (depth > 0) // skip root node 
            {
                if (depth == 1)
                    output.Write("<li>");  // main menu
                else
                    output.Write(@"<li class=""indented"">");  // sub menu

                output.Write(@"<a href=""" + item.Link + @""">");

                if (item.Item == SelectedItem)  // selected item
                    output.Write(@"<span class=""selected"">" + item.Item + "</span>");
                else
                    output.Write(item.Item);  // unselected item.

                output.Write("</a>");
            }

            // recursively iterate over its children

            for (int i = 0; i < item.Children.Count; i++)
            {
                RecursiveRender(output, item.Children[i], depth + 1);
            }
        }
Exemple #3
0
        // establishes the composite menu hierarchy which is present on all pages.
        
        protected void Page_Load(object sender, EventArgs e)
        {
            if (!IsPostBack)
            {
                // build the composite menu tree
                // this tree implements the Composite Design Pattern

                var root = new MenuCompositeItem("root", null);
                var home = new MenuCompositeItem("home", UrlMaker.ToDefault());
                var shop = new MenuCompositeItem("shopping", UrlMaker.ToShopping());
                var prod = new MenuCompositeItem("products", UrlMaker.ToProducts());
                var srch = new MenuCompositeItem("search", UrlMaker.ToSearch());
                var admn = new MenuCompositeItem("administration", UrlMaker.ToAdmin());
                var cust = new MenuCompositeItem("members", UrlMaker.ToMembers());
                var ordr = new MenuCompositeItem("orders", UrlMaker.ToOrders());

                MenuCompositeItem auth;
                if (Request.IsAuthenticated)
                    auth = new MenuCompositeItem("logout", UrlMaker.ToLogout());
                else
                    auth = new MenuCompositeItem("login", UrlMaker.ToLogin());

                shop.Children.Add(prod);
                shop.Children.Add(srch);
                admn.Children.Add(cust);
                admn.Children.Add(ordr);
                root.Children.Add(home);
                root.Children.Add(shop);
                root.Children.Add(admn);
                root.Children.Add(auth);


                TheMenuComposite.MenuItems = root;
            }
        }