private void AssertAnchor(XmlNode link, IMenuTab tab) { var anchorBody = link.GetAssertedChildElement("span", 0); anchorBody.AssertAttributeValueEquals("class", _renderer.CssClassTabAnchorBody); var textWithHotkey = HotkeyParser.Parse(tab.Text); string text = textWithHotkey.Text ?? string.Empty; var hasIcon = tab.Icon != null && !string.IsNullOrEmpty(tab.Icon.Url); if (hasIcon) { string url = tab.Icon.Url.TrimStart('~'); string alt = tab.Icon.AlternateText ?? string.Empty; text = HtmlHelper.WhiteSpace + text; var image = anchorBody.GetAssertedChildElement("img", 0); image.AssertAttributeValueEquals("src", url); image.AssertAttributeValueEquals("alt", alt); } if (string.IsNullOrEmpty(text)) { text = HtmlHelper.WhiteSpace; } anchorBody.AssertTextNode(text, hasIcon ? 1 : 0); }
private void AssertTabs(XmlNode list, bool isDesignMode) { var tabs = _webTabStrip.GetVisibleTabs(); int itemCount = list.ChildNodes.Count; if (!isDesignMode) { Assert.That(itemCount, Is.EqualTo(tabs.Count)); } for (int i = 0; i < itemCount; i++) { IMenuTab tab = (IMenuTab)tabs[i]; bool isLastItem = (i == itemCount - 1); var item = list.GetAssertedChildElement("li", i); AssertItem(item, tab, isLastItem, isDesignMode); if (isLastItem) { var lastSpan = item.GetAssertedChildElement("span", 1); lastSpan.AssertAttributeValueEquals("class", "last"); } } }
/// <summary> Gets the parameters required for selecting the <paramref name="menuTab"/>. </summary> /// <param name="menuTab"> /// The <see cref="MenuTab"/> that should be selected by the when using the returned URL parameters. /// Must not be <see langword="null"/>. /// </param> /// <returns> /// A <see cref="NameValueCollection"/> that contains the URL parameters parameters required by this /// <see cref="TabbedMenu"/>. /// </returns> public virtual NameValueCollection GetUrlParameters(IMenuTab menuTab) { ArgumentUtility.CheckNotNull("menuTab", menuTab); MainMenuTab mainMenuTab = menuTab as MainMenuTab; SubMenuTab subMenuTab = menuTab as SubMenuTab; string[] tabIDs; if (mainMenuTab != null) { tabIDs = ConvertTabIDsToArray(mainMenuTab, null); } else if (subMenuTab != null) { tabIDs = ConvertTabIDsToArray(subMenuTab.Parent, subMenuTab); } else { throw new NotSupportedException(string.Format("menuTab is of unsupported type '{0}'.", menuTab.GetType().FullName)); } string value = (string)TypeConversionProvider.Convert(typeof(string[]), typeof(string), tabIDs); NameValueCollection urlParameters = new NameValueCollection(); urlParameters.Add(SelectionID, value); return(urlParameters); }
/// <summary> /// Checks list of tabs for tab matching given content. /// </summary> /// <param name="menuContent"></param> /// <returns>Returns matching tab. Returns null if no tab found.</returns> private IMenuTab GetTabForContent(IMenuContent menuContent) { int index = GetIndexOfTabForContent(menuContent); IMenuTab tab = GetTabAtIndex(index); return(tab); }
/// <summary> /// Updates tab draw order and views the given menu content. /// </summary> /// <param name="tab"></param> /// <param name="content"></param> /// <param name="fadeTime"></param> private void TabAndContentToShow(IMenuTab tab, IMenuContent content, float fadeTime) { if (tab == null || content == null) { return; } CanvasGroup previousCGroup = currentContent?.CGroup; IMenuContent previousContent = currentContent; currentContent = content; UpdateTabDrawOrder(); if (previousCGroup != null) { void finishAction() { previousCGroup.gameObject.SetActive(false); previousContent.OnClose(); } StartCoroutine(TimedAction(fadeTime, (float delta) => previousCGroup.alpha = 1f - delta, finishAction)); } CanvasGroup currentCGroup = currentContent.CGroup; currentCGroup.gameObject.SetActive(true); currentContent.OnOpen(); StartCoroutine(TimedAction(fadeTime, (float delta) => currentCGroup.alpha = delta, null)); }
private void AssertItem(XmlNode item, IMenuTab webTab, bool isLastItem, bool isDesignMode) { if (isDesignMode) { item.AssertStyleAttribute("float", "left"); item.AssertStyleAttribute("display", "block"); item.AssertStyleAttribute("white-space", "nowrap"); } item.AssertChildElementCount(isLastItem ? 2 : 1); var wrapper = item.GetAssertedChildElement("span", 0); wrapper.AssertAttributeValueEquals("class", _renderer.CssClassTabWrapper); var separator = wrapper.GetAssertedChildElement("span", 0); separator.AssertAttributeValueEquals("class", _renderer.CssClassSeparator); separator.AssertChildElementCount(1); var empty = separator.GetAssertedChildElement("span", 0); empty.AssertChildElementCount(0); var tab = wrapper.GetAssertedChildElement("span", 1); tab.AssertAttributeValueEquals("id", _webTabStrip.ClientID + "_" + webTab.ItemID); tab.AssertAttributeValueContains("class", webTab.IsSelected ? _renderer.CssClassTabSelected : _renderer.CssClassTab); if (!webTab.EvaluateEnabled()) { tab.AssertAttributeValueContains("class", _renderer.CssClassDisabled); } var link = tab.GetAssertedChildElement("a", 0); link.AssertAttributeValueEquals("id", _webTabStrip.ClientID + "_" + webTab.ItemID + "_Command"); bool isDisabledBySelection = webTab.IsSelected && !_webTabStrip.EnableSelectedTab; if (webTab.EvaluateEnabled()) { link.AssertAttributeValueEquals("href", "#"); } if (webTab.EvaluateEnabled() && !isDisabledBySelection) { string clickScript = _pageStub.ClientScript.GetPostBackClientHyperlink(_webTabStrip, webTab.ItemID); link.AssertAttributeValueEquals("onclick", clickScript); } var textWithHotkey = HotkeyParser.Parse(webTab.Text); if (webTab.EvaluateEnabled() && textWithHotkey.Hotkey.HasValue) { var accessKey = new NoneHotkeyFormatter().FormatHotkey(textWithHotkey); link.AssertAttributeValueEquals("accesskey", accessKey); } AssertAnchor(link, webTab); }
/// <summary> /// Checks list of menu contents for matching tab. /// </summary> /// <param name="tab"></param> /// <returns>Returns matching menu content. Returns null if no match found.</returns> private IMenuContent GetContentMatchingTab(IMenuTab tab) { int index = GetIndexOfContentMatchingTab(tab); if (index < 0 || index >= menuContents.Count) { return(null); } return(menuContents[index]); }
private Command GetRenderingCommand(bool isEnabled, IMenuTab activeTab) { if (isEnabled && activeTab.EvaluateEnabled()) { return(activeTab.Command); } return(new Command(CommandType.None) { OwnerControl = activeTab.OwnerControl }); }
/// <summary> /// Checks list of menu contents for matching tab. /// </summary> /// <param name="tab"></param> /// <returns>Returns index of matching menu content. Returns -1 if no match found.</returns> private int GetIndexOfContentMatchingTab(IMenuTab tab) { if (tab == null) { return(-1); } for (int i = 0; i < menuContents.Count; i++) { if (menuContents[i].TabName == tab.TabText) { return(i); } } return(-1); }
private void PopulateTabStrip() { _tab0 = MockRepository.GenerateStub <IMenuTab>(); _tab0.Stub(stub => stub.ItemID).Return("Tab0"); _tab0.Stub(stub => stub.Text).Return("&First Tab"); _tab0.Stub(stub => stub.Icon).Return(new IconInfo()); _tab0.Stub(stub => stub.EvaluateEnabled()).Return(true); _tab0.Stub(stub => stub.GetPostBackClientEvent()).Return(_pageStub.ClientScript.GetPostBackClientHyperlink(_webTabStrip, _tab0.ItemID)); _tab0.Stub(stub => stub.GetActiveTab()).Return(_tab0); _tab0.Stub(stub => stub.Command).Return(new NavigationCommand(CommandType.Event)); _tab0.Stub(stub => stub.GetRenderer()).IgnoreArguments().Return(CreateWebTabRenderer()); _tab1 = MockRepository.GenerateStub <IMenuTab>(); _tab1.Stub(stub => stub.ItemID).Return("Tab1"); _tab1.Stub(stub => stub.Text).Return("Second Tab"); _tab1.Stub(stub => stub.Icon).Return(new IconInfo("/myImageUrl")); _tab1.Stub(stub => stub.EvaluateEnabled()).Return(true); _tab1.Stub(stub => stub.GetPostBackClientEvent()).Return(_pageStub.ClientScript.GetPostBackClientHyperlink(_webTabStrip, _tab1.ItemID)); _tab1.Stub(stub => stub.GetActiveTab()).Return(_tab1); _tab1.Stub(stub => stub.Command).Return(new NavigationCommand(CommandType.Event)); _tab1.Stub(stub => stub.GetRenderer()).IgnoreArguments().Return(CreateWebTabRenderer()); _tab2 = MockRepository.GenerateStub <IMenuTab>(); _tab2.Stub(stub => stub.ItemID).Return("Tab2"); _tab2.Stub(stub => stub.Text).Return("Third Tab"); _tab2.Stub(stub => stub.Icon).Return(null); _tab2.Stub(stub => stub.EvaluateEnabled()).Return(true); _tab2.Stub(stub => stub.GetPostBackClientEvent()).Return(_pageStub.ClientScript.GetPostBackClientHyperlink(_webTabStrip, _tab2.ItemID)); _tab2.Stub(stub => stub.GetActiveTab()).Return(_tab2); _tab2.Stub(stub => stub.Command).Return(new NavigationCommand(CommandType.Event)); _tab2.Stub(stub => stub.GetRenderer()).IgnoreArguments().Return(CreateWebTabRenderer()); _tab3 = MockRepository.GenerateStub <IMenuTab>(); _tab3.Stub(stub => stub.ItemID).Return("Tab3"); _tab3.Stub(stub => stub.Text).Return(null); _tab3.Stub(stub => stub.Icon).Return(null); _tab3.Stub(stub => stub.EvaluateEnabled()).Return(true); _tab3.Stub(stub => stub.GetPostBackClientEvent()).Return(_pageStub.ClientScript.GetPostBackClientHyperlink(_webTabStrip, _tab3.ItemID)); _tab3.Stub(stub => stub.GetActiveTab()).Return(_tab3); _tab3.Stub(stub => stub.Command).Return(new NavigationCommand(CommandType.Event)); _tab3.Stub(stub => stub.GetRenderer()).IgnoreArguments().Return(CreateWebTabRenderer()); _webTabStrip.GetVisibleTabs().Add(_tab0); _webTabStrip.GetVisibleTabs().Add(_tab1); _webTabStrip.GetVisibleTabs().Add(_tab2); _webTabStrip.GetVisibleTabs().Add(_tab3); }
/// <summary> /// Create tabs for all menu contents. /// </summary> private void CreateTabs() { tabs.Clear(); IMenuTab prefab = tabPrefab as IMenuTab; if (prefab == null) { Debug.Log($"Tab prefab is not of type: {typeof(IMenuTab)}", tabPrefab); return; } for (int i = 0; i < menuContents.Count; i++) { IMenuTab newTab = prefab.CreateCopy(tabsHolder); newTab.TabText = menuContents[i].TabName; tabs.Add(newTab); } }
/// <summary> /// Checks list of tabs looking for a match with given content. /// </summary> /// <param name="menuContent"></param> /// <returns>Returns true if matching tab is found.</returns> private bool TabExistsForContent(IMenuContent menuContent) { IMenuTab tab = GetTabForContent(menuContent); return(tab != null); }
/// <summary> /// Updates tab draw order and views the given menu content. /// </summary> /// <param name="content"></param> /// <param name="fadeTime"></param> private void ContentToShow(IMenuContent content, float fadeTime) { IMenuTab tab = GetTabForContent(content); TabAndContentToShow(tab, content, fadeTime); }
/// <summary> /// Updates tab draw order and views the appropriate menu content associated with the given tab. /// </summary> /// <param name="tab"></param> /// <param name="fadeTime"></param> private void TabToShow(IMenuTab tab, float fadeTime) { IMenuContent content = GetContentMatchingTab(tab); TabAndContentToShow(tab, content, fadeTime); }
private void TabClicked(IMenuTab tab) { TabToShow(tab, tabFadeDuration); }