SIL.FieldWorks.Common.Framework.FwEditingHelper.AddHyperlink C# (CSharp) Method

AddHyperlink() public static method

Appends the given text as a hyperlink to the given URL.
public static AddHyperlink ( ITsStrBldr strBldr, int ws, string sLinkText, string sUrl, FwStyleSheet stylesheet ) : bool
strBldr ITsStrBldr The string builder.
ws int The HVO of the writing system to use for the added text.
sLinkText string The text which should appear as the hyperlink text
sUrl string The URL that is the target of the hyperlink.
stylesheet FwStyleSheet The stylesheet.
return bool
		public static bool AddHyperlink(ITsStrBldr strBldr, int ws, string sLinkText, string sUrl,
			FwStyleSheet stylesheet)
		{
			var hyperlinkStyle = stylesheet.FindStyle(StyleServices.Hyperlink);
			if (hyperlinkStyle == null)
				return false;

			if (stylesheet != null && stylesheet.Cache != null && stylesheet.Cache.ProjectId != null)
				sUrl = FwLinkArgs.FixSilfwUrlForCurrentProject(sUrl, stylesheet.Cache.ProjectId.Name,
					stylesheet.Cache.ProjectId.ServerName);
			int ichStart = strBldr.Length;
			strBldr.Replace(ichStart, ichStart, sLinkText, StyleUtils.CharStyleTextProps(null, ws));
			StringServices.MarkTextInBldrAsHyperlink(strBldr, ichStart, strBldr.Length,
				sUrl, hyperlinkStyle);
			return true;
		}
		#endregion

Usage Example

Beispiel #1
0
        public void AddHyperlink()
        {
            ITsStrBldr strBldr = TsStringUtils.MakeStrBldr();

            LcmStyleSheet mockStylesheet     = MockRepository.GenerateStub <LcmStyleSheet>();
            IStStyle      mockHyperlinkStyle = MockRepository.GenerateStub <IStStyle>();

            mockHyperlinkStyle.Name = StyleServices.Hyperlink;
            mockHyperlinkStyle.Stub(x => x.InUse).Return(true);
            mockStylesheet.Stub(x => x.FindStyle(StyleServices.Hyperlink)).Return(mockHyperlinkStyle);

            Assert.IsTrue(FwEditingHelper.AddHyperlink(strBldr, Cache.DefaultAnalWs, "Click Here",
                                                       "www.google.com", mockStylesheet));
            Assert.AreEqual(1, strBldr.RunCount);
            Assert.AreEqual("Click Here", strBldr.get_RunText(0));
            ITsTextProps props = strBldr.get_Properties(0);

            LcmTestHelper.VerifyHyperlinkPropsAreCorrect(props, Cache.DefaultAnalWs, "www.google.com");
        }