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); }
protected virtual void RenderContents(WebTabStripRenderingContext renderingContext, IWebTab tab) { ArgumentUtility.CheckNotNull("renderingContext", renderingContext); renderingContext.Writer.AddAttribute(HtmlTextWriterAttribute.Class, CssClassTabAnchorBody); renderingContext.Writer.RenderBeginTag(HtmlTextWriterTag.Span); // Begin anchor body span bool hasIcon = tab.Icon != null && tab.Icon.HasRenderingInformation; bool hasText = !string.IsNullOrEmpty(tab.Text); if (hasIcon) { tab.Icon.Render(renderingContext.Writer, renderingContext.Control); } if (hasIcon && hasText) { renderingContext.Writer.Write(" "); } if (hasText) { var textWithHotkey = HotkeyParser.Parse(tab.Text); renderingContext.Writer.Write(_hotkeyFormatter.FormatText(textWithHotkey, false)); // Do not HTML encode } if (!hasIcon && !hasText) { renderingContext.Writer.Write(" "); } renderingContext.Writer.RenderEndTag(); // End anchor body span }
public void Parse_TextWithHotkeyMarkerBeforePunctuation_IgnoreHotkeyMarker() { var result = HotkeyParser.Parse("No &. Hotkey"); Assert.That(result.Text, Is.EqualTo("No &. Hotkey")); Assert.That(result.Hotkey, Is.Null); Assert.That(result.HotkeyIndex, Is.Null); }
public void Parse_TextWithHotkeyAtEnd() { var result = HotkeyParser.Parse("A Hotke&y"); Assert.That(result.Text, Is.EqualTo("A Hotkey")); Assert.That(result.Hotkey, Is.EqualTo('y')); Assert.That(result.HotkeyIndex, Is.EqualTo(7)); }
public void Parse_TextWithMultipleHotkeyMarkers_IgnoreHotkeyMarkers() { var result = HotkeyParser.Parse("&No &Hotkey"); Assert.That(result.Text, Is.EqualTo("&No &Hotkey")); Assert.That(result.Hotkey, Is.Null); Assert.That(result.HotkeyIndex, Is.Null); }
public void Parse_TextWithHotkey() { var result = HotkeyParser.Parse("A &Hotkey"); Assert.That(result.Text, Is.EqualTo("A Hotkey")); Assert.That(result.Hotkey, Is.EqualTo('H')); Assert.That(result.HotkeyIndex, Is.EqualTo(2)); }
public void Parse_TextIsNull() { var result = HotkeyParser.Parse(null); Assert.That(result.Text, Is.Empty); Assert.That(result.Hotkey, Is.Null); Assert.That(result.HotkeyIndex, Is.Null); }
public void Parse_TextWithoutHotkey() { var result = HotkeyParser.Parse("No Hotkey"); Assert.That(result.Text, Is.EqualTo("No Hotkey")); Assert.That(result.Hotkey, Is.Null); Assert.That(result.HotkeyIndex, Is.Null); }
public void Parse_TextWithHotkey_AndIgnoredHotkeyMarkers_AndEscapedHotkeyMarkers_IntegrationTest() { var result = HotkeyParser.Parse("&&Hotkey & &Integration &&Test&"); Assert.That(result.Text, Is.EqualTo("&Hotkey & Integration &Test&")); Assert.That(result.Hotkey, Is.EqualTo('I')); Assert.That(result.HotkeyIndex, Is.EqualTo(10)); }
public void Parse_TextWithMultipleHotkeyMarkers_AndEscapedHotkeyMarkers_IgnoreHotkeyMarker_IntegrationTest() { var result = HotkeyParser.Parse("&Hotkey &&Integration &Test"); Assert.That(result.Text, Is.EqualTo("&Hotkey &&Integration &Test")); Assert.That(result.Hotkey, Is.Null); Assert.That(result.HotkeyIndex, Is.Null); }
public void Parse_TextWithEscapedHotkeyMarker_AndFollowedByHotkey() { var result = HotkeyParser.Parse("A &&&Hotkey"); Assert.That(result.Text, Is.EqualTo("A &Hotkey")); Assert.That(result.Hotkey, Is.EqualTo('H')); Assert.That(result.HotkeyIndex, Is.EqualTo(3)); }
public void Parse_TextWithEscapedHotkeyMarker_IgnoreHotkeyMarker() { var result = HotkeyParser.Parse("No &&Hotkey"); Assert.That(result.Text, Is.EqualTo("No &Hotkey")); Assert.That(result.Hotkey, Is.Null); Assert.That(result.HotkeyIndex, Is.Null); }
public void Parse_TextWithHotkeyAtStart() { var result = HotkeyParser.Parse("&A Hotkey"); Assert.That(result.Text, Is.EqualTo("A Hotkey")); Assert.That(result.Hotkey, Is.EqualTo('A')); Assert.That(result.HotkeyIndex, Is.EqualTo(0)); }
public void Parse_TextWithHotkeyMarkerAsLastCharacter_IgnoreHotkeyMarker() { var result = HotkeyParser.Parse("No Hotkey&"); Assert.That(result.Text, Is.EqualTo("No Hotkey&")); Assert.That(result.Hotkey, Is.Null); Assert.That(result.HotkeyIndex, Is.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); }
protected override Command RenderBeginTagForCommand(WebTabStripRenderingContext renderingContext, IWebTab tab, bool isEnabled, WebTabStyle style) { ArgumentUtility.CheckNotNull("style", style); var menuTab = ((IMenuTab)tab).GetActiveTab(); var command = GetRenderingCommand(isEnabled, menuTab); var additionalUrlParameters = menuTab.GetUrlParameters(); var backupID = command.ItemID; var backupAccessKey = command.AccessKey; try { if (string.IsNullOrEmpty(command.ItemID) && !string.IsNullOrEmpty(tab.ItemID)) { command.ItemID = tab.ItemID + "_Command"; } if (string.IsNullOrEmpty(command.AccessKey)) { var textWithHotkey = HotkeyParser.Parse(tab.Text); if (textWithHotkey.Hotkey.HasValue) { command.AccessKey = HotkeyFormatter.FormatHotkey(textWithHotkey); } } command.RenderBegin( renderingContext.Writer, RenderingFeatures, tab.GetPostBackClientEvent(), new string[0], string.Empty, null, additionalUrlParameters, false, style); return(command); } finally { command.ItemID = backupID; command.AccessKey = backupAccessKey; } }
protected virtual Command RenderBeginTagForCommand(WebTabStripRenderingContext renderingContext, IWebTab tab, bool isEnabled, WebTabStyle style) { ArgumentUtility.CheckNotNull("renderingContext", renderingContext); ArgumentUtility.CheckNotNull("style", style); var command = new Command(); command.OwnerControl = renderingContext.Control; command.ItemID = tab.ItemID + "_Command"; if (isEnabled && tab.EvaluateEnabled()) { command.Type = CommandType.Event; var textWithHotkey = HotkeyParser.Parse(tab.Text); if (textWithHotkey.Hotkey.HasValue) { command.AccessKey = _hotkeyFormatter.FormatHotkey(textWithHotkey); } } else { command.Type = CommandType.None; } command.RenderBegin( renderingContext.Writer, RenderingFeatures, tab.GetPostBackClientEvent(), new string[0], string.Empty, null, new NameValueCollection(), false, style); return(command); }
protected override void Render(HtmlTextWriter writer) { _textWithHotkey = HotkeyParser.Parse(Text); base.Render(writer); }