protected NavigationPageCollection GetNonRemovedDescendants(NavigationPageCollection removedNodes) { if (removedNodes == null) { throw new ArgumentNullException("removedNodes"); } bool alwaysIncludeChildrenOfRemovedNodes = this.IncludeChildrenOfRemovedNodesMode.Equals(IncludeChildrenOfRemovedNodesMode.Always); var nonRemovedDescendants = new NavigationPageCollection(); foreach (var removedNode in removedNodes) { if (alwaysIncludeChildrenOfRemovedNodes || this.IsPageInSelectedPath(this.RootPage, removedNode, this.SelectedNavigationPage)) { foreach (var child in this.GetChildren(removedNode)) { if (alwaysIncludeChildrenOfRemovedNodes || this.IsPageInSelectedPath(this.RootPage, child, this.SelectedNavigationPage)) { nonRemovedDescendants.Add(child); } } var removedChildNodes = new NavigationPageCollection(); nonRemovedDescendants = this.FilterNavigation(nonRemovedDescendants, removedChildNodes); nonRemovedDescendants.AddRange(GetNonRemovedDescendants(removedChildNodes)); } } return(nonRemovedDescendants); }
protected virtual bool VisibleInNavigation(INavigationPage page) { if (page == null) { throw new ArgumentNullException("page"); } var pdc = new NavigationPageCollection(); pdc.Add(page); pdc = this.FilterNavigation(pdc, null); return(pdc.Count > 0); }
public override void DataBind() { this.hedHeadline.InnerSpan = this.HeadingInnerSpan; this.hedHeadline.Level = this.HeadingLevel; if (this.HeaderTemplate == null) { this.HeaderTemplate = new DefaultHeaderTemplate(this.RenderId ? this.ID : null, this.CssClass); } if (this.ItemTemplate == null) { this.ItemTemplate = new DefaultItemTemplate(); } if (this.FooterTemplate == null) { this.FooterTemplate = new DefaultFooterTemplate(); } if (this.PopulateNavigationItemDelegate == null) { this.PopulateNavigationItemDelegate = PopulateNavigationItem; } if (this.GetNavigationItemNameDelegate == null) { this.GetNavigationItemNameDelegate = GetNavigationItemName; } if (this.GetNavigationItemLinkDelegate == null) { this.GetNavigationItemLinkDelegate = GetNavigationItemLink; } if (this.GetNavigationItemDelegate == null) { this.GetNavigationItemDelegate = GetNavigationItem; } if (this.GetNavigationAnchorDelegate == null) { this.GetNavigationAnchorDelegate = GetNavigationAnchor; } if (this.CreateWebNavigationControlDelegate == null) { this.CreateWebNavigationControlDelegate = this.CreateWebNavigationControl; } this.OnDataBinding(EventArgs.Empty); if (this.StartLevelFromRoot < 0) { this.StartLevelFromRoot = this.ExpandAll ? 0 : 1; } if (this.SelectedNavigationPage == null) { this.SelectedNavigationPage = this.CurrentPage; } if (this.RootPage == null || this.RootPage.Id == null) { this.RootPage = this.SiteRoot; } if (!this.HeadingVisible && !this.HeadingAlwaysVisible) { hedHeadline.Visible = false; } if (this.NavPage == null) { this.NavPage = GetPageToExpand(this.RootPage, this.SelectedNavigationPage, this.StartLevelFromRoot); } if (this.NavPage == null && this.FallbackStartLevel >= 0) { this.NavPage = GetPageToExpand(this.RootPage, this.SelectedNavigationPage, this.FallbackStartLevel); } if (this.NavPage != null) { var npa = new WebNavigationPageArgs(this.NavPage); ancHeadline.Text = this.GetNavigationItemNameDelegate(npa); if (this.HeadingClickable) { ancHeadline.NavigateUrl = this.GetNavigationItemLinkDelegate(npa); } else { ancHeadline.NoLink = true; } NavigationPageCollection childNodes; if (this.IncludeRootLevelInList) { childNodes = new NavigationPageCollection(); childNodes.Add(this.NavPage); } else if (this.NavPage.Id.Equals(this.RootPage.Id) || this.IncludeChildrenOfRemovedNodesMode.Equals(IncludeChildrenOfRemovedNodesMode.Always) || this.FilterNavigation(new NavigationPageCollection(new[] { this.NavPage }), null).Count.Equals(1)) { childNodes = this.GetChildren(this.NavPage); } else { childNodes = new NavigationPageCollection(); if (this.IncludeChildrenOfRemovedNodesMode.Equals(IncludeChildrenOfRemovedNodesMode.OnlyInSelectedPath)) { foreach (var child in this.GetChildren(this.NavPage)) { if (this.IsPageInSelectedPath(this.RootPage, child, this.SelectedNavigationPage)) { childNodes.Add(child); } } } } var removedChildNodes = !this.IncludeRootLevelInList && this.IncludeChildrenOfRemovedNodesMode > IncludeChildrenOfRemovedNodesMode.Never ? new NavigationPageCollection() : null; childNodes = FilterNavigation(childNodes, removedChildNodes); if (!this.IncludeRootLevelInList && this.IncludeChildrenOfRemovedNodesMode > IncludeChildrenOfRemovedNodesMode.Never) { var nonRemovedDescendants = GetNonRemovedDescendants(removedChildNodes); if (this.IncludeChildrenOfRemovedNodesMode.Equals(IncludeChildrenOfRemovedNodesMode.OnlyInSelectedPath)) { foreach (var descendant in nonRemovedDescendants) { if (this.IsPageInSelectedPath(this.RootPage, descendant, this.SelectedNavigationPage)) { childNodes.Add(descendant); } } } else { childNodes.AddRange(nonRemovedDescendants); } } rptNavigation.DataSource = childNodes; rptNavigation.DataBind(); } if (this.visibleChildren == 0) { if (this.HeadingAlwaysVisible && ancHeadline.Text.Length > 0) { rptNavigation.Visible = false; } else { this.Visible = false; } } else { this.visibleLevels++; } OnDataBound(EventArgs.Empty); }
protected NavigationPageCollection GetSelectedPath(INavigationPage navigationRoot, INavigationPage currentPageReference, NavigationPageCollection pageDataCollection) { if (pageDataCollection == null) { throw new ArgumentNullException("pageDataCollection"); } var subPage = this.GetNavigationPage(currentPageReference); if (subPage != null) { var count = pageDataCollection.Count; pageDataCollection.Insert(0, subPage); if (count == 0) // Remove all non visible pages unitl if there already isn't a visible page in the path { pageDataCollection = this.FilterNavigation(pageDataCollection, null); } } var parent = subPage != null?this.GetNavigationPage(subPage.ParentId) : null; if (subPage == null || subPage.Id.Equals(navigationRoot.Id) || parent == null) { return(pageDataCollection); } return(this.GetSelectedPath(navigationRoot, parent, pageDataCollection)); }
protected abstract NavigationPageCollection FilterNavigation(NavigationPageCollection childNodes, NavigationPageCollection removedChildNodes);