Example #1
0
        protected void treeMenu1_TreeNodeExpanded(object sender, TreeNodeEventArgs e)
        {
            if (sender == null)
            {
                return;
            }
            if (e == null)
            {
                return;
            }

            TreeView treeView = sender as TreeView;

            CTreeView.ExpandToValuePath(treeView, e.Node.ValuePath);
        }
Example #2
0
        private void RenderTreeView()
        {
            Page.EnableViewState = true;
            //pageMenu.Visible = false;
            PageSettings currentPage = CacheHelper.GetCurrentPage();

            CTreeView treeMenu1;

            if (useArtisteer)
            {
                treeMenu1 = new ArtisteerTreeView();
            }
            else
            {
                treeMenu1 = new CTreeView();
            }
            this.menuPlaceHolder.Controls.Add(treeMenu1);

            treeMenu1.ShowExpandCollapse = treeViewShowExpandCollapse;

            if (treeViewShowExpandCollapse)
            {
                treeMenu1.EnableViewState   = true;
                treeMenu1.TreeNodeExpanded += new TreeNodeEventHandler(treeMenu1_TreeNodeExpanded);
            }
            else
            {
                treeMenu1.EnableViewState = false;
                //treeMenu1.EnableClientScript = true;
            }

            //treeMenu1.EnableClientScript = false;
            //treeMenu1.ShowExpandCollapse = treeViewShowExpandCollapse;
            treeMenu1.PopulateNodesFromClient = treeViewPopulateOnDemand;

            treeMenu1.ExpandDepth = treeViewExpandDepth;



            //treeMenu1.TreeNodePopulate += new TreeNodeEventHandler(treeMenu1_TreeNodePopulate);
            treeMenu1.TreeNodeDataBound += new TreeNodeEventHandler(treeMenu1_TreeNodeDataBound);

            treeMenu1.CollapseImageToolTip = Resource.TreeMenuCollapseTooltip;
            treeMenu1.ExpandImageToolTip   = Resource.TreeMenuExpandTooltip;


            //// older skins have this
            //StyleSheet stylesheet = (StyleSheet)Page.Master.FindControl("StyleSheet");
            //if (stylesheet != null)
            //{
            //    if (stylesheet.FindControl("treeviewcss") == null)
            //    {
            //        Literal cssLink = new Literal();
            //        cssLink.ID = "treeviewcss";
            //        cssLink.Text = "\n<link href='"
            //        + SiteUtils.GetSkinBaseUrl(Page)
            //        + "styletreeview.css' type='text/css' rel='stylesheet' media='screen' />";

            //        stylesheet.Controls.Add(cssLink);
            //        log.Debug("added stylesheet for treeiew");
            //    }
            //}


            //bool useFolderForSiteDetection
            //    = WebConfigSettings.UseFoldersInsteadOfHostnamesForMultipleSites;
            //string virtualFolder = VirtualFolderEvaluator.VirtualFolderName();

            if (isSubMenu)
            {
                if (
                    (currentPage != null) &&
                    (currentPage.ParentId == -1)
                    )
                {
                    if (
                        (currentPage.UseUrl) &&
                        (currentPage.Url.Length > 0)
                        )
                    {
                        pageMapDataSource.StartingNodeUrl = currentPage.Url;
                    }
                    else
                    {
                        String pageUrl = "~/Default.aspx?pageid=" + currentPage.PageId.ToString(CultureInfo.InvariantCulture);
                        pageMapDataSource.StartingNodeUrl = pageUrl;
                    }
                }
                else
                {
                    //pageMapDataSource.StartingNodeUrl
                    //    = SiteUtils.GetTopParentUrlForPageMenu(pageMapDataSource.Provider.RootNode);
                    pageMapDataSource.StartingNodeUrl = SiteUtils.GetStartUrlForPageMenu(pageMapDataSource.Provider.RootNode, startingNodeOffset);
                }
            }

            if (Page.IsPostBack)
            {
                // return if menu already bound
                if (treeMenu1.Nodes.Count > 0)
                {
                    return;
                }
            }


            if (startingNodeOffset > (currentPageDepth + 1))
            {
                this.Visible = false;
                return;
            }

            //if (startingNodeOffset > 0)
            //{
            //    pageMapDataSource.StartingNodeOffset = startingNodeOffset;
            //}

            //if (treeViewExpandDepth > 0)
            //{
            //    treeMenu1.ExpandDepth = treeViewExpandDepth;
            //}

            //treeViewPopulateOnDemand = false;
            //treeMenu1.PopulateNodesFromClient = treeViewPopulateOnDemand;

            treeMenu1.PathSeparator = '|';
            treeMenu1.DataSourceID  = pageMapDataSource.ID;
            try
            {
                treeMenu1.DataBind();
            }
            catch (ArgumentException ex)
            {
                log.Error(ex);
            }



            if (treeMenu1.SelectedNode != null)
            {
                CTreeView.ExpandToValuePath(treeMenu1, treeMenu1.SelectedNode.ValuePath);
            }
            else
            {
                //bool didSelect = false;

                String valuePath = SiteUtils.GetPageMenuActivePageValuePath(pageMapDataSource.Provider.RootNode);
                if (startingNodeOffset > 0)
                {
                    for (int i = 1; i <= startingNodeOffset; i++)
                    {
                        if (valuePath.IndexOf("|") > -1)
                        {
                            valuePath = valuePath.Remove(0, valuePath.IndexOf("|") + 1);
                        }
                    }
                }

                CTreeView.ExpandToValuePath(treeMenu1, valuePath);

                TreeNode nodeToSelect = treeMenu1.FindNode(valuePath);
                if (nodeToSelect == null)
                {
                    nodeToSelect = treeMenu1.FindNode(currentPage.PageName);
                }

                if (nodeToSelect != null)
                {
                    try
                    {
                        nodeToSelect.Selected = true;
                        //didSelect = true;
                    }
                    catch (InvalidOperationException)
                    {
                        //can happen if node disabled or unselectable
                    }
                }
            }

            if (treeMenu1.Nodes.Count == 0)
            {
                this.Visible = false;
            }
        }
Example #3
0
        private void RenderTreeView()
        {
            Page.EnableViewState = true;
            //menu1.Visible = false;

            CTreeView treeMenu1 = new CTreeView();

            this.menuPlaceHolder.Controls.Add(treeMenu1);

            treeMenu1.EnableViewState = true;
            //treeMenu1.EnableClientScript = true;
            treeMenu1.ShowExpandCollapse = treeViewShowExpandCollapse;
#if !MONO
            treeMenu1.PopulateNodesFromClient = treeviewPopulateNodesFromClient;
#endif
            treeMenu1.ExpandDepth = 0;


            //treeMenu1.TreeNodePopulate += new TreeNodeEventHandler(treeMenu1_TreeNodePopulate);
            treeMenu1.TreeNodeDataBound += new TreeNodeEventHandler(treeMenu1_TreeNodeDataBound);
            treeMenu1.TreeNodeExpanded  += new TreeNodeEventHandler(treeMenu1_TreeNodeExpanded);


            //older skins have this
            StyleSheet stylesheet = (StyleSheet)Page.Master.FindControl("StyleSheet");
            if (stylesheet != null)
            {
                if (stylesheet.FindControl("treeviewcss") == null)
                {
                    Literal cssLink = new Literal();
                    cssLink.ID   = "treeviewcss";
                    cssLink.Text = "\n<link href='"
                                   + SiteUtils.GetSkinBaseUrl(Page)
                                   + "styletreeview.css' type='text/css' rel='stylesheet' media='screen' />";

                    stylesheet.Controls.Add(cssLink);
                    log.Debug("added stylesheet for treeiew");
                }
            }

            if (treeViewExpandDepth > 0)
            {
                treeMenu1.ExpandDepth = treeViewExpandDepth;
                log.Debug("set ExpandDepth to " + treeViewExpandDepth.ToString(CultureInfo.InvariantCulture));
            }

#if !MONO
            treeMenu1.PopulateNodesFromClient = treeViewPopulateOnDemand;
#endif
            treeMenu1.CollapseImageToolTip = Resource.TreeMenuCollapseTooltip;
            treeMenu1.ExpandImageToolTip   = Resource.TreeMenuExpandTooltip;


            if (Page.IsPostBack)
            {
                // return if menu already bound
                if (treeMenu1.Nodes.Count > 0)
                {
                    return;
                }
            }
            treeMenu1.PathSeparator = '|';
            treeMenu1.DataSourceID  = this.siteMapDataSource.ID;
            try
            {
                treeMenu1.DataBind();
            }
            catch (ArgumentException ex)
            {
                log.Error(ex);
            }

            if (
                (treeMenu1.SelectedNode != null) &&
                (!suppressPageSelection)
                )
            {
                CTreeView.ExpandToValuePath(treeMenu1, treeMenu1.SelectedNode.ValuePath);
                log.Debug("called CTreeview.ExpandToValuePath for selectednode value path: " + treeMenu1.SelectedNode.ValuePath);
            }
            else
            {
                bool didSelect = false;

                if (!suppressPageSelection)
                {
                    String valuePath = SiteUtils.GetActivePageValuePath(siteMapDataSource.Provider.RootNode, startingNodeOffset, Request.RawUrl);
                    CTreeView.ExpandToValuePath(treeMenu1, valuePath);
                    log.Debug("called CTreeview.ExpandToValuePath for value path: " + valuePath);


                    TreeNode nodeToSelect = treeMenu1.FindNode(valuePath);
                    if (nodeToSelect != null)
                    {
                        try
                        {
                            nodeToSelect.Selected = true;
                            didSelect             = true;
                            log.Debug("selected node " + nodeToSelect.Text);
                        }
                        catch (InvalidOperationException)
                        {
                            //can happen if node disabled or unselectable
                        }
                    }

                    if (!didSelect)
                    {
                        valuePath = SiteUtils.GetActivePageValuePath(siteMapDataSource.Provider.RootNode, startingNodeOffset);
                        CTreeView.ExpandToValuePath(treeMenu1, valuePath);
                        log.Debug("called CTreeview.ExpandToValuePath for value path: " + valuePath);


                        nodeToSelect = treeMenu1.FindNode(valuePath);
                        if (nodeToSelect != null)
                        {
                            try
                            {
                                nodeToSelect.Selected = true;
                                didSelect             = true;
                                log.Debug("selected node " + nodeToSelect.Text);
                            }
                            catch (InvalidOperationException)
                            {
                                //can happen if node disabled or unselectable
                            }
                        }
                    }
                }
            }
        }